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); }