Example #1
0
        /// <summary>
        /// Checks all server settings, auto vc channels, active vc channels and the welcome message
        /// </summary>
        /// <returns></returns>
        public async Task CheckConnectedServerSettings()
        {
            Logger.Log("Checking pre-connected server settings...");

            //To avoid saving possibly 100 times we will only save once if something has changed
            bool somethingChanged = false;

            List <ServerList> serversToRemove = new List <ServerList>();

            ServerList[] servers = ServerListsManager.GetServers();
            foreach (ServerList server in servers)
            {
                //The bot is not longer in this guild, remove it from the server settings
                if (_client.GetGuild(server.GuildId) == null)
                {
                    somethingChanged = true;
                    serversToRemove.Add(server);
                    continue;
                }

                await CheckServerWelcomeSettings(server);
                await CheckServerRuleMessageChannel(server);

                CheckServerVoiceChannels(server);
                CheckServerActiveVoiceChannels(server);
                CheckServerPerms(server);

                //Start up all votes
                foreach (Vote serverVote in server.Votes)
                {
#pragma warning disable 4014
                    Task.Run(() => VotingService.RunVote(serverVote, _client.GetGuild(server.GuildId)));
#pragma warning restore 4014
                }
            }

            //Like all the other ones, we remove all the unnecessary servers after to avoid System.InvalidOperationException
            foreach (ServerList toRemove in serversToRemove)
            {
                Logger.Log($"The bot is not longer in the {toRemove.GuildId}, Removing server settings...");
                ServerListsManager.RemoveServer(toRemove);
            }

            //If a server was updated then save the ServerList.json file
            if (somethingChanged)
            {
                ServerListsManager.SaveServerList();
            }

            Logger.Log("Checked all server settings.");
        }