Exemple #1
0
 public async Task SetChannel(ITextChannel channel)
 {
     if (!Service.Rules.TryGetValue(channel.GuildId, out var set))
     {
         set = new Classes.Rules.RuleSet();
         Service.Rules[channel.GuildId] = set;
     }
     set.RuleChannel = channel;
     Service.OnSave();
     await ReplyAsync("Set channel to " + channel.Mention);
 }
Exemple #2
0
        public async Task Create()
        {
            if (!Service.Rules.TryGetValue(Context.Guild.Id, out var set))
            {
                set = new Classes.Rules.RuleSet();
                Service.Rules[Context.Guild.Id] = set;
                await ReplyAsync($"Please use `{Program.Prefix}rules channel [mention]` to set the channel rules are listed in");

                return;
            }
            await ReplyAsync("Please provide the short text for this rule (will be bolded)");

            var rep1 = (await NextMessageAsync(timeout: TimeSpan.FromMinutes(5))).Value;

            if (rep1 == null || string.IsNullOrWhiteSpace(rep1.Content))
            {
                return;
            }
            await ReplyAsync("Please provide a longer description or further text for this rule");

            var rep2 = (await NextMessageAsync(timeout: TimeSpan.FromMinutes(10))).Value;

            if (rep2 == null || string.IsNullOrWhiteSpace(rep2.Content))
            {
                return;
            }


            var longText = rep2.Content;

            if (RuleSet.shouldAddSpace(longText))
            {
                longText = " " + longText;
            }
            if (longText == ".")
            {
                longText = "";
            }
            var field = new EmbedFieldBuilder()
            {
                Name  = "#69",
                Value = $"**{rep1.Content}**{longText}"
            };

            await ReplyAsync("Does this look correct? [y/n]", embed : new EmbedBuilder().AddField(field).Build());

            var confirm = (await NextMessageAsync()).Value;

            if (confirm == null || string.IsNullOrWhiteSpace(confirm.Content) || confirm.Content.StartsWith('y') == false)
            {
                await ReplyAsync("Cancelling.");

                return;
            }
            set.CurrentRules.Add(new Classes.Rules.ServerRule()
            {
                Id    = Interlocked.Increment(ref set.Counter),
                Short = rep1.Content,
                Long  = rep2.Content
            });
            await Service.Update(set);

            Service.OnSave();
            await ReplyAsync("Done.");
        }