Beispiel #1
0
        public async Task SetAsync([Summary("The new prefix."), Remainder] string prefix = null)
        {
            if (string.IsNullOrWhiteSpace(prefix))
            {
                var interaction = await _inter.SendSelectionAsync(new ButtonSelectionBuilder <string>()
                                                                  .AddUser(Context.User)
                                                                  .WithSelectionPage(new PageBuilder()
                                                                                     .WithTitle("⚠️ Warning ⚠️")
                                                                                     .WithDescription($"My current prefix is {_db.GetPrefix(Context.Guild.Id).Prefix}`. Did you intend to reset it?")
                                                                                     .WithCurrentTimestamp()
                                                                                     .WithColor(_rand.RandomColor()
                                                                                                ))
                                                                  .WithInputType(InputType.Buttons)
                                                                  .WithOptions(new[] { new ButtonOption <string>("Confirm", ButtonStyle.Primary), new ButtonOption <string>("Cancel", ButtonStyle.Danger) })
                                                                  .Build(), Context.Channel, timeout : TimeSpan.FromSeconds(10));

                if (interaction.IsSuccess && interaction.Value.Option == "Confirm")
                {
                    _db.RemovePrefix(Context.Guild.Id);
                    await ReplyAsync("The prefix has been reset to default; mention me if you are unsure of what that is.");
                }

                await interaction.Message.DeleteAsync();

                return;
            }

            var gp = new GuildPrefix {
                GuildId = Context.Guild.Id, Prefix = prefix
            };

            _db.RemovePrefix(Context.Guild.Id);
            var suc = _db.AddItem <GuildPrefix>("prefixes", gp);

            if (suc)
            {
                await ReplyAsync($"Changed the prefix to `{prefix}`.");
            }
            else
            {
                await ReplyAsync("Failed to change the prefix.");
            }
        }
        public async Task RemovePrefix(
            CommandContext context,
            [Description("The specific string prefix to remove from the guild's prefixes.")]
            string prefixToRemove)
        {
            using IBotAccessProvider dataAccessProvider = this.botAccessProvider.Build();
            GuildPrefix guildPrefix = dataAccessProvider.GetAllAssociatedGuildPrefixes(context.Guild.Id)
                                      .FirstOrDefault(e => e.Prefix.Equals(prefixToRemove));

            if (guildPrefix is null)
            {
                await context.RespondAsync(
                    $"{context.User.Mention}, I'm sorry but the prefix you have given me does not exist for this guild.");

                return;
            }

            dataAccessProvider.DeleteGuildPrefix(guildPrefix);
            await context.RespondAsync(
                $"{context.User.Mention}, I have removed the prefix {guildPrefix.Prefix} for this server.");
        }
        public async Task InteractiveRemovePrefix(CommandContext context)
        {
            using IBotAccessProvider provider = this.botAccessProvider.Build();

            List <GuildPrefix> guildPrefixes = provider.GetAllAssociatedGuildPrefixes(context.Guild.Id).ToList();

            if (!guildPrefixes.Any())
            {
                await context.RespondAsync("You don't have any custom prefixes to remove");

                return;
            }

            DiscordMessage msg = await context.RespondAsync(
                $":wave: Hi, {context.User.Mention}! You want to remove a prefix from your guild list?");

            await msg.CreateReactionAsync(DiscordEmoji.FromName(context.Client, ":regional_indicator_y:"));

            await msg.CreateReactionAsync(DiscordEmoji.FromName(context.Client, ":regional_indicator_n:"));

            InteractivityExtension interactivity = context.Client.GetInteractivity();

            InteractivityResult <MessageReactionAddEventArgs> interactivityResult =
                await interactivity.WaitForReactionAsync(msg, context.User);

            if (interactivityResult.TimedOut ||
                !interactivityResult.Result.Emoji.Equals(
                    DiscordEmoji.FromName(context.Client, ":regional_indicator_y:")))
            {
                DiscordMessage snark = await context.RespondAsync("Well then why did you get my attention! Thanks for wasting my time.");

                await Task.Delay(5000);

                await context.Channel.DeleteMessagesAsync(new List <DiscordMessage> {
                    msg, snark
                });

                return;
            }

            DiscordEmbedBuilder removeEventEmbed = new DiscordEmbedBuilder()
                                                   .WithTitle("Select a prefix to remove by typing: <prefix number>")
                                                   .WithColor(context.Member.Color);

            Task <(bool, int)> messageValidationAndReturn(MessageCreateEventArgs messageE)
            {
                if (messageE.Author.Equals(context.User) && int.TryParse(messageE.Message.Content, out int eventToChoose))
                {
                    return(Task.FromResult((true, eventToChoose)));
                }
                else
                {
                    return(Task.FromResult((false, -1)));
                }
            }

            await msg.DeleteAllReactionsAsync();

            CustomResult <int> result = await context.WaitForMessageAndPaginateOnMsg(
                GetGuildPrefixPages(guildPrefixes, interactivity, removeEventEmbed),
                messageValidationAndReturn,
                msg : msg);

            if (result.TimedOut || result.Cancelled)
            {
                DiscordMessage snark = await context.RespondAsync("You never gave me a valid input. Thanks for wasting my time. :triumph:");

                await Task.Delay(5000);

                await context.Channel.DeleteMessagesAsync(new List <DiscordMessage> {
                    msg, snark
                });

                return;
            }

            GuildPrefix selectedPrefix = guildPrefixes[result.Result - 1];

            provider.DeleteGuildPrefix(selectedPrefix);

            await msg.ModifyAsync(
                $"You have deleted the prefix \"{selectedPrefix.Prefix}\" from this guild's prefixes.", embed : null);
        }
Beispiel #4
0
 public PrefixCommand(MiscService misc, DbService db, GuildPrefix def)
 {
     _misc    = misc;
     _db      = db;
     _default = def;
 }
Beispiel #5
0
 public Delete(GuildPrefix prefix)
 {
     this.Prefix = prefix;
 }