示例#1
0
        public async Task AddEmoteLimitAsync(
            [Summary("The channel to display the limits for")] ITextChannel channel,
            [Summary("The emote to allow"), OverrideTypeReader(typeof(EmoteTypeReader))] IEmote emote)
        {
            if (channel == null)
            {
                throw new ArgumentException("Given Channel does not exist");
            }

            if (emote == null)
            {
                throw new ArgumentException("Given Emote does not exist");
            }

            Dictionary <ulong, List <string> > limits = Data.Configuration.EmoteRestrictions;

            if (limits == null)
            {
                limits = new Dictionary <ulong, List <string> >();
            }

            List <string> newLimits = limits.GetValueOrDefault(channel.Id, new List <string>());

            if (newLimits.Contains(emote.StringVal()))
            {
                throw new ArgumentException($"Emote {emote.Emotify()} is aleady permitted");
            }

            newLimits.Add(emote.StringVal());

            Console.WriteLine(newLimits);

            if (limits.ContainsKey(channel.Id))
            {
                limits.Remove(channel.Id);
            }

            limits.Add(channel.Id, newLimits);

            await new EmbedBuilder().WithColor(Color.Green)
            .WithDescription($"Channel {channel.Mention} now limits to {string.Join(", ", newLimits.ConvertAll(ConvertToVisual))}")
            .Build()
            .SendToChannel(Context.Channel);

            Data.Configuration.EmoteRestrictions = limits;
            Data.SaveConfiguration();
        }