示例#1
0
        /// <summary>
        /// Checks the given channel if it's already autocleared.
        ///     if true, then remove the channel from auto-clear
        ///     if false, then add the channel to auto-clear
        ///     if the guild does not exist, make the guild and put the channel to auto-clear
        /// </summary>
        /// <param name="channel">The text channel to be toggled.</param>
        /// <returns></returns>
        private async Task ToggleChannel(SocketTextChannel channel)
        {
            ulong channelID = channel.Id;

            if (guildManager.guilds.TryGetValue(guild.Id, out KappaGuild kGuild))
            {
                if (kGuild.clearedChannels.Contains(channelID)) // Channel is removed if it is already being cleared
                {
                    kGuild.clearedChannels.Remove(channelID);
                    await ReplyAsync(string.Format(ResponseManager.GetLine("ClearedChannelsRemoved"), guildName, channel.Mention));
                }
                else
                {
                    kGuild.clearedChannels.Add(channelID);
                    await ReplyAsync(string.Format(ResponseManager.GetLine("ClearedChannelsAdded"), guildName, channel.Mention));
                }
            }
            else
            {
                // When the guild doesn't exist in guilds.json
                kGuild = new KappaGuild(new ulong[] { channelID });
                guildManager.guilds.Add(guild.Id, kGuild);
                await ReplyAsync(string.Format(ResponseManager.GetLine("ClearedChannelsAdded"), guildName, channel.Mention));
            }
            await guildManager.ReplaceGuildsJson();
        }
示例#2
0
 /// <summary>
 /// Loads or reloads the guilds.json.
 /// </summary>
 /// <param name="path">The path to the guilds.json file</param>
 public void ReadGuilds(JObject jsonFile)
 {
     foreach (JProperty guildData in jsonFile.Properties())
     {
         KappaGuild guild = guildData.Value.ToObject <KappaGuild>();
         guilds.Add(ulong.Parse(guildData.Name), guild);
     }
 }