From d28c7b500d38c1817e4be5800dd886a9104574bc Mon Sep 17 00:00:00 2001 From: Kwoth Date: Mon, 29 Apr 2024 01:13:45 +0000 Subject: [PATCH] Part2 of the response system rework --- src/Nadeko.Medusa/Context/AnyContext.cs | 2 +- .../Extensions/EmbedBuilderExtensions.cs | 13 - .../Extensions/MedusaExtensions.cs | 130 ++++----- src/Nadeko.Medusa/IEmbedBuilder.cs | 20 +- src/NadekoBot/.editorconfig | 1 + .../Modules/Administration/Administration.cs | 62 ++--- .../AutoAssignRoleCommands.cs | 14 +- .../DangerousCommands/DangerousCommands.cs | 12 +- .../GameVoiceChannelCommands.cs | 6 +- .../Administration/GreetBye/GreetCommands.cs | 58 ++-- .../Administration/LocalizationCommands.cs | 20 +- .../Administration/Mute/MuteCommands.cs | 50 ++-- .../Administration/Mute/MuteService.cs | 4 +- .../DiscordPermOverrideCommands.cs | 12 +- .../PlayingRotate/PlayingRotateCommands.cs | 16 +- .../Administration/Prefix/PrefixCommands.cs | 8 +- .../Protection/ProtectionCommands.cs | 50 ++-- .../Role/ReactionRoleCommands.cs | 10 +- .../Administration/Role/RoleCommands.cs | 40 +-- .../Self/CheckForUpdatesService.cs | 2 +- .../Administration/Self/SelfCommands.cs | 129 ++++----- .../Administration/Self/SelfService.cs | 6 +- .../SelfAssignedRolesCommands.cs | 54 ++-- .../ServerLog/ServerLogCommandService.cs | 49 ++-- .../ServerLog/ServerLogCommands.cs | 36 +-- .../Timezone/TimeZoneCommands.cs | 8 +- .../UserPunish/UserPunishCommands.cs | 166 +++++++----- .../Administration/VcRole/VcRoleCommands.cs | 14 +- .../Modules/Expressions/NadekoExpressions.cs | 86 +++--- .../Expressions/NadekoExpressionsService.cs | 127 +++++---- .../AnimalRacing/AnimalRacingCommands.cs | 60 +++-- .../Modules/Gambling/Bank/BankCommands.cs | 16 +- .../Gambling/BlackJack/BlackJackCommands.cs | 12 +- .../Gambling/Connect4/Connect4Commands.cs | 15 +- .../Gambling/DiceRoll/DiceRollCommands.cs | 18 +- .../Modules/Gambling/Draw/DrawCommands.cs | 10 +- .../Gambling/Events/CurrencyEventsCommands.cs | 8 +- .../Gambling/Events/CurrencyEventsService.cs | 2 +- .../Gambling/Events/GameStatusEvent.cs | 6 +- .../Modules/Gambling/Events/ReactionEvent.cs | 6 +- .../Gambling/FlipCoin/FlipCoinCommands.cs | 10 +- src/NadekoBot/Modules/Gambling/Gambling.cs | 233 ++++++++-------- .../Gambling/GamblingTopLevelModule.cs | 4 +- .../PlantPick/PlantAndPickCommands.cs | 12 +- .../Gambling/Raffle/CurrencyRaffleCommands.cs | 20 +- .../Modules/Gambling/Shop/ShopCommands.cs | 66 ++--- .../Modules/Gambling/Slot/SlotCommands.cs | 4 +- .../Gambling/Waifus/WaifuClaimCommands.cs | 114 ++++---- .../Games/Acrophobia/AcropobiaCommands.cs | 24 +- .../Games/ChatterBot/ChatterbotService.cs | 51 ++-- .../Games/ChatterBot/CleverBotCommands.cs | 4 +- src/NadekoBot/Modules/Games/Games.cs | 6 +- .../Modules/Games/Hangman/HangmanCommands.cs | 16 +- .../Modules/Games/Nunchi/NunchiCommands.cs | 37 +-- .../Games/SpeedTyping/SpeedTypingCommands.cs | 20 +- .../Modules/Games/SpeedTyping/TypingGame.cs | 42 +-- .../Modules/Games/TicTacToe/TicTacToe.cs | 8 +- .../Games/TicTacToe/TicTacToeCommands.cs | 2 +- src/NadekoBot/Modules/Games/Trivia/Games.cs | 85 +++--- src/NadekoBot/Modules/Help/Help.cs | 211 ++++++++------- src/NadekoBot/Modules/Medusae/Medusa.cs | 36 +-- src/NadekoBot/Modules/Music/Music.cs | 112 ++++---- .../Modules/Music/PlaylistCommands.cs | 24 +- .../Modules/Music/Services/IMusicService.cs | 2 +- .../Modules/Music/Services/MusicService.cs | 6 +- .../Patronage/CurrencyRewardService.cs | 2 +- .../Modules/Patronage/PatronageCommands.cs | 16 +- .../Modules/Patronage/PatronageService.cs | 102 +++---- .../Blacklist/BlacklistCommands.cs | 12 +- .../CommandCooldown/CmdCdsCommands.cs | 10 +- .../Permissions/Filter/FilterCommands.cs | 36 +-- .../GlobalPermissionCommands.cs | 14 +- .../Modules/Permissions/Permissions.cs | 164 +++++++----- .../Modules/Permissions/PermissionsService.cs | 20 +- .../Permissions/ResetPermissionsCommands.cs | 4 +- .../Searches/Anime/AnimeSearchCommands.cs | 22 +- .../Modules/Searches/Crypto/CryptoCommands.cs | 16 +- .../Modules/Searches/Feeds/FeedCommands.cs | 20 +- .../Modules/Searches/Feeds/FeedsService.cs | 2 +- .../Modules/Searches/JokeCommands.cs | 14 +- .../Modules/Searches/MemegenCommands.cs | 2 +- src/NadekoBot/Modules/Searches/OsuCommands.cs | 26 +- .../Modules/Searches/PathOfExileCommands.cs | 28 +- .../Modules/Searches/PokemonSearchCommands.cs | 12 +- .../Modules/Searches/Search/SearchCommands.cs | 30 +-- src/NadekoBot/Modules/Searches/Searches.cs | 182 +++++++------ .../StreamNotificationCommands.cs | 49 ++-- .../StreamNotificationService.cs | 4 +- .../Searches/Translate/TranslateService.cs | 2 +- .../Searches/Translate/TranslatorCommands.cs | 24 +- .../Modules/Searches/XkcdCommands.cs | 12 +- .../Searches/YoutubeTrack/YtUploadCommands.cs | 12 +- .../Modules/Utility/Alias/AliasCommands.cs | 12 +- .../Modules/Utility/Alias/AliasService.cs | 15 +- .../Modules/Utility/Calc/CalcCommands.cs | 6 +- .../Modules/Utility/ConfigCommands.cs | 26 +- .../Utility/Giveaway/GiveawayCommands.cs | 22 +- .../Modules/Utility/Info/InfoCommands.cs | 20 +- .../Modules/Utility/Info/InviteCommands.cs | 6 +- .../Modules/Utility/Quote/QuoteCommands.cs | 126 ++++----- .../Modules/Utility/Remind/RemindCommands.cs | 35 +-- .../Modules/Utility/Remind/RemindService.cs | 2 +- .../Utility/Repeater/RepeatCommands.cs | 32 +-- .../Utility/StreamRole/StreamRoleCommands.cs | 26 +- .../Modules/Utility/Todo/TodoCommands.cs | 28 +- .../UnitConversion/UnitConversionCommands.cs | 22 +- src/NadekoBot/Modules/Utility/Utility.cs | 110 ++++---- src/NadekoBot/Modules/Xp/Club/Club.cs | 132 ++++----- src/NadekoBot/Modules/Xp/Club/ClubService.cs | 2 +- src/NadekoBot/Modules/Xp/Xp.cs | 134 +++++----- src/NadekoBot/Modules/Xp/XpRewards.cs | 18 +- src/NadekoBot/Modules/Xp/XpService.cs | 247 +++++++++-------- src/NadekoBot/_common/CleanupModuleBase.cs | 4 +- .../Common/Adapters/DmContextAdapter.cs | 4 +- .../Common/Adapters/GuildContextAdapter.cs | 2 +- src/NadekoBot/_common/NadekoModule.cs | 62 +---- .../_common/Sender/IMessageSenderService.cs | 7 + .../MessageChannelExtensions.cs} | 94 +------ .../_common/Sender/MessageSenderService.cs | 24 ++ .../_common/Sender/ResponseBuilder.cs | 252 ++++++++++++++++++ .../Sender/ResponseBuilderExtensions.cs | 18 ++ .../_common/Services/IEmbedBuilderService.cs | 34 ++- .../Services/Impl/CommandsUtilityService.cs | 94 +++---- src/NadekoBot/_common/SmartText/SmartText.cs | 3 + .../_common/_Extensions/Extensions.cs | 24 +- .../SocketMessageComponentExtensions.cs | 13 +- .../_common/_Extensions/UserExtensions.cs | 10 +- .../data/strings/commands/commands.en-US.yml | 2 +- 128 files changed, 2723 insertions(+), 2289 deletions(-) delete mode 100644 src/Nadeko.Medusa/Extensions/EmbedBuilderExtensions.cs create mode 100644 src/NadekoBot/_common/Sender/IMessageSenderService.cs rename src/NadekoBot/_common/{_Extensions/IMessageChannelExtensions.cs => Sender/MessageChannelExtensions.cs} (77%) create mode 100644 src/NadekoBot/_common/Sender/MessageSenderService.cs create mode 100644 src/NadekoBot/_common/Sender/ResponseBuilder.cs create mode 100644 src/NadekoBot/_common/Sender/ResponseBuilderExtensions.cs diff --git a/src/Nadeko.Medusa/Context/AnyContext.cs b/src/Nadeko.Medusa/Context/AnyContext.cs index 52f25d7b6..f2bb17046 100644 --- a/src/Nadeko.Medusa/Context/AnyContext.cs +++ b/src/Nadeko.Medusa/Context/AnyContext.cs @@ -48,5 +48,5 @@ public abstract class AnyContext /// instead of manually creating embedbuilder instances /// /// A context-aware instance - public abstract IEmbedBuilder Embed(); + public abstract EmbedBuilder Embed(); } \ No newline at end of file diff --git a/src/Nadeko.Medusa/Extensions/EmbedBuilderExtensions.cs b/src/Nadeko.Medusa/Extensions/EmbedBuilderExtensions.cs deleted file mode 100644 index 0e8f70417..000000000 --- a/src/Nadeko.Medusa/Extensions/EmbedBuilderExtensions.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace NadekoBot.Medusa; - -public static class EmbedBuilderExtensions -{ - public static IEmbedBuilder WithOkColor(this IEmbedBuilder eb) - => eb.WithColor(EmbedColor.Ok); - - public static IEmbedBuilder WithPendingColor(this IEmbedBuilder eb) - => eb.WithColor(EmbedColor.Pending); - - public static IEmbedBuilder WithErrorColor(this IEmbedBuilder eb) - => eb.WithColor(EmbedColor.Error); -} \ No newline at end of file diff --git a/src/Nadeko.Medusa/Extensions/MedusaExtensions.cs b/src/Nadeko.Medusa/Extensions/MedusaExtensions.cs index 48ed2ceb4..e5af4a1e1 100644 --- a/src/Nadeko.Medusa/Extensions/MedusaExtensions.cs +++ b/src/Nadeko.Medusa/Extensions/MedusaExtensions.cs @@ -1,65 +1,65 @@ -using Discord; - -namespace NadekoBot.Medusa; - -public static class MedusaExtensions -{ - public static Task EmbedAsync(this IMessageChannel ch, IEmbedBuilder embed, string msg = "") - => ch.SendMessageAsync(msg, - embed: embed.Build(), - options: new() - { - RetryMode = RetryMode.Retry502 - }); - - // unlocalized - public static Task SendConfirmAsync(this IMessageChannel ch, AnyContext ctx, string msg) - => ch.EmbedAsync(ctx.Embed().WithOkColor().WithDescription(msg)); - - public static Task SendPendingAsync(this IMessageChannel ch, AnyContext ctx, string msg) - => ch.EmbedAsync(ctx.Embed().WithPendingColor().WithDescription(msg)); - - public static Task SendErrorAsync(this IMessageChannel ch, AnyContext ctx, string msg) - => ch.EmbedAsync(ctx.Embed().WithErrorColor().WithDescription(msg)); - - // unlocalized - public static Task SendConfirmAsync(this AnyContext ctx, string msg) - => ctx.Channel.SendConfirmAsync(ctx, msg); - - public static Task SendPendingAsync(this AnyContext ctx, string msg) - => ctx.Channel.SendPendingAsync(ctx, msg); - - public static Task SendErrorAsync(this AnyContext ctx, string msg) - => ctx.Channel.SendErrorAsync(ctx, msg); - - // localized - public static Task ConfirmAsync(this AnyContext ctx) - => ctx.Message.AddReactionAsync(new Emoji("✅")); - - public static Task ErrorAsync(this AnyContext ctx) - => ctx.Message.AddReactionAsync(new Emoji("❌")); - - public static Task WarningAsync(this AnyContext ctx) - => ctx.Message.AddReactionAsync(new Emoji("⚠️")); - - public static Task WaitAsync(this AnyContext ctx) - => ctx.Message.AddReactionAsync(new Emoji("🤔")); - - public static Task ErrorLocalizedAsync(this AnyContext ctx, string key, params object[]? args) - => ctx.SendErrorAsync(ctx.GetText(key, args)); - - public static Task PendingLocalizedAsync(this AnyContext ctx, string key, params object[]? args) - => ctx.SendPendingAsync(ctx.GetText(key, args)); - - public static Task ConfirmLocalizedAsync(this AnyContext ctx, string key, params object[]? args) - => ctx.SendConfirmAsync(ctx.GetText(key, args)); - - public static Task ReplyErrorLocalizedAsync(this AnyContext ctx, string key, params object[]? args) - => ctx.SendErrorAsync($"{Format.Bold(ctx.User.ToString())} {ctx.GetText(key, args)}"); - - public static Task ReplyPendingLocalizedAsync(this AnyContext ctx, string key, params object[]? args) - => ctx.SendPendingAsync($"{Format.Bold(ctx.User.ToString())} {ctx.GetText(key, args)}"); - - public static Task ReplyConfirmLocalizedAsync(this AnyContext ctx, string key, params object[]? args) - => ctx.SendConfirmAsync($"{Format.Bold(ctx.User.ToString())} {ctx.GetText(key, args)}"); -} \ No newline at end of file +// using Discord; +// +// namespace NadekoBot.Medusa; +// +// public static class MedusaExtensions +// { +// public static Task EmbedAsync(this IMessageChannel ch, EmbedBuilder embed, string msg = "") +// => ch.SendMessageAsync(msg, +// embed: embed.Build(), +// options: new() +// { +// RetryMode = RetryMode.Retry502 +// }); +// +// // unlocalized +// public static Task SendConfirmAsync(this IMessageChannel ch, AnyContext ctx, string msg) +// => ch.EmbedAsync(ctx.Embed().WithOkColor().WithDescription(msg)); +// +// public static Task SendPendingAsync(this IMessageChannel ch, AnyContext ctx, string msg) +// => ch.EmbedAsync(ctx.Embed().WithPendingColor().WithDescription(msg)); +// +// public static Task SendErrorAsync(this IMessageChannel ch, AnyContext ctx, string msg) +// => ch.EmbedAsync(ctx.Embed().WithErrorColor().WithDescription(msg)); +// +// // unlocalized +// public static Task SendConfirmAsync(this AnyContext ctx, string msg) +// => ctx.Channel.SendConfirmAsync(ctx, msg); +// +// public static Task SendPendingAsync(this AnyContext ctx, string msg) +// => ctx.Channel.SendPendingAsync(ctx, msg); +// +// public static Task SendErrorAsync(this AnyContext ctx, string msg) +// => ctx.Channel.SendErrorAsync(ctx, msg); +// +// // localized +// public static Task ConfirmAsync(this AnyContext ctx) +// => ctx.Message.AddReactionAsync(new Emoji("✅")); +// +// public static Task ErrorAsync(this AnyContext ctx) +// => ctx.Message.AddReactionAsync(new Emoji("❌")); +// +// public static Task WarningAsync(this AnyContext ctx) +// => ctx.Message.AddReactionAsync(new Emoji("⚠️")); +// +// public static Task WaitAsync(this AnyContext ctx) +// => ctx.Message.AddReactionAsync(new Emoji("🤔")); +// +// public static Task ErrorLocalizedAsync(this AnyContext ctx, string key, params object[]? args) +// => ctx.SendErrorAsync(ctx.GetText(key, args)); +// +// public static Task PendingLocalizedAsync(this AnyContext ctx, string key, params object[]? args) +// => ctx.SendPendingAsync(ctx.GetText(key, args)); +// +// public static Task ConfirmLocalizedAsync(this AnyContext ctx, string key, params object[]? args) +// => ctx.SendConfirmAsync(ctx.GetText(key, args)); +// +// public static Task ReplyErrorLocalizedAsync(this AnyContext ctx, string key, params object[]? args) +// => ctx.SendErrorAsync($"{Format.Bold(ctx.User.ToString())} {ctx.GetText(key, args)}"); +// +// public static Task ReplyPendingLocalizedAsync(this AnyContext ctx, string key, params object[]? args) +// => ctx.SendPendingAsync($"{Format.Bold(ctx.User.ToString())} {ctx.GetText(key, args)}"); +// +// public static Task ReplyConfirmLocalizedAsync(this AnyContext ctx, string key, params object[]? args) +// => ctx.SendConfirmAsync($"{Format.Bold(ctx.User.ToString())} {ctx.GetText(key, args)}"); +// } \ No newline at end of file diff --git a/src/Nadeko.Medusa/IEmbedBuilder.cs b/src/Nadeko.Medusa/IEmbedBuilder.cs index d44936fc1..fa94ea6f4 100644 --- a/src/Nadeko.Medusa/IEmbedBuilder.cs +++ b/src/Nadeko.Medusa/IEmbedBuilder.cs @@ -4,15 +4,15 @@ namespace NadekoBot; public interface IEmbedBuilder { - IEmbedBuilder WithDescription(string? desc); - IEmbedBuilder WithTitle(string? title); - IEmbedBuilder AddField(string title, object value, bool isInline = false); - IEmbedBuilder WithFooter(string text, string? iconUrl = null); - IEmbedBuilder WithAuthor(string name, string? iconUrl = null, string? url = null); - IEmbedBuilder WithColor(EmbedColor color); - IEmbedBuilder WithDiscordColor(Color color); + EmbedBuilder WithDescription(string? desc); + EmbedBuilder WithTitle(string? title); + EmbedBuilder AddField(string title, object value, bool isInline = false); + EmbedBuilder WithFooter(string text, string? iconUrl = null); + EmbedBuilder WithAuthor(string name, string? iconUrl = null, string? url = null); + EmbedBuilder WithColor(EmbedColor color); + EmbedBuilder WithDiscordColor(Color color); Embed Build(); - IEmbedBuilder WithUrl(string url); - IEmbedBuilder WithImageUrl(string url); - IEmbedBuilder WithThumbnailUrl(string url); + EmbedBuilder WithUrl(string url); + EmbedBuilder WithImageUrl(string url); + EmbedBuilder WithThumbnailUrl(string url); } \ No newline at end of file diff --git a/src/NadekoBot/.editorconfig b/src/NadekoBot/.editorconfig index 041e023c1..f23547b92 100644 --- a/src/NadekoBot/.editorconfig +++ b/src/NadekoBot/.editorconfig @@ -357,3 +357,4 @@ resharper_arrange_redundant_parentheses_highlighting = hint # IDE0011: Add braces dotnet_diagnostic.IDE0011.severity = warning + diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index 86e3223f7..59f2fdaba 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -49,9 +49,9 @@ public partial class Administration : NadekoModule { var newValue = await _somethingOnly.ToggleImageOnlyChannelAsync(ctx.Guild.Id, ctx.Channel.Id); if (newValue) - await ReplyConfirmLocalizedAsync(strs.imageonly_enable); + await Response().Confirm(strs.imageonly_enable).SendAsync(); else - await ReplyPendingLocalizedAsync(strs.imageonly_disable); + await Response().Pending(strs.imageonly_disable).SendAsync(); } [Cmd] @@ -62,9 +62,9 @@ public partial class Administration : NadekoModule { var newValue = await _somethingOnly.ToggleLinkOnlyChannelAsync(ctx.Guild.Id, ctx.Channel.Id); if (newValue) - await ReplyConfirmLocalizedAsync(strs.linkonly_enable); + await Response().Confirm(strs.linkonly_enable).SendAsync(); else - await ReplyPendingLocalizedAsync(strs.linkonly_disable); + await Response().Pending(strs.linkonly_disable).SendAsync(); } [Cmd] @@ -95,7 +95,7 @@ public partial class Administration : NadekoModule var guild = (SocketGuild)ctx.Guild; var (enabled, channels) = _service.GetDelMsgOnCmdData(ctx.Guild.Id); - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.server_delmsgoncmd)) .WithDescription(enabled ? "✅" : "❌"); @@ -113,7 +113,7 @@ public partial class Administration : NadekoModule embed.AddField(GetText(strs.channel_delmsgoncmd), str); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -126,12 +126,12 @@ public partial class Administration : NadekoModule if (_service.ToggleDeleteMessageOnCommand(ctx.Guild.Id)) { _service.DeleteMessagesOnCommand.Add(ctx.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.delmsg_on); + await Response().Confirm(strs.delmsg_on).SendAsync(); } else { _service.DeleteMessagesOnCommand.TryRemove(ctx.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.delmsg_off); + await Response().Confirm(strs.delmsg_off).SendAsync(); } } @@ -154,11 +154,11 @@ public partial class Administration : NadekoModule await _service.SetDelMsgOnCmdState(ctx.Guild.Id, actualChId, s); if (s == State.Disable) - await ReplyConfirmLocalizedAsync(strs.delmsg_channel_off); + await Response().Confirm(strs.delmsg_channel_off).SendAsync(); else if (s == State.Enable) - await ReplyConfirmLocalizedAsync(strs.delmsg_channel_on); + await Response().Confirm(strs.delmsg_channel_on).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.delmsg_channel_inherit); + await Response().Confirm(strs.delmsg_channel_inherit).SendAsync(); } [Cmd] @@ -168,7 +168,7 @@ public partial class Administration : NadekoModule public async Task Deafen(params IGuildUser[] users) { await _service.DeafenUsers(true, users); - await ReplyConfirmLocalizedAsync(strs.deafen); + await Response().Confirm(strs.deafen).SendAsync(); } [Cmd] @@ -178,7 +178,7 @@ public partial class Administration : NadekoModule public async Task UnDeafen(params IGuildUser[] users) { await _service.DeafenUsers(false, users); - await ReplyConfirmLocalizedAsync(strs.undeafen); + await Response().Confirm(strs.undeafen).SendAsync(); } [Cmd] @@ -188,7 +188,7 @@ public partial class Administration : NadekoModule public async Task DelVoiChanl([Leftover] IVoiceChannel voiceChannel) { await voiceChannel.DeleteAsync(); - await ReplyConfirmLocalizedAsync(strs.delvoich(Format.Bold(voiceChannel.Name))); + await Response().Confirm(strs.delvoich(Format.Bold(voiceChannel.Name))).SendAsync(); } [Cmd] @@ -198,7 +198,7 @@ public partial class Administration : NadekoModule public async Task CreatVoiChanl([Leftover] string channelName) { var ch = await ctx.Guild.CreateVoiceChannelAsync(channelName); - await ReplyConfirmLocalizedAsync(strs.createvoich(Format.Bold(ch.Name))); + await Response().Confirm(strs.createvoich(Format.Bold(ch.Name))).SendAsync(); } [Cmd] @@ -208,7 +208,7 @@ public partial class Administration : NadekoModule public async Task DelTxtChanl([Leftover] ITextChannel toDelete) { await toDelete.DeleteAsync(); - await ReplyConfirmLocalizedAsync(strs.deltextchan(Format.Bold(toDelete.Name))); + await Response().Confirm(strs.deltextchan(Format.Bold(toDelete.Name))).SendAsync(); } [Cmd] @@ -218,7 +218,7 @@ public partial class Administration : NadekoModule public async Task CreaTxtChanl([Leftover] string channelName) { var txtCh = await ctx.Guild.CreateTextChannelAsync(channelName); - await ReplyConfirmLocalizedAsync(strs.createtextchan(Format.Bold(txtCh.Name))); + await Response().Confirm(strs.createtextchan(Format.Bold(txtCh.Name))).SendAsync(); } [Cmd] @@ -230,7 +230,7 @@ public partial class Administration : NadekoModule var channel = (ITextChannel)ctx.Channel; topic ??= ""; await channel.ModifyAsync(c => c.Topic = topic); - await ReplyConfirmLocalizedAsync(strs.set_topic); + await Response().Confirm(strs.set_topic).SendAsync(); } [Cmd] @@ -241,7 +241,7 @@ public partial class Administration : NadekoModule { var channel = (ITextChannel)ctx.Channel; await channel.ModifyAsync(c => c.Name = name); - await ReplyConfirmLocalizedAsync(strs.set_channel_name); + await Response().Confirm(strs.set_channel_name).SendAsync(); } [Cmd] @@ -256,9 +256,9 @@ public partial class Administration : NadekoModule await channel.ModifyAsync(c => c.IsNsfw = !isEnabled); if (isEnabled) - await ReplyConfirmLocalizedAsync(strs.nsfw_set_false); + await Response().Confirm(strs.nsfw_set_false).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.nsfw_set_true); + await Response().Confirm(strs.nsfw_set_true).SendAsync(); } [Cmd] @@ -277,13 +277,13 @@ public partial class Administration : NadekoModule var botPerms = ((SocketGuild)ctx.Guild).CurrentUser.GetPermissions(channel); if (!userPerms.Has(ChannelPermission.ManageMessages)) { - await ReplyErrorLocalizedAsync(strs.insuf_perms_u); + await Response().Error(strs.insuf_perms_u).SendAsync(); return; } if (!botPerms.Has(ChannelPermission.ViewChannel)) { - await ReplyErrorLocalizedAsync(strs.insuf_perms_i); + await Response().Error(strs.insuf_perms_i).SendAsync(); return; } @@ -312,13 +312,13 @@ public partial class Administration : NadekoModule var botPerms = ((SocketGuild)ctx.Guild).CurrentUser.GetPermissions(channel); if (!userPerms.Has(ChannelPermission.ManageMessages)) { - await ReplyErrorLocalizedAsync(strs.insuf_perms_u); + await Response().Error(strs.insuf_perms_u).SendAsync(); return; } if (!botPerms.Has(ChannelPermission.ManageMessages)) { - await ReplyErrorLocalizedAsync(strs.insuf_perms_i); + await Response().Error(strs.insuf_perms_i).SendAsync(); return; } @@ -326,7 +326,7 @@ public partial class Administration : NadekoModule var msg = await channel.GetMessageAsync(messageId); if (msg is null) { - await ReplyErrorLocalizedAsync(strs.msg_not_found); + await Response().Error(strs.msg_not_found).SendAsync(); return; } @@ -342,7 +342,7 @@ public partial class Administration : NadekoModule } else { - await ReplyErrorLocalizedAsync(strs.time_too_long); + await Response().Error(strs.time_too_long).SendAsync(); return; } @@ -373,7 +373,7 @@ public partial class Administration : NadekoModule if (t is null) { - await ReplyErrorLocalizedAsync(strs.not_found); + await Response().Error(strs.not_found).SendAsync(); return; } @@ -387,7 +387,7 @@ public partial class Administration : NadekoModule { if (ctx.Channel.GetChannelType() != ChannelType.News) { - await ReplyErrorLocalizedAsync(strs.req_announcement_channel); + await Response().Error(strs.req_announcement_channel).SendAsync(); return; } @@ -395,11 +395,11 @@ public partial class Administration : NadekoModule if (newState) { - await ReplyConfirmLocalizedAsync(strs.autopublish_enable); + await Response().Confirm(strs.autopublish_enable).SendAsync(); } else { - await ReplyConfirmLocalizedAsync(strs.autopublish_disable); + await Response().Confirm(strs.autopublish_disable).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Administration/AutoAssignableRoles/AutoAssignRoleCommands.cs b/src/NadekoBot/Modules/Administration/AutoAssignableRoles/AutoAssignRoleCommands.cs index 791da0280..86af7cc0d 100644 --- a/src/NadekoBot/Modules/Administration/AutoAssignableRoles/AutoAssignRoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/AutoAssignableRoles/AutoAssignRoleCommands.cs @@ -21,17 +21,17 @@ public partial class Administration // the user can't aar the role which is higher or equal to his highest role if (ctx.User.Id != guser.Guild.OwnerId && guser.GetRoles().Max(x => x.Position) <= role.Position) { - await ReplyErrorLocalizedAsync(strs.hierarchy); + await Response().Error(strs.hierarchy).SendAsync(); return; } var roles = await _service.ToggleAarAsync(ctx.Guild.Id, role.Id); if (roles.Count == 0) - await ReplyConfirmLocalizedAsync(strs.aar_disabled); + await Response().Confirm(strs.aar_disabled).SendAsync(); else if (roles.Contains(role.Id)) await AutoAssignRole(); else - await ReplyConfirmLocalizedAsync(strs.aar_role_removed(Format.Bold(role.ToString()))); + await Response().Confirm(strs.aar_role_removed(Format.Bold(role.ToString()))).SendAsync(); } [Cmd] @@ -42,7 +42,7 @@ public partial class Administration { if (!_service.TryGetRoles(ctx.Guild.Id, out var roles)) { - await ReplyConfirmLocalizedAsync(strs.aar_none); + await Response().Confirm(strs.aar_none).SendAsync(); return; } @@ -51,8 +51,10 @@ public partial class Administration if (existing.Count != roles.Count) await _service.SetAarRolesAsync(ctx.Guild.Id, existing.Select(x => x.Id)); - await ReplyConfirmLocalizedAsync(strs.aar_roles( - '\n' + existing.Select(x => Format.Bold(x.ToString())).Join(",\n"))); + await Response() + .Confirm(strs.aar_roles( + '\n' + existing.Select(x => Format.Bold(x.ToString())).Join(",\n"))) + .SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Administration/DangerousCommands/DangerousCommands.cs b/src/NadekoBot/Modules/Administration/DangerousCommands/DangerousCommands.cs index 7c02bc8a7..d766b55d0 100644 --- a/src/NadekoBot/Modules/Administration/DangerousCommands/DangerousCommands.cs +++ b/src/NadekoBot/Modules/Administration/DangerousCommands/DangerousCommands.cs @@ -41,9 +41,9 @@ public partial class Administration var items = result.Results.Skip(cur * 20).Take(20).ToList(); if (!items.Any()) - return _eb.Create().WithErrorColor().WithFooter(sql).WithDescription("-"); + return new EmbedBuilder().WithErrorColor().WithFooter(sql).WithDescription("-"); - return _eb.Create() + return new EmbedBuilder() .WithOkColor() .WithFooter(sql) .WithTitle(string.Join(" ║ ", result.ColumnNames)) @@ -99,7 +99,7 @@ public partial class Administration { try { - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithTitle(GetText(strs.sql_confirm_exec)) .WithDescription(Format.Code(sql)); @@ -107,11 +107,11 @@ public partial class Administration return; var res = await _ds.ExecuteSql(sql); - await SendConfirmAsync(res.ToString()); + await Response().Confirm(res.ToString()).SendAsync(); } catch (Exception ex) { - await SendErrorAsync(ex.ToString()); + await Response().Error(ex.ToString()).SendAsync(); } } @@ -119,7 +119,7 @@ public partial class Administration [OwnerOnly] public async Task PurgeUser(ulong userId) { - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithDescription(GetText(strs.purge_user_confirm(Format.Bold(userId.ToString())))); if (!await PromptUserConfirmAsync(embed)) diff --git a/src/NadekoBot/Modules/Administration/GameVoiceChannel/GameVoiceChannelCommands.cs b/src/NadekoBot/Modules/Administration/GameVoiceChannel/GameVoiceChannelCommands.cs index 848c3f3a5..b30c56ddb 100644 --- a/src/NadekoBot/Modules/Administration/GameVoiceChannel/GameVoiceChannelCommands.cs +++ b/src/NadekoBot/Modules/Administration/GameVoiceChannel/GameVoiceChannelCommands.cs @@ -18,18 +18,18 @@ public partial class Administration if (vch is null) { - await ReplyErrorLocalizedAsync(strs.not_in_voice); + await Response().Error(strs.not_in_voice).SendAsync(); return; } var id = _service.ToggleGameVoiceChannel(ctx.Guild.Id, vch.Id); if (id is null) - await ReplyConfirmLocalizedAsync(strs.gvc_disabled); + await Response().Confirm(strs.gvc_disabled).SendAsync(); else { _service.GameVoiceChannels.Add(vch.Id); - await ReplyConfirmLocalizedAsync(strs.gvc_enabled(Format.Bold(vch.Name))); + await Response().Confirm(strs.gvc_enabled(Format.Bold(vch.Name))).SendAsync(); } } } diff --git a/src/NadekoBot/Modules/Administration/GreetBye/GreetCommands.cs b/src/NadekoBot/Modules/Administration/GreetBye/GreetCommands.cs index 901b97b2d..d77a836d4 100644 --- a/src/NadekoBot/Modules/Administration/GreetBye/GreetCommands.cs +++ b/src/NadekoBot/Modules/Administration/GreetBye/GreetCommands.cs @@ -13,9 +13,9 @@ public partial class Administration var enabled = await _service.ToggleBoost(ctx.Guild.Id, ctx.Channel.Id); if (enabled) - await ReplyConfirmLocalizedAsync(strs.boost_on); + await Response().Confirm(strs.boost_on).SendAsync(); else - await ReplyPendingLocalizedAsync(strs.boost_off); + await Response().Pending(strs.boost_off).SendAsync(); } [Cmd] @@ -29,9 +29,9 @@ public partial class Administration await _service.SetBoostDel(ctx.Guild.Id, timer); if (timer > 0) - await ReplyConfirmLocalizedAsync(strs.boostdel_on(timer)); + await Response().Confirm(strs.boostdel_on(timer)).SendAsync(); else - await ReplyPendingLocalizedAsync(strs.boostdel_off); + await Response().Pending(strs.boostdel_off).SendAsync(); } [Cmd] @@ -42,15 +42,15 @@ public partial class Administration if (string.IsNullOrWhiteSpace(text)) { var boostMessage = _service.GetBoostMessage(ctx.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.boostmsg_cur(boostMessage?.SanitizeMentions())); + await Response().Confirm(strs.boostmsg_cur(boostMessage?.SanitizeMentions())).SendAsync(); return; } var sendBoostEnabled = _service.SetBoostMessage(ctx.Guild.Id, ref text); - await ReplyConfirmLocalizedAsync(strs.boostmsg_new); + await Response().Confirm(strs.boostmsg_new).SendAsync(); if (!sendBoostEnabled) - await ReplyPendingLocalizedAsync(strs.boostmsg_enable($"`{prefix}boost`")); + await Response().Pending(strs.boostmsg_enable($"`{prefix}boost`")).SendAsync(); } [Cmd] @@ -64,9 +64,9 @@ public partial class Administration await _service.SetGreetDel(ctx.Guild.Id, timer); if (timer > 0) - await ReplyConfirmLocalizedAsync(strs.greetdel_on(timer)); + await Response().Confirm(strs.greetdel_on(timer)).SendAsync(); else - await ReplyPendingLocalizedAsync(strs.greetdel_off); + await Response().Pending(strs.greetdel_off).SendAsync(); } [Cmd] @@ -77,9 +77,9 @@ public partial class Administration var enabled = await _service.SetGreet(ctx.Guild.Id, ctx.Channel.Id); if (enabled) - await ReplyConfirmLocalizedAsync(strs.greet_on); + await Response().Confirm(strs.greet_on).SendAsync(); else - await ReplyPendingLocalizedAsync(strs.greet_off); + await Response().Pending(strs.greet_off).SendAsync(); } [Cmd] @@ -90,16 +90,16 @@ public partial class Administration if (string.IsNullOrWhiteSpace(text)) { var greetMsg = _service.GetGreetMsg(ctx.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.greetmsg_cur(greetMsg?.SanitizeMentions())); + await Response().Confirm(strs.greetmsg_cur(greetMsg?.SanitizeMentions())).SendAsync(); return; } var sendGreetEnabled = _service.SetGreetMessage(ctx.Guild.Id, ref text); - await ReplyConfirmLocalizedAsync(strs.greetmsg_new); + await Response().Confirm(strs.greetmsg_new).SendAsync(); if (!sendGreetEnabled) - await ReplyPendingLocalizedAsync(strs.greetmsg_enable($"`{prefix}greet`")); + await Response().Pending(strs.greetmsg_enable($"`{prefix}greet`")).SendAsync(); } [Cmd] @@ -110,9 +110,9 @@ public partial class Administration var enabled = await _service.SetGreetDm(ctx.Guild.Id); if (enabled) - await ReplyConfirmLocalizedAsync(strs.greetdm_on); + await Response().Confirm(strs.greetdm_on).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.greetdm_off); + await Response().Confirm(strs.greetdm_off).SendAsync(); } [Cmd] @@ -123,15 +123,15 @@ public partial class Administration if (string.IsNullOrWhiteSpace(text)) { var dmGreetMsg = _service.GetDmGreetMsg(ctx.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.greetdmmsg_cur(dmGreetMsg?.SanitizeMentions())); + await Response().Confirm(strs.greetdmmsg_cur(dmGreetMsg?.SanitizeMentions())).SendAsync(); return; } var sendGreetEnabled = _service.SetGreetDmMessage(ctx.Guild.Id, ref text); - await ReplyConfirmLocalizedAsync(strs.greetdmmsg_new); + await Response().Confirm(strs.greetdmmsg_new).SendAsync(); if (!sendGreetEnabled) - await ReplyPendingLocalizedAsync(strs.greetdmmsg_enable($"`{prefix}greetdm`")); + await Response().Pending(strs.greetdmmsg_enable($"`{prefix}greetdm`")).SendAsync(); } [Cmd] @@ -142,9 +142,9 @@ public partial class Administration var enabled = await _service.SetBye(ctx.Guild.Id, ctx.Channel.Id); if (enabled) - await ReplyConfirmLocalizedAsync(strs.bye_on); + await Response().Confirm(strs.bye_on).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.bye_off); + await Response().Confirm(strs.bye_off).SendAsync(); } [Cmd] @@ -155,15 +155,15 @@ public partial class Administration if (string.IsNullOrWhiteSpace(text)) { var byeMsg = _service.GetByeMessage(ctx.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.byemsg_cur(byeMsg?.SanitizeMentions())); + await Response().Confirm(strs.byemsg_cur(byeMsg?.SanitizeMentions())).SendAsync(); return; } var sendByeEnabled = _service.SetByeMessage(ctx.Guild.Id, ref text); - await ReplyConfirmLocalizedAsync(strs.byemsg_new); + await Response().Confirm(strs.byemsg_new).SendAsync(); if (!sendByeEnabled) - await ReplyPendingLocalizedAsync(strs.byemsg_enable($"`{prefix}bye`")); + await Response().Pending(strs.byemsg_enable($"`{prefix}bye`")).SendAsync(); } [Cmd] @@ -174,9 +174,9 @@ public partial class Administration await _service.SetByeDel(ctx.Guild.Id, timer); if (timer > 0) - await ReplyConfirmLocalizedAsync(strs.byedel_on(timer)); + await Response().Confirm(strs.byedel_on(timer)).SendAsync(); else - await ReplyPendingLocalizedAsync(strs.byedel_off); + await Response().Pending(strs.byedel_off).SendAsync(); } @@ -191,7 +191,7 @@ public partial class Administration await _service.ByeTest((ITextChannel)ctx.Channel, user); var enabled = _service.GetByeEnabled(ctx.Guild.Id); if (!enabled) - await ReplyPendingLocalizedAsync(strs.byemsg_enable($"`{prefix}bye`")); + await Response().Pending(strs.byemsg_enable($"`{prefix}bye`")).SendAsync(); } [Cmd] @@ -205,7 +205,7 @@ public partial class Administration await _service.GreetTest((ITextChannel)ctx.Channel, user); var enabled = _service.GetGreetEnabled(ctx.Guild.Id); if (!enabled) - await ReplyPendingLocalizedAsync(strs.greetmsg_enable($"`{prefix}greet`")); + await Response().Pending(strs.greetmsg_enable($"`{prefix}greet`")).SendAsync(); } [Cmd] @@ -223,7 +223,7 @@ public partial class Administration await ctx.WarningAsync(); var enabled = _service.GetGreetDmEnabled(ctx.Guild.Id); if (!enabled) - await ReplyPendingLocalizedAsync(strs.greetdmmsg_enable($"`{prefix}greetdm`")); + await Response().Pending(strs.greetdmmsg_enable($"`{prefix}greetdm`")).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Administration/LocalizationCommands.cs b/src/NadekoBot/Modules/Administration/LocalizationCommands.cs index 46287c956..bb0190f65 100644 --- a/src/NadekoBot/Modules/Administration/LocalizationCommands.cs +++ b/src/NadekoBot/Modules/Administration/LocalizationCommands.cs @@ -42,8 +42,8 @@ public partial class Administration [RequireContext(ContextType.Guild)] [Priority(0)] public async Task LanguageSet() - => await ReplyConfirmLocalizedAsync(strs.lang_set_show(Format.Bold(Culture.ToString()), - Format.Bold(Culture.NativeName))); + => await Response().Confirm(strs.lang_set_show(Format.Bold(Culture.ToString()), + Format.Bold(Culture.NativeName))).SendAsync(); [Cmd] [RequireContext(ContextType.Guild)] @@ -68,11 +68,11 @@ public partial class Administration var nativeName = ci.NativeName; if (ci.Name == "ts-TS") nativeName = _supportedLocales[ci.Name]; - await ReplyConfirmLocalizedAsync(strs.lang_set(Format.Bold(ci.ToString()), Format.Bold(nativeName))); + await Response().Confirm(strs.lang_set(Format.Bold(ci.ToString()), Format.Bold(nativeName))).SendAsync(); } catch (Exception) { - await ReplyErrorLocalizedAsync(strs.lang_set_fail); + await Response().Error(strs.lang_set_fail).SendAsync(); } } @@ -80,7 +80,7 @@ public partial class Administration public async Task LanguageSetDefault() { var cul = _localization.DefaultCultureInfo; - await ReplyErrorLocalizedAsync(strs.lang_set_bot_show(cul, cul.NativeName)); + await Response().Error(strs.lang_set_bot_show(cul, cul.NativeName)).SendAsync(); } [Cmd] @@ -101,23 +101,23 @@ public partial class Administration _localization.SetDefaultCulture(ci); } - await ReplyConfirmLocalizedAsync(strs.lang_set_bot(Format.Bold(ci.ToString()), - Format.Bold(ci.NativeName))); + await Response().Confirm(strs.lang_set_bot(Format.Bold(ci.ToString()), + Format.Bold(ci.NativeName))).SendAsync(); } catch (Exception) { - await ReplyErrorLocalizedAsync(strs.lang_set_fail); + await Response().Error(strs.lang_set_fail).SendAsync(); } } [Cmd] public async Task LanguagesList() - => await EmbedAsync(_eb.Create() + => await Response().Embed(new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.lang_list)) .WithDescription(string.Join("\n", _supportedLocales.Select( - x => $"{Format.Code(x.Key),-10} => {x.Value}")))); + x => $"{Format.Code(x.Key),-10} => {x.Value}")))).SendAsync(); } } /* list of language codes for reference. diff --git a/src/NadekoBot/Modules/Administration/Mute/MuteCommands.cs b/src/NadekoBot/Modules/Administration/Mute/MuteCommands.cs index 1831c5934..709dc8d0d 100644 --- a/src/NadekoBot/Modules/Administration/Mute/MuteCommands.cs +++ b/src/NadekoBot/Modules/Administration/Mute/MuteCommands.cs @@ -16,7 +16,7 @@ public partial class Administration if (runnerUser.Id != ctx.Guild.OwnerId && runnerUserRoles.Max(x => x.Position) <= targetUserRoles.Max(x => x.Position)) { - await ReplyErrorLocalizedAsync(strs.mute_perms); + await Response().Error(strs.mute_perms).SendAsync(); return false; } @@ -31,20 +31,20 @@ public partial class Administration if (role is null) { var muteRole = await _service.GetMuteRole(ctx.Guild); - await ReplyConfirmLocalizedAsync(strs.mute_role(Format.Code(muteRole.Name))); + await Response().Confirm(strs.mute_role(Format.Code(muteRole.Name))).SendAsync(); return; } if (ctx.User.Id != ctx.Guild.OwnerId && role.Position >= ((SocketGuildUser)ctx.User).Roles.Max(x => x.Position)) { - await ReplyErrorLocalizedAsync(strs.insuf_perms_u); + await Response().Error(strs.insuf_perms_u).SendAsync(); return; } await _service.SetMuteRoleAsync(ctx.Guild.Id, role.Name); - await ReplyConfirmLocalizedAsync(strs.mute_role_set); + await Response().Confirm(strs.mute_role_set).SendAsync(); } [Cmd] @@ -59,12 +59,12 @@ public partial class Administration return; await _service.MuteUser(target, ctx.User, reason: reason); - await ReplyConfirmLocalizedAsync(strs.user_muted(Format.Bold(target.ToString()))); + await Response().Confirm(strs.user_muted(Format.Bold(target.ToString()))).SendAsync(); } catch (Exception ex) { Log.Warning(ex, "Exception in the mute command"); - await ReplyErrorLocalizedAsync(strs.mute_error); + await Response().Error(strs.mute_error).SendAsync(); } } @@ -82,13 +82,13 @@ public partial class Administration return; await _service.TimedMute(user, ctx.User, time.Time, reason: reason); - await ReplyConfirmLocalizedAsync(strs.user_muted_time(Format.Bold(user.ToString()), - (int)time.Time.TotalMinutes)); + await Response().Confirm(strs.user_muted_time(Format.Bold(user.ToString()), + (int)time.Time.TotalMinutes)).SendAsync(); } catch (Exception ex) { Log.Warning(ex, "Error in mute command"); - await ReplyErrorLocalizedAsync(strs.mute_error); + await Response().Error(strs.mute_error).SendAsync(); } } @@ -100,11 +100,11 @@ public partial class Administration try { await _service.UnmuteUser(user.GuildId, user.Id, ctx.User, reason: reason); - await ReplyConfirmLocalizedAsync(strs.user_unmuted(Format.Bold(user.ToString()))); + await Response().Confirm(strs.user_unmuted(Format.Bold(user.ToString()))).SendAsync(); } catch { - await ReplyErrorLocalizedAsync(strs.mute_error); + await Response().Error(strs.mute_error).SendAsync(); } } @@ -120,12 +120,12 @@ public partial class Administration return; await _service.MuteUser(user, ctx.User, MuteType.Chat, reason); - await ReplyConfirmLocalizedAsync(strs.user_chat_mute(Format.Bold(user.ToString()))); + await Response().Confirm(strs.user_chat_mute(Format.Bold(user.ToString()))).SendAsync(); } catch (Exception ex) { Log.Warning(ex, "Exception in the chatmute command"); - await ReplyErrorLocalizedAsync(strs.mute_error); + await Response().Error(strs.mute_error).SendAsync(); } } @@ -143,13 +143,13 @@ public partial class Administration return; await _service.TimedMute(user, ctx.User, time.Time, MuteType.Chat, reason); - await ReplyConfirmLocalizedAsync(strs.user_chat_mute_time(Format.Bold(user.ToString()), - (int)time.Time.TotalMinutes)); + await Response().Confirm(strs.user_chat_mute_time(Format.Bold(user.ToString()), + (int)time.Time.TotalMinutes)).SendAsync(); } catch (Exception ex) { Log.Warning(ex, "Error in chatmute command"); - await ReplyErrorLocalizedAsync(strs.mute_error); + await Response().Error(strs.mute_error).SendAsync(); } } @@ -161,11 +161,11 @@ public partial class Administration try { await _service.UnmuteUser(user.Guild.Id, user.Id, ctx.User, MuteType.Chat, reason); - await ReplyConfirmLocalizedAsync(strs.user_chat_unmute(Format.Bold(user.ToString()))); + await Response().Confirm(strs.user_chat_unmute(Format.Bold(user.ToString()))).SendAsync(); } catch { - await ReplyErrorLocalizedAsync(strs.mute_error); + await Response().Error(strs.mute_error).SendAsync(); } } @@ -181,11 +181,11 @@ public partial class Administration return; await _service.MuteUser(user, ctx.User, MuteType.Voice, reason); - await ReplyConfirmLocalizedAsync(strs.user_voice_mute(Format.Bold(user.ToString()))); + await Response().Confirm(strs.user_voice_mute(Format.Bold(user.ToString()))).SendAsync(); } catch { - await ReplyErrorLocalizedAsync(strs.mute_error); + await Response().Error(strs.mute_error).SendAsync(); } } @@ -203,12 +203,12 @@ public partial class Administration return; await _service.TimedMute(user, ctx.User, time.Time, MuteType.Voice, reason); - await ReplyConfirmLocalizedAsync(strs.user_voice_mute_time(Format.Bold(user.ToString()), - (int)time.Time.TotalMinutes)); + await Response().Confirm(strs.user_voice_mute_time(Format.Bold(user.ToString()), + (int)time.Time.TotalMinutes)).SendAsync(); } catch { - await ReplyErrorLocalizedAsync(strs.mute_error); + await Response().Error(strs.mute_error).SendAsync(); } } @@ -220,11 +220,11 @@ public partial class Administration try { await _service.UnmuteUser(user.GuildId, user.Id, ctx.User, MuteType.Voice, reason); - await ReplyConfirmLocalizedAsync(strs.user_voice_unmute(Format.Bold(user.ToString()))); + await Response().Confirm(strs.user_voice_unmute(Format.Bold(user.ToString()))).SendAsync(); } catch { - await ReplyErrorLocalizedAsync(strs.mute_error); + await Response().Error(strs.mute_error).SendAsync(); } } } diff --git a/src/NadekoBot/Modules/Administration/Mute/MuteService.cs b/src/NadekoBot/Modules/Administration/Mute/MuteService.cs index 8331a7a06..7a5db10d9 100644 --- a/src/NadekoBot/Modules/Administration/Mute/MuteService.cs +++ b/src/NadekoBot/Modules/Administration/Mute/MuteService.cs @@ -122,7 +122,7 @@ public class MuteService : INService if (string.IsNullOrWhiteSpace(reason)) return; - _ = Task.Run(() => user.SendMessageAsync(embed: _eb.Create() + _ = Task.Run(() => user.SendMessageAsync(embed: new EmbedBuilder() .WithDescription( $"You've been muted in {user.Guild} server") .AddField("Mute Type", type.ToString()) @@ -140,7 +140,7 @@ public class MuteService : INService if (string.IsNullOrWhiteSpace(reason)) return; - _ = Task.Run(() => user.SendMessageAsync(embed: _eb.Create() + _ = Task.Run(() => user.SendMessageAsync(embed: new EmbedBuilder() .WithDescription( $"You've been unmuted in {user.Guild} server") .AddField("Unmute Type", type.ToString()) diff --git a/src/NadekoBot/Modules/Administration/PermOverrides/DiscordPermOverrideCommands.cs b/src/NadekoBot/Modules/Administration/PermOverrides/DiscordPermOverrideCommands.cs index 469404715..8d03e22a8 100644 --- a/src/NadekoBot/Modules/Administration/PermOverrides/DiscordPermOverrideCommands.cs +++ b/src/NadekoBot/Modules/Administration/PermOverrides/DiscordPermOverrideCommands.cs @@ -18,15 +18,15 @@ public partial class Administration if (perms is null || perms.Length == 0) { await _service.RemoveOverride(ctx.Guild.Id, cmd.Name); - await ReplyConfirmLocalizedAsync(strs.perm_override_reset); + await Response().Confirm(strs.perm_override_reset).SendAsync(); return; } var aggregatePerms = perms.Aggregate((acc, seed) => seed | acc); await _service.AddOverride(ctx.Guild.Id, cmd.Name, aggregatePerms); - await ReplyConfirmLocalizedAsync(strs.perm_override(Format.Bold(aggregatePerms.ToString()), - Format.Code(cmd.Name))); + await Response().Confirm(strs.perm_override(Format.Bold(aggregatePerms.ToString()), + Format.Code(cmd.Name))).SendAsync(); } [Cmd] @@ -34,7 +34,7 @@ public partial class Administration [UserPerm(GuildPerm.Administrator)] public async Task DiscordPermOverrideReset() { - var result = await PromptUserConfirmAsync(_eb.Create() + var result = await PromptUserConfirmAsync(new EmbedBuilder() .WithOkColor() .WithDescription(GetText(strs.perm_override_all_confirm))); @@ -43,7 +43,7 @@ public partial class Administration await _service.ClearAllOverrides(ctx.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.perm_override_all); + await Response().Confirm(strs.perm_override_all).SendAsync(); } [Cmd] @@ -59,7 +59,7 @@ public partial class Administration await ctx.SendPaginatedConfirmAsync(page, curPage => { - var eb = _eb.Create().WithTitle(GetText(strs.perm_overrides)).WithOkColor(); + var eb = new EmbedBuilder().WithTitle(GetText(strs.perm_overrides)).WithOkColor(); var thisPageOverrides = overrides.Skip(9 * curPage).Take(9).ToList(); diff --git a/src/NadekoBot/Modules/Administration/PlayingRotate/PlayingRotateCommands.cs b/src/NadekoBot/Modules/Administration/PlayingRotate/PlayingRotateCommands.cs index ac9878dde..912e421ce 100644 --- a/src/NadekoBot/Modules/Administration/PlayingRotate/PlayingRotateCommands.cs +++ b/src/NadekoBot/Modules/Administration/PlayingRotate/PlayingRotateCommands.cs @@ -13,9 +13,9 @@ public partial class Administration public async Task RotatePlaying() { if (_service.ToggleRotatePlaying()) - await ReplyConfirmLocalizedAsync(strs.ropl_enabled); + await Response().Confirm(strs.ropl_enabled).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.ropl_disabled); + await Response().Confirm(strs.ropl_disabled).SendAsync(); } [Cmd] @@ -24,7 +24,7 @@ public partial class Administration { await _service.AddPlaying(t, status); - await ReplyConfirmLocalizedAsync(strs.ropl_added); + await Response().Confirm(strs.ropl_added).SendAsync(); } [Cmd] @@ -34,12 +34,14 @@ public partial class Administration var statuses = _service.GetRotatingStatuses(); if (!statuses.Any()) - await ReplyErrorLocalizedAsync(strs.ropl_not_set); + await Response().Error(strs.ropl_not_set).SendAsync(); else { var i = 1; - await ReplyConfirmLocalizedAsync(strs.ropl_list(string.Join("\n\t", - statuses.Select(rs => $"`{i++}.` *{rs.Type}* {rs.Status}")))); + await Response() + .Confirm(strs.ropl_list(string.Join("\n\t", + statuses.Select(rs => $"`{i++}.` *{rs.Type}* {rs.Status}")))) + .SendAsync(); } } @@ -54,7 +56,7 @@ public partial class Administration if (msg is null) return; - await ReplyConfirmLocalizedAsync(strs.reprm(msg)); + await Response().Confirm(strs.reprm(msg)).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Administration/Prefix/PrefixCommands.cs b/src/NadekoBot/Modules/Administration/Prefix/PrefixCommands.cs index b91753f9a..d91017264 100644 --- a/src/NadekoBot/Modules/Administration/Prefix/PrefixCommands.cs +++ b/src/NadekoBot/Modules/Administration/Prefix/PrefixCommands.cs @@ -14,7 +14,7 @@ public partial class Administration [Cmd] [Priority(1)] public async Task Prefix() - => await ReplyConfirmLocalizedAsync(strs.prefix_current(Format.Code(_cmdHandler.GetPrefix(ctx.Guild)))); + => await Response().Confirm(strs.prefix_current(Format.Code(_cmdHandler.GetPrefix(ctx.Guild)))).SendAsync(); [Cmd] [RequireContext(ContextType.Guild)] @@ -35,7 +35,7 @@ public partial class Administration var oldPrefix = prefix; var newPrefix = _cmdHandler.SetPrefix(ctx.Guild, toSet); - await ReplyConfirmLocalizedAsync(strs.prefix_new(Format.Code(oldPrefix), Format.Code(newPrefix))); + await Response().Confirm(strs.prefix_new(Format.Code(oldPrefix), Format.Code(newPrefix))).SendAsync(); } [Cmd] @@ -44,14 +44,14 @@ public partial class Administration { if (string.IsNullOrWhiteSpace(toSet)) { - await ReplyConfirmLocalizedAsync(strs.defprefix_current(_cmdHandler.GetPrefix())); + await Response().Confirm(strs.defprefix_current(_cmdHandler.GetPrefix())).SendAsync(); return; } var oldPrefix = _cmdHandler.GetPrefix(); var newPrefix = _cmdHandler.SetDefaultPrefix(toSet); - await ReplyConfirmLocalizedAsync(strs.defprefix_new(Format.Code(oldPrefix), Format.Code(newPrefix))); + await Response().Confirm(strs.defprefix_new(Format.Code(oldPrefix), Format.Code(newPrefix))).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Administration/Protection/ProtectionCommands.cs b/src/NadekoBot/Modules/Administration/Protection/ProtectionCommands.cs index 961ebdbf0..8c6659fab 100644 --- a/src/NadekoBot/Modules/Administration/Protection/ProtectionCommands.cs +++ b/src/NadekoBot/Modules/Administration/Protection/ProtectionCommands.cs @@ -17,11 +17,11 @@ public partial class Administration { if (await _service.TryStopAntiAlt(ctx.Guild.Id)) { - await ReplyConfirmLocalizedAsync(strs.prot_disable("Anti-Alt")); + await Response().Confirm(strs.prot_disable("Anti-Alt")).SendAsync(); return; } - await ReplyConfirmLocalizedAsync(strs.protection_not_running("Anti-Alt")); + await Response().Confirm(strs.protection_not_running("Anti-Alt")).SendAsync(); } [Cmd] @@ -74,8 +74,8 @@ public partial class Administration public Task AntiRaid() { if (_service.TryStopAntiRaid(ctx.Guild.Id)) - return ReplyConfirmLocalizedAsync(strs.prot_disable("Anti-Raid")); - return ReplyPendingLocalizedAsync(strs.protection_not_running("Anti-Raid")); + return Response().Confirm(strs.prot_disable("Anti-Raid")).SendAsync(); + return Response().Pending(strs.protection_not_running("Anti-Raid")).SendAsync(); } [Cmd] @@ -104,33 +104,33 @@ public partial class Administration { if (action == PunishmentAction.AddRole) { - await ReplyErrorLocalizedAsync(strs.punishment_unsupported(action)); + await Response().Error(strs.punishment_unsupported(action)).SendAsync(); return; } if (userThreshold is < 2 or > 30) { - await ReplyErrorLocalizedAsync(strs.raid_cnt(2, 30)); + await Response().Error(strs.raid_cnt(2, 30)).SendAsync(); return; } if (seconds is < 2 or > 300) { - await ReplyErrorLocalizedAsync(strs.raid_time(2, 300)); + await Response().Error(strs.raid_time(2, 300)).SendAsync(); return; } if (punishTime is not null) { if (!_service.IsDurationAllowed(action)) - await ReplyErrorLocalizedAsync(strs.prot_cant_use_time); + await Response().Error(strs.prot_cant_use_time).SendAsync(); } var time = (int?)punishTime?.Time.TotalMinutes ?? 0; if (time is < 0 or > 60 * 24) return; - - if(action is PunishmentAction.TimeOut && time < 1) + + if (action is PunishmentAction.TimeOut && time < 1) return; var stats = await _service.StartAntiRaidAsync(ctx.Guild.Id, userThreshold, seconds, action, time); @@ -138,8 +138,10 @@ public partial class Administration if (stats is null) return; - await SendConfirmAsync(GetText(strs.prot_enable("Anti-Raid")), - $"{ctx.User.Mention} {GetAntiRaidString(stats)}"); + await Response() + .Confirm(GetText(strs.prot_enable("Anti-Raid")), + $"{ctx.User.Mention} {GetAntiRaidString(stats)}") + .SendAsync(); } [Cmd] @@ -148,8 +150,8 @@ public partial class Administration public Task AntiSpam() { if (_service.TryStopAntiSpam(ctx.Guild.Id)) - return ReplyConfirmLocalizedAsync(strs.prot_disable("Anti-Spam")); - return ReplyPendingLocalizedAsync(strs.protection_not_running("Anti-Spam")); + return Response().Confirm(strs.prot_disable("Anti-Spam")).SendAsync(); + return Response().Pending(strs.protection_not_running("Anti-Spam")).SendAsync(); } [Cmd] @@ -190,7 +192,7 @@ public partial class Administration if (timeData is not null) { if (!_service.IsDurationAllowed(action)) - await ReplyErrorLocalizedAsync(strs.prot_cant_use_time); + await Response().Error(strs.prot_cant_use_time).SendAsync(); } var time = (int?)timeData?.Time.TotalMinutes ?? 0; @@ -202,8 +204,10 @@ public partial class Administration var stats = await _service.StartAntiSpamAsync(ctx.Guild.Id, messageCount, action, time, role?.Id); - await SendConfirmAsync(GetText(strs.prot_enable("Anti-Spam")), - $"{ctx.User.Mention} {GetAntiSpamString(stats)}"); + await Response() + .Confirm(GetText(strs.prot_enable("Anti-Spam")), + $"{ctx.User.Mention} {GetAntiSpamString(stats)}") + .SendAsync(); } [Cmd] @@ -215,14 +219,14 @@ public partial class Administration if (added is null) { - await ReplyErrorLocalizedAsync(strs.protection_not_running("Anti-Spam")); + await Response().Error(strs.protection_not_running("Anti-Spam")).SendAsync(); return; } if (added.Value) - await ReplyConfirmLocalizedAsync(strs.spam_ignore("Anti-Spam")); + await Response().Confirm(strs.spam_ignore("Anti-Spam")).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.spam_not_ignore("Anti-Spam")); + await Response().Confirm(strs.spam_not_ignore("Anti-Spam")).SendAsync(); } [Cmd] @@ -233,11 +237,11 @@ public partial class Administration if (spam is null && raid is null && alt is null) { - await ReplyConfirmLocalizedAsync(strs.prot_none); + await Response().Confirm(strs.prot_none).SendAsync(); return; } - var embed = _eb.Create().WithOkColor().WithTitle(GetText(strs.prot_active)); + var embed = new EmbedBuilder().WithOkColor().WithTitle(GetText(strs.prot_active)); if (spam is not null) embed.AddField("Anti-Spam", GetAntiSpamString(spam).TrimTo(1024), true); @@ -248,7 +252,7 @@ public partial class Administration if (alt is not null) embed.AddField("Anti-Alt", GetAntiAltString(alt), true); - await ctx.Channel.EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } private string GetAntiAltString(AntiAltStats alt) diff --git a/src/NadekoBot/Modules/Administration/Role/ReactionRoleCommands.cs b/src/NadekoBot/Modules/Administration/Role/ReactionRoleCommands.cs index 8a8fc32fc..d82420bc8 100644 --- a/src/NadekoBot/Modules/Administration/Role/ReactionRoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/Role/ReactionRoleCommands.cs @@ -33,13 +33,13 @@ public partial class Administration var msg = await ctx.Channel.GetMessageAsync(messageId); if (msg is null) { - await ReplyErrorLocalizedAsync(strs.not_found); + await Response().Error(strs.not_found).SendAsync(); return; } if (ctx.User.Id != ctx.Guild.OwnerId && ((IGuildUser)ctx.User).GetRoles().Max(x => x.Position) <= role.Position) { - await ReplyErrorLocalizedAsync(strs.hierarchy); + await Response().Error(strs.hierarchy).SendAsync(); return; } @@ -58,8 +58,8 @@ public partial class Administration { _ = msg.RemoveReactionAsync(emote, ctx.Client.CurrentUser); return !fl.IsPatronLimit - ? ReplyErrorLocalizedAsync(strs.limit_reached(fl.Quota)) - : ReplyPendingLocalizedAsync(strs.feature_limit_reached_owner(fl.Quota, fl.Name)); + ? Response().Error(strs.limit_reached(fl.Quota)).SendAsync() + : Response().Pending(strs.feature_limit_reached_owner(fl.Quota, fl.Name)).SendAsync(); }); } @@ -76,7 +76,7 @@ public partial class Administration await ctx.SendPaginatedConfirmAsync(page, curPage => { - var embed = _eb.Create(ctx) + var embed = new EmbedBuilder() .WithOkColor(); var content = string.Empty; diff --git a/src/NadekoBot/Modules/Administration/Role/RoleCommands.cs b/src/NadekoBot/Modules/Administration/Role/RoleCommands.cs index 329f64b5a..b6d9a1200 100644 --- a/src/NadekoBot/Modules/Administration/Role/RoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/Role/RoleCommands.cs @@ -36,13 +36,13 @@ public partial class Administration { await targetUser.AddRoleAsync(roleToAdd); - await ReplyConfirmLocalizedAsync(strs.setrole(Format.Bold(roleToAdd.Name), - Format.Bold(targetUser.ToString()))); + await Response().Confirm(strs.setrole(Format.Bold(roleToAdd.Name), + Format.Bold(targetUser.ToString()))).SendAsync(); } catch (Exception ex) { Log.Warning(ex, "Error in setrole command"); - await ReplyErrorLocalizedAsync(strs.setrole_err); + await Response().Error(strs.setrole_err).SendAsync(); } } @@ -59,12 +59,12 @@ public partial class Administration try { await targetUser.RemoveRoleAsync(roleToRemove); - await ReplyConfirmLocalizedAsync(strs.remrole(Format.Bold(roleToRemove.Name), - Format.Bold(targetUser.ToString()))); + await Response().Confirm(strs.remrole(Format.Bold(roleToRemove.Name), + Format.Bold(targetUser.ToString()))).SendAsync(); } catch { - await ReplyErrorLocalizedAsync(strs.remrole_err); + await Response().Error(strs.remrole_err).SendAsync(); } } @@ -81,16 +81,16 @@ public partial class Administration { if (roleToEdit.Position > (await ctx.Guild.GetCurrentUserAsync()).GetRoles().Max(r => r.Position)) { - await ReplyErrorLocalizedAsync(strs.renrole_perms); + await Response().Error(strs.renrole_perms).SendAsync(); return; } await roleToEdit.ModifyAsync(g => g.Name = newname); - await ReplyConfirmLocalizedAsync(strs.renrole); + await Response().Confirm(strs.renrole).SendAsync(); } catch (Exception) { - await ReplyErrorLocalizedAsync(strs.renrole_err); + await Response().Error(strs.renrole_err).SendAsync(); } } @@ -111,11 +111,11 @@ public partial class Administration try { await user.RemoveRolesAsync(userRoles); - await ReplyConfirmLocalizedAsync(strs.rar(Format.Bold(user.ToString()))); + await Response().Confirm(strs.rar(Format.Bold(user.ToString()))).SendAsync(); } catch (Exception) { - await ReplyErrorLocalizedAsync(strs.rar_err); + await Response().Error(strs.rar_err).SendAsync(); } } @@ -129,7 +129,7 @@ public partial class Administration return; var r = await ctx.Guild.CreateRoleAsync(roleName, isMentionable: false); - await ReplyConfirmLocalizedAsync(strs.cr(Format.Bold(r.Name))); + await Response().Confirm(strs.cr(Format.Bold(r.Name))).SendAsync(); } [Cmd] @@ -143,7 +143,7 @@ public partial class Administration return; await role.DeleteAsync(); - await ReplyConfirmLocalizedAsync(strs.dr(Format.Bold(role.Name))); + await Response().Confirm(strs.dr(Format.Bold(role.Name))).SendAsync(); } [Cmd] @@ -155,16 +155,16 @@ public partial class Administration var newHoisted = !role.IsHoisted; await role.ModifyAsync(r => r.Hoist = newHoisted); if (newHoisted) - await ReplyConfirmLocalizedAsync(strs.rolehoist_enabled(Format.Bold(role.Name))); + await Response().Confirm(strs.rolehoist_enabled(Format.Bold(role.Name))).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.rolehoist_disabled(Format.Bold(role.Name))); + await Response().Confirm(strs.rolehoist_disabled(Format.Bold(role.Name))).SendAsync(); } [Cmd] [RequireContext(ContextType.Guild)] [Priority(1)] public async Task RoleColor([Leftover] IRole role) - => await SendConfirmAsync("Role Color", role.Color.RawValue.ToString("x6")); + => await Response().Confirm("Role Color", role.Color.RawValue.ToString("x6")).SendAsync(); [Cmd] [RequireContext(ContextType.Guild)] @@ -177,11 +177,11 @@ public partial class Administration { var rgba32 = color.ToPixel(); await role.ModifyAsync(r => r.Color = new Discord.Color(rgba32.R, rgba32.G, rgba32.B)); - await ReplyConfirmLocalizedAsync(strs.rc(Format.Bold(role.Name))); + await Response().Confirm(strs.rc(Format.Bold(role.Name))).SendAsync(); } catch (Exception) { - await ReplyErrorLocalizedAsync(strs.rc_perms); + await Response().Error(strs.rc_perms).SendAsync(); } } @@ -195,11 +195,11 @@ public partial class Administration if (newState) { - await ReplyConfirmLocalizedAsync(strs.sticky_roles_enabled); + await Response().Confirm(strs.sticky_roles_enabled).SendAsync(); } else { - await ReplyConfirmLocalizedAsync(strs.sticky_roles_disabled); + await Response().Confirm(strs.sticky_roles_disabled).SendAsync(); } } } diff --git a/src/NadekoBot/Modules/Administration/Self/CheckForUpdatesService.cs b/src/NadekoBot/Modules/Administration/Self/CheckForUpdatesService.cs index 0b6b8387e..e18b10092 100644 --- a/src/NadekoBot/Modules/Administration/Self/CheckForUpdatesService.cs +++ b/src/NadekoBot/Modules/Administration/Self/CheckForUpdatesService.cs @@ -78,7 +78,7 @@ public sealed class CheckForUpdatesService : INService, IReadyExecutor if (user is null) return; - var eb = _ebs.Create() + var eb = new EmbedBuilder() .WithOkColor() .WithAuthor($"NadekoBot v{latestVersion} Released!") .WithTitle("Changelog") diff --git a/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs b/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs index b7508f6e6..9d050b8a1 100644 --- a/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs +++ b/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs @@ -50,22 +50,22 @@ public partial class Administration public async Task CacheUsers(IGuild guild) { var downloadUsersTask = guild.DownloadUsersAsync(); - var message = await ReplyPendingLocalizedAsync(strs.cache_users_pending); + var message = await Response().Pending(strs.cache_users_pending).SendAsync(); using var dbContext = _db.GetDbContext(); await downloadUsersTask; var users = (await guild.GetUsersAsync(CacheMode.CacheOnly)) - .Cast() - .ToList(); + .Cast() + .ToList(); var (added, updated) = await _service.RefreshUsersAsync(users); await message.ModifyAsync(x => - x.Embed = _eb.Create() - .WithDescription(GetText(strs.cache_users_done(added, updated))) - .WithOkColor() - .Build() + x.Embed = new EmbedBuilder() + .WithDescription(GetText(strs.cache_users_done(added, updated))) + .WithOkColor() + .Build() ); } @@ -76,16 +76,17 @@ public partial class Administration if (ctx.User is not IGuildUser { GuildPermissions.Administrator: true }) return; - if (ctx.Guild is SocketGuild sg && ctx.Channel is ISocketMessageChannel ch + if (ctx.Guild is SocketGuild sg + && ctx.Channel is ISocketMessageChannel ch && ctx.Message is SocketUserMessage msg) { var fakeMessage = new DoAsUserMessage(msg, user, message); - + await _cmdHandler.TryRunCommand(sg, ch, fakeMessage); } else { - await ReplyErrorLocalizedAsync(strs.error_occured); + await Response().Error(strs.error_occured).SendAsync(); } } @@ -112,14 +113,14 @@ public partial class Administration }; _service.AddNewAutoCommand(cmd); - await EmbedAsync(_eb.Create() - .WithOkColor() - .WithTitle(GetText(strs.scadd)) - .AddField(GetText(strs.server), - cmd.GuildId is null ? "-" : $"{cmd.GuildName}/{cmd.GuildId}", - true) - .AddField(GetText(strs.channel), $"{cmd.ChannelName}/{cmd.ChannelId}", true) - .AddField(GetText(strs.command_text), cmdText)); + await Response().Embed(new EmbedBuilder() + .WithOkColor() + .WithTitle(GetText(strs.scadd)) + .AddField(GetText(strs.server), + cmd.GuildId is null ? "-" : $"{cmd.GuildName}/{cmd.GuildId}", + true) + .AddField(GetText(strs.channel), $"{cmd.ChannelName}/{cmd.ChannelId}", true) + .AddField(GetText(strs.command_text), cmdText)).SendAsync(); } [Cmd] @@ -148,7 +149,7 @@ public partial class Administration }; _service.AddNewAutoCommand(cmd); - await ReplyConfirmLocalizedAsync(strs.autocmd_add(Format.Code(Format.Sanitize(cmdText)), cmd.Interval)); + await Response().Confirm(strs.autocmd_add(Format.Code(Format.Sanitize(cmdText)), cmd.Interval)).SendAsync(); } [Cmd] @@ -162,18 +163,20 @@ public partial class Administration var scmds = _service.GetStartupCommands().Skip(page * 5).Take(5).ToList(); if (scmds.Count == 0) - await ReplyErrorLocalizedAsync(strs.startcmdlist_none); + await Response().Error(strs.startcmdlist_none).SendAsync(); else { var i = 0; - await SendConfirmAsync(text: string.Join("\n", - scmds.Select(x => $@"```css + await Response() + .Confirm(text: string.Join("\n", + scmds.Select(x => $@"```css #{++i + (page * 5)} [{GetText(strs.server)}]: {(x.GuildId.HasValue ? $"{x.GuildName} #{x.GuildId}" : "-")} [{GetText(strs.channel)}]: {x.ChannelName} #{x.ChannelId} [{GetText(strs.command_text)}]: {x.CommandText}```")), - title: string.Empty, - footer: GetText(strs.page(page + 1))); + title: string.Empty, + footer: GetText(strs.page(page + 1))) + .SendAsync(); } } @@ -187,19 +190,21 @@ public partial class Administration var scmds = _service.GetAutoCommands().Skip(page * 5).Take(5).ToList(); if (!scmds.Any()) - await ReplyErrorLocalizedAsync(strs.autocmdlist_none); + await Response().Error(strs.autocmdlist_none).SendAsync(); else { var i = 0; - await SendConfirmAsync(text: string.Join("\n", - scmds.Select(x => $@"```css + await Response() + .Confirm(text: string.Join("\n", + scmds.Select(x => $@"```css #{++i + (page * 5)} [{GetText(strs.server)}]: {(x.GuildId.HasValue ? $"{x.GuildName} #{x.GuildId}" : "-")} [{GetText(strs.channel)}]: {x.ChannelName} #{x.ChannelId} {GetIntervalText(x.Interval)} [{GetText(strs.command_text)}]: {x.CommandText}```")), - title: string.Empty, - footer: GetText(strs.page(page + 1))); + title: string.Empty, + footer: GetText(strs.page(page + 1))) + .SendAsync(); } } @@ -215,7 +220,7 @@ public partial class Administration ctx.Message.DeleteAfter(0); try { - var msg = await SendConfirmAsync($"⏲ {miliseconds}ms"); + var msg = await Response().Confirm($"⏲ {miliseconds}ms").SendAsync(); msg.DeleteAfter(miliseconds / 1000); } catch { } @@ -231,7 +236,7 @@ public partial class Administration { if (!_service.RemoveAutoCommand(--index, out _)) { - await ReplyErrorLocalizedAsync(strs.acrm_fail); + await Response().Error(strs.acrm_fail).SendAsync(); return; } @@ -244,9 +249,9 @@ public partial class Administration public async Task StartupCommandRemove([Leftover] int index) { if (!_service.RemoveStartupCommand(--index, out _)) - await ReplyErrorLocalizedAsync(strs.scrm_fail); + await Response().Error(strs.scrm_fail).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.scrm); + await Response().Confirm(strs.scrm).SendAsync(); } [Cmd] @@ -257,7 +262,7 @@ public partial class Administration { _service.ClearStartupCommands(); - await ReplyConfirmLocalizedAsync(strs.startcmds_cleared); + await Response().Confirm(strs.startcmds_cleared).SendAsync(); } [Cmd] @@ -267,9 +272,9 @@ public partial class Administration var enabled = _service.ForwardMessages(); if (enabled) - await ReplyConfirmLocalizedAsync(strs.fwdm_start); + await Response().Confirm(strs.fwdm_start).SendAsync(); else - await ReplyPendingLocalizedAsync(strs.fwdm_stop); + await Response().Pending(strs.fwdm_stop).SendAsync(); } [Cmd] @@ -279,9 +284,9 @@ public partial class Administration var enabled = _service.ForwardToAll(); if (enabled) - await ReplyConfirmLocalizedAsync(strs.fwall_start); + await Response().Confirm(strs.fwall_start).SendAsync(); else - await ReplyPendingLocalizedAsync(strs.fwall_stop); + await Response().Pending(strs.fwall_stop).SendAsync(); } [Cmd] @@ -292,9 +297,9 @@ public partial class Administration var enabled = _service.ForwardToChannel(ctx.Channel.Id); if (enabled) - await ReplyConfirmLocalizedAsync(strs.fwch_start); + await Response().Confirm(strs.fwch_start).SendAsync(); else - await ReplyPendingLocalizedAsync(strs.fwch_stop); + await Response().Pending(strs.fwch_stop).SendAsync(); } [Cmd] @@ -331,7 +336,7 @@ public partial class Administration if (string.IsNullOrWhiteSpace(str)) str = GetText(strs.no_shards_on_page); - return _eb.Create().WithOkColor().WithDescription($"{status}\n\n{str}"); + return new EmbedBuilder().WithOkColor().WithDescription($"{status}\n\n{str}"); }, allShardStrings.Length, 25); @@ -355,9 +360,9 @@ public partial class Administration { var success = _coord.RestartShard(shardId); if (success) - await ReplyConfirmLocalizedAsync(strs.shard_reconnecting(Format.Bold("#" + shardId))); + await Response().Confirm(strs.shard_reconnecting(Format.Bold("#" + shardId))).SendAsync(); else - await ReplyErrorLocalizedAsync(strs.no_shard_id); + await Response().Error(strs.no_shard_id).SendAsync(); } [Cmd] @@ -393,7 +398,7 @@ public partial class Administration } } - await ReplyConfirmLocalizedAsync(strs.deleted_x_servers(toLeave.Count)); + await Response().Confirm(strs.deleted_x_servers(toLeave.Count)).SendAsync(); } [Cmd] @@ -403,8 +408,8 @@ public partial class Administration try { await _client.SetStatusAsync(UserStatus.Invisible); - _ = _client.StopAsync(); - await ReplyConfirmLocalizedAsync(strs.shutting_down); + _ = _client.StopAsync(); + await Response().Confirm(strs.shutting_down).SendAsync(); } catch { @@ -422,11 +427,11 @@ public partial class Administration var success = _coord.RestartBot(); if (!success) { - await ReplyErrorLocalizedAsync(strs.restart_fail); + await Response().Error(strs.restart_fail).SendAsync(); return; } - try { await ReplyConfirmLocalizedAsync(strs.restarting); } + try { await Response().Confirm(strs.restarting).SendAsync(); } catch { } } @@ -446,7 +451,7 @@ public partial class Administration Log.Warning("You've been ratelimited. Wait 2 hours to change your name"); } - await ReplyConfirmLocalizedAsync(strs.bot_name(Format.Bold(newName))); + await Response().Confirm(strs.bot_name(Format.Bold(newName))).SendAsync(); } [Cmd] @@ -460,7 +465,7 @@ public partial class Administration var curUser = await ctx.Guild.GetCurrentUserAsync(); await curUser.ModifyAsync(u => u.Nickname = newNick); - await ReplyConfirmLocalizedAsync(strs.bot_nick(Format.Bold(newNick) ?? "-")); + await Response().Confirm(strs.bot_nick(Format.Bold(newNick) ?? "-")).SendAsync(); } [Cmd] @@ -473,13 +478,15 @@ public partial class Administration if (sg.OwnerId == gu.Id || gu.GetRoles().Max(r => r.Position) >= sg.CurrentUser.GetRoles().Max(r => r.Position)) { - await ReplyErrorLocalizedAsync(strs.insuf_perms_i); + await Response().Error(strs.insuf_perms_i).SendAsync(); return; } await gu.ModifyAsync(u => u.Nickname = newNick); - await ReplyConfirmLocalizedAsync(strs.user_nick(Format.Bold(gu.ToString()), Format.Bold(newNick) ?? "-")); + await Response() + .Confirm(strs.user_nick(Format.Bold(gu.ToString()), Format.Bold(newNick) ?? "-")) + .SendAsync(); } [Cmd] @@ -488,7 +495,7 @@ public partial class Administration { await _client.SetStatusAsync(SettableUserStatusToUserStatus(status)); - await ReplyConfirmLocalizedAsync(strs.bot_status(Format.Bold(status.ToString()))); + await Response().Confirm(strs.bot_status(Format.Bold(status.ToString()))).SendAsync(); } [Cmd] @@ -498,9 +505,9 @@ public partial class Administration var success = await _service.SetAvatar(img); if (success) - await ReplyConfirmLocalizedAsync(strs.set_avatar); + await Response().Confirm(strs.set_avatar).SendAsync(); } - + [Cmd] [OwnerOnly] public async Task SetBanner([Leftover] string img = null) @@ -508,7 +515,7 @@ public partial class Administration var success = await _service.SetBanner(img); if (success) - await ReplyConfirmLocalizedAsync(strs.set_banner); + await Response().Confirm(strs.set_banner).SendAsync(); } [Cmd] @@ -520,7 +527,7 @@ public partial class Administration var repCtx = new ReplacementContext(ctx); await _service.SetGameAsync(game is null ? game : await repSvc.ReplaceAsync(game, repCtx), type); - await ReplyConfirmLocalizedAsync(strs.set_game); + await Response().Confirm(strs.set_game).SendAsync(); } [Cmd] @@ -531,7 +538,7 @@ public partial class Administration await _service.SetStreamAsync(name, url); - await ReplyConfirmLocalizedAsync(strs.set_stream); + await Response().Confirm(strs.set_stream).SendAsync(); } [Cmd] @@ -574,11 +581,11 @@ public partial class Administration } else { - await ReplyErrorLocalizedAsync(strs.invalid_format); + await Response().Error(strs.invalid_format).SendAsync(); return; } - await ReplyConfirmLocalizedAsync(strs.message_sent); + await Response().Confirm(strs.message_sent).SendAsync(); } [Cmd] @@ -587,7 +594,7 @@ public partial class Administration { _strings.Reload(); await _medusaLoader.ReloadStrings(); - await ReplyConfirmLocalizedAsync(strs.bot_strings_reloaded); + await Response().Confirm(strs.bot_strings_reloaded).SendAsync(); } [Cmd] diff --git a/src/NadekoBot/Modules/Administration/Self/SelfService.cs b/src/NadekoBot/Modules/Administration/Self/SelfService.cs index 292bdf687..15e200c47 100644 --- a/src/NadekoBot/Modules/Administration/Self/SelfService.cs +++ b/src/NadekoBot/Modules/Administration/Self/SelfService.cs @@ -225,7 +225,7 @@ public sealed class SelfService : IExecNoCommand, IReadyExecutor, INService { try { - await ownerCh.SendConfirmAsync(_eb, title, toSend); + await ownerCh.Response(_strings, _eb).Confirm(title, toSend).SendAsync(); } catch { @@ -238,7 +238,7 @@ public sealed class SelfService : IExecNoCommand, IReadyExecutor, INService try { if (_client.GetChannel(cid) is ITextChannel ch) - await ch.SendConfirmAsync(_eb, title, toSend); + await ch.Response(_strings, _eb).Confirm(title, toSend).SendAsync(); } catch { @@ -252,7 +252,7 @@ public sealed class SelfService : IExecNoCommand, IReadyExecutor, INService { try { - await firstOwnerChannel.SendConfirmAsync(_eb, title, toSend); + await firstOwnerChannel.Response(_strings, _eb).Confirm(title, toSend).SendAsync(); } catch { diff --git a/src/NadekoBot/Modules/Administration/SelfAssignableRoles/SelfAssignedRolesCommands.cs b/src/NadekoBot/Modules/Administration/SelfAssignableRoles/SelfAssignedRolesCommands.cs index c54f37944..d005773a3 100644 --- a/src/NadekoBot/Modules/Administration/SelfAssignableRoles/SelfAssignedRolesCommands.cs +++ b/src/NadekoBot/Modules/Administration/SelfAssignableRoles/SelfAssignedRolesCommands.cs @@ -18,9 +18,9 @@ public partial class Administration var newVal = _service.ToggleAdSarm(ctx.Guild.Id); if (newVal) - await ReplyConfirmLocalizedAsync(strs.adsarm_enable(prefix)); + await Response().Confirm(strs.adsarm_enable(prefix)).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.adsarm_disable(prefix)); + await Response().Confirm(strs.adsarm_disable(prefix)).SendAsync(); } [Cmd] @@ -46,11 +46,12 @@ public partial class Administration if (succ) { - await ReplyConfirmLocalizedAsync(strs.role_added(Format.Bold(role.Name), - Format.Bold(@group.ToString()))); + await Response() + .Confirm(strs.role_added(Format.Bold(role.Name), Format.Bold(group.ToString()))) + .SendAsync(); } else - await ReplyErrorLocalizedAsync(strs.role_in_list(Format.Bold(role.Name))); + await Response().Error(strs.role_in_list(Format.Bold(role.Name))).SendAsync(); } [Cmd] @@ -64,11 +65,12 @@ public partial class Administration if (set) { - await ReplyConfirmLocalizedAsync( - strs.group_name_added(Format.Bold(@group.ToString()), Format.Bold(name))); + await Response() + .Confirm(strs.group_name_added(Format.Bold(group.ToString()), Format.Bold(name))) + .SendAsync(); } else - await ReplyConfirmLocalizedAsync(strs.group_name_removed(Format.Bold(group.ToString()))); + await Response().Confirm(strs.group_name_removed(Format.Bold(group.ToString()))).SendAsync(); } [Cmd] @@ -82,9 +84,9 @@ public partial class Administration var success = _service.RemoveSar(role.Guild.Id, role.Id); if (!success) - await ReplyErrorLocalizedAsync(strs.self_assign_not); + await Response().Error(strs.self_assign_not).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.self_assign_rem(Format.Bold(role.Name))); + await Response().Confirm(strs.self_assign_rem(Format.Bold(role.Name))).SendAsync(); } [Cmd] @@ -133,7 +135,7 @@ public partial class Administration rolesStr.AppendLine(); } - return _eb.Create() + return new EmbedBuilder() .WithOkColor() .WithTitle(Format.Bold(GetText(strs.self_assign_list(roles.Count())))) .WithDescription(rolesStr.ToString()) @@ -153,9 +155,9 @@ public partial class Administration { var areExclusive = _service.ToggleEsar(ctx.Guild.Id); if (areExclusive) - await ReplyConfirmLocalizedAsync(strs.self_assign_excl); + await Response().Confirm(strs.self_assign_excl).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.self_assign_no_excl); + await Response().Confirm(strs.self_assign_no_excl).SendAsync(); } [Cmd] @@ -171,12 +173,14 @@ public partial class Administration if (!succ) { - await ReplyErrorLocalizedAsync(strs.self_assign_not); + await Response().Error(strs.self_assign_not).SendAsync(); return; } - await ReplyConfirmLocalizedAsync(strs.self_assign_level_req(Format.Bold(role.Name), - Format.Bold(level.ToString()))); + await Response() + .Confirm(strs.self_assign_level_req(Format.Bold(role.Name), + Format.Bold(level.ToString()))) + .SendAsync(); } [Cmd] @@ -189,15 +193,15 @@ public partial class Administration IUserMessage msg; if (result == SelfAssignedRolesService.AssignResult.ErrNotAssignable) - msg = await ReplyErrorLocalizedAsync(strs.self_assign_not); + msg = await Response().Error(strs.self_assign_not).SendAsync(); else if (result == SelfAssignedRolesService.AssignResult.ErrLvlReq) - msg = await ReplyErrorLocalizedAsync(strs.self_assign_not_level(Format.Bold(extra.ToString()))); + msg = await Response().Error(strs.self_assign_not_level(Format.Bold(extra.ToString()))).SendAsync(); else if (result == SelfAssignedRolesService.AssignResult.ErrAlreadyHave) - msg = await ReplyErrorLocalizedAsync(strs.self_assign_already(Format.Bold(role.Name))); + msg = await Response().Error(strs.self_assign_already(Format.Bold(role.Name))).SendAsync(); else if (result == SelfAssignedRolesService.AssignResult.ErrNotPerms) - msg = await ReplyErrorLocalizedAsync(strs.self_assign_perms); + msg = await Response().Error(strs.self_assign_perms).SendAsync(); else - msg = await ReplyConfirmLocalizedAsync(strs.self_assign_success(Format.Bold(role.Name))); + msg = await Response().Confirm(strs.self_assign_success(Format.Bold(role.Name))).SendAsync(); if (autoDelete) { @@ -216,13 +220,13 @@ public partial class Administration IUserMessage msg; if (result == SelfAssignedRolesService.RemoveResult.ErrNotAssignable) - msg = await ReplyErrorLocalizedAsync(strs.self_assign_not); + msg = await Response().Error(strs.self_assign_not).SendAsync(); else if (result == SelfAssignedRolesService.RemoveResult.ErrNotHave) - msg = await ReplyErrorLocalizedAsync(strs.self_assign_not_have(Format.Bold(role.Name))); + msg = await Response().Error(strs.self_assign_not_have(Format.Bold(role.Name))).SendAsync(); else if (result == SelfAssignedRolesService.RemoveResult.ErrNotPerms) - msg = await ReplyErrorLocalizedAsync(strs.self_assign_perms); + msg = await Response().Error(strs.self_assign_perms).SendAsync(); else - msg = await ReplyConfirmLocalizedAsync(strs.self_assign_remove(Format.Bold(role.Name))); + msg = await Response().Confirm(strs.self_assign_remove(Format.Bold(role.Name))).SendAsync(); if (autoDelete) { diff --git a/src/NadekoBot/Modules/Administration/ServerLog/ServerLogCommandService.cs b/src/NadekoBot/Modules/Administration/ServerLog/ServerLogCommandService.cs index 428df607c..08c840ad3 100644 --- a/src/NadekoBot/Modules/Administration/ServerLog/ServerLogCommandService.cs +++ b/src/NadekoBot/Modules/Administration/ServerLog/ServerLogCommandService.cs @@ -27,6 +27,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor private readonly ConcurrentHashSet _ignoreMessageIds = new(); private readonly UserPunishService _punishService; + private readonly IMessageSenderService _sender; public LogCommandService( DiscordSocketClient client, @@ -37,7 +38,8 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor GuildTimezoneService tz, IMemoryCache memoryCache, IEmbedBuilderService eb, - UserPunishService punishService) + UserPunishService punishService, + IMessageSenderService sender) { _client = client; _memoryCache = memoryCache; @@ -48,6 +50,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor _prot = prot; _tz = tz; _punishService = punishService; + _sender = sender; using (var uow = db.GetDbContext()) { @@ -165,7 +168,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor var title = GetText(logChannel.Guild, strs.thread_deleted); - await logChannel.EmbedAsync(_eb.Create() + await logChannel.EmbedAsync(new EmbedBuilder() .WithOkColor() .WithTitle("🗑 " + title) .WithDescription($"{ch.Name} | {ch.Id}") @@ -195,7 +198,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor var title = GetText(logChannel.Guild, strs.thread_created); - await logChannel.EmbedAsync(_eb.Create() + await logChannel.EmbedAsync(new EmbedBuilder() .WithOkColor() .WithTitle("🆕 " + title) .WithDescription($"{ch.Name} | {ch.Id}") @@ -229,16 +232,16 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor { var keys = PresenceUpdates.Keys.ToList(); - await keys.Select(key => + await keys.Select(channel => { - if (!((SocketGuild)key.Guild).CurrentUser.GetPermissions(key).SendMessages) + if (!((SocketGuild)channel.Guild).CurrentUser.GetPermissions(channel).SendMessages) return Task.CompletedTask; - if (PresenceUpdates.TryRemove(key, out var msgs)) + if (PresenceUpdates.TryRemove(channel, out var msgs)) { - var title = GetText(key.Guild, strs.presence_updates); + var title = GetText(channel.Guild, strs.presence_updates); var desc = string.Join(Environment.NewLine, msgs); - return key.SendConfirmAsync(_eb, title, desc.TrimTo(2048)!); + return _sender.Response(channel).Confirm(title, desc.TrimTo(2048)!).SendAsync(); } return Task.CompletedTask; @@ -328,7 +331,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor if ((logChannel = await TryGetLogChannel(g, logSetting, LogType.UserWarned)) is null) return; - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle($"⚠️ User Warned") .WithDescription($"<@{arg.UserId}> | {arg.UserId}") @@ -357,7 +360,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor if ((logChannel = await TryGetLogChannel(g, logSetting, LogType.UserUpdated)) is null) return; - var embed = _eb.Create(); + var embed = new EmbedBuilder(); if (before.Username != after.Username) { @@ -542,7 +545,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor break; } - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithAuthor(mutes) .WithTitle($"{usr.Username}#{usr.Discriminator} | {usr.Id}") .WithFooter(CurrentTime(usr.Guild)) @@ -589,7 +592,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor break; } - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithAuthor(mutes) .WithTitle($"{usr.Username}#{usr.Discriminator} | {usr.Id}") .WithFooter($"{CurrentTime(usr.Guild)}") @@ -643,7 +646,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor break; } - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithAuthor($"🛡 Anti-{protection}") .WithTitle(GetText(logChannel.Guild, strs.users) + " " + punishment) .WithDescription(string.Join("\n", users.Select(u => u.ToString()))) @@ -696,7 +699,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor if (logSetting.UserUpdatedId is not null && (logChannel = await TryGetLogChannel(before.Guild, logSetting, LogType.UserUpdated)) is not null) { - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithFooter(CurrentTime(before.Guild)) .WithTitle($"{before.Username}#{before.Discriminator} | {before.Id}"); @@ -767,7 +770,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor if ((logChannel = await TryGetLogChannel(before.Guild, logSetting, LogType.ChannelUpdated)) is null) return; - var embed = _eb.Create().WithOkColor().WithFooter(CurrentTime(before.Guild)); + var embed = new EmbedBuilder().WithOkColor().WithFooter(CurrentTime(before.Guild)); var beforeTextChannel = cbefore as ITextChannel; var afterTextChannel = cafter as ITextChannel; @@ -823,7 +826,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor else title = GetText(logChannel.Guild, strs.text_chan_destroyed); - await logChannel.EmbedAsync(_eb.Create() + await logChannel.EmbedAsync(new EmbedBuilder() .WithOkColor() .WithTitle("🆕 " + title) .WithDescription($"{ch.Name} | {ch.Id}") @@ -859,7 +862,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor else title = GetText(logChannel.Guild, strs.text_chan_created); - await logChannel.EmbedAsync(_eb.Create() + await logChannel.EmbedAsync(new EmbedBuilder() .WithOkColor() .WithTitle("🆕 " + title) .WithDescription($"{ch.Name} | {ch.Id}") @@ -962,7 +965,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor ITextChannel? logChannel; if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserLeft)) is null) return; - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle("❌ " + GetText(logChannel.Guild, strs.user_left)) .WithDescription(usr.ToString()) @@ -995,7 +998,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserJoined)) is null) return; - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle("✅ " + GetText(logChannel.Guild, strs.user_joined)) .WithDescription($"{usr.Mention} `{usr}`") @@ -1036,7 +1039,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor ITextChannel? logChannel; if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserUnbanned)) is null) return; - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle("♻️ " + GetText(logChannel.Guild, strs.user_unbanned)) .WithDescription(usr.ToString()!) @@ -1083,7 +1086,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor { } - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle("🚫 " + GetText(logChannel.Guild, strs.user_banned)) .WithDescription(usr.ToString()!) @@ -1134,7 +1137,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor return; var resolvedMessage = msg.Resolve(TagHandling.FullName); - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle("🗑 " + GetText(logChannel.Guild, strs.msg_del(((ITextChannel)msg.Channel).Name))) @@ -1194,7 +1197,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor || logChannel.Id == after.Channel.Id) return; - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle("📝 " + GetText(logChannel.Guild, diff --git a/src/NadekoBot/Modules/Administration/ServerLog/ServerLogCommands.cs b/src/NadekoBot/Modules/Administration/ServerLog/ServerLogCommands.cs index accc6b06f..e27a00536 100644 --- a/src/NadekoBot/Modules/Administration/ServerLog/ServerLogCommands.cs +++ b/src/NadekoBot/Modules/Administration/ServerLog/ServerLogCommands.cs @@ -17,9 +17,9 @@ public partial class Administration { await _service.LogServer(ctx.Guild.Id, ctx.Channel.Id, action.Value); if (action.Value) - await ReplyConfirmLocalizedAsync(strs.log_all); + await Response().Confirm(strs.log_all).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.log_disabled); + await Response().Confirm(strs.log_disabled).SendAsync(); } [Cmd] @@ -35,7 +35,7 @@ public partial class Administration var usrs = settings?.LogIgnores.Where(x => x.ItemType == IgnoredItemType.User).ToList() ?? new List(); - var eb = _eb.Create(ctx) + var eb = new EmbedBuilder() .WithOkColor() .AddField(GetText(strs.log_ignored_channels), chs.Count == 0 @@ -46,7 +46,7 @@ public partial class Administration ? "-" : string.Join('\n', usrs.Select(x => $"{x.LogItemId} | <@{x.LogItemId}>"))); - await EmbedAsync(eb); + await Response().Embed(eb).SendAsync(); } [Cmd] @@ -59,13 +59,17 @@ public partial class Administration if (!removed) { - await ReplyConfirmLocalizedAsync( - strs.log_ignore_chan(Format.Bold(target.Mention + "(" + target.Id + ")"))); + await Response() + .Confirm( + strs.log_ignore_chan(Format.Bold(target.Mention + "(" + target.Id + ")"))) + .SendAsync(); } else { - await ReplyConfirmLocalizedAsync( - strs.log_not_ignore_chan(Format.Bold(target.Mention + "(" + target.Id + ")"))); + await Response() + .Confirm( + strs.log_not_ignore_chan(Format.Bold(target.Mention + "(" + target.Id + ")"))) + .SendAsync(); } } @@ -79,13 +83,15 @@ public partial class Administration if (!removed) { - await ReplyConfirmLocalizedAsync( - strs.log_ignore_user(Format.Bold(target.Mention + "(" + target.Id + ")"))); + await Response() + .Confirm(strs.log_ignore_user(Format.Bold(target.Mention + "(" + target.Id + ")"))) + .SendAsync(); } else { - await ReplyConfirmLocalizedAsync( - strs.log_not_ignore_user(Format.Bold(target.Mention + "(" + target.Id + ")"))); + await Response() + .Confirm(strs.log_not_ignore_user(Format.Bold(target.Mention + "(" + target.Id + ")"))) + .SendAsync(); } } @@ -106,7 +112,7 @@ public partial class Administration return Format.Bold(x); })); - await SendConfirmAsync(Format.Bold(GetText(strs.log_events)) + "\n" + str); + await Response().Confirm(Format.Bold(GetText(strs.log_events)) + "\n" + str).SendAsync(); } private static ulong? GetLogProperty(LogSetting l, LogType type) @@ -163,9 +169,9 @@ public partial class Administration var val = _service.Log(ctx.Guild.Id, ctx.Channel.Id, type); if (val) - await ReplyConfirmLocalizedAsync(strs.log(Format.Bold(type.ToString()))); + await Response().Confirm(strs.log(Format.Bold(type.ToString()))).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.log_stop(Format.Bold(type.ToString()))); + await Response().Confirm(strs.log_stop(Format.Bold(type.ToString()))).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Administration/Timezone/TimeZoneCommands.cs b/src/NadekoBot/Modules/Administration/Timezone/TimeZoneCommands.cs index 448bc1b7d..0df0ecc80 100644 --- a/src/NadekoBot/Modules/Administration/Timezone/TimeZoneCommands.cs +++ b/src/NadekoBot/Modules/Administration/Timezone/TimeZoneCommands.cs @@ -37,7 +37,7 @@ public partial class Administration await ctx.SendPaginatedConfirmAsync(page, - curPage => _eb.Create() + curPage => new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.timezones_available)) .WithDescription(string.Join("\n", @@ -49,7 +49,7 @@ public partial class Administration [Cmd] [RequireContext(ContextType.Guild)] public async Task Timezone() - => await ReplyConfirmLocalizedAsync(strs.timezone_guild(_service.GetTimeZoneOrUtc(ctx.Guild.Id))); + => await Response().Confirm(strs.timezone_guild(_service.GetTimeZoneOrUtc(ctx.Guild.Id))).SendAsync(); [Cmd] [RequireContext(ContextType.Guild)] @@ -63,13 +63,13 @@ public partial class Administration if (tz is null) { - await ReplyErrorLocalizedAsync(strs.timezone_not_found); + await Response().Error(strs.timezone_not_found).SendAsync(); return; } _service.SetTimeZone(ctx.Guild.Id, tz); - await SendConfirmAsync(tz.ToString()); + await Response().Confirm(tz.ToString()).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Administration/UserPunish/UserPunishCommands.cs b/src/NadekoBot/Modules/Administration/UserPunish/UserPunishCommands.cs index 7f37cc170..3657a869c 100644 --- a/src/NadekoBot/Modules/Administration/UserPunish/UserPunishCommands.cs +++ b/src/NadekoBot/Modules/Administration/UserPunish/UserPunishCommands.cs @@ -38,7 +38,7 @@ public partial class Administration || (ctx.User.Id != ownerId && targetMaxRole >= modMaxRole) || target.Id == ownerId) { - await ReplyErrorLocalizedAsync(strs.hierarchy); + await Response().Error(strs.hierarchy).SendAsync(); return false; } @@ -65,7 +65,7 @@ public partial class Administration var dmFailed = false; try { - await user.EmbedAsync(_eb.Create() + await user.EmbedAsync(new EmbedBuilder() .WithErrorColor() .WithDescription(GetText(strs.warned_on(ctx.Guild.ToString()))) .AddField(GetText(strs.moderator), ctx.User.ToString()) @@ -84,16 +84,16 @@ public partial class Administration catch (Exception ex) { Log.Warning(ex, "Exception occured while warning a user"); - var errorEmbed = _eb.Create().WithErrorColor().WithDescription(GetText(strs.cant_apply_punishment)); + var errorEmbed = new EmbedBuilder().WithErrorColor().WithDescription(GetText(strs.cant_apply_punishment)); if (dmFailed) errorEmbed.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user)); - await ctx.Channel.EmbedAsync(errorEmbed); + await Response().Embed(errorEmbed).SendAsync(); return; } - var embed = _eb.Create().WithOkColor(); + var embed = new EmbedBuilder().WithOkColor(); if (punishment is null) embed.WithDescription(GetText(strs.user_warned(Format.Bold(user.ToString())))); else @@ -105,7 +105,7 @@ public partial class Administration if (dmFailed) embed.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user)); - await ctx.Channel.EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -118,9 +118,9 @@ public partial class Administration var expireDays = await _service.GetWarnExpire(ctx.Guild.Id); if (expireDays == 0) - await ReplyConfirmLocalizedAsync(strs.warns_dont_expire); + await Response().Confirm(strs.warns_dont_expire).SendAsync(); else - await ReplyErrorLocalizedAsync(strs.warns_expire_in(expireDays)); + await Response().Error(strs.warns_expire_in(expireDays)).SendAsync(); } [Cmd] @@ -140,14 +140,14 @@ public partial class Administration await _service.WarnExpireAsync(ctx.Guild.Id, days, opts.Delete); if (days == 0) { - await ReplyConfirmLocalizedAsync(strs.warn_expire_reset); + await Response().Confirm(strs.warn_expire_reset).SendAsync(); return; } if (opts.Delete) - await ReplyConfirmLocalizedAsync(strs.warn_expire_set_delete(Format.Bold(days.ToString()))); + await Response().Confirm(strs.warn_expire_set_delete(Format.Bold(days.ToString()))).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.warn_expire_set_clear(Format.Bold(days.ToString()))); + await Response().Confirm(strs.warn_expire_set_clear(Format.Bold(days.ToString()))).SendAsync(); } [Cmd] @@ -200,7 +200,7 @@ public partial class Administration var warnings = allWarnings.Skip(page * 9).Take(9).ToArray(); var user = (ctx.Guild as SocketGuild)?.GetUser(userId)?.ToString() ?? userId.ToString(); - var embed = _eb.Create().WithOkColor().WithTitle(GetText(strs.warnlog_for(user))); + var embed = new EmbedBuilder().WithOkColor().WithTitle(GetText(strs.warnlog_for(user))); if (!warnings.Any()) embed.WithDescription(GetText(strs.warnings_none)); @@ -260,7 +260,7 @@ public partial class Administration + $" | {total} ({all} - {forgiven})"; }); - return _eb.Create() + return new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.warnings_list)) .WithDescription(string.Join("\n", ws)); @@ -285,13 +285,13 @@ public partial class Administration var success = await _service.WarnClearAsync(ctx.Guild.Id, userId, index, ctx.User.ToString()); var userStr = Format.Bold((ctx.Guild as SocketGuild)?.GetUser(userId)?.ToString() ?? userId.ToString()); if (index == 0) - await ReplyErrorLocalizedAsync(strs.warnings_cleared(userStr)); + await Response().Error(strs.warnings_cleared(userStr)).SendAsync(); else { if (success) - await ReplyConfirmLocalizedAsync(strs.warning_cleared(Format.Bold(index.ToString()), userStr)); + await Response().Confirm(strs.warning_cleared(Format.Bold(index.ToString()), userStr)).SendAsync(); else - await ReplyErrorLocalizedAsync(strs.warning_clear_fail); + await Response().Error(strs.warning_clear_fail).SendAsync(); } } @@ -310,7 +310,7 @@ public partial class Administration if (ctx.Guild.OwnerId != ctx.User.Id && role.Position >= ((IGuildUser)ctx.User).GetRoles().Max(x => x.Position)) { - await ReplyErrorLocalizedAsync(strs.role_too_high); + await Response().Error(strs.role_too_high).SendAsync(); return; } @@ -321,14 +321,18 @@ public partial class Administration if (time is null) { - await ReplyConfirmLocalizedAsync(strs.warn_punish_set(Format.Bold(punish.ToString()), - Format.Bold(number.ToString()))); + await Response() + .Confirm(strs.warn_punish_set(Format.Bold(punish.ToString()), + Format.Bold(number.ToString()))) + .SendAsync(); } else { - await ReplyConfirmLocalizedAsync(strs.warn_punish_set_timed(Format.Bold(punish.ToString()), - Format.Bold(number.ToString()), - Format.Bold(time.Input))); + await Response() + .Confirm(strs.warn_punish_set_timed(Format.Bold(punish.ToString()), + Format.Bold(number.ToString()), + Format.Bold(time.Input))) + .SendAsync(); } } @@ -353,14 +357,18 @@ public partial class Administration if (time is null) { - await ReplyConfirmLocalizedAsync(strs.warn_punish_set(Format.Bold(punish.ToString()), - Format.Bold(number.ToString()))); + await Response() + .Confirm(strs.warn_punish_set(Format.Bold(punish.ToString()), + Format.Bold(number.ToString()))) + .SendAsync(); } else { - await ReplyConfirmLocalizedAsync(strs.warn_punish_set_timed(Format.Bold(punish.ToString()), - Format.Bold(number.ToString()), - Format.Bold(time.Input))); + await Response() + .Confirm(strs.warn_punish_set_timed(Format.Bold(punish.ToString()), + Format.Bold(number.ToString()), + Format.Bold(time.Input))) + .SendAsync(); } } @@ -372,7 +380,7 @@ public partial class Administration if (!_service.WarnPunishRemove(ctx.Guild.Id, number)) return; - await ReplyConfirmLocalizedAsync(strs.warn_punish_rem(Format.Bold(number.ToString()))); + await Response().Confirm(strs.warn_punish_rem(Format.Bold(number.ToString()))).SendAsync(); } [Cmd] @@ -391,7 +399,7 @@ public partial class Administration else list = GetText(strs.warnpl_none); - await SendConfirmAsync(GetText(strs.warn_punish_list), list); + await Response().Confirm(GetText(strs.warn_punish_list), list).SendAsync(); } [Cmd] @@ -401,7 +409,7 @@ public partial class Administration [Priority(1)] public Task Ban(StoopidTime time, IUser user, [Leftover] string msg = null) => Ban(time, user.Id, msg); - + [Cmd] [RequireContext(ContextType.Guild)] [UserPerm(GuildPerm.BanMembers)] @@ -413,7 +421,7 @@ public partial class Administration return; var guildUser = await ((DiscordSocketClient)Context.Client).Rest.GetGuildUserAsync(ctx.Guild.Id, userId); - + if (guildUser is not null && !await CheckRoleHierarchy(guildUser)) return; @@ -438,10 +446,10 @@ public partial class Administration var user = await ctx.Client.GetUserAsync(userId); var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7; await _mute.TimedBan(ctx.Guild, userId, time.Time, (ctx.User + " | " + msg).TrimTo(512), banPrune); - var toSend = _eb.Create() + var toSend = new EmbedBuilder() .WithOkColor() .WithTitle("⛔️ " + GetText(strs.banned_user)) - .AddField(GetText(strs.username), user?.ToString() ?? userId.ToString(), true) + .AddField(GetText(strs.username), user?.ToString() ?? userId.ToString(), true) .AddField("ID", userId.ToString(), true) .AddField(GetText(strs.duration), time.Time.Humanize(3, minUnit: TimeUnit.Minute, culture: Culture), @@ -450,7 +458,7 @@ public partial class Administration if (dmFailed) toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user)); - await ctx.Channel.EmbedAsync(toSend); + await Response().Embed(toSend).SendAsync(); } [Cmd] @@ -466,7 +474,7 @@ public partial class Administration var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7; await ctx.Guild.AddBanAsync(userId, banPrune, (ctx.User + " | " + msg).TrimTo(512)); - await ctx.Channel.EmbedAsync(_eb.Create() + await ctx.Channel.EmbedAsync(new EmbedBuilder() .WithOkColor() .WithTitle("⛔️ " + GetText(strs.banned_user)) .AddField("ID", userId.ToString(), true)); @@ -502,7 +510,7 @@ public partial class Administration var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7; await ctx.Guild.AddBanAsync(user, banPrune, (ctx.User + " | " + msg).TrimTo(512)); - var toSend = _eb.Create() + var toSend = new EmbedBuilder() .WithOkColor() .WithTitle("⛔️ " + GetText(strs.banned_user)) .AddField(GetText(strs.username), user.ToString(), true) @@ -511,7 +519,7 @@ public partial class Administration if (dmFailed) toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user)); - await ctx.Channel.EmbedAsync(toSend); + await Response().Embed(toSend).SendAsync(); } [Cmd] @@ -522,16 +530,16 @@ public partial class Administration { if (days < 0 || days > 7) { - await ReplyErrorLocalizedAsync(strs.invalid_input); + await Response().Error(strs.invalid_input).SendAsync(); return; } - + await _service.SetBanPruneAsync(ctx.Guild.Id, days); - + if (days == 0) - await ReplyConfirmLocalizedAsync(strs.ban_prune_disabled); + await Response().Confirm(strs.ban_prune_disabled).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.ban_prune(days)); + await Response().Confirm(strs.ban_prune(days)).SendAsync(); } [Cmd] @@ -545,11 +553,11 @@ public partial class Administration var template = _service.GetBanTemplate(ctx.Guild.Id); if (template is null) { - await ReplyConfirmLocalizedAsync(strs.banmsg_default); + await Response().Confirm(strs.banmsg_default).SendAsync(); return; } - await SendConfirmAsync(template); + await Response().Confirm(template).SendAsync(); return; } @@ -586,10 +594,14 @@ public partial class Administration private async Task InternalBanMessageTest(string reason, TimeSpan? duration) { var defaultMessage = GetText(strs.bandm(Format.Bold(ctx.Guild.Name), reason)); - var embed = await _service.GetBanUserDmEmbed(Context, (IGuildUser)ctx.User, defaultMessage, reason, duration); + var embed = await _service.GetBanUserDmEmbed(Context, + (IGuildUser)ctx.User, + defaultMessage, + reason, + duration); if (embed is null) - await ConfirmLocalizedAsync(strs.banmsg_disabled); + await Response().Confirm(strs.banmsg_disabled).SendAsync(); else { try @@ -598,7 +610,7 @@ public partial class Administration } catch (Exception) { - await ReplyErrorLocalizedAsync(strs.unable_to_dm_user); + await Response().Error(strs.unable_to_dm_user).SendAsync(); return; } @@ -618,7 +630,7 @@ public partial class Administration if (bun is null) { - await ReplyErrorLocalizedAsync(strs.user_not_found); + await Response().Error(strs.user_not_found).SendAsync(); return; } @@ -635,7 +647,7 @@ public partial class Administration if (bun is null) { - await ReplyErrorLocalizedAsync(strs.user_not_found); + await Response().Error(strs.user_not_found).SendAsync(); return; } @@ -646,7 +658,7 @@ public partial class Administration { await ctx.Guild.RemoveBanAsync(user); - await ReplyConfirmLocalizedAsync(strs.unbanned_user(Format.Bold(user.ToString()))); + await Response().Confirm(strs.unbanned_user(Format.Bold(user.ToString()))).SendAsync(); } [Cmd] @@ -678,7 +690,10 @@ public partial class Administration try { - await user.SendErrorAsync(_eb, GetText(strs.sbdm(Format.Bold(ctx.Guild.Name), msg))); + await Response() + .Channel(await user.CreateDMChannelAsync()) + .Error(GetText(strs.sbdm(Format.Bold(ctx.Guild.Name), msg))) + .SendAsync(); } catch { @@ -690,7 +705,7 @@ public partial class Administration try { await ctx.Guild.RemoveBanAsync(user); } catch { await ctx.Guild.RemoveBanAsync(user); } - var toSend = _eb.Create() + var toSend = new EmbedBuilder() .WithOkColor() .WithTitle("☣ " + GetText(strs.sb_user)) .AddField(GetText(strs.username), user.ToString(), true) @@ -699,7 +714,7 @@ public partial class Administration if (dmFailed) toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user)); - await ctx.Channel.EmbedAsync(toSend); + await Response().Embed(toSend).SendAsync(); } [Cmd] @@ -733,7 +748,10 @@ public partial class Administration try { - await user.SendErrorAsync(_eb, GetText(strs.kickdm(Format.Bold(ctx.Guild.Name), msg))); + await Response() + .Channel(await user.CreateDMChannelAsync()) + .Error(GetText(strs.kickdm(Format.Bold(ctx.Guild.Name), msg))) + .SendAsync(); } catch { @@ -742,7 +760,7 @@ public partial class Administration await user.KickAsync((ctx.User + " | " + msg).TrimTo(512)); - var toSend = _eb.Create() + var toSend = new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.kicked_user)) .AddField(GetText(strs.username), user.ToString(), true) @@ -751,21 +769,21 @@ public partial class Administration if (dmFailed) toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user)); - await ctx.Channel.EmbedAsync(toSend); + await Response().Embed(toSend).SendAsync(); } - + [Cmd] [RequireContext(ContextType.Guild)] [UserPerm(GuildPerm.ModerateMembers)] [BotPerm(GuildPerm.ModerateMembers)] [Priority(2)] - public async Task Timeout(IUser globalUser, StoopidTime time, [Leftover] string msg = null) + public async Task Timeout(IUser globalUser, StoopidTime time, [Leftover] string msg = null) { var user = await ctx.Guild.GetUserAsync(globalUser.Id); if (user is null) return; - + if (!await CheckRoleHierarchy(user)) return; @@ -774,27 +792,27 @@ public partial class Administration try { var dmMessage = GetText(strs.timeoutdm(Format.Bold(ctx.Guild.Name), msg)); - await user.EmbedAsync(_eb.Create(ctx) - .WithPendingColor() - .WithDescription(dmMessage)); + await user.EmbedAsync(new EmbedBuilder() + .WithPendingColor() + .WithDescription(dmMessage)); } catch { dmFailed = true; } - + await user.SetTimeOutAsync(time.Time); - var toSend = _eb.Create() - .WithOkColor() - .WithTitle("⏳ " + GetText(strs.timedout_user)) - .AddField(GetText(strs.username), user.ToString(), true) - .AddField("ID", user.Id.ToString(), true); + var toSend = new EmbedBuilder() + .WithOkColor() + .WithTitle("⏳ " + GetText(strs.timedout_user)) + .AddField(GetText(strs.username), user.ToString(), true) + .AddField("ID", user.Id.ToString(), true); if (dmFailed) toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user)); - await ctx.Channel.EmbedAsync(toSend); + await Response().Embed(toSend).SendAsync(); } [Cmd] @@ -846,12 +864,12 @@ public partial class Administration if (string.IsNullOrWhiteSpace(missStr)) missStr = "-"; - var toSend = _eb.Create(ctx) + var toSend = new EmbedBuilder() .WithDescription(GetText(strs.mass_ban_in_progress(banning.Count))) .AddField(GetText(strs.invalid(missing.Count)), missStr) .WithPendingColor(); - var banningMessage = await ctx.Channel.EmbedAsync(toSend); + var banningMessage = await Response().Embed(toSend).SendAsync(); var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7; foreach (var toBan in banning) @@ -866,7 +884,7 @@ public partial class Administration } } - await banningMessage.ModifyAsync(x => x.Embed = _eb.Create() + await banningMessage.ModifyAsync(x => x.Embed = new EmbedBuilder() .WithDescription( GetText(strs.mass_ban_completed(banning.Count()))) .AddField(GetText(strs.invalid(missing.Count)), missStr) @@ -891,7 +909,7 @@ public partial class Administration missStr = "-"; //send a message but don't wait for it - var banningMessageTask = ctx.Channel.EmbedAsync(_eb.Create() + var banningMessageTask = ctx.Channel.EmbedAsync(new EmbedBuilder() .WithDescription( GetText(strs.mass_kill_in_progress(bans.Count()))) .AddField(GetText(strs.invalid(missing)), missStr) @@ -911,7 +929,7 @@ public partial class Administration //wait for the message and edit it var banningMessage = await banningMessageTask; - await banningMessage.ModifyAsync(x => x.Embed = _eb.Create() + await banningMessage.ModifyAsync(x => x.Embed = new EmbedBuilder() .WithDescription( GetText(strs.mass_kill_completed(bans.Count()))) .AddField(GetText(strs.invalid(missing)), missStr) diff --git a/src/NadekoBot/Modules/Administration/VcRole/VcRoleCommands.cs b/src/NadekoBot/Modules/Administration/VcRole/VcRoleCommands.cs index b0e5dfeab..84e658d7e 100644 --- a/src/NadekoBot/Modules/Administration/VcRole/VcRoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/VcRole/VcRoleCommands.cs @@ -15,9 +15,9 @@ public partial class Administration public async Task VcRoleRm(ulong vcId) { if (_service.RemoveVcRole(ctx.Guild.Id, vcId)) - await ReplyConfirmLocalizedAsync(strs.vcrole_removed(Format.Bold(vcId.ToString()))); + await Response().Confirm(strs.vcrole_removed(Format.Bold(vcId.ToString()))).SendAsync(); else - await ReplyErrorLocalizedAsync(strs.vcrole_not_found); + await Response().Error(strs.vcrole_not_found).SendAsync(); } [Cmd] @@ -32,19 +32,19 @@ public partial class Administration if (vc is null || vc.GuildId != user.GuildId) { - await ReplyErrorLocalizedAsync(strs.must_be_in_voice); + await Response().Error(strs.must_be_in_voice).SendAsync(); return; } if (role is null) { if (_service.RemoveVcRole(ctx.Guild.Id, vc.Id)) - await ReplyConfirmLocalizedAsync(strs.vcrole_removed(Format.Bold(vc.Name))); + await Response().Confirm(strs.vcrole_removed(Format.Bold(vc.Name))).SendAsync(); } else { _service.AddVcRole(ctx.Guild.Id, role, vc.Id); - await ReplyConfirmLocalizedAsync(strs.vcrole_added(Format.Bold(vc.Name), Format.Bold(role.Name))); + await Response().Confirm(strs.vcrole_added(Format.Bold(vc.Name), Format.Bold(role.Name))).SendAsync(); } } @@ -68,10 +68,10 @@ public partial class Administration else text = GetText(strs.no_vcroles); - await EmbedAsync(_eb.Create() + await Response().Embed(new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.vc_role_list)) - .WithDescription(text)); + .WithDescription(text)).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Expressions/NadekoExpressions.cs b/src/NadekoBot/Modules/Expressions/NadekoExpressions.cs index 26aadc5c8..9a5f9ee1f 100644 --- a/src/NadekoBot/Modules/Expressions/NadekoExpressions.cs +++ b/src/NadekoBot/Modules/Expressions/NadekoExpressions.cs @@ -32,13 +32,13 @@ public partial class NadekoExpressions : NadekoModule var ex = await _service.AddAsync(ctx.Guild?.Id, key, message); - await EmbedAsync(_eb.Create() - .WithOkColor() - .WithTitle(GetText(strs.expr_new)) - .WithDescription($"#{new kwum(ex.Id)}") - .AddField(GetText(strs.trigger), key) - .AddField(GetText(strs.response), - message.Length > 1024 ? GetText(strs.redacted_too_long) : message)); + await Response().Embed(new EmbedBuilder() + .WithOkColor() + .WithTitle(GetText(strs.expr_new)) + .WithDescription($"#{new kwum(ex.Id)}") + .AddField(GetText(strs.trigger), key) + .AddField(GetText(strs.response), + message.Length > 1024 ? GetText(strs.redacted_too_long) : message)).SendAsync(); } [Cmd] @@ -47,11 +47,11 @@ public partial class NadekoExpressions : NadekoModule { var result = await _service.ToggleGlobalExpressionsAsync(ctx.Guild.Id); if (result) - await ReplyConfirmLocalizedAsync(strs.expr_global_disabled); + await Response().Confirm(strs.expr_global_disabled).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.expr_global_enabled); + await Response().Confirm(strs.expr_global_enabled).SendAsync(); } - + [Cmd] [UserPerm(GuildPerm.Administrator)] public async Task ExprAddServer(string key, [Leftover] string message) @@ -74,7 +74,7 @@ public partial class NadekoExpressions : NadekoModule if (!AdminInGuildOrOwnerInDm()) { - await ReplyErrorLocalizedAsync(strs.expr_insuff_perms); + await Response().Error(strs.expr_insuff_perms).SendAsync(); return; } @@ -93,14 +93,14 @@ public partial class NadekoExpressions : NadekoModule if ((channel is null && !_creds.IsOwner(ctx.User)) || (channel is not null && !((IGuildUser)ctx.User).GuildPermissions.Administrator)) { - await ReplyErrorLocalizedAsync(strs.expr_insuff_perms); + await Response().Error(strs.expr_insuff_perms).SendAsync(); return; } var ex = await _service.EditAsync(ctx.Guild?.Id, id, message); if (ex is not null) { - await ctx.Channel.EmbedAsync(_eb.Create() + await ctx.Channel.EmbedAsync(new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.expr_edited)) .WithDescription($"#{id}") @@ -110,7 +110,7 @@ public partial class NadekoExpressions : NadekoModule } else { - await ReplyErrorLocalizedAsync(strs.expr_no_found_id); + await Response().Error(strs.expr_no_found_id).SendAsync(); } } @@ -127,7 +127,7 @@ public partial class NadekoExpressions : NadekoModule if (expressions is null || !expressions.Any()) { - await ReplyErrorLocalizedAsync(strs.expr_no_found); + await Response().Error(strs.expr_no_found).SendAsync(); return; } @@ -146,7 +146,7 @@ public partial class NadekoExpressions : NadekoModule : " // " + string.Join(" ", ex.GetReactions()))) .Join('\n'); - return _eb.Create().WithOkColor().WithTitle(GetText(strs.expressions)).WithDescription(desc); + return new EmbedBuilder().WithOkColor().WithTitle(GetText(strs.expressions)).WithDescription(desc); }, expressions.Length, 20); @@ -159,11 +159,11 @@ public partial class NadekoExpressions : NadekoModule if (found is null) { - await ReplyErrorLocalizedAsync(strs.expr_no_found_id); + await Response().Error(strs.expr_no_found_id).SendAsync(); return; } - await ctx.Channel.EmbedAsync(_eb.Create() + await ctx.Channel.EmbedAsync(new EmbedBuilder() .WithOkColor() .WithDescription($"#{id}") .AddField(GetText(strs.trigger), found.Trigger.TrimTo(1024)) @@ -177,7 +177,7 @@ public partial class NadekoExpressions : NadekoModule if (ex is not null) { - await ctx.Channel.EmbedAsync(_eb.Create() + await ctx.Channel.EmbedAsync(new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.expr_deleted)) .WithDescription($"#{id}") @@ -186,7 +186,7 @@ public partial class NadekoExpressions : NadekoModule } else { - await ReplyErrorLocalizedAsync(strs.expr_no_found_id); + await Response().Error(strs.expr_no_found_id).SendAsync(); } } @@ -201,7 +201,7 @@ public partial class NadekoExpressions : NadekoModule { if (!AdminInGuildOrOwnerInDm()) { - await ReplyErrorLocalizedAsync(strs.expr_insuff_perms); + await Response().Error(strs.expr_insuff_perms).SendAsync(); return; } @@ -213,21 +213,21 @@ public partial class NadekoExpressions : NadekoModule { if (!AdminInGuildOrOwnerInDm()) { - await ReplyErrorLocalizedAsync(strs.expr_insuff_perms); + await Response().Error(strs.expr_insuff_perms).SendAsync(); return; } var ex = _service.GetExpression(ctx.Guild?.Id, id); if (ex is null) { - await ReplyErrorLocalizedAsync(strs.expr_no_found_id); + await Response().Error(strs.expr_no_found_id).SendAsync(); return; } if (emojiStrs.Length == 0) { await _service.ResetExprReactions(ctx.Guild?.Id, id); - await ReplyConfirmLocalizedAsync(strs.expr_reset(Format.Bold(id.ToString()))); + await Response().Confirm(strs.expr_reset(Format.Bold(id.ToString()))).SendAsync(); return; } @@ -253,15 +253,17 @@ public partial class NadekoExpressions : NadekoModule if (succ.Count == 0) { - await ReplyErrorLocalizedAsync(strs.invalid_emojis); + await Response().Error(strs.invalid_emojis).SendAsync(); return; } await _service.SetExprReactions(ctx.Guild?.Id, id, succ); - await ReplyConfirmLocalizedAsync(strs.expr_set(Format.Bold(id.ToString()), - succ.Select(static x => x.ToString()).Join(", "))); + await Response() + .Confirm(strs.expr_set(Format.Bold(id.ToString()), + succ.Select(static x => x.ToString()).Join(", "))) + .SendAsync(); } [Cmd] @@ -293,26 +295,30 @@ public partial class NadekoExpressions : NadekoModule { if (!AdminInGuildOrOwnerInDm()) { - await ReplyErrorLocalizedAsync(strs.expr_insuff_perms); + await Response().Error(strs.expr_insuff_perms).SendAsync(); return; } var (success, newVal) = await _service.ToggleExprOptionAsync(ctx.Guild?.Id, id, option); if (!success) { - await ReplyErrorLocalizedAsync(strs.expr_no_found_id); + await Response().Error(strs.expr_no_found_id).SendAsync(); return; } if (newVal) { - await ReplyConfirmLocalizedAsync(strs.option_enabled(Format.Code(option.ToString()), - Format.Code(id.ToString()))); + await Response() + .Confirm(strs.option_enabled(Format.Code(option.ToString()), + Format.Code(id.ToString()))) + .SendAsync(); } else { - await ReplyConfirmLocalizedAsync(strs.option_disabled(Format.Code(option.ToString()), - Format.Code(id.ToString()))); + await Response() + .Confirm(strs.option_disabled(Format.Code(option.ToString()), + Format.Code(id.ToString()))) + .SendAsync(); } } @@ -321,12 +327,12 @@ public partial class NadekoExpressions : NadekoModule [UserPerm(GuildPerm.Administrator)] public async Task ExprClear() { - if (await PromptUserConfirmAsync(_eb.Create() + if (await PromptUserConfirmAsync(new EmbedBuilder() .WithTitle("Expression clear") .WithDescription("This will delete all expressions on this server."))) { var count = _service.DeleteAllExpressions(ctx.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.exprs_cleared(count)); + await Response().Confirm(strs.exprs_cleared(count)).SendAsync(); } } @@ -335,7 +341,7 @@ public partial class NadekoExpressions : NadekoModule { if (!AdminInGuildOrOwnerInDm()) { - await ReplyErrorLocalizedAsync(strs.expr_insuff_perms); + await Response().Error(strs.expr_insuff_perms).SendAsync(); return; } @@ -354,7 +360,7 @@ public partial class NadekoExpressions : NadekoModule { if (!AdminInGuildOrOwnerInDm()) { - await ReplyErrorLocalizedAsync(strs.expr_insuff_perms); + await Response().Error(strs.expr_insuff_perms).SendAsync(); return; } @@ -367,7 +373,7 @@ public partial class NadekoExpressions : NadekoModule var attachment = ctx.Message.Attachments.FirstOrDefault(); if (attachment is null) { - await ReplyErrorLocalizedAsync(strs.expr_import_no_input); + await Response().Error(strs.expr_import_no_input).SendAsync(); return; } @@ -376,7 +382,7 @@ public partial class NadekoExpressions : NadekoModule if (string.IsNullOrWhiteSpace(input)) { - await ReplyErrorLocalizedAsync(strs.expr_import_no_input); + await Response().Error(strs.expr_import_no_input).SendAsync(); return; } } @@ -384,7 +390,7 @@ public partial class NadekoExpressions : NadekoModule var succ = await _service.ImportExpressionsAsync(ctx.Guild?.Id, input); if (!succ) { - await ReplyErrorLocalizedAsync(strs.expr_import_invalid_data); + await Response().Error(strs.expr_import_invalid_data).SendAsync(); return; } diff --git a/src/NadekoBot/Modules/Expressions/NadekoExpressionsService.cs b/src/NadekoBot/Modules/Expressions/NadekoExpressionsService.cs index 85ef31e0e..d81da7bd4 100644 --- a/src/NadekoBot/Modules/Expressions/NadekoExpressionsService.cs +++ b/src/NadekoBot/Modules/Expressions/NadekoExpressionsService.cs @@ -33,14 +33,14 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor """; private static readonly ISerializer _exportSerializer = new SerializerBuilder() - .WithEventEmitter(args - => new MultilineScalarFlowStyleEmitter(args)) - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .WithIndentedSequences() - .ConfigureDefaultValuesHandling(DefaultValuesHandling - .OmitDefaults) - .DisableAliases() - .Build(); + .WithEventEmitter(args + => new MultilineScalarFlowStyleEmitter(args)) + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .WithIndentedSequences() + .ConfigureDefaultValuesHandling(DefaultValuesHandling + .OmitDefaults) + .DisableAliases() + .Build(); public int Priority => 0; @@ -112,36 +112,39 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor private async Task ReloadInternal(IReadOnlyList allGuildIds) { await using var uow = _db.GetDbContext(); - var guildItems = await uow.Set().AsNoTracking() - .Where(x => allGuildIds.Contains(x.GuildId.Value)) - .ToListAsync(); + var guildItems = await uow.Set() + .AsNoTracking() + .Where(x => allGuildIds.Contains(x.GuildId.Value)) + .ToListAsync(); newguildExpressions = guildItems.GroupBy(k => k.GuildId!.Value) - .ToDictionary(g => g.Key, - g => g.Select(x => - { - x.Trigger = x.Trigger.Replace(MENTION_PH, _client.CurrentUser.Mention); - return x; - }) - .ToArray()) - .ToConcurrent(); + .ToDictionary(g => g.Key, + g => g.Select(x => + { + x.Trigger = x.Trigger.Replace(MENTION_PH, + _client.CurrentUser.Mention); + return x; + }) + .ToArray()) + .ToConcurrent(); _disabledGlobalExpressionGuilds = new(await uow.Set() - .Where(x => x.DisableGlobalExpressions) - .Select(x => x.GuildId) - .ToListAsyncLinqToDB()); + .Where(x => x.DisableGlobalExpressions) + .Select(x => x.GuildId) + .ToListAsyncLinqToDB()); lock (_gexprWriteLock) { - var globalItems = uow.Set().AsNoTracking() - .Where(x => x.GuildId == null || x.GuildId == 0) - .AsEnumerable() - .Select(x => - { - x.Trigger = x.Trigger.Replace(MENTION_PH, _client.CurrentUser.Mention); - return x; - }) - .ToArray(); + var globalItems = uow.Set() + .AsNoTracking() + .Where(x => x.GuildId == null || x.GuildId == 0) + .AsEnumerable() + .Select(x => + { + x.Trigger = x.Trigger.Replace(MENTION_PH, _client.CurrentUser.Mention); + return x; + }) + .ToArray(); globalExpressions = globalItems; } @@ -262,7 +265,10 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor try { - await msg.Channel.SendErrorAsync(_eb, permissionMessage); + await msg.Channel + .Response(_strings, _eb) + .Error(permissionMessage) + .SendAsync(); } catch { @@ -552,19 +558,20 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor foreach (var entry in data) { var trigger = entry.Key; - await uow.Set().AddRangeAsync(entry.Value - .Where(expr => !string.IsNullOrWhiteSpace(expr.Res)) - .Select(expr => new NadekoExpression - { - GuildId = guildId, - Response = expr.Res, - Reactions = expr.React?.Join("@@@"), - Trigger = trigger, - AllowTarget = expr.At, - ContainsAnywhere = expr.Ca, - DmResponse = expr.Dm, - AutoDeleteTrigger = expr.Ad - })); + await uow.Set() + .AddRangeAsync(entry.Value + .Where(expr => !string.IsNullOrWhiteSpace(expr.Res)) + .Select(expr => new NadekoExpression + { + GuildId = guildId, + Response = expr.Res, + Reactions = expr.React?.Join("@@@"), + Trigger = trigger, + AllowTarget = expr.At, + ContainsAnywhere = expr.Ca, + DmResponse = expr.Dm, + AutoDeleteTrigger = expr.Ad + })); } await uow.SaveChangesAsync(); @@ -651,8 +658,13 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor #region Basic Operations - public async Task AddAsync(ulong? guildId, string key, string message, - bool ca = false, bool ad = false, bool dm = false) + public async Task AddAsync( + ulong? guildId, + string key, + string message, + bool ca = false, + bool ad = false, + bool dm = false) { key = key.ToLowerInvariant(); var expr = new NadekoExpression @@ -679,8 +691,13 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor return expr; } - public async Task EditAsync(ulong? guildId, int id, string message, - bool? ca = null, bool? ad = null, bool? dm = null) + public async Task EditAsync( + ulong? guildId, + int id, + string message, + bool? ca = null, + bool? ad = null, + bool? dm = null) { await using var uow = _db.GetDbContext(); var expr = uow.Set().GetById(id); @@ -756,17 +773,19 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor } - public async Task<(IReadOnlyCollection Exprs, int TotalCount)> FindExpressionsAsync(ulong guildId, - string query, int page) + public async Task<(IReadOnlyCollection Exprs, int TotalCount)> FindExpressionsAsync( + ulong guildId, + string query, + int page) { await using var ctx = _db.GetDbContext(); if (newguildExpressions.TryGetValue(guildId, out var exprs)) { return (exprs.Where(x => x.Trigger.Contains(query)) - .Skip(page * 9) - .Take(9) - .ToArray(), exprs.Length); + .Skip(page * 9) + .Take(9) + .ToArray(), exprs.Length); } return ([], 0); diff --git a/src/NadekoBot/Modules/Gambling/AnimalRacing/AnimalRacingCommands.cs b/src/NadekoBot/Modules/Gambling/AnimalRacing/AnimalRacingCommands.cs index 7ed2a971d..ce001f7a6 100644 --- a/src/NadekoBot/Modules/Gambling/AnimalRacing/AnimalRacingCommands.cs +++ b/src/NadekoBot/Modules/Gambling/AnimalRacing/AnimalRacingCommands.cs @@ -41,7 +41,9 @@ public partial class Gambling var ar = new AnimalRace(options, _cs, _gamesConf.Data.RaceAnimals.Shuffle()); if (!_service.AnimalRaces.TryAdd(ctx.Guild.Id, ar)) - return SendErrorAsync(GetText(strs.animal_race), GetText(strs.animal_race_already_started)); + return Response() + .Error(GetText(strs.animal_race), GetText(strs.animal_race_already_started)) + .SendAsync(); ar.Initialize(); @@ -71,15 +73,19 @@ public partial class Gambling var winner = race.FinishedUsers[0]; if (race.FinishedUsers[0].Bet > 0) { - return SendConfirmAsync(GetText(strs.animal_race), - GetText(strs.animal_race_won_money(Format.Bold(winner.Username), - winner.Animal.Icon, - (race.FinishedUsers[0].Bet * (race.Users.Count - 1)) + CurrencySign))); + return Response() + .Confirm(GetText(strs.animal_race), + GetText(strs.animal_race_won_money(Format.Bold(winner.Username), + winner.Animal.Icon, + (race.FinishedUsers[0].Bet * (race.Users.Count - 1)) + CurrencySign))) + .SendAsync(); } ar.Dispose(); - return SendConfirmAsync(GetText(strs.animal_race), - GetText(strs.animal_race_won(Format.Bold(winner.Username), winner.Animal.Icon))); + return Response() + .Confirm(GetText(strs.animal_race), + GetText(strs.animal_race_won(Format.Bold(winner.Username), winner.Animal.Icon))) + .SendAsync(); } ar.OnStartingFailed += Ar_OnStartingFailed; @@ -88,17 +94,21 @@ public partial class Gambling ar.OnStarted += Ar_OnStarted; _client.MessageReceived += ClientMessageReceived; - return SendConfirmAsync(GetText(strs.animal_race), - GetText(strs.animal_race_starting(options.StartTime)), - footer: GetText(strs.animal_race_join_instr(prefix))); + return Response() + .Confirm(GetText(strs.animal_race), + GetText(strs.animal_race_starting(options.StartTime)), + footer: GetText(strs.animal_race_join_instr(prefix))) + .SendAsync(); } private Task Ar_OnStarted(AnimalRace race) { if (race.Users.Count == race.MaxUsers) - return SendConfirmAsync(GetText(strs.animal_race), GetText(strs.animal_race_full)); - return SendConfirmAsync(GetText(strs.animal_race), - GetText(strs.animal_race_starting_with_x(race.Users.Count))); + return Response().Confirm(GetText(strs.animal_race), GetText(strs.animal_race_full)).SendAsync(); + return Response() + .Confirm(GetText(strs.animal_race), + GetText(strs.animal_race_starting_with_x(race.Users.Count))) + .SendAsync(); } private async Task Ar_OnStateUpdate(AnimalRace race) @@ -115,10 +125,10 @@ public partial class Gambling var msg = raceMessage; if (msg is null) - raceMessage = await SendConfirmAsync(text); + raceMessage = await Response().Confirm(text).SendAsync(); else { - await msg.ModifyAsync(x => x.Embed = _eb.Create() + await msg.ModifyAsync(x => x.Embed = new EmbedBuilder() .WithTitle(GetText(strs.animal_race)) .WithDescription(text) .WithOkColor() @@ -130,7 +140,7 @@ public partial class Gambling { _service.AnimalRaces.TryRemove(ctx.Guild.Id, out _); race.Dispose(); - return ReplyErrorLocalizedAsync(strs.animal_race_failed); + return Response().Error(strs.animal_race_failed).SendAsync(); } [Cmd] @@ -142,7 +152,7 @@ public partial class Gambling if (!_service.AnimalRaces.TryGetValue(ctx.Guild.Id, out var ar)) { - await ReplyErrorLocalizedAsync(strs.race_not_exist); + await Response().Error(strs.race_not_exist).SendAsync(); return; } @@ -151,12 +161,16 @@ public partial class Gambling var user = await ar.JoinRace(ctx.User.Id, ctx.User.ToString(), amount); if (amount > 0) { - await SendConfirmAsync(GetText(strs.animal_race_join_bet(ctx.User.Mention, - user.Animal.Icon, - amount + CurrencySign))); + await Response() + .Confirm(GetText(strs.animal_race_join_bet(ctx.User.Mention, + user.Animal.Icon, + amount + CurrencySign))) + .SendAsync(); } else - await SendConfirmAsync(GetText(strs.animal_race_join(ctx.User.Mention, user.Animal.Icon))); + await Response() + .Confirm(GetText(strs.animal_race_join(ctx.User.Mention, user.Animal.Icon))) + .SendAsync(); } catch (ArgumentOutOfRangeException) { @@ -172,11 +186,11 @@ public partial class Gambling } catch (AnimalRaceFullException) { - await SendConfirmAsync(GetText(strs.animal_race), GetText(strs.animal_race_full)); + await Response().Confirm(GetText(strs.animal_race), GetText(strs.animal_race_full)).SendAsync(); } catch (NotEnoughFundsException) { - await SendErrorAsync(GetText(strs.not_enough(CurrencySign))); + await Response().Error(GetText(strs.not_enough(CurrencySign))).SendAsync(); } } } diff --git a/src/NadekoBot/Modules/Gambling/Bank/BankCommands.cs b/src/NadekoBot/Modules/Gambling/Bank/BankCommands.cs index f3a9d9a6f..5b827b5a0 100644 --- a/src/NadekoBot/Modules/Gambling/Bank/BankCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Bank/BankCommands.cs @@ -30,11 +30,11 @@ public partial class Gambling if (await _bank.DepositAsync(ctx.User.Id, amount)) { - await ReplyConfirmLocalizedAsync(strs.bank_deposited(N(amount))); + await Response().Confirm(strs.bank_deposited(N(amount))).SendAsync(); } else { - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); } } @@ -46,11 +46,11 @@ public partial class Gambling if (await _bank.WithdrawAsync(ctx.User.Id, amount)) { - await ReplyConfirmLocalizedAsync(strs.bank_withdrew(N(amount))); + await Response().Confirm(strs.bank_withdrew(N(amount))).SendAsync(); } else { - await ReplyErrorLocalizedAsync(strs.bank_withdraw_insuff(CurrencySign)); + await Response().Error(strs.bank_withdraw_insuff(CurrencySign)).SendAsync(); } } @@ -59,7 +59,7 @@ public partial class Gambling { var bal = await _bank.GetBalanceAsync(ctx.User.Id); - var eb = _eb.Create(ctx) + var eb = new EmbedBuilder() .WithOkColor() .WithDescription(GetText(strs.bank_balance(N(bal)))); @@ -70,7 +70,7 @@ public partial class Gambling } catch { - await ReplyErrorLocalizedAsync(strs.cant_dm); + await Response().Error(strs.cant_dm).SendAsync(); } } @@ -82,10 +82,10 @@ public partial class Gambling return; } - await ReplyErrorLocalizedAsync(strs.take_fail(N(amount), + await Response().Error(strs.take_fail(N(amount), _client.GetUser(userId)?.ToString() ?? userId.ToString(), - CurrencySign)); + CurrencySign)).SendAsync(); } private async Task BankAwardInternalAsync(long amount, ulong userId) diff --git a/src/NadekoBot/Modules/Gambling/BlackJack/BlackJackCommands.cs b/src/NadekoBot/Modules/Gambling/BlackJack/BlackJackCommands.cs index 6c2813ce2..dc42a792a 100644 --- a/src/NadekoBot/Modules/Gambling/BlackJack/BlackJackCommands.cs +++ b/src/NadekoBot/Modules/Gambling/BlackJack/BlackJackCommands.cs @@ -42,7 +42,7 @@ public partial class Gambling if (!await bj.Join(ctx.User, amount)) { _service.Games.TryRemove(ctx.Channel.Id, out _); - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); return; } @@ -50,12 +50,12 @@ public partial class Gambling bj.GameEnded += Bj_GameEnded; bj.Start(); - await ReplyConfirmLocalizedAsync(strs.bj_created); + await Response().Confirm(strs.bj_created).SendAsync(); } else { if (await bj.Join(ctx.User, amount)) - await ReplyConfirmLocalizedAsync(strs.bj_joined); + await Response().Confirm(strs.bj_joined).SendAsync(); else { Log.Information("{User} can't join a blackjack game as it's in {BlackjackState} state already", @@ -95,7 +95,7 @@ public partial class Gambling var cStr = string.Concat(c.Select(x => x[..^1] + " ")); cStr += "\n" + string.Concat(c.Select(x => x.Last() + " ")); - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle("BlackJack") .AddField($"{dealerIcon} Dealer's Hand | Value: {bj.Dealer.GetHandValue()}", cStr); @@ -128,7 +128,7 @@ public partial class Gambling embed.AddField(full, cStr); } - msg = await EmbedAsync(embed); + msg = await Response().Embed(embed).SendAsync(); } catch { @@ -174,7 +174,7 @@ public partial class Gambling else if (a == BjAction.Double) { if (!await bj.Double(ctx.User)) - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); } await ctx.Message.DeleteAsync(); diff --git a/src/NadekoBot/Modules/Gambling/Connect4/Connect4Commands.cs b/src/NadekoBot/Modules/Gambling/Connect4/Connect4Commands.cs index b26c64313..9bc247229 100644 --- a/src/NadekoBot/Modules/Gambling/Connect4/Connect4Commands.cs +++ b/src/NadekoBot/Modules/Gambling/Connect4/Connect4Commands.cs @@ -68,7 +68,7 @@ public partial class Gambling { if (!await _cs.RemoveAsync(ctx.User.Id, options.Bet, new("connect4", "bet"))) { - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); _service.Connect4Games.TryRemove(ctx.Channel.Id, out _); game.Dispose(); return; @@ -82,9 +82,9 @@ public partial class Gambling game.Initialize(); if (options.Bet == 0) - await ReplyConfirmLocalizedAsync(strs.connect4_created); + await Response().Confirm(strs.connect4_created).SendAsync(); else - await ReplyErrorLocalizedAsync(strs.connect4_created_bet(N(options.Bet))); + await Response().Error(strs.connect4_created_bet(N(options.Bet))).SendAsync(); Task ClientMessageReceived(SocketMessage arg) { @@ -125,7 +125,7 @@ public partial class Gambling toDispose.Dispose(); } - return ErrorLocalizedAsync(strs.connect4_failed_to_start); + return Response().Error(strs.connect4_failed_to_start).SendAsync(); } Task GameOnGameEnded(Connect4Game arg, Connect4Game.Result result) @@ -150,7 +150,7 @@ public partial class Gambling else title = GetText(strs.connect4_draw); - return msg.ModifyAsync(x => x.Embed = _eb.Create() + return msg.ModifyAsync(x => x.Embed = new EmbedBuilder() .WithTitle(title) .WithDescription(GetGameStateText(game)) .WithOkColor() @@ -160,14 +160,14 @@ public partial class Gambling private async Task Game_OnGameStateUpdated(Connect4Game game) { - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithTitle($"{game.CurrentPlayer.Username} vs {game.OtherPlayer.Username}") .WithDescription(GetGameStateText(game)) .WithOkColor(); if (msg is null) - msg = await EmbedAsync(embed); + msg = await Response().Embed(embed).SendAsync(); else await msg.ModifyAsync(x => x.Embed = embed.Build()); } @@ -198,6 +198,7 @@ public partial class Gambling for (var i = 0; i < Connect4Game.NUMBER_OF_COLUMNS; i++) sb.Append(_numbers[i]); + return sb.ToString(); } } diff --git a/src/NadekoBot/Modules/Gambling/DiceRoll/DiceRollCommands.cs b/src/NadekoBot/Modules/Gambling/DiceRoll/DiceRollCommands.cs index facb155ac..b37b680e3 100644 --- a/src/NadekoBot/Modules/Gambling/DiceRoll/DiceRollCommands.cs +++ b/src/NadekoBot/Modules/Gambling/DiceRoll/DiceRollCommands.cs @@ -38,7 +38,7 @@ public partial class Gambling var fileName = $"dice.{format.FileExtensions.First()}"; - var eb = _eb.Create(ctx) + var eb = new EmbedBuilder() .WithOkColor() .WithAuthor(ctx.User) .AddField(GetText(strs.roll2), gen) @@ -74,7 +74,7 @@ public partial class Gambling { if (num is < 1 or > 30) { - await ReplyErrorLocalizedAsync(strs.dice_invalid_number(1, 30)); + await Response().Error(strs.dice_invalid_number(1, 30)).SendAsync(); return; } @@ -115,7 +115,7 @@ public partial class Gambling d.Dispose(); var imageName = $"dice.{format.FileExtensions.First()}"; - var eb = _eb.Create(ctx) + var eb = new EmbedBuilder() .WithOkColor() .WithAuthor(ctx.User) .AddField(GetText(strs.rolls), values.Select(x => Format.Code(x.ToString())).Join(' '), true) @@ -141,14 +141,14 @@ public partial class Gambling for (var i = 0; i < n1; i++) rolls.Add(_fateRolls[rng.Next(0, _fateRolls.Length)]); - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithAuthor(ctx.User) .WithDescription(GetText(strs.dice_rolled_num(Format.Bold(n1.ToString())))) .AddField(Format.Bold("Result"), string.Join(" ", rolls.Select(c => Format.Code($"[{c}]")))); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } else if ((match = _dndRegex.Match(arg)).Length != 0) { @@ -170,7 +170,7 @@ public partial class Gambling arr[i] = rng.Next(1, n2 + 1); var sum = arr.Sum(); - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithAuthor(ctx.User) .WithDescription(GetText(strs.dice_rolled_num(n1 + $"`1 - {n2}`"))) @@ -180,7 +180,7 @@ public partial class Gambling => Format.Code(x.ToString())))) .AddField(Format.Bold("Sum"), sum + " + " + add + " - " + sub + " = " + (sum + add - sub)); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } } } @@ -194,7 +194,7 @@ public partial class Gambling var arr = range.Split('-').Take(2).Select(int.Parse).ToArray(); if (arr[0] > arr[1]) { - await ReplyErrorLocalizedAsync(strs.second_larger_than_first); + await Response().Error(strs.second_larger_than_first).SendAsync(); return; } @@ -203,7 +203,7 @@ public partial class Gambling else rolled = new NadekoRandom().Next(0, int.Parse(range) + 1); - await ReplyConfirmLocalizedAsync(strs.dice_rolled(Format.Bold(rolled.ToString()))); + await Response().Confirm(strs.dice_rolled(Format.Bold(rolled.ToString()))).SendAsync(); } private async Task> GetDiceAsync(int num) diff --git a/src/NadekoBot/Modules/Gambling/Draw/DrawCommands.cs b/src/NadekoBot/Modules/Gambling/Draw/DrawCommands.cs index d83d0263b..017aafeed 100644 --- a/src/NadekoBot/Modules/Gambling/Draw/DrawCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Draw/DrawCommands.cs @@ -34,7 +34,7 @@ public partial class Gambling { try { - await ReplyErrorLocalizedAsync(strs.no_more_cards); + await Response().Error(strs.no_more_cards).SendAsync(); } catch { @@ -55,7 +55,7 @@ public partial class Gambling foreach (var i in images) i.Dispose(); - var eb = _eb.Create(ctx) + var eb = new EmbedBuilder() .WithOkColor(); var toSend = string.Empty; @@ -131,7 +131,7 @@ public partial class Gambling return c; }); - await ReplyConfirmLocalizedAsync(strs.deck_reshuffled); + await Response().Confirm(strs.deck_reshuffled).SendAsync(); } [Cmd] @@ -156,11 +156,11 @@ public partial class Gambling if (!res.TryPickT0(out var result, out _)) { - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); return; } - var eb = _eb.Create(ctx) + var eb = new EmbedBuilder() .WithOkColor() .WithAuthor(ctx.User) .WithDescription(result.Card.GetEmoji()) diff --git a/src/NadekoBot/Modules/Gambling/Events/CurrencyEventsCommands.cs b/src/NadekoBot/Modules/Gambling/Events/CurrencyEventsCommands.cs index 34e6a1b34..141658b5f 100644 --- a/src/NadekoBot/Modules/Gambling/Events/CurrencyEventsCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Events/CurrencyEventsCommands.cs @@ -24,18 +24,18 @@ public partial class Gambling { var (opts, _) = OptionsParser.ParseFrom(new EventOptions(), options); if (!await _service.TryCreateEventAsync(ctx.Guild.Id, ctx.Channel.Id, ev, opts, GetEmbed)) - await ReplyErrorLocalizedAsync(strs.start_event_fail); + await Response().Error(strs.start_event_fail).SendAsync(); } - private IEmbedBuilder GetEmbed(CurrencyEvent.Type type, EventOptions opts, long currentPot) + private EmbedBuilder GetEmbed(CurrencyEvent.Type type, EventOptions opts, long currentPot) => type switch { - CurrencyEvent.Type.Reaction => _eb.Create() + CurrencyEvent.Type.Reaction => new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.event_title(type.ToString()))) .WithDescription(GetReactionDescription(opts.Amount, currentPot)) .WithFooter(GetText(strs.event_duration_footer(opts.Hours))), - CurrencyEvent.Type.GameStatus => _eb.Create() + CurrencyEvent.Type.GameStatus => new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.event_title(type.ToString()))) .WithDescription(GetGameStatusDescription(opts.Amount, currentPot)) diff --git a/src/NadekoBot/Modules/Gambling/Events/CurrencyEventsService.cs b/src/NadekoBot/Modules/Gambling/Events/CurrencyEventsService.cs index 01b6c68c4..944c99629 100644 --- a/src/NadekoBot/Modules/Gambling/Events/CurrencyEventsService.cs +++ b/src/NadekoBot/Modules/Gambling/Events/CurrencyEventsService.cs @@ -25,7 +25,7 @@ public class CurrencyEventsService : INService ulong channelId, CurrencyEvent.Type type, EventOptions opts, - Func embed) + Func embed) { var g = _client.GetGuild(guildId); if (g?.GetChannel(channelId) is not ITextChannel ch) diff --git a/src/NadekoBot/Modules/Gambling/Events/GameStatusEvent.cs b/src/NadekoBot/Modules/Gambling/Events/GameStatusEvent.cs index ebcc81616..40f35bace 100644 --- a/src/NadekoBot/Modules/Gambling/Events/GameStatusEvent.cs +++ b/src/NadekoBot/Modules/Gambling/Events/GameStatusEvent.cs @@ -16,7 +16,7 @@ public class GameStatusEvent : ICurrencyEvent private readonly ICurrencyService _cs; private readonly long _amount; - private readonly Func _embedFunc; + private readonly Func _embedFunc; private readonly bool _isPotLimited; private readonly ITextChannel _channel; private readonly ConcurrentHashSet _awardedUsers = new(); @@ -43,7 +43,7 @@ public class GameStatusEvent : ICurrencyEvent SocketGuild g, ITextChannel ch, EventOptions opt, - Func embedFunc) + Func embedFunc) { _client = client; _guild = g; @@ -113,7 +113,7 @@ public class GameStatusEvent : ICurrencyEvent _t.Change(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2)); } - private IEmbedBuilder GetEmbed(long pot) + private EmbedBuilder GetEmbed(long pot) => _embedFunc(CurrencyEvent.Type.GameStatus, _opts, pot); private async Task OnMessageDeleted(Cacheable message, Cacheable cacheable) diff --git a/src/NadekoBot/Modules/Gambling/Events/ReactionEvent.cs b/src/NadekoBot/Modules/Gambling/Events/ReactionEvent.cs index 4e9ade90c..c0b558a4c 100644 --- a/src/NadekoBot/Modules/Gambling/Events/ReactionEvent.cs +++ b/src/NadekoBot/Modules/Gambling/Events/ReactionEvent.cs @@ -16,7 +16,7 @@ public class ReactionEvent : ICurrencyEvent private readonly ICurrencyService _cs; private readonly long _amount; - private readonly Func _embedFunc; + private readonly Func _embedFunc; private readonly bool _isPotLimited; private readonly ITextChannel _channel; private readonly ConcurrentHashSet _awardedUsers = new(); @@ -38,7 +38,7 @@ public class ReactionEvent : ICurrencyEvent ITextChannel ch, EventOptions opt, GamblingConfig config, - Func embedFunc) + Func embedFunc) { _client = client; _guild = g; @@ -109,7 +109,7 @@ public class ReactionEvent : ICurrencyEvent _t.Change(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2)); } - private IEmbedBuilder GetEmbed(long pot) + private EmbedBuilder GetEmbed(long pot) => _embedFunc(CurrencyEvent.Type.Reaction, _opts, pot); private async Task OnMessageDeleted(Cacheable message, Cacheable cacheable) diff --git a/src/NadekoBot/Modules/Gambling/FlipCoin/FlipCoinCommands.cs b/src/NadekoBot/Modules/Gambling/FlipCoin/FlipCoinCommands.cs index f6d03778b..32d98d508 100644 --- a/src/NadekoBot/Modules/Gambling/FlipCoin/FlipCoinCommands.cs +++ b/src/NadekoBot/Modules/Gambling/FlipCoin/FlipCoinCommands.cs @@ -45,7 +45,7 @@ public partial class Gambling { if (count is > 10 or < 1) { - await ReplyErrorLocalizedAsync(strs.flip_invalid(10)); + await Response().Error(strs.flip_invalid(10)).SendAsync(); return; } @@ -84,7 +84,7 @@ public partial class Gambling ? Format.Bold(GetText(strs.heads)) : Format.Bold(GetText(strs.tails)))); - var eb = _eb.Create(ctx) + var eb = new EmbedBuilder() .WithOkColor() .WithAuthor(ctx.User) .WithDescription(msg) @@ -104,7 +104,7 @@ public partial class Gambling var res = await _service.BetFlipAsync(ctx.User.Id, amount, (byte)guess); if (!res.TryPickT0(out var result, out _)) { - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); return; } @@ -130,11 +130,11 @@ public partial class Gambling str = Format.Bold(GetText(strs.better_luck)); } - await EmbedAsync(_eb.Create() + await Response().Embed(new EmbedBuilder() .WithAuthor(ctx.User) .WithDescription(str) .WithOkColor() - .WithImageUrl(imageToSend.ToString())); + .WithImageUrl(imageToSend.ToString())).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index d2c2c06ed..73d6858b5 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -73,18 +73,18 @@ public partial class Gambling : GamblingModule { var stats = await _gamblingTxTracker.GetAllAsync(); - var eb = _eb.Create(ctx) - .WithOkColor(); + var eb = new EmbedBuilder() + .WithOkColor(); var str = "` Feature `|`   Bet  `|`Paid Out`|`  RoI  `\n"; str += "――――――――――――――――――――\n"; foreach (var stat in stats) { var perc = (stat.PaidOut / stat.Bet).ToString("P2", Culture); - str += $"`{stat.Feature.PadBoth(9)}`" + - $"|`{stat.Bet.ToString("N0").PadLeft(8, ' ')}`" + - $"|`{stat.PaidOut.ToString("N0").PadLeft(8, ' ')}`" + - $"|`{perc.PadLeft(6, ' ')}`\n"; + str += $"`{stat.Feature.PadBoth(9)}`" + + $"|`{stat.Bet.ToString("N0").PadLeft(8, ' ')}`" + + $"|`{stat.PaidOut.ToString("N0").PadLeft(8, ' ')}`" + + $"|`{perc.PadLeft(6, ' ')}`\n"; } var bet = stats.Sum(x => x.Bet); @@ -95,14 +95,14 @@ public partial class Gambling : GamblingModule var tPerc = (paidOut / bet).ToString("P2", Culture); str += "――――――――――――――――――――\n"; - str += $"` {("TOTAL").PadBoth(7)}` " + - $"|**{N(bet).PadLeft(8, ' ')}**" + - $"|**{N(paidOut).PadLeft(8, ' ')}**" + - $"|`{tPerc.PadLeft(6, ' ')}`"; + str += $"` {("TOTAL").PadBoth(7)}` " + + $"|**{N(bet).PadLeft(8, ' ')}**" + + $"|**{N(paidOut).PadLeft(8, ' ')}**" + + $"|`{tPerc.PadLeft(6, ' ')}`"; eb.WithDescription(str); - await EmbedAsync(eb); + await Response().Embed(eb).SendAsync(); } [Cmd] @@ -118,19 +118,19 @@ public partial class Gambling : GamblingModule } // [21:03] Bob Page: Kinda remids me of US economy - var embed = _eb.Create() - .WithTitle(GetText(strs.economy_state)) - .AddField(GetText(strs.currency_owned), N(ec.Cash - ec.Bot)) - .AddField(GetText(strs.currency_one_percent), (onePercent * 100).ToString("F2") + "%") - .AddField(GetText(strs.currency_planted), N(ec.Planted)) - .AddField(GetText(strs.owned_waifus_total), N(ec.Waifus)) - .AddField(GetText(strs.bot_currency), N(ec.Bot)) - .AddField(GetText(strs.bank_accounts), N(ec.Bank)) - .AddField(GetText(strs.total), N(ec.Cash + ec.Planted + ec.Waifus + ec.Bank)) - .WithOkColor(); + var embed = new EmbedBuilder() + .WithTitle(GetText(strs.economy_state)) + .AddField(GetText(strs.currency_owned), N(ec.Cash - ec.Bot)) + .AddField(GetText(strs.currency_one_percent), (onePercent * 100).ToString("F2") + "%") + .AddField(GetText(strs.currency_planted), N(ec.Planted)) + .AddField(GetText(strs.owned_waifus_total), N(ec.Waifus)) + .AddField(GetText(strs.bot_currency), N(ec.Bot)) + .AddField(GetText(strs.bank_accounts), N(ec.Bank)) + .AddField(GetText(strs.total), N(ec.Cash + ec.Planted + ec.Waifus + ec.Bank)) + .WithOkColor(); // ec.Cash already contains ec.Bot as it's the total of all values in the CurrencyAmount column of the DiscordUser table - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } private static readonly FeatureLimitKey _timelyKey = new FeatureLimitKey() @@ -153,7 +153,7 @@ public partial class Gambling : GamblingModule await smc.RespondConfirmAsync(_eb, GetText(strs.remind_timely(tt)), ephemeral: true); } - + private NadekoInteraction CreateRemindMeInteraction(int period) { return _inter @@ -174,10 +174,10 @@ public partial class Gambling : GamblingModule var period = Config.Timely.Cooldown; if (val <= 0 || period <= 0) { - await ReplyErrorLocalizedAsync(strs.timely_none); + await Response().Error(strs.timely_none).SendAsync(); return; } - + var inter = CreateRemindMeInteraction(period); if (await _service.ClaimTimelyAsync(ctx.User.Id, period) is { } rem) @@ -187,10 +187,10 @@ public partial class Gambling : GamblingModule { inter = null; } - + var now = DateTime.UtcNow; var relativeTag = TimestampTag.FromDateTime(now.Add(rem), TimestampTagStyles.Relative); - await ReplyPendingLocalizedAsync(strs.timely_already_claimed(relativeTag), inter); + await Response().Pending(strs.timely_already_claimed(relativeTag)).Interaction(inter).SendAsync(); return; } @@ -200,15 +200,15 @@ public partial class Gambling : GamblingModule await _cs.AddAsync(ctx.User.Id, val, new("timely", "claim")); - await ReplyConfirmLocalizedAsync(strs.timely(N(val), period), inter); + await Response().Confirm(strs.timely(N(val), period)).Interaction(inter).SendAsync(); } - + [Cmd] [OwnerOnly] public async Task TimelyReset() { await _service.RemoveAllTimelyClaimsAsync(); - await ReplyConfirmLocalizedAsync(strs.timely_reset); + await Response().Confirm(strs.timely_reset).SendAsync(); } [Cmd] @@ -228,11 +228,13 @@ public partial class Gambling : GamblingModule if (amount == 0) { - await ReplyConfirmLocalizedAsync(strs.timely_set_none); + await Response().Confirm(strs.timely_set_none).SendAsync(); } else { - await ReplyConfirmLocalizedAsync(strs.timely_set(Format.Bold(N(amount)), Format.Bold(period.ToString()))); + await Response() + .Confirm(strs.timely_set(Format.Bold(N(amount)), Format.Bold(period.ToString()))) + .SendAsync(); } } @@ -250,9 +252,11 @@ public partial class Gambling : GamblingModule } var usr = membersArray[new NadekoRandom().Next(0, membersArray.Length)]; - await SendConfirmAsync("🎟 " + GetText(strs.raffled_user), - $"**{usr.Username}**", - footer: $"ID: {usr.Id}"); + await Response() + .Confirm("🎟 " + GetText(strs.raffled_user), + $"**{usr.Username}**", + footer: $"ID: {usr.Id}") + .SendAsync(); } [Cmd] @@ -269,9 +273,11 @@ public partial class Gambling : GamblingModule } var usr = membersArray[new NadekoRandom().Next(0, membersArray.Length)]; - await SendConfirmAsync("🎟 " + GetText(strs.raffled_user), - $"**{usr.Username}**", - footer: $"ID: {usr.Id}"); + await Response() + .Confirm("🎟 " + GetText(strs.raffled_user), + $"**{usr.Username}**", + footer: $"ID: {usr.Id}") + .SendAsync(); } [Cmd] @@ -304,10 +310,10 @@ public partial class Gambling : GamblingModule trs = await uow.Set().GetPageFor(userId, page); } - var embed = _eb.Create() - .WithTitle(GetText(strs.transactions(((SocketGuild)ctx.Guild)?.GetUser(userId)?.ToString() - ?? $"{userId}"))) - .WithOkColor(); + var embed = new EmbedBuilder() + .WithTitle(GetText(strs.transactions(((SocketGuild)ctx.Guild)?.GetUser(userId)?.ToString() + ?? $"{userId}"))) + .WithOkColor(); var sb = new StringBuilder(); foreach (var tr in trs) @@ -331,7 +337,7 @@ public partial class Gambling : GamblingModule embed.WithDescription(sb.ToString()); embed.WithFooter(GetText(strs.page(page + 1))); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } private static string GetFormattedCurtrDate(CurrencyTransaction ct) @@ -343,17 +349,18 @@ public partial class Gambling : GamblingModule int intId = id; await using var uow = _db.GetDbContext(); - var tr = await uow.Set().ToLinqToDBTable() - .Where(x => x.Id == intId && x.UserId == ctx.User.Id) - .FirstOrDefaultAsync(); + var tr = await uow.Set() + .ToLinqToDBTable() + .Where(x => x.Id == intId && x.UserId == ctx.User.Id) + .FirstOrDefaultAsync(); if (tr is null) { - await ReplyErrorLocalizedAsync(strs.not_found); + await Response().Error(strs.not_found).SendAsync(); return; } - var eb = _eb.Create(ctx).WithOkColor(); + var eb = new EmbedBuilder().WithOkColor(); eb.WithAuthor(ctx.User); eb.WithTitle(GetText(strs.transaction)); @@ -374,7 +381,7 @@ public partial class Gambling : GamblingModule eb.WithFooter(GetFormattedCurtrDate(tr)); - await EmbedAsync(eb); + await Response().Embed(eb).SendAsync(); } private string GetHumanReadableTransaction(string type, string subType, ulong? maybeUserId) @@ -398,7 +405,7 @@ public partial class Gambling : GamblingModule public async Task Cash(ulong userId) { var cur = await GetBalanceStringAsync(userId); - await ReplyConfirmLocalizedAsync(strs.has(Format.Code(userId.ToString()), cur)); + await Response().Confirm(strs.has(Format.Code(userId.ToString()), cur)).SendAsync(); } private async Task BankAction(SocketMessageComponent smc, object _) @@ -406,9 +413,9 @@ public partial class Gambling : GamblingModule var balance = await _bank.GetBalanceAsync(ctx.User.Id); await N(balance) - .Pipe(strs.bank_balance) - .Pipe(GetText) - .Pipe(text => smc.RespondConfirmAsync(_eb, text, ephemeral: true)); + .Pipe(strs.bank_balance) + .Pipe(GetText) + .Pipe(text => smc.RespondConfirmAsync(_eb, text, ephemeral: true)); } private NadekoInteraction CreateCashInteraction() @@ -429,18 +436,24 @@ public partial class Gambling : GamblingModule ? CreateCashInteraction() : null; - await ConfirmLocalizedAsync( - user.ToString() - .Pipe(Format.Bold) - .With(cur) - .Pipe(strs.has), - inter); + await Response() + .Confirm( + user.ToString() + .Pipe(Format.Bold) + .With(cur) + .Pipe(strs.has)) + .Interaction(inter) + .SendAsync(); } [Cmd] [RequireContext(ContextType.Guild)] [Priority(0)] - public async Task Give([OverrideTypeReader(typeof(BalanceTypeReader))] long amount, IGuildUser receiver, [Leftover] string msg) + public async Task Give( + [OverrideTypeReader(typeof(BalanceTypeReader))] + long amount, + IGuildUser receiver, + [Leftover] string msg) { if (amount <= 0 || ctx.User.Id == receiver.Id || receiver.IsBot) { @@ -449,11 +462,11 @@ public partial class Gambling : GamblingModule if (!await _cs.TransferAsync(_eb, ctx.User, receiver, amount, msg, N(amount))) { - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); return; } - await ReplyConfirmLocalizedAsync(strs.gifted(N(amount), Format.Bold(receiver.ToString()))); + await Response().Confirm(strs.gifted(N(amount), Format.Bold(receiver.ToString()))).SendAsync(); } [Cmd] @@ -490,12 +503,12 @@ public partial class Gambling : GamblingModule if (usr is null) { - await ReplyErrorLocalizedAsync(strs.user_not_found); + await Response().Error(strs.user_not_found).SendAsync(); return; } await _cs.AddAsync(usr.Id, amount, new("award", ctx.User.ToString()!, msg, ctx.User.Id)); - await ReplyConfirmLocalizedAsync(strs.awarded(N(amount), $"<@{usrId}>")); + await Response().Confirm(strs.awarded(N(amount), $"<@{usrId}>")).SendAsync(); } [Cmd] @@ -510,9 +523,11 @@ public partial class Gambling : GamblingModule amount, new("award", ctx.User.ToString()!, role.Name, ctx.User.Id)); - await ReplyConfirmLocalizedAsync(strs.mass_award(N(amount), - Format.Bold(users.Count.ToString()), - Format.Bold(role.Name))); + await Response() + .Confirm(strs.mass_award(N(amount), + Format.Bold(users.Count.ToString()), + Format.Bold(role.Name))) + .SendAsync(); } [Cmd] @@ -527,9 +542,11 @@ public partial class Gambling : GamblingModule amount, new("take", ctx.User.ToString()!, null, ctx.User.Id)); - await ReplyConfirmLocalizedAsync(strs.mass_take(N(amount), - Format.Bold(users.Count.ToString()), - Format.Bold(role.Name))); + await Response() + .Confirm(strs.mass_take(N(amount), + Format.Bold(users.Count.ToString()), + Format.Bold(role.Name))) + .SendAsync(); } [Cmd] @@ -547,11 +564,11 @@ public partial class Gambling : GamblingModule if (await _cs.RemoveAsync(user.Id, amount, extra)) { - await ReplyConfirmLocalizedAsync(strs.take(N(amount), Format.Bold(user.ToString()))); + await Response().Confirm(strs.take(N(amount), Format.Bold(user.ToString()))).SendAsync(); } else { - await ReplyErrorLocalizedAsync(strs.take_fail(N(amount), Format.Bold(user.ToString()), CurrencySign)); + await Response().Error(strs.take_fail(N(amount), Format.Bold(user.ToString()), CurrencySign)).SendAsync(); } } @@ -568,11 +585,11 @@ public partial class Gambling : GamblingModule if (await _cs.RemoveAsync(usrId, amount, extra)) { - await ReplyConfirmLocalizedAsync(strs.take(N(amount), $"<@{usrId}>")); + await Response().Confirm(strs.take(N(amount), $"<@{usrId}>")).SendAsync(); } else { - await ReplyErrorLocalizedAsync(strs.take_fail(N(amount), Format.Code(usrId.ToString()), CurrencySign)); + await Response().Error(strs.take_fail(N(amount), Format.Code(usrId.ToString()), CurrencySign)).SendAsync(); } } @@ -607,7 +624,7 @@ public partial class Gambling : GamblingModule return; } - var embed = _eb.Create().WithOkColor().WithTitle(GetText(strs.roll_duel)); + var embed = new EmbedBuilder().WithOkColor().WithTitle(GetText(strs.roll_duel)); var description = string.Empty; @@ -617,7 +634,7 @@ public partial class Gambling : GamblingModule { if (other.Amount != amount) { - await ReplyErrorLocalizedAsync(strs.roll_duel_already_challenged); + await Response().Error(strs.roll_duel_already_challenged).SendAsync(); } else { @@ -632,9 +649,11 @@ public partial class Gambling : GamblingModule game.OnGameTick += GameOnGameTick; game.OnEnded += GameOnEnded; - await ReplyConfirmLocalizedAsync(strs.roll_duel_challenge(Format.Bold(ctx.User.ToString()), - Format.Bold(u.ToString()), - Format.Bold(N(amount)))); + await Response() + .Confirm(strs.roll_duel_challenge(Format.Bold(ctx.User.ToString()), + Format.Bold(u.ToString()), + Format.Bold(N(amount)))) + .SendAsync(); } async Task GameOnGameTick(RollDuelGame arg) @@ -648,7 +667,7 @@ public partial class Gambling : GamblingModule if (rdMsg is null) { - rdMsg = await ctx.Channel.EmbedAsync(embed); + rdMsg = await Response().Embed(embed).SendAsync(); } else { @@ -671,11 +690,11 @@ public partial class Gambling : GamblingModule } else if (reason == RollDuelGame.Reason.Timeout) { - await ReplyErrorLocalizedAsync(strs.roll_duel_timeout); + await Response().Error(strs.roll_duel_timeout).SendAsync(); } else if (reason == RollDuelGame.Reason.NoFunds) { - await ReplyErrorLocalizedAsync(strs.roll_duel_no_funds); + await Response().Error(strs.roll_duel_no_funds).SendAsync(); } } finally @@ -696,7 +715,7 @@ public partial class Gambling : GamblingModule var maybeResult = await _gs.BetRollAsync(ctx.User.Id, amount); if (!maybeResult.TryPickT0(out var result, out _)) { - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); return; } @@ -712,13 +731,13 @@ public partial class Gambling : GamblingModule str = GetText(strs.better_luck); } - var eb = _eb.Create(ctx) - .WithAuthor(ctx.User) - .WithDescription(Format.Bold(str)) - .AddField(GetText(strs.roll2), result.Roll.ToString(CultureInfo.InvariantCulture)) - .WithOkColor(); + var eb = new EmbedBuilder() + .WithAuthor(ctx.User) + .WithDescription(Format.Bold(str)) + .AddField(GetText(strs.roll2), result.Roll.ToString(CultureInfo.InvariantCulture)) + .WithOkColor(); - await ctx.Channel.EmbedAsync(eb); + await Response().Embed(eb).SendAsync(); } [Cmd] @@ -768,7 +787,7 @@ public partial class Gambling : GamblingModule await ctx.SendPaginatedConfirmAsync(page, async curPage => { - var embed = _eb.Create().WithOkColor().WithTitle(CurrencySign + " " + GetText(strs.leaderboard)); + var embed = new EmbedBuilder().WithOkColor().WithTitle(CurrencySign + " " + GetText(strs.leaderboard)); List toSend; if (!opts.Clean) @@ -838,11 +857,11 @@ public partial class Gambling : GamblingModule if (!res.TryPickT0(out var result, out _)) { - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); return; } - var embed = _eb.Create(); + var embed = new EmbedBuilder(); string msg; if (result.Result == RpsResultType.Draw) @@ -869,7 +888,7 @@ public partial class Gambling : GamblingModule .WithOkColor() .WithDescription(msg); - await ctx.Channel.EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } private static readonly ImmutableArray _emojis = @@ -884,7 +903,7 @@ public partial class Gambling : GamblingModule var res = await _gs.LulaAsync(ctx.User.Id, amount); if (!res.TryPickT0(out var result, out _)) { - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); return; } @@ -903,15 +922,15 @@ public partial class Gambling : GamblingModule sb.AppendLine(); } - var eb = _eb.Create(ctx) - .WithOkColor() - .WithDescription(sb.ToString()) - .AddField(GetText(strs.multiplier), $"{result.Multiplier:0.##}x", true) - .AddField(GetText(strs.won), $"{(long)result.Won}", true) - .WithAuthor(ctx.User); + var eb = new EmbedBuilder() + .WithOkColor() + .WithDescription(sb.ToString()) + .AddField(GetText(strs.multiplier), $"{result.Multiplier:0.##}x", true) + .AddField(GetText(strs.won), $"{(long)result.Won}", true) + .WithAuthor(ctx.User); - await ctx.Channel.EmbedAsync(eb); + await Response().Embed(eb).SendAsync(); } @@ -935,8 +954,8 @@ public partial class Gambling : GamblingModule var values = Enum.GetValues() .Select(x => $"`{x}`") .Join(", "); - - await SendConfirmAsync(GetText(strs.available_tests), values); + + await Response().Confirm(GetText(strs.available_tests), values).SendAsync(); } [Cmd] @@ -1006,8 +1025,10 @@ public partial class Gambling : GamblingModule sb.AppendLine($"Longest win streak: `{maxW}`"); sb.AppendLine($"Longest lose streak: `{maxL}`"); - await SendConfirmAsync(GetText(strs.test_results_for(target)), - sb.ToString(), - footer: $"Total Bet: {tests} | Payout: {payout:F0} | {payout * 1.0M / tests * 100}%"); + await Response() + .Confirm(GetText(strs.test_results_for(target)), + sb.ToString(), + footer: $"Total Bet: {tests} | Payout: {payout:F0} | {payout * 1.0M / tests * 100}%") + .SendAsync(); } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Gambling/GamblingTopLevelModule.cs b/src/NadekoBot/Modules/Gambling/GamblingTopLevelModule.cs index 5ab57b689..25828c25c 100644 --- a/src/NadekoBot/Modules/Gambling/GamblingTopLevelModule.cs +++ b/src/NadekoBot/Modules/Gambling/GamblingTopLevelModule.cs @@ -26,13 +26,13 @@ public abstract class GamblingModule : NadekoModule return false; if (amount < Config.MinBet) { - await ReplyErrorLocalizedAsync(strs.min_bet_limit(Format.Bold(Config.MinBet.ToString()) + CurrencySign)); + await Response().Error(strs.min_bet_limit(Format.Bold(Config.MinBet.ToString()) + CurrencySign)).SendAsync(); return false; } if (Config.MaxBet > 0 && amount > Config.MaxBet) { - await ReplyErrorLocalizedAsync(strs.max_bet_limit(Format.Bold(Config.MaxBet.ToString()) + CurrencySign)); + await Response().Error(strs.max_bet_limit(Format.Bold(Config.MaxBet.ToString()) + CurrencySign)).SendAsync(); return false; } diff --git a/src/NadekoBot/Modules/Gambling/PlantPick/PlantAndPickCommands.cs b/src/NadekoBot/Modules/Gambling/PlantPick/PlantAndPickCommands.cs index 672f787a1..fc8a5e505 100644 --- a/src/NadekoBot/Modules/Gambling/PlantPick/PlantAndPickCommands.cs +++ b/src/NadekoBot/Modules/Gambling/PlantPick/PlantAndPickCommands.cs @@ -27,7 +27,7 @@ public partial class Gambling if (picked > 0) { - var msg = await ReplyConfirmLocalizedAsync(strs.picked(N(picked))); + var msg = await Response().Confirm(strs.picked(N(picked))).SendAsync(); msg.DeleteAfter(10); } @@ -66,7 +66,7 @@ public partial class Gambling pass); if (!success) - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); } [Cmd] @@ -79,9 +79,9 @@ public partial class Gambling { var enabled = _service.ToggleCurrencyGeneration(ctx.Guild.Id, ctx.Channel.Id); if (enabled) - await ReplyConfirmLocalizedAsync(strs.curgen_enabled); + await Response().Confirm(strs.curgen_enabled).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.curgen_disabled); + await Response().Confirm(strs.curgen_disabled).SendAsync(); } [Cmd] @@ -100,9 +100,9 @@ public partial class Gambling var items = enabledIn.Skip(page * 9).Take(9).ToList(); if (!items.Any()) - return _eb.Create().WithErrorColor().WithDescription("-"); + return new EmbedBuilder().WithErrorColor().WithDescription("-"); - return items.Aggregate(_eb.Create().WithOkColor(), + return items.Aggregate(new EmbedBuilder().WithOkColor(), (eb, i) => eb.AddField(i.GuildId.ToString(), i.ChannelId)); }, enabledIn.Count(), diff --git a/src/NadekoBot/Modules/Gambling/Raffle/CurrencyRaffleCommands.cs b/src/NadekoBot/Modules/Gambling/Raffle/CurrencyRaffleCommands.cs index 1dda32bc5..12ddf90a4 100644 --- a/src/NadekoBot/Modules/Gambling/Raffle/CurrencyRaffleCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Raffle/CurrencyRaffleCommands.cs @@ -32,25 +32,29 @@ public partial class Gambling async Task OnEnded(IUser arg, long won) { - await SendConfirmAsync(GetText(strs.rafflecur_ended(CurrencyName, - Format.Bold(arg.ToString()), - won + CurrencySign))); + await Response() + .Confirm(GetText(strs.rafflecur_ended(CurrencyName, + Format.Bold(arg.ToString()), + won + CurrencySign))) + .SendAsync(); } var res = await _service.JoinOrCreateGame(ctx.Channel.Id, ctx.User, amount, mixed, OnEnded); if (res.Item1 is not null) { - await SendConfirmAsync(GetText(strs.rafflecur(res.Item1.GameType.ToString())), - string.Join("\n", res.Item1.Users.Select(x => $"{x.DiscordUser} ({N(x.Amount)})")), - footer: GetText(strs.rafflecur_joined(ctx.User.ToString()))); + await Response() + .Confirm(GetText(strs.rafflecur(res.Item1.GameType.ToString())), + string.Join("\n", res.Item1.Users.Select(x => $"{x.DiscordUser} ({N(x.Amount)})")), + footer: GetText(strs.rafflecur_joined(ctx.User.ToString()))) + .SendAsync(); } else { if (res.Item2 == CurrencyRaffleService.JoinErrorType.AlreadyJoinedOrInvalidAmount) - await ReplyErrorLocalizedAsync(strs.rafflecur_already_joined); + await Response().Error(strs.rafflecur_already_joined).SendAsync(); else if (res.Item2 == CurrencyRaffleService.JoinErrorType.NotEnoughCurrency) - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); } } } diff --git a/src/NadekoBot/Modules/Gambling/Shop/ShopCommands.cs b/src/NadekoBot/Modules/Gambling/Shop/ShopCommands.cs index 9504a32f4..e494b86ac 100644 --- a/src/NadekoBot/Modules/Gambling/Shop/ShopCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Shop/ShopCommands.cs @@ -54,8 +54,8 @@ public partial class Gambling var theseEntries = entries.Skip(curPage * 9).Take(9).ToArray(); if (!theseEntries.Any()) - return _eb.Create().WithErrorColor().WithDescription(GetText(strs.shop_none)); - var embed = _eb.Create().WithOkColor().WithTitle(GetText(strs.shop)); + return new EmbedBuilder().WithErrorColor().WithDescription(GetText(strs.shop_none)); + var embed = new EmbedBuilder().WithOkColor().WithTitle(GetText(strs.shop)); for (var i = 0; i < theseEntries.Length; i++) { @@ -100,7 +100,7 @@ public partial class Gambling if (entry is null) { - await ReplyErrorLocalizedAsync(strs.shop_item_not_found); + await Response().Error(strs.shop_item_not_found).SendAsync(); return; } @@ -109,14 +109,14 @@ public partial class Gambling var role = ctx.Guild.GetRole(reqRoleId); if (role is null) { - await ReplyErrorLocalizedAsync(strs.shop_item_req_role_not_found); + await Response().Error(strs.shop_item_req_role_not_found).SendAsync(); return; } var guser = (IGuildUser)ctx.User; if (!guser.RoleIds.Contains(reqRoleId)) { - await ReplyErrorLocalizedAsync(strs.shop_item_req_role_unfulfilled(Format.Bold(role.ToString()))); + await Response().Error(strs.shop_item_req_role_unfulfilled(Format.Bold(role.ToString()))).SendAsync(); return; } } @@ -128,13 +128,13 @@ public partial class Gambling if (role is null) { - await ReplyErrorLocalizedAsync(strs.shop_role_not_found); + await Response().Error(strs.shop_role_not_found).SendAsync(); return; } if (guser.RoleIds.Any(id => id == role.Id)) { - await ReplyErrorLocalizedAsync(strs.shop_role_already_bought); + await Response().Error(strs.shop_role_already_bought).SendAsync(); return; } @@ -148,18 +148,18 @@ public partial class Gambling { Log.Warning(ex, "Error adding shop role"); await _cs.AddAsync(ctx.User.Id, entry.Price, new("shop", "error-refund")); - await ReplyErrorLocalizedAsync(strs.shop_role_purchase_error); + await Response().Error(strs.shop_role_purchase_error).SendAsync(); return; } var profit = GetProfitAmount(entry.Price); await _cs.AddAsync(entry.AuthorId, profit, new("shop", "sell", $"Shop sell item - {entry.Type}")); await _cs.AddAsync(ctx.Client.CurrentUser.Id, entry.Price - profit, new("shop", "cut")); - await ReplyConfirmLocalizedAsync(strs.shop_role_purchase(Format.Bold(role.Name))); + await Response().Confirm(strs.shop_role_purchase(Format.Bold(role.Name))).SendAsync(); return; } - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); return; } @@ -167,7 +167,7 @@ public partial class Gambling { if (entry.Items.Count == 0) { - await ReplyErrorLocalizedAsync(strs.out_of_stock); + await Response().Error(strs.out_of_stock).SendAsync(); return; } @@ -183,7 +183,7 @@ public partial class Gambling try { - await ctx.User.EmbedAsync(_eb.Create() + await ctx.User.EmbedAsync(new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.shop_purchase(ctx.Guild.Name))) .AddField(GetText(strs.item), item.Text) @@ -211,14 +211,14 @@ public partial class Gambling } } - await ReplyErrorLocalizedAsync(strs.shop_buy_error); + await Response().Error(strs.shop_buy_error).SendAsync(); return; } - await ReplyConfirmLocalizedAsync(strs.shop_item_purchase); + await Response().Confirm(strs.shop_item_purchase).SendAsync(); } else - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); } else if (entry.Type == ShopEntryType.Command) { @@ -229,24 +229,24 @@ public partial class Gambling if (guild is null || channel is null || msg is null || user is null) { - await ReplyErrorLocalizedAsync(strs.shop_command_invalid_context); + await Response().Error(strs.shop_command_invalid_context).SendAsync(); return; } if (!await _cs.RemoveAsync(ctx.User.Id, entry.Price, new("shop", "buy", entry.Type.ToString()))) { - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); return; } else { var cmd = entry.Command.Replace("%you%", ctx.User.Id.ToString()); - var eb = _eb.Create() + var eb = new EmbedBuilder() .WithPendingColor() .WithTitle("Executing shop command") .WithDescription(cmd); - var msgTask = EmbedAsync(eb); + var msgTask = Response().Embed(eb).SendAsync(); await _cs.AddAsync(entry.AuthorId, GetProfitAmount(entry.Price), @@ -290,7 +290,7 @@ public partial class Gambling var entry = await _service.AddShopCommandAsync(ctx.Guild.Id, ctx.User.Id, price, command); - await ctx.Channel.EmbedAsync(EntryToEmbed(entry).WithTitle(GetText(strs.shop_item_add))); + await Response().Embed(EntryToEmbed(entry).WithTitle(GetText(strs.shop_item_add))).SendAsync(); } [Cmd] @@ -324,7 +324,7 @@ public partial class Gambling uow.SaveChanges(); } - await ctx.Channel.EmbedAsync(EntryToEmbed(entry).WithTitle(GetText(strs.shop_item_add))); + await Response().Embed(EntryToEmbed(entry).WithTitle(GetText(strs.shop_item_add))).SendAsync(); } [Cmd] @@ -356,7 +356,7 @@ public partial class Gambling uow.SaveChanges(); } - await ctx.Channel.EmbedAsync(EntryToEmbed(entry).WithTitle(GetText(strs.shop_item_add))); + await Response().Embed(EntryToEmbed(entry).WithTitle(GetText(strs.shop_item_add))).SendAsync(); } [Cmd] @@ -392,13 +392,13 @@ public partial class Gambling } if (entry is null) - await ReplyErrorLocalizedAsync(strs.shop_item_not_found); + await Response().Error(strs.shop_item_not_found).SendAsync(); else if (!rightType) - await ReplyErrorLocalizedAsync(strs.shop_item_wrong_type); + await Response().Error(strs.shop_item_wrong_type).SendAsync(); else if (added == false) - await ReplyErrorLocalizedAsync(strs.shop_list_item_not_unique); + await Response().Error(strs.shop_list_item_not_unique).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.shop_list_item_added); + await Response().Confirm(strs.shop_list_item_added).SendAsync(); } [Cmd] @@ -426,9 +426,9 @@ public partial class Gambling } if (removed is null) - await ReplyErrorLocalizedAsync(strs.shop_item_not_found); + await Response().Error(strs.shop_item_not_found).SendAsync(); else - await ctx.Channel.EmbedAsync(EntryToEmbed(removed).WithTitle(GetText(strs.shop_item_rm))); + await Response().Embed(EntryToEmbed(removed).WithTitle(GetText(strs.shop_item_rm))).SendAsync(); } [Cmd] @@ -514,19 +514,19 @@ public partial class Gambling var succ = await _service.SetItemRoleRequirementAsync(ctx.Guild.Id, itemIndex, role?.Id); if (!succ) { - await ReplyErrorLocalizedAsync(strs.shop_item_not_found); + await Response().Error(strs.shop_item_not_found).SendAsync(); return; } if (role is null) - await ReplyConfirmLocalizedAsync(strs.shop_item_role_no_req(itemIndex)); + await Response().Confirm(strs.shop_item_role_no_req(itemIndex)).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.shop_item_role_req(itemIndex + 1, role)); + await Response().Confirm(strs.shop_item_role_req(itemIndex + 1, role)).SendAsync(); } - public IEmbedBuilder EntryToEmbed(ShopEntry entry) + public EmbedBuilder EntryToEmbed(ShopEntry entry) { - var embed = _eb.Create().WithOkColor(); + var embed = new EmbedBuilder().WithOkColor(); if (entry.Type == ShopEntryType.Role) { diff --git a/src/NadekoBot/Modules/Gambling/Slot/SlotCommands.cs b/src/NadekoBot/Modules/Gambling/Slot/SlotCommands.cs index 8756a8d6e..8ca24fbc6 100644 --- a/src/NadekoBot/Modules/Gambling/Slot/SlotCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Slot/SlotCommands.cs @@ -59,7 +59,7 @@ public partial class Gambling if (await InternalSlotAsync(amount) is not SlotResult result) { - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); return; } @@ -69,7 +69,7 @@ public partial class Gambling await using var imgStream = await image.ToStreamAsync(); - var eb = _eb.Create(ctx) + var eb = new EmbedBuilder() .WithAuthor(ctx.User) .WithDescription(Format.Bold(text)) .WithImageUrl($"attachment://result.png") diff --git a/src/NadekoBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs b/src/NadekoBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs index fb792f9c1..146c3327c 100644 --- a/src/NadekoBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs @@ -20,7 +20,7 @@ public partial class Gambling public async Task WaifuReset() { var price = _service.GetResetPrice(ctx.User); - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithTitle(GetText(strs.waifu_reset_confirm)) .WithDescription(GetText(strs.waifu_reset_price(Format.Bold(N(price))))); @@ -29,11 +29,11 @@ public partial class Gambling if (await _service.TryReset(ctx.User)) { - await ReplyConfirmLocalizedAsync(strs.waifu_reset); + await Response().Confirm(strs.waifu_reset).SendAsync(); return; } - await ReplyErrorLocalizedAsync(strs.waifu_reset_fail); + await Response().Error(strs.waifu_reset_fail).SendAsync(); } [Cmd] @@ -42,13 +42,13 @@ public partial class Gambling { if (amount < Config.Waifu.MinPrice) { - await ReplyErrorLocalizedAsync(strs.waifu_isnt_cheap(Config.Waifu.MinPrice + CurrencySign)); + await Response().Error(strs.waifu_isnt_cheap(Config.Waifu.MinPrice + CurrencySign)).SendAsync(); return; } if (target.Id == ctx.User.Id) { - await ReplyErrorLocalizedAsync(strs.waifu_not_yourself); + await Response().Error(strs.waifu_not_yourself).SendAsync(); return; } @@ -56,14 +56,16 @@ public partial class Gambling if (result == WaifuClaimResult.InsufficientAmount) { - await ReplyErrorLocalizedAsync( - strs.waifu_not_enough(N((long)Math.Ceiling(w.Price * (isAffinity ? 0.88f : 1.1f))))); + await Response() + .Error( + strs.waifu_not_enough(N((long)Math.Ceiling(w.Price * (isAffinity ? 0.88f : 1.1f))))) + .SendAsync(); return; } if (result == WaifuClaimResult.NotEnoughFunds) { - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); return; } @@ -72,7 +74,7 @@ public partial class Gambling msg += "\n" + GetText(strs.waifu_fulfilled(target, N(w.Price))); else msg = " " + msg; - await SendConfirmAsync(ctx.User.Mention + msg); + await Response().Confirm(ctx.User.Mention + msg).SendAsync(); } [Cmd] @@ -82,13 +84,15 @@ public partial class Gambling { if (!await _service.WaifuTransfer(ctx.User, waifuId, newOwner)) { - await ReplyErrorLocalizedAsync(strs.waifu_transfer_fail); + await Response().Error(strs.waifu_transfer_fail).SendAsync(); return; } - await ReplyConfirmLocalizedAsync(strs.waifu_transfer_success(Format.Bold(waifuId.ToString()), - Format.Bold(ctx.User.ToString()), - Format.Bold(newOwner.ToString()))); + await Response() + .Confirm(strs.waifu_transfer_success(Format.Bold(waifuId.ToString()), + Format.Bold(ctx.User.ToString()), + Format.Bold(newOwner.ToString()))) + .SendAsync(); } [Cmd] @@ -98,13 +102,15 @@ public partial class Gambling { if (!await _service.WaifuTransfer(ctx.User, waifu.Id, newOwner)) { - await ReplyErrorLocalizedAsync(strs.waifu_transfer_fail); + await Response().Error(strs.waifu_transfer_fail).SendAsync(); return; } - await ReplyConfirmLocalizedAsync(strs.waifu_transfer_success(Format.Bold(waifu.ToString()), - Format.Bold(ctx.User.ToString()), - Format.Bold(newOwner.ToString()))); + await Response() + .Confirm(strs.waifu_transfer_success(Format.Bold(waifu.ToString()), + Format.Bold(ctx.User.ToString()), + Format.Bold(newOwner.ToString()))) + .SendAsync(); } [Cmd] @@ -114,7 +120,7 @@ public partial class Gambling { var waifuUserId = _service.GetWaifuUserId(ctx.User.Id, target); if (waifuUserId == default) - return ReplyErrorLocalizedAsync(strs.waifu_not_yours); + return Response().Error(strs.waifu_not_yours).SendAsync(); return Divorce(waifuUserId); } @@ -137,18 +143,22 @@ public partial class Gambling if (result == DivorceResult.SucessWithPenalty) { - await ReplyConfirmLocalizedAsync(strs.waifu_divorced_like(Format.Bold(w.Waifu.ToString()), - N(amount))); + await Response() + .Confirm(strs.waifu_divorced_like(Format.Bold(w.Waifu.ToString()), + N(amount))) + .SendAsync(); } else if (result == DivorceResult.Success) - await ReplyConfirmLocalizedAsync(strs.waifu_divorced_notlike(N(amount))); + await Response().Confirm(strs.waifu_divorced_notlike(N(amount))).SendAsync(); else if (result == DivorceResult.NotYourWife) - await ReplyErrorLocalizedAsync(strs.waifu_not_yours); + await Response().Error(strs.waifu_not_yours).SendAsync(); else { - await ReplyErrorLocalizedAsync(strs.waifu_recent_divorce( - Format.Bold(((int)remaining?.TotalHours).ToString()), - Format.Bold(remaining?.Minutes.ToString()))); + await Response() + .Error(strs.waifu_recent_divorce( + Format.Bold(((int)remaining?.TotalHours).ToString()), + Format.Bold(remaining?.Minutes.ToString()))) + .SendAsync(); } } @@ -158,7 +168,7 @@ public partial class Gambling { if (user?.Id == ctx.User.Id) { - await ReplyErrorLocalizedAsync(strs.waifu_egomaniac); + await Response().Error(strs.waifu_egomaniac).SendAsync(); return; } @@ -167,24 +177,28 @@ public partial class Gambling { if (remaining is not null) { - await ReplyErrorLocalizedAsync(strs.waifu_affinity_cooldown( - Format.Bold(((int)remaining?.TotalHours).ToString()), - Format.Bold(remaining?.Minutes.ToString()))); + await Response() + .Error(strs.waifu_affinity_cooldown( + Format.Bold(((int)remaining?.TotalHours).ToString()), + Format.Bold(remaining?.Minutes.ToString()))) + .SendAsync(); } else - await ReplyErrorLocalizedAsync(strs.waifu_affinity_already); + await Response().Error(strs.waifu_affinity_already).SendAsync(); return; } if (user is null) - await ReplyConfirmLocalizedAsync(strs.waifu_affinity_reset); + await Response().Confirm(strs.waifu_affinity_reset).SendAsync(); else if (oldAff is null) - await ReplyConfirmLocalizedAsync(strs.waifu_affinity_set(Format.Bold(user.ToString()))); + await Response().Confirm(strs.waifu_affinity_set(Format.Bold(user.ToString()))).SendAsync(); else { - await ReplyConfirmLocalizedAsync(strs.waifu_affinity_changed(Format.Bold(oldAff.ToString()), - Format.Bold(user.ToString()))); + await Response() + .Confirm(strs.waifu_affinity_changed(Format.Bold(oldAff.ToString()), + Format.Bold(user.ToString()))) + .SendAsync(); } } @@ -204,11 +218,11 @@ public partial class Gambling if (waifus.Count == 0) { - await ReplyConfirmLocalizedAsync(strs.waifus_none); + await Response().Confirm(strs.waifus_none).SendAsync(); return; } - var embed = _eb.Create().WithTitle(GetText(strs.waifus_top_waifus)).WithOkColor(); + var embed = new EmbedBuilder().WithTitle(GetText(strs.waifus_top_waifus)).WithOkColor(); var i = 0; foreach (var w in waifus) @@ -217,7 +231,7 @@ public partial class Gambling embed.AddField("#" + ((page * 9) + j + 1) + " - " + N(w.Price), GetLbString(w)); } - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } private string GetLbString(WaifuLbResult w) @@ -284,15 +298,15 @@ public partial class Gambling var fansList = await _service.GetFansNames(wi.WaifuId); var fansStr = fansList - .Shuffle() - .Take(30) - .Select((x) => claimsNames.Contains(x) ? $"{x} 💞" : x) - .Join('\n'); + .Shuffle() + .Take(30) + .Select((x) => claimsNames.Contains(x) ? $"{x} 💞" : x) + .Join('\n'); if (string.IsNullOrWhiteSpace(fansStr)) fansStr = "-"; - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.waifu) + " " @@ -312,7 +326,7 @@ public partial class Gambling true) .AddField(GetText(strs.gifts), itemsStr, true); - await ctx.Channel.EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -327,7 +341,7 @@ public partial class Gambling await ctx.SendPaginatedConfirmAsync(page, cur => { - var embed = _eb.Create().WithTitle(GetText(strs.waifu_gift_shop)).WithOkColor(); + var embed = new EmbedBuilder().WithTitle(GetText(strs.waifu_gift_shop)).WithOkColor(); waifuItems.OrderBy(x => x.Negative) .ThenBy(x => x.Price) @@ -357,7 +371,7 @@ public partial class Gambling var item = allItems.FirstOrDefault(x => x.Name.ToLowerInvariant() == itemName.ToLowerInvariant()); if (item is null) { - await ReplyErrorLocalizedAsync(strs.waifu_gift_not_exist); + await Response().Error(strs.waifu_gift_not_exist).SendAsync(); return; } @@ -365,11 +379,13 @@ public partial class Gambling if (sucess) { - await ReplyConfirmLocalizedAsync(strs.waifu_gift(Format.Bold(item + " " + item.ItemEmoji), - Format.Bold(waifu.ToString()))); + await Response() + .Confirm(strs.waifu_gift(Format.Bold(item + " " + item.ItemEmoji), + Format.Bold(waifu.ToString()))) + .SendAsync(); } else - await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); + await Response().Error(strs.not_enough(CurrencySign)).SendAsync(); } } -} +} \ No newline at end of file diff --git a/src/NadekoBot/Modules/Games/Acrophobia/AcropobiaCommands.cs b/src/NadekoBot/Modules/Games/Acrophobia/AcropobiaCommands.cs index a22f67977..dbb28b101 100644 --- a/src/NadekoBot/Modules/Games/Acrophobia/AcropobiaCommands.cs +++ b/src/NadekoBot/Modules/Games/Acrophobia/AcropobiaCommands.cs @@ -43,7 +43,7 @@ public partial class Games } } else - await ReplyErrorLocalizedAsync(strs.acro_running); + await Response().Error(strs.acro_running).SendAsync(); Task ClientMessageReceived(SocketMessage msg) { @@ -67,18 +67,18 @@ public partial class Games private Task Game_OnStarted(AcrophobiaGame game) { - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.acrophobia)) .WithDescription( GetText(strs.acro_started(Format.Bold(string.Join(".", game.StartingLetters))))) .WithFooter(GetText(strs.acro_started_footer(game.Opts.SubmissionTime))); - return EmbedAsync(embed); + return Response().Embed(embed).SendAsync(); } private Task Game_OnUserVoted(string user) - => SendConfirmAsync(GetText(strs.acrophobia), GetText(strs.acro_vote_cast(Format.Bold(user)))); + => Response().Confirm(GetText(strs.acrophobia), GetText(strs.acro_vote_cast(Format.Bold(user)))).SendAsync(); private async Task Game_OnVotingStarted( AcrophobiaGame game, @@ -86,24 +86,24 @@ public partial class Games { if (submissions.Length == 0) { - await SendErrorAsync(GetText(strs.acrophobia), GetText(strs.acro_ended_no_sub)); + await Response().Error(GetText(strs.acrophobia), GetText(strs.acro_ended_no_sub)).SendAsync(); return; } if (submissions.Length == 1) { - await EmbedAsync(_eb.Create() + await Response().Embed(new EmbedBuilder() .WithOkColor() .WithDescription(GetText( strs.acro_winner_only( Format.Bold(submissions.First().Key.UserName)))) - .WithFooter(submissions.First().Key.Input)); + .WithFooter(submissions.First().Key.Input)).SendAsync(); return; } var i = 0; - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.acrophobia) + " - " + GetText(strs.submissions_closed)) .WithDescription(GetText(strs.acro_nym_was( @@ -114,27 +114,27 @@ public partial class Games --"))) .WithFooter(GetText(strs.acro_vote)); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } private async Task Game_OnEnded(AcrophobiaGame game, ImmutableArray> votes) { if (!votes.Any() || votes.All(x => x.Value == 0)) { - await SendErrorAsync(GetText(strs.acrophobia), GetText(strs.acro_no_votes_cast)); + await Response().Error(GetText(strs.acrophobia), GetText(strs.acro_no_votes_cast)).SendAsync(); return; } var table = votes.OrderByDescending(v => v.Value); var winner = table.First(); - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.acrophobia)) .WithDescription(GetText(strs.acro_winner(Format.Bold(winner.Key.UserName), Format.Bold(winner.Value.ToString())))) .WithFooter(winner.Key.Input); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Games/ChatterBot/ChatterbotService.cs b/src/NadekoBot/Modules/Games/ChatterBot/ChatterbotService.cs index 2fe7afb2c..5ab1a15a3 100644 --- a/src/NadekoBot/Modules/Games/ChatterBot/ChatterbotService.cs +++ b/src/NadekoBot/Modules/Games/ChatterBot/ChatterbotService.cs @@ -26,6 +26,7 @@ public class ChatterBotService : IExecOnMessage private readonly IHttpClientFactory _httpFactory; private readonly IPatronageService _ps; private readonly GamesConfigService _gcs; + private readonly IMessageSenderService _sender; public ChatterBotService( DiscordSocketClient client, @@ -37,7 +38,8 @@ public class ChatterBotService : IExecOnMessage IBotCredentials creds, IEmbedBuilderService eb, IPatronageService ps, - GamesConfigService gcs) + GamesConfigService gcs, + IMessageSenderService sender) { _client = client; _perms = perms; @@ -49,6 +51,7 @@ public class ChatterBotService : IExecOnMessage _ps = ps; _perms = perms; _gcs = gcs; + _sender = sender; _flKey = new FeatureLimitKey() { @@ -133,7 +136,7 @@ public class ChatterBotService : IExecOnMessage usrMsg.Author, "games", CleverBotResponseStr.CLEVERBOT_RESPONSE); - + if (!res.IsAllowed) return false; @@ -163,20 +166,24 @@ public class ChatterBotService : IExecOnMessage { if (ql.Quota == 0) { - await channel.SendErrorAsync(_eb, - null!, - text: - "In order to use the cleverbot feature, the owner of this server should be [Patron Tier X](https://patreon.com/join/nadekobot) on patreon.", - footer: - "You may disable the cleverbot feature, and this message via '.cleverbot' command"); + await channel + .Response(_strings, _eb) + .Error(null, + text: + "In order to use the cleverbot feature, the owner of this server should be [Patron Tier X](https://patreon.com/join/nadekobot) on patreon.", + footer: + "You may disable the cleverbot feature, and this message via '.cleverbot' command") + .SendAsync(); return true; } - await channel.SendErrorAsync(_eb, - null!, - $"You've reached your quota limit of **{ql.Quota}** responses {ql.QuotaPeriod.ToFullName()} for the cleverbot feature.", - footer: "You may wait for the quota reset or ."); + await channel.Response(_strings, _eb) + .Error( + null!, + $"You've reached your quota limit of **{ql.Quota}** responses {ql.QuotaPeriod.ToFullName()} for the cleverbot feature.", + footer: "You may wait for the quota reset or .") + .SendAsync(); return true; } @@ -184,19 +191,17 @@ public class ChatterBotService : IExecOnMessage _ = channel.TriggerTypingAsync(); var response = await cbs.Think(message, usrMsg.Author.ToString()); - await channel.SendConfirmAsync(_eb, - title: null, - response.SanitizeMentions(true) - // , footer: counter > 0 ? counter.ToString() : null - ); + await _sender.Response(channel) + .Confirm(response) + .SendAsync(); Log.Information(""" - CleverBot Executed - Server: {GuildName} [{GuildId}] - Channel: {ChannelName} [{ChannelId}] - UserId: {Author} [{AuthorId}] - Message: {Content} - """, + CleverBot Executed + Server: {GuildName} [{GuildId}] + Channel: {ChannelName} [{ChannelId}] + UserId: {Author} [{AuthorId}] + Message: {Content} + """, guild.Name, guild.Id, usrMsg.Channel?.Name, diff --git a/src/NadekoBot/Modules/Games/ChatterBot/CleverBotCommands.cs b/src/NadekoBot/Modules/Games/ChatterBot/CleverBotCommands.cs index 7cb48b2f9..820c8aa75 100644 --- a/src/NadekoBot/Modules/Games/ChatterBot/CleverBotCommands.cs +++ b/src/NadekoBot/Modules/Games/ChatterBot/CleverBotCommands.cs @@ -30,7 +30,7 @@ public partial class Games await uow.SaveChangesAsync(); } - await ReplyConfirmLocalizedAsync(strs.cleverbot_disabled); + await Response().Confirm(strs.cleverbot_disabled).SendAsync(); return; } @@ -42,7 +42,7 @@ public partial class Games await uow.SaveChangesAsync(); } - await ReplyConfirmLocalizedAsync(strs.cleverbot_enabled); + await Response().Confirm(strs.cleverbot_enabled).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Games/Games.cs b/src/NadekoBot/Modules/Games/Games.cs index ab12d5e27..becfa2eeb 100644 --- a/src/NadekoBot/Modules/Games/Games.cs +++ b/src/NadekoBot/Modules/Games/Games.cs @@ -28,7 +28,7 @@ public partial class Games : NadekoModule if (listArr.Length < 2) return; var rng = new NadekoRandom(); - await SendConfirmAsync("🤔", listArr[rng.Next(0, listArr.Length)]); + await Response().Confirm("🤔", listArr[rng.Next(0, listArr.Length)]).SendAsync(); } [Cmd] @@ -38,10 +38,10 @@ public partial class Games : NadekoModule return; var res = _service.GetEightballResponse(ctx.User.Id, question); - await EmbedAsync(_eb.Create() + await Response().Embed(new EmbedBuilder() .WithOkColor() .WithDescription(ctx.User.ToString()) .AddField("❓ " + GetText(strs.question), question) - .AddField("🎱 " + GetText(strs._8ball), res)); + .AddField("🎱 " + GetText(strs._8ball), res)).SendAsync(); } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Games/Hangman/HangmanCommands.cs b/src/NadekoBot/Modules/Games/Hangman/HangmanCommands.cs index 226099daa..bc3c9999f 100644 --- a/src/NadekoBot/Modules/Games/Hangman/HangmanCommands.cs +++ b/src/NadekoBot/Modules/Games/Hangman/HangmanCommands.cs @@ -10,7 +10,7 @@ public partial class Games [Cmd] [RequireContext(ContextType.Guild)] public async Task Hangmanlist() - => await SendConfirmAsync(GetText(strs.hangman_types(prefix)), _service.GetHangmanTypes().Join('\n')); + => await Response().Confirm(GetText(strs.hangman_types(prefix)), _service.GetHangmanTypes().Join('\n')).SendAsync(); private static string Draw(HangmanGame.State state) => $""" @@ -23,11 +23,11 @@ public partial class Games /-\ """; - public static IEmbedBuilder GetEmbed(IEmbedBuilderService eb, HangmanGame.State state) + public static EmbedBuilder GetEmbed(IEmbedBuilderService eb, HangmanGame.State state) { if (state.Phase == HangmanGame.Phase.Running) { - return eb.Create() + return new EmbedBuilder() .WithOkColor() .AddField("Hangman", Draw(state)) .AddField("Guess", Format.Code(state.Word)) @@ -36,14 +36,14 @@ public partial class Games if (state.Phase == HangmanGame.Phase.Ended && state.Failed) { - return eb.Create() + return new EmbedBuilder() .WithErrorColor() .AddField("Hangman", Draw(state)) .AddField("Guess", Format.Code(state.Word)) .WithFooter(state.MissedLetters.Join(' ')); } - return eb.Create() + return new EmbedBuilder() .WithOkColor() .AddField("Hangman", Draw(state)) .AddField("Guess", Format.Code(state.Word)) @@ -56,13 +56,13 @@ public partial class Games { if (!_service.StartHangman(ctx.Channel.Id, type, out var hangman)) { - await ReplyErrorLocalizedAsync(strs.hangman_running); + await Response().Error(strs.hangman_running).SendAsync(); return; } var eb = GetEmbed(_eb, hangman); eb.WithDescription(GetText(strs.hangman_game_started)); - await EmbedAsync(eb); + await Response().Embed(eb).SendAsync(); } [Cmd] @@ -70,7 +70,7 @@ public partial class Games public async Task HangmanStop() { if (await _service.StopHangman(ctx.Channel.Id)) - await ReplyConfirmLocalizedAsync(strs.hangman_stopped); + await Response().Confirm(strs.hangman_stopped).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Games/Nunchi/NunchiCommands.cs b/src/NadekoBot/Modules/Games/Nunchi/NunchiCommands.cs index f7041ac96..329cff5fa 100644 --- a/src/NadekoBot/Modules/Games/Nunchi/NunchiCommands.cs +++ b/src/NadekoBot/Modules/Games/Nunchi/NunchiCommands.cs @@ -25,17 +25,16 @@ public partial class Games if ((nunchi = _service.NunchiGames.GetOrAdd(ctx.Guild.Id, newNunchi)) != newNunchi) { // join it + // if you failed joining, that means game is running or just ended if (!await nunchi.Join(ctx.User.Id, ctx.User.ToString())) - // if you failed joining, that means game is running or just ended - // await ReplyErrorLocalized("nunchi_already_started"); return; - await ReplyErrorLocalizedAsync(strs.nunchi_joined(nunchi.ParticipantCount)); + await Response().Error(strs.nunchi_joined(nunchi.ParticipantCount)).SendAsync(); return; } - try { await ConfirmLocalizedAsync(strs.nunchi_created); } + try { await Response().Confirm(strs.nunchi_created).SendAsync(); } catch { } nunchi.OnGameEnded += NunchiOnGameEnded; @@ -50,7 +49,7 @@ public partial class Games { if (_service.NunchiGames.TryRemove(ctx.Guild.Id, out var game)) game.Dispose(); - await ConfirmLocalizedAsync(strs.nunchi_failed_to_start); + await Response().Confirm(strs.nunchi_failed_to_start).SendAsync(); } Task ClientMessageReceived(SocketMessage arg) @@ -82,30 +81,34 @@ public partial class Games } if (arg2 is null) - return ConfirmLocalizedAsync(strs.nunchi_ended_no_winner); - return ConfirmLocalizedAsync(strs.nunchi_ended(Format.Bold(arg2))); + return Response().Confirm(strs.nunchi_ended_no_winner).SendAsync(); + return Response().Confirm(strs.nunchi_ended(Format.Bold(arg2))).SendAsync(); } } private Task Nunchi_OnRoundStarted(NunchiGame arg, int cur) - => ConfirmLocalizedAsync(strs.nunchi_round_started(Format.Bold(arg.ParticipantCount.ToString()), - Format.Bold(cur.ToString()))); + => Response() + .Confirm(strs.nunchi_round_started(Format.Bold(arg.ParticipantCount.ToString()), + Format.Bold(cur.ToString()))) + .SendAsync(); private Task Nunchi_OnUserGuessed(NunchiGame arg) - => ConfirmLocalizedAsync(strs.nunchi_next_number(Format.Bold(arg.CurrentNumber.ToString()))); + => Response().Confirm(strs.nunchi_next_number(Format.Bold(arg.CurrentNumber.ToString()))).SendAsync(); private Task Nunchi_OnRoundEnded(NunchiGame arg1, (ulong Id, string Name)? arg2) { if (arg2.HasValue) - return ConfirmLocalizedAsync(strs.nunchi_round_ended(Format.Bold(arg2.Value.Name))); - return ConfirmLocalizedAsync(strs.nunchi_round_ended_boot( - Format.Bold("\n" - + string.Join("\n, ", - arg1.Participants.Select(x - => x.Name))))); // this won't work if there are too many users + return Response().Confirm(strs.nunchi_round_ended(Format.Bold(arg2.Value.Name))).SendAsync(); + return Response() + .Confirm(strs.nunchi_round_ended_boot( + Format.Bold("\n" + + string.Join("\n, ", + arg1.Participants.Select(x + => x.Name))))) + .SendAsync(); // this won't work if there are too many users } private Task Nunchi_OnGameStarted(NunchiGame arg) - => ConfirmLocalizedAsync(strs.nunchi_started(Format.Bold(arg.ParticipantCount.ToString()))); + => Response().Confirm(strs.nunchi_started(Format.Bold(arg.ParticipantCount.ToString()))).SendAsync(); } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Games/SpeedTyping/SpeedTypingCommands.cs b/src/NadekoBot/Modules/Games/SpeedTyping/SpeedTypingCommands.cs index 3a69913fc..0e7bc5234 100644 --- a/src/NadekoBot/Modules/Games/SpeedTyping/SpeedTypingCommands.cs +++ b/src/NadekoBot/Modules/Games/SpeedTyping/SpeedTypingCommands.cs @@ -27,10 +27,10 @@ public partial class Games var channel = (ITextChannel)ctx.Channel; var game = _service.RunningContests.GetOrAdd(ctx.Guild.Id, - _ => new(_games, _client, channel, prefix, options, _eb)); + _ => new(_games, _client, channel, prefix, options, _sender)); if (game.IsActive) - await SendErrorAsync($"Contest already running in {game.Channel.Mention} channel."); + await Response().Error($"Contest already running in {game.Channel.Mention} channel.").SendAsync(); else await game.Start(); } @@ -45,7 +45,7 @@ public partial class Games return; } - await SendErrorAsync("No contest to stop on this channel."); + await Response().Error("No contest to stop on this channel.").SendAsync(); } @@ -59,7 +59,7 @@ public partial class Games _games.AddTypingArticle(ctx.User, text); - await SendConfirmAsync("Added new article for typing game."); + await Response().Confirm("Added new article for typing game.").SendAsync(); } [Cmd] @@ -73,13 +73,15 @@ public partial class Games if (!articles.Any()) { - await SendErrorAsync($"{ctx.User.Mention} `No articles found on that page.`"); + await Response().Error($"{ctx.User.Mention} `No articles found on that page.`").SendAsync(); return; } var i = (page - 1) * 15; - await SendConfirmAsync("List of articles for Type Race", - string.Join("\n", articles.Select(a => $"`#{++i}` - {a.Text.TrimTo(50)}"))); + await Response() + .Confirm("List of articles for Type Race", + string.Join("\n", articles.Select(a => $"`#{++i}` - {a.Text.TrimTo(50)}"))) + .SendAsync(); } [Cmd] @@ -92,12 +94,12 @@ public partial class Games if (removed is null) return; - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithTitle($"Removed typing article #{index + 1}") .WithDescription(removed.Text.TrimTo(50)) .WithOkColor(); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Games/SpeedTyping/TypingGame.cs b/src/NadekoBot/Modules/Games/SpeedTyping/TypingGame.cs index a8bd85ce8..3d676d808 100644 --- a/src/NadekoBot/Modules/Games/SpeedTyping/TypingGame.cs +++ b/src/NadekoBot/Modules/Games/SpeedTyping/TypingGame.cs @@ -17,7 +17,7 @@ public class TypingGame private readonly GamesService _games; private readonly string _prefix; private readonly Options _options; - private readonly IEmbedBuilderService _eb; + private readonly IMessageSenderService _sender; public TypingGame( GamesService games, @@ -25,13 +25,13 @@ public class TypingGame ITextChannel channel, string prefix, Options options, - IEmbedBuilderService eb) + IMessageSenderService sender) { _games = games; _client = client; _prefix = prefix; _options = options; - _eb = eb; + _sender = sender; Channel = channel; IsActive = false; @@ -50,7 +50,9 @@ public class TypingGame _sw.Reset(); try { - await Channel.SendConfirmAsync(_eb, "Typing contest stopped."); + await _sender.Response(Channel) + .Confirm("Typing contest stopped.") + .SendAsync(); } catch { @@ -68,8 +70,10 @@ public class TypingGame var i = (int)(CurrentSentence.Length / WORD_VALUE * 1.7f); try { - await Channel.SendConfirmAsync(_eb, - $":clock2: Next contest will last for {i} seconds. Type the bolded text as fast as you can."); + await _sender.Response(Channel) + .Confirm( + $":clock2: Next contest will last for {i} seconds. Type the bolded text as fast as you can.") + .SendAsync(); var time = _options.StartTime; @@ -139,18 +143,26 @@ public class TypingGame var elapsed = _sw.Elapsed; var wpm = CurrentSentence.Length / WORD_VALUE / elapsed.TotalSeconds * 60; _finishedUserIds.Add(msg.Author.Id); - await Channel.EmbedAsync(_eb.Create() - .WithOkColor() - .WithTitle($"{msg.Author} finished the race!") - .AddField("Place", $"#{_finishedUserIds.Count}", true) - .AddField("WPM", $"{wpm:F1} *[{elapsed.TotalSeconds:F2}sec]*", true) - .AddField("Errors", distance.ToString(), true)); + + await _sender.Response(Channel) + .Embed(eb => new EmbedBuilder() + .WithOkColor() + .WithTitle($"{msg.Author} finished the race!") + .AddField("Place", $"#{_finishedUserIds.Count}", true) + .AddField("WPM", $"{wpm:F1} *[{elapsed.TotalSeconds:F2}sec]*", true) + .AddField("Errors", distance.ToString(), true)) + .SendAsync(); if (_finishedUserIds.Count % 4 == 0) { - await Channel.SendConfirmAsync(_eb, - ":exclamation: A lot of people finished, here is the text for those still typing:" - + $"\n\n**{Format.Sanitize(CurrentSentence.Replace(" ", " \x200B", StringComparison.InvariantCulture)).SanitizeMentions(true)}**"); + await _sender.Response(Channel) + .Confirm( + $""" + :exclamation: A lot of people finished, here is the text for those still typing: + + **{Format.Sanitize(CurrentSentence.Replace(" ", " \x200B", StringComparison.InvariantCulture)).SanitizeMentions(true)}** + """) + .SendAsync(); } } } diff --git a/src/NadekoBot/Modules/Games/TicTacToe/TicTacToe.cs b/src/NadekoBot/Modules/Games/TicTacToe/TicTacToe.cs index 8d260259f..477dd89b1 100644 --- a/src/NadekoBot/Modules/Games/TicTacToe/TicTacToe.cs +++ b/src/NadekoBot/Modules/Games/TicTacToe/TicTacToe.cs @@ -71,9 +71,9 @@ public class TicTacToe return sb.ToString(); } - public IEmbedBuilder GetEmbed(string title = null) + public EmbedBuilder GetEmbed(string title = null) { - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithDescription(Environment.NewLine + GetState()) .WithAuthor(GetText(strs.vs(_users[0], _users[1]))); @@ -115,13 +115,13 @@ public class TicTacToe { if (phase is Phase.Started or Phase.Ended) { - await _channel.SendErrorAsync(_eb, user.Mention + GetText(strs.ttt_already_running)); + await _channel.Response(_strings, _eb).Error(user.Mention + GetText(strs.ttt_already_running)).SendAsync(); return; } if (_users[0] == user) { - await _channel.SendErrorAsync(_eb, user.Mention + GetText(strs.ttt_against_yourself)); + await _channel.Response(_strings, _eb).Error(user.Mention + GetText(strs.ttt_against_yourself)).SendAsync(); return; } diff --git a/src/NadekoBot/Modules/Games/TicTacToe/TicTacToeCommands.cs b/src/NadekoBot/Modules/Games/TicTacToe/TicTacToeCommands.cs index e1885bc81..ecf127e9a 100644 --- a/src/NadekoBot/Modules/Games/TicTacToe/TicTacToeCommands.cs +++ b/src/NadekoBot/Modules/Games/TicTacToe/TicTacToeCommands.cs @@ -37,7 +37,7 @@ public partial class Games game = new(Strings, _client, channel, (IGuildUser)ctx.User, options, _eb); _service.TicTacToeGames.Add(channel.Id, game); - await ReplyConfirmLocalizedAsync(strs.ttt_created); + await Response().Confirm(strs.ttt_created).SendAsync(); game.OnEnded += _ => { diff --git a/src/NadekoBot/Modules/Games/Trivia/Games.cs b/src/NadekoBot/Modules/Games/Trivia/Games.cs index 9490a6015..6949ce6b5 100644 --- a/src/NadekoBot/Modules/Games/Trivia/Games.cs +++ b/src/NadekoBot/Modules/Games/Trivia/Games.cs @@ -36,7 +36,9 @@ public partial class Games var (opts, _) = OptionsParser.ParseFrom(new TriviaOptions(), args); var config = _gamesConfig.Data; - if (opts.WinRequirement != 0 && config.Trivia.MinimumWinReq > 0 && config.Trivia.MinimumWinReq > opts.WinRequirement) + if (opts.WinRequirement != 0 + && config.Trivia.MinimumWinReq > 0 + && config.Trivia.MinimumWinReq > opts.WinRequirement) return; var trivia = new TriviaGame(opts, _cache); @@ -49,11 +51,11 @@ public partial class Games if (_service.RunningTrivias.TryGetValue(ctx.Guild.Id, out var tg)) { - await SendErrorAsync(GetText(strs.trivia_already_running)); + await Response().Error(GetText(strs.trivia_already_running)).SendAsync(); await tg.TriggerQuestionAsync(); } } - + [Cmd] [RequireContext(ContextType.Guild)] public async Task Tl() @@ -64,7 +66,7 @@ public partial class Games return; } - await ReplyErrorLocalizedAsync(strs.trivia_none); + await Response().Error(strs.trivia_none).SendAsync(); } [Cmd] @@ -79,9 +81,9 @@ public partial class Games { try { - await ctx.Channel.SendConfirmAsync(_eb, - GetText(strs.trivia_game), - GetText(strs.trivia_stopping)); + await Response() + .Confirm(GetText(strs.trivia_game), GetText(strs.trivia_stopping)) + .SendAsync(); } catch (Exception ex) { @@ -92,7 +94,7 @@ public partial class Games return; } - await ReplyErrorLocalizedAsync(strs.trivia_none); + await Response().Error(strs.trivia_none).SendAsync(); } private string GetLeaderboardString(TriviaGame tg) @@ -103,13 +105,12 @@ public partial class Games sb.AppendLine(GetText(strs.trivia_points(Format.Bold($"<@{id}>"), pts))); return sb.ToString(); - } - private IEmbedBuilder? questionEmbed = null; + private EmbedBuilder? questionEmbed = null; private IUserMessage? questionMessage = null; private bool showHowToQuit = false; - + private void RegisterEvents(TriviaGame trivia) { trivia.OnQuestion += OnTriviaQuestion; @@ -119,7 +120,7 @@ public partial class Games trivia.OnStats += OnTriviaStats; trivia.OnTimeout += OnTriviaTimeout; } - + private void UnregisterEvents(TriviaGame trivia) { trivia.OnQuestion -= OnTriviaQuestion; @@ -141,7 +142,8 @@ public partial class Games } if (questionEmbed is not null) - await questionMessage.ModifyAsync(m => m.Embed = questionEmbed.WithFooter(question.GetHint()).Build()); + await questionMessage.ModifyAsync(m + => m.Embed = questionEmbed.WithFooter(question.GetHint()).Build()); } catch (HttpException ex) when (ex.HttpCode is HttpStatusCode.NotFound or HttpStatusCode.Forbidden) { @@ -158,11 +160,11 @@ public partial class Games { try { - questionEmbed = _eb.Create() - .WithOkColor() - .WithTitle(GetText(strs.trivia_game)) - .AddField(GetText(strs.category), question.Category) - .AddField(GetText(strs.question), question.Question); + questionEmbed = new EmbedBuilder() + .WithOkColor() + .WithTitle(GetText(strs.trivia_game)) + .AddField(GetText(strs.category), question.Category) + .AddField(GetText(strs.question), question.Question); showHowToQuit = !showHowToQuit; if (showHowToQuit) @@ -171,9 +173,10 @@ public partial class Games if (Uri.IsWellFormedUriString(question.ImageUrl, UriKind.Absolute)) questionEmbed.WithImageUrl(question.ImageUrl); - questionMessage = await EmbedAsync(questionEmbed); + questionMessage = await Response().Embed(questionEmbed).SendAsync(); } - catch (HttpException ex) when (ex.HttpCode is HttpStatusCode.NotFound or HttpStatusCode.Forbidden + catch (HttpException ex) when (ex.HttpCode is HttpStatusCode.NotFound + or HttpStatusCode.Forbidden or HttpStatusCode.BadRequest) { Log.Warning("Unable to send trivia questions. Stopping immediately"); @@ -186,15 +189,15 @@ public partial class Games { try { - var embed = _eb.Create() - .WithErrorColor() - .WithTitle(GetText(strs.trivia_game)) - .WithDescription(GetText(strs.trivia_times_up(Format.Bold(question.Answer)))); + var embed = new EmbedBuilder() + .WithErrorColor() + .WithTitle(GetText(strs.trivia_game)) + .WithDescription(GetText(strs.trivia_times_up(Format.Bold(question.Answer)))); if (Uri.IsWellFormedUriString(question.AnswerImageUrl, UriKind.Absolute)) embed.WithImageUrl(question.AnswerImageUrl); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } catch { @@ -206,7 +209,7 @@ public partial class Games { try { - await SendConfirmAsync(GetText(strs.leaderboard), GetLeaderboardString(game)); + await Response().Confirm(GetText(strs.leaderboard), GetLeaderboardString(game)).SendAsync(); } catch { @@ -218,11 +221,11 @@ public partial class Games { try { - await EmbedAsync(_eb.Create(ctx) - .WithOkColor() - .WithAuthor(GetText(strs.trivia_ended)) - .WithTitle(GetText(strs.leaderboard)) - .WithDescription(GetLeaderboardString(game))); + await Response().Embed(new EmbedBuilder() + .WithOkColor() + .WithAuthor(GetText(strs.trivia_ended)) + .WithTitle(GetText(strs.leaderboard)) + .WithDescription(GetLeaderboardString(game))).SendAsync(); } catch { @@ -236,15 +239,19 @@ public partial class Games UnregisterEvents(game); } - private async Task OnTriviaGuess(TriviaGame _, TriviaUser user, TriviaQuestion question, bool isWin) + private async Task OnTriviaGuess( + TriviaGame _, + TriviaUser user, + TriviaQuestion question, + bool isWin) { try { - var embed = _eb.Create() - .WithOkColor() - .WithTitle(GetText(strs.trivia_game)) - .WithDescription(GetText(strs.trivia_win(user.Name, - Format.Bold(question.Answer)))); + var embed = new EmbedBuilder() + .WithOkColor() + .WithTitle(GetText(strs.trivia_game)) + .WithDescription(GetText(strs.trivia_win(user.Name, + Format.Bold(question.Answer)))); if (Uri.IsWellFormedUriString(question.AnswerImageUrl, UriKind.Absolute)) embed.WithImageUrl(question.AnswerImageUrl); @@ -252,7 +259,7 @@ public partial class Games if (isWin) { - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); var reward = _gamesConfig.Data.Trivia.CurrencyReward; if (reward > 0) @@ -264,7 +271,7 @@ public partial class Games embed.WithDescription(GetText(strs.trivia_guess(user.Name, Format.Bold(question.Answer)))); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } catch { diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 66d873d65..fc43ee88f 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -56,10 +56,10 @@ public sealed class Help : NadekoModule var clientId = await _lazyClientId.Value; var repCtx = new ReplacementContext(Context) - .WithOverride("{0}", () => clientId.ToString()) - .WithOverride("{1}", () => prefix) - .WithOverride("%prefix%", () => prefix) - .WithOverride("%bot.prefix%", () => prefix); + .WithOverride("{0}", () => clientId.ToString()) + .WithOverride("{1}", () => prefix) + .WithOverride("%prefix%", () => prefix) + .WithOverride("%bot.prefix%", () => prefix); var text = SmartText.CreateFrom(botSettings.HelpText); return await repSvc.ReplaceAsync(text, repCtx); @@ -74,8 +74,11 @@ public sealed class Help : NadekoModule var topLevelModules = new List(); foreach (var m in _cmds.Modules.GroupBy(x => x.GetTopLevelModule()).Select(x => x.Key)) { - var result = await _perms.CheckPermsAsync(ctx.Guild, ctx.Channel, ctx.User, - m.Name, null); + var result = await _perms.CheckPermsAsync(ctx.Guild, + ctx.Channel, + ctx.User, + m.Name, + null); if (result.IsAllowed) topLevelModules.Add(m); @@ -84,7 +87,7 @@ public sealed class Help : NadekoModule await ctx.SendPaginatedConfirmAsync(page, cur => { - var embed = _eb.Create().WithOkColor().WithTitle(GetText(strs.list_of_modules)); + var embed = new EmbedBuilder().WithOkColor().WithTitle(GetText(strs.list_of_modules)); var localModules = topLevelModules.Skip(12 * cur).Take(12).ToList(); @@ -95,12 +98,12 @@ public sealed class Help : NadekoModule } localModules.OrderBy(module => module.Name) - .ToList() - .ForEach(module => embed.AddField($"{GetModuleEmoji(module.Name)} {module.Name}", - GetModuleDescription(module.Name) - + "\n" - + Format.Code(GetText(strs.module_footer(prefix, module.Name.ToLowerInvariant()))), - true)); + .ToList() + .ForEach(module => embed.AddField($"{GetModuleEmoji(module.Name)} {module.Name}", + GetModuleDescription(module.Name) + + "\n" + + Format.Code(GetText(strs.module_footer(prefix, module.Name.ToLowerInvariant()))), + true)); return embed; }, @@ -116,11 +119,11 @@ public sealed class Help : NadekoModule if (key.Key == strs.module_description_missing.Key) { var desc = _medusae - .GetLoadedMedusae(Culture) - .FirstOrDefault(m => m.Sneks - .Any(x => x.Name.Equals(moduleName, - StringComparison.InvariantCultureIgnoreCase))) - ?.Description; + .GetLoadedMedusae(Culture) + .FirstOrDefault(m => m.Sneks + .Any(x => x.Name.Equals(moduleName, + StringComparison.InvariantCultureIgnoreCase))) + ?.Description; if (desc is not null) return desc; @@ -216,20 +219,23 @@ public sealed class Help : NadekoModule var allowed = new List(); foreach (var cmd in _cmds.Commands - .Where(c => c.Module.GetTopLevelModule() - .Name - .StartsWith(module, StringComparison.InvariantCultureIgnoreCase))) + .Where(c => c.Module.GetTopLevelModule() + .Name + .StartsWith(module, StringComparison.InvariantCultureIgnoreCase))) { - var result = await _perms.CheckPermsAsync(ctx.Guild, ctx.Channel, ctx.User, cmd.Module.GetTopLevelModule().Name, + var result = await _perms.CheckPermsAsync(ctx.Guild, + ctx.Channel, + ctx.User, + cmd.Module.GetTopLevelModule().Name, cmd.Name); - + if (result.IsAllowed) allowed.Add(cmd); } var cmds = allowed.OrderBy(c => c.Aliases[0]) - .DistinctBy(x => x.Aliases[0]) - .ToList(); + .DistinctBy(x => x.Aliases[0]) + .ToList(); // check preconditions for all commands, but only if it's not 'all' @@ -238,12 +244,12 @@ public sealed class Help : NadekoModule if (opts.View != CommandsOptions.ViewType.All) { succ = new((await cmds.Select(async x => - { - var pre = await x.CheckPreconditionsAsync(Context, _services); - return (Cmd: x, Succ: pre.IsSuccess); - }) - .WhenAll()).Where(x => x.Succ) - .Select(x => x.Cmd)); + { + var pre = await x.CheckPreconditionsAsync(Context, _services); + return (Cmd: x, Succ: pre.IsSuccess); + }) + .WhenAll()).Where(x => x.Succ) + .Select(x => x.Cmd)); if (opts.View == CommandsOptions.ViewType.Hide) // if hidden is specified, completely remove these commands from the list @@ -251,63 +257,62 @@ public sealed class Help : NadekoModule } var cmdsWithGroup = cmds.GroupBy(c => c.Module.GetGroupName()) - .OrderBy(x => x.Key == x.First().Module.Name ? int.MaxValue : x.Count()) - .ToList(); + .OrderBy(x => x.Key == x.First().Module.Name ? int.MaxValue : x.Count()) + .ToList(); if (cmdsWithGroup.Count == 0) { if (opts.View != CommandsOptions.ViewType.Hide) - await ReplyErrorLocalizedAsync(strs.module_not_found); + await Response().Error(strs.module_not_found).SendAsync(); else - await ReplyErrorLocalizedAsync(strs.module_not_found_or_cant_exec); + await Response().Error(strs.module_not_found_or_cant_exec).SendAsync(); return; } var cnt = 0; var groups = cmdsWithGroup.GroupBy(_ => cnt++ / 48).ToArray(); - var embed = _eb.Create().WithOkColor(); + var embed = new EmbedBuilder().WithOkColor(); foreach (var g in groups) { var last = g.Count(); for (var i = 0; i < last; i++) { var transformed = g.ElementAt(i) - .Select(x => - { - //if cross is specified, and the command doesn't satisfy the requirements, cross it out - if (opts.View == CommandsOptions.ViewType.Cross) - { - return - $"{(succ.Contains(x) ? "✅" : "❌")} {prefix + x.Aliases[0]}"; - } + .Select(x => + { + //if cross is specified, and the command doesn't satisfy the requirements, cross it out + if (opts.View == CommandsOptions.ViewType.Cross) + { + return + $"{(succ.Contains(x) ? "✅" : "❌")} {prefix + x.Aliases[0]}"; + } - if (x.Aliases.Count == 1) - return prefix + x.Aliases[0]; + if (x.Aliases.Count == 1) + return prefix + x.Aliases[0]; + + return prefix + x.Aliases[0] + " / " + prefix + x.Aliases[1]; + }); - return prefix + x.Aliases[0] + " / " + prefix + x.Aliases[1]; - - }); - embed.AddField(g.ElementAt(i).Key, "" + string.Join("\n", transformed) + "", true); } } embed.WithFooter(GetText(strs.commands_instr(prefix))); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } private async Task Group(ModuleInfo group) { - var eb = _eb.Create(ctx) - .WithTitle(GetText(strs.cmd_group_commands(group.Name))) - .WithOkColor(); + var eb = new EmbedBuilder() + .WithTitle(GetText(strs.cmd_group_commands(group.Name))) + .WithOkColor(); foreach (var cmd in group.Commands.DistinctBy(x => x.Aliases[0])) { eb.AddField(prefix + cmd.Aliases.First(), cmd.RealSummary(_strings, _medusae, Culture, prefix)); } - await EmbedAsync(eb); + await Response().Embed(eb).SendAsync(); } [Cmd] @@ -326,9 +331,9 @@ public sealed class Help : NadekoModule fail = fail.Substring(prefix.Length); var group = _cmds.Modules - .SelectMany(x => x.Submodules) - .Where(x => !string.IsNullOrWhiteSpace(x.Group)) - .FirstOrDefault(x => x.Group.Equals(fail, StringComparison.InvariantCultureIgnoreCase)); + .SelectMany(x => x.Submodules) + .Where(x => !string.IsNullOrWhiteSpace(x.Group)) + .FirstOrDefault(x => x.Group.Equals(fail, StringComparison.InvariantCultureIgnoreCase)); if (group is not null) { @@ -336,7 +341,7 @@ public sealed class Help : NadekoModule return; } - await ReplyErrorLocalizedAsync(strs.command_not_found); + await Response().Error(strs.command_not_found).SendAsync(); } [Cmd] @@ -364,7 +369,7 @@ public sealed class Help : NadekoModule } catch (Exception) { - await ReplyErrorLocalizedAsync(strs.cant_dm); + await Response().Error(strs.cant_dm).SendAsync(); } return; @@ -383,29 +388,29 @@ public sealed class Help : NadekoModule // order commands by top level module name // and make a dictionary of > var cmdData = _cmds.Commands.GroupBy(x => x.Module.GetTopLevelModule().Name) - .OrderBy(x => x.Key) - .ToDictionary(x => x.Key, - x => x.DistinctBy(c => c.Aliases.First()) - .Select(com => - { - List optHelpStr = null; + .OrderBy(x => x.Key) + .ToDictionary(x => x.Key, + x => x.DistinctBy(c => c.Aliases.First()) + .Select(com => + { + List optHelpStr = null; - var opt = CommandsUtilityService.GetNadekoOptionType(com.Attributes); - if (opt is not null) - optHelpStr = CommandsUtilityService.GetCommandOptionHelpList(opt); + var opt = CommandsUtilityService.GetNadekoOptionType(com.Attributes); + if (opt is not null) + optHelpStr = CommandsUtilityService.GetCommandOptionHelpList(opt); - return new CommandJsonObject - { - Aliases = com.Aliases.Select(alias => prefix + alias).ToArray(), - Description = com.RealSummary(_strings, _medusae, Culture, prefix), - Usage = com.RealRemarksArr(_strings, _medusae, Culture, prefix), - Submodule = com.Module.Name, - Module = com.Module.GetTopLevelModule().Name, - Options = optHelpStr, - Requirements = CommandsUtilityService.GetCommandRequirements(com) - }; - }) - .ToList()); + return new CommandJsonObject + { + Aliases = com.Aliases.Select(alias => prefix + alias).ToArray(), + Description = com.RealSummary(_strings, _medusae, Culture, prefix), + Usage = com.RealRemarksArr(_strings, _medusae, Culture, prefix), + Submodule = com.Module.Name, + Module = com.Module.GetTopLevelModule().Name, + Options = optHelpStr, + Requirements = CommandsUtilityService.GetCommandRequirements(com) + }; + }) + .ToList()); var readableData = JsonConvert.SerializeObject(cmdData, Formatting.Indented); var uploadData = JsonConvert.SerializeObject(cmdData, Formatting.None); @@ -498,21 +503,23 @@ public sealed class Help : NadekoModule [Cmd] public async Task Guide() - => await ConfirmLocalizedAsync(strs.guide("https://nadeko.bot/commands", - "https://nadekobot.readthedocs.io/en/latest/")); + => await Response() + .Confirm(strs.guide("https://nadeko.bot/commands", + "https://nadekobot.readthedocs.io/en/latest/")) + .SendAsync(); private Task SelfhostAction(SocketMessageComponent smc, object _) => smc.RespondConfirmAsync(_eb, """ - - In case you don't want or cannot Donate to NadekoBot project, but you - - NadekoBot is a completely free and fully [open source](https://gitlab.com/kwoth/nadekobot) project which means you can run your own "selfhosted" instance on your computer or server for free. - - *Keep in mind that running the bot on your computer means that the bot will be offline when you turn off your computer* - - - You can find the selfhosting guides by using the `.guide` command and clicking on the second link that pops up. - - If you decide to selfhost the bot, still consider [supporting the project](https://patreon.com/join/nadekobot) to keep the development going :) - """, + - In case you don't want or cannot Donate to NadekoBot project, but you + - NadekoBot is a completely free and fully [open source](https://gitlab.com/kwoth/nadekobot) project which means you can run your own "selfhosted" instance on your computer or server for free. + + *Keep in mind that running the bot on your computer means that the bot will be offline when you turn off your computer* + + - You can find the selfhosting guides by using the `.guide` command and clicking on the second link that pops up. + - If you decide to selfhost the bot, still consider [supporting the project](https://patreon.com/join/nadekobot) to keep the development going :) + """, true); [Cmd] @@ -527,9 +534,9 @@ public sealed class Help : NadekoModule label: "Selfhosting"), SelfhostAction)); - var eb = _eb.Create(ctx) - .WithOkColor() - .WithTitle("Thank you for considering to donate to the NadekoBot project!"); + var eb = new EmbedBuilder() + .WithOkColor() + .WithTitle("Thank you for considering to donate to the NadekoBot project!"); eb .WithDescription("NadekoBot relies on donations to keep the servers, services and APIs running.\n" @@ -558,13 +565,13 @@ Nadeko will DM you the welcome instructions, and you may start using the patron- ") .AddField("Troubleshooting", """ - - *In case you didn't receive the rewards within 5 minutes:* - `1.` Make sure your DMs are open to everyone. Maybe your pledge was processed successfully but the bot was unable to DM you. Use the `.patron` command to check your status. - `2.` Make sure you've connected the CORRECT Discord account. Quite often users log in to different Discord accounts in their browser. You may also try disconnecting and reconnecting your account. - `3.` Make sure your payment has been processed and not declined by Patreon. - `4.` If any of the previous steps don't help, you can join the nadeko support server and ask for help in the #help channel - """); + + *In case you didn't receive the rewards within 5 minutes:* + `1.` Make sure your DMs are open to everyone. Maybe your pledge was processed successfully but the bot was unable to DM you. Use the `.patron` command to check your status. + `2.` Make sure you've connected the CORRECT Discord account. Quite often users log in to different Discord accounts in their browser. You may also try disconnecting and reconnecting your account. + `3.` Make sure your payment has been processed and not declined by Patreon. + `4.` If any of the previous steps don't help, you can join the nadeko support server and ask for help in the #help channel + """); try { @@ -573,7 +580,7 @@ Nadeko will DM you the welcome instructions, and you may start using the patron- } catch { - await ReplyErrorLocalizedAsync(strs.cant_dm); + await Response().Error(strs.cant_dm).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Medusae/Medusa.cs b/src/NadekoBot/Modules/Medusae/Medusa.cs index fa418cb27..66437a476 100644 --- a/src/NadekoBot/Modules/Medusae/Medusa.cs +++ b/src/NadekoBot/Modules/Medusae/Medusa.cs @@ -29,14 +29,14 @@ public partial class Medusa : NadekoModule if (unloaded.Length == 0) { - await ReplyPendingLocalizedAsync(strs.no_medusa_available); + await Response().Pending(strs.no_medusa_available).SendAsync(); return; } await ctx.SendPaginatedConfirmAsync(0, page => { - return _eb.Create(ctx) + return new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.list_of_unloaded)) .WithDescription(unloaded.Skip(10 * page).Take(10).Join('\n')); @@ -48,7 +48,7 @@ public partial class Medusa : NadekoModule var res = await _service.LoadMedusaAsync(name); if (res == MedusaLoadResult.Success) - await ReplyConfirmLocalizedAsync(strs.medusa_loaded(Format.Code(name))); + await Response().Confirm(strs.medusa_loaded(Format.Code(name))).SendAsync(); else { var locStr = res switch @@ -60,7 +60,7 @@ public partial class Medusa : NadekoModule _ => strs.error_occured }; - await ReplyErrorLocalizedAsync(locStr); + await Response().Error(locStr).SendAsync(); } } @@ -73,22 +73,22 @@ public partial class Medusa : NadekoModule var loaded = _service.GetLoadedMedusae(); if (loaded.Count == 0) { - await ReplyPendingLocalizedAsync(strs.no_medusa_loaded); + await Response().Pending(strs.no_medusa_loaded).SendAsync(); return; } - await EmbedAsync(_eb.Create(ctx) + await Response().Embed(new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.loaded_medusae)) .WithDescription(loaded.Select(x => x.Name) - .Join("\n"))); + .Join("\n"))).SendAsync(); return; } var res = await _service.UnloadMedusaAsync(name); if (res == MedusaUnloadResult.Success) - await ReplyConfirmLocalizedAsync(strs.medusa_unloaded(Format.Code(name))); + await Response().Confirm(strs.medusa_unloaded(Format.Code(name))).SendAsync(); else { var locStr = res switch @@ -98,7 +98,7 @@ public partial class Medusa : NadekoModule _ => strs.error_occured }; - await ReplyErrorLocalizedAsync(locStr); + await Response().Error(locStr).SendAsync(); } } @@ -110,7 +110,7 @@ public partial class Medusa : NadekoModule if (all.Count == 0) { - await ReplyPendingLocalizedAsync(strs.no_medusa_available); + await Response().Pending(strs.no_medusa_available).SendAsync(); return; } @@ -128,7 +128,7 @@ public partial class Medusa : NadekoModule await ctx.SendPaginatedConfirmAsync(0, - page => _eb.Create(ctx) + page => new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.list_of_medusae)) .WithDescription(output.Skip(page * 10).Take(10).Join('\n')), @@ -150,7 +150,7 @@ public partial class Medusa : NadekoModule if (found is null) { - await ReplyErrorLocalizedAsync(strs.medusa_name_not_found); + await Response().Error(strs.medusa_name_not_found).SendAsync(); return; } @@ -161,7 +161,7 @@ public partial class Medusa : NadekoModule : $"{x.Prefix} {x.Name}")) .Join("\n"); - var eb = _eb.Create(ctx) + var eb = new EmbedBuilder() .WithOkColor() .WithAuthor(GetText(strs.medusa_info)) .WithTitle(found.Name) @@ -177,20 +177,20 @@ public partial class Medusa : NadekoModule : cmdNames, true); - await EmbedAsync(eb); + await Response().Embed(eb).SendAsync(); return; } if (medusae.Count == 0) { - await ReplyPendingLocalizedAsync(strs.no_medusa_loaded); + await Response().Pending(strs.no_medusa_loaded).SendAsync(); return; } await ctx.SendPaginatedConfirmAsync(0, page => { - var eb = _eb.Create(ctx) + var eb = new EmbedBuilder() .WithOkColor(); foreach (var medusa in medusae.Skip(page * 9).Take(9)) @@ -212,7 +212,7 @@ public partial class Medusa : NadekoModule [OwnerOnly] public async Task MedusaSearch() { - var eb = _eb.Create() + var eb = new EmbedBuilder() .WithTitle(GetText(strs.list_of_medusae)) .WithOkColor(); @@ -224,6 +224,6 @@ public partial class Medusa : NadekoModule """, true); } - await EmbedAsync(eb); + await Response().Embed(eb).SendAsync(); } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 9fdb26cf0..5c8d18fb8 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -33,14 +33,14 @@ public sealed partial class Music : NadekoModule if (userVoiceChannelId is null) { - await ReplyErrorLocalizedAsync(strs.must_be_in_voice); + await Response().Error(strs.must_be_in_voice).SendAsync(); return false; } var currentUser = await ctx.Guild.GetCurrentUserAsync(); if (currentUser.VoiceChannel?.Id != userVoiceChannelId) { - await ReplyErrorLocalizedAsync(strs.not_with_bot_in_voice); + await Response().Error(strs.not_with_bot_in_voice).SendAsync(); return false; } @@ -69,7 +69,7 @@ public sealed partial class Music : NadekoModule if (voiceChannelId is null) { - await ReplyErrorLocalizedAsync(strs.must_be_in_voice); + await Response().Error(strs.must_be_in_voice).SendAsync(); return false; } @@ -80,7 +80,7 @@ public sealed partial class Music : NadekoModule if (botUser.VoiceChannel?.Id != voiceChannelId) { - await ReplyErrorLocalizedAsync(strs.not_with_bot_in_voice); + await Response().Error(strs.not_with_bot_in_voice).SendAsync(); return false; } @@ -96,20 +96,20 @@ public sealed partial class Music : NadekoModule var mp = await _service.GetOrCreateMusicPlayerAsync((ITextChannel)ctx.Channel); if (mp is null) { - await ReplyErrorLocalizedAsync(strs.no_player); + await Response().Error(strs.no_player).SendAsync(); return; } var (trackInfo, index) = await mp.TryEnqueueTrackAsync(query, ctx.User.ToString(), asNext, forcePlatform); if (trackInfo is null) { - await ReplyErrorLocalizedAsync(strs.track_not_found); + await Response().Error(strs.track_not_found).SendAsync(); return; } try { - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithAuthor(GetText(strs.queued_track) + " #" + (index + 1), MUSIC_ICON_URL) .WithDescription($"{trackInfo.PrettyName()}\n{GetText(strs.queue)} ") @@ -122,7 +122,7 @@ public sealed partial class Music : NadekoModule queuedMessage?.DeleteAfter(10, _logService); if (mp.IsStopped) { - var msg = await ReplyPendingLocalizedAsync(strs.queue_stopped(Format.Code(prefix + "play"))); + var msg = await Response().Pending(strs.queue_stopped(Format.Code(prefix + "play"))).SendAsync(); msg.DeleteAfter(10, _logService); } } @@ -144,7 +144,7 @@ public sealed partial class Music : NadekoModule var mp = await _service.GetOrCreateMusicPlayerAsync((ITextChannel)ctx.Channel); if (mp is null) { - await ReplyErrorLocalizedAsync(strs.no_player); + await Response().Error(strs.no_player).SendAsync(); return; } @@ -162,7 +162,7 @@ public sealed partial class Music : NadekoModule if (voiceChannelId is null) { - await ReplyErrorLocalizedAsync(strs.must_be_in_voice); + await Response().Error(strs.must_be_in_voice).SendAsync(); return; } @@ -218,7 +218,7 @@ public sealed partial class Music : NadekoModule { if (vol is < 0 or > 100) { - await ReplyErrorLocalizedAsync(strs.volume_input_invalid); + await Response().Error(strs.volume_input_invalid).SendAsync(); return; } @@ -227,7 +227,7 @@ public sealed partial class Music : NadekoModule return; await _service.SetVolumeAsync(ctx.Guild.Id, vol); - await ReplyConfirmLocalizedAsync(strs.volume_set(vol)); + await Response().Confirm(strs.volume_set(vol)).SendAsync(); } [Cmd] @@ -240,7 +240,7 @@ public sealed partial class Music : NadekoModule var success = await _service.PlayAsync(ctx.Guild.Id, ((IGuildUser)ctx.User).VoiceChannel.Id); if (!success) - await ReplyErrorLocalizedAsync(strs.no_player); + await Response().Error(strs.no_player).SendAsync(); } // list queue, relevant page @@ -251,7 +251,7 @@ public sealed partial class Music : NadekoModule // show page with the current track if (!_service.TryGetMusicPlayer(ctx.Guild.Id, out var mp)) { - await ReplyErrorLocalizedAsync(strs.no_player); + await Response().Error(strs.no_player).SendAsync(); return; } @@ -269,11 +269,11 @@ public sealed partial class Music : NadekoModule IReadOnlyCollection tracks; if (!_service.TryGetMusicPlayer(ctx.Guild.Id, out var mp) || (tracks = mp.GetQueuedTracks()).Count == 0) { - await ReplyErrorLocalizedAsync(strs.no_player); + await Response().Error(strs.no_player).SendAsync(); return; } - IEmbedBuilder PrintAction(int curPage) + EmbedBuilder PrintAction(int curPage) { var desc = string.Empty; var current = mp.GetCurrentTrack(out var currentIndex); @@ -315,7 +315,7 @@ public sealed partial class Music : NadekoModule if (!string.IsNullOrWhiteSpace(add)) desc = add + "\n" + desc; - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithAuthor(GetText(strs.player_queue(curPage + 1, (tracks.Count / LQ_ITEMS_PER_PAGE) + 1)), MUSIC_ICON_URL) .WithDescription(desc) @@ -339,13 +339,13 @@ public sealed partial class Music : NadekoModule if (videos.Count == 0) { - await ReplyErrorLocalizedAsync(strs.track_not_found); + await Response().Error(strs.track_not_found).SendAsync(); return; } var resultsString = videos.Select((x, i) => $"`{i + 1}.`\n\t{Format.Bold(x.Title)}\n\t{x.Url}").Join('\n'); - var msg = await SendConfirmAsync(resultsString); + var msg = await Response().Confirm(resultsString).SendAsync(); try { @@ -388,7 +388,7 @@ public sealed partial class Music : NadekoModule { if (index < 1) { - await ReplyErrorLocalizedAsync(strs.removed_track_error); + await Response().Error(strs.removed_track_error).SendAsync(); return; } @@ -398,17 +398,17 @@ public sealed partial class Music : NadekoModule if (!_service.TryGetMusicPlayer(ctx.Guild.Id, out var mp)) { - await ReplyErrorLocalizedAsync(strs.no_player); + await Response().Error(strs.no_player).SendAsync(); return; } if (!mp.TryRemoveTrackAt(index - 1, out var track)) { - await ReplyErrorLocalizedAsync(strs.removed_track_error); + await Response().Error(strs.removed_track_error).SendAsync(); return; } - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithAuthor(GetText(strs.removed_track) + " #" + index, MUSIC_ICON_URL) .WithDescription(track.PrettyName()) .WithFooter(track.PrettyInfo()) @@ -428,12 +428,12 @@ public sealed partial class Music : NadekoModule if (!_service.TryGetMusicPlayer(ctx.Guild.Id, out var mp)) { - await ReplyErrorLocalizedAsync(strs.no_player); + await Response().Error(strs.no_player).SendAsync(); return; } mp.Clear(); - await ReplyConfirmLocalizedAsync(strs.queue_cleared); + await Response().Confirm(strs.queue_cleared).SendAsync(); } [Cmd] @@ -446,7 +446,7 @@ public sealed partial class Music : NadekoModule if (!_service.TryGetMusicPlayer(ctx.Guild.Id, out var mp)) { - await ReplyErrorLocalizedAsync(strs.no_player); + await Response().Error(strs.no_player).SendAsync(); return; } @@ -473,11 +473,11 @@ public sealed partial class Music : NadekoModule await _service.SetRepeatAsync(ctx.Guild.Id, InputToDbType(type)); if (type == InputRepeatType.None) - await ReplyConfirmLocalizedAsync(strs.repeating_none); + await Response().Confirm(strs.repeating_none).SendAsync(); else if (type == InputRepeatType.Queue) - await ReplyConfirmLocalizedAsync(strs.repeating_queue); + await Response().Confirm(strs.repeating_queue).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.repeating_track); + await Response().Confirm(strs.repeating_track).SendAsync(); } [Cmd] @@ -490,7 +490,7 @@ public sealed partial class Music : NadekoModule if (!_service.TryGetMusicPlayer(ctx.Guild.Id, out var mp) || mp.GetCurrentTrack(out _) is null) { - await ReplyErrorLocalizedAsync(strs.no_player); + await Response().Error(strs.no_player).SendAsync(); return; } @@ -521,7 +521,7 @@ public sealed partial class Music : NadekoModule if (voiceChannelId is null) { - await ReplyErrorLocalizedAsync(strs.must_be_in_voice); + await Response().Error(strs.must_be_in_voice).SendAsync(); return; } @@ -532,20 +532,20 @@ public sealed partial class Music : NadekoModule if (botUser.VoiceChannel?.Id != voiceChannelId) { - await ReplyErrorLocalizedAsync(strs.not_with_bot_in_voice); + await Response().Error(strs.not_with_bot_in_voice).SendAsync(); return; } var mp = await _service.GetOrCreateMusicPlayerAsync((ITextChannel)ctx.Channel); if (mp is null) { - await ReplyErrorLocalizedAsync(strs.no_player); + await Response().Error(strs.no_player).SendAsync(); return; } await _service.EnqueueDirectoryAsync(mp, dirPath, ctx.User.ToString()); - await ReplyConfirmLocalizedAsync(strs.dir_queue_complete); + await Response().Confirm(strs.dir_queue_complete).SendAsync(); } [Cmd] @@ -554,7 +554,7 @@ public sealed partial class Music : NadekoModule { if (--from < 0 || --to < 0 || from == to) { - await ReplyErrorLocalizedAsync(strs.invalid_input); + await Response().Error(strs.invalid_input).SendAsync(); return; } @@ -565,18 +565,18 @@ public sealed partial class Music : NadekoModule var mp = await _service.GetOrCreateMusicPlayerAsync((ITextChannel)ctx.Channel); if (mp is null) { - await ReplyErrorLocalizedAsync(strs.no_player); + await Response().Error(strs.no_player).SendAsync(); return; } var track = mp.MoveTrack(from, to); if (track is null) { - await ReplyErrorLocalizedAsync(strs.invalid_input); + await Response().Error(strs.invalid_input).SendAsync(); return; } - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithTitle(track.Title.TrimTo(65)) .WithAuthor(GetText(strs.track_moved), MUSIC_ICON_URL) .AddField(GetText(strs.from_position), $"#{from + 1}", true) @@ -586,7 +586,7 @@ public sealed partial class Music : NadekoModule if (Uri.IsWellFormedUriString(track.Url, UriKind.Absolute)) embed.WithUrl(track.Url); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -603,7 +603,7 @@ public sealed partial class Music : NadekoModule var mp = await _service.GetOrCreateMusicPlayerAsync((ITextChannel)ctx.Channel); if (mp is null) { - await ReplyErrorLocalizedAsync(strs.no_player); + await Response().Error(strs.no_player).SendAsync(); return; } @@ -613,7 +613,7 @@ public sealed partial class Music : NadekoModule var queuedCount = await _service.EnqueueYoutubePlaylistAsync(mp, playlistQuery, ctx.User.ToString()); if (queuedCount == 0) { - await ReplyErrorLocalizedAsync(strs.no_search_results); + await Response().Error(strs.no_search_results).SendAsync(); return; } @@ -627,7 +627,7 @@ public sealed partial class Music : NadekoModule var mp = await _service.GetOrCreateMusicPlayerAsync((ITextChannel)ctx.Channel); if (mp is null) { - await ReplyErrorLocalizedAsync(strs.no_player); + await Response().Error(strs.no_player).SendAsync(); return; } @@ -635,7 +635,7 @@ public sealed partial class Music : NadekoModule if (currentTrack is null) return; - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithAuthor(GetText(strs.now_playing), MUSIC_ICON_URL) .WithDescription(currentTrack.PrettyName()) @@ -643,7 +643,7 @@ public sealed partial class Music : NadekoModule .WithFooter( $"{mp.PrettyVolume()} | {mp.PrettyTotalTime()} | {currentTrack.Platform} | {currentTrack.Queuer}"); - await ctx.Channel.EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -657,12 +657,12 @@ public sealed partial class Music : NadekoModule var mp = await _service.GetOrCreateMusicPlayerAsync((ITextChannel)ctx.Channel); if (mp is null) { - await ReplyErrorLocalizedAsync(strs.no_player); + await Response().Error(strs.no_player).SendAsync(); return; } mp.ShuffleQueue(); - await ReplyConfirmLocalizedAsync(strs.queue_shuffled); + await Response().Confirm(strs.queue_shuffled).SendAsync(); } [Cmd] @@ -672,7 +672,7 @@ public sealed partial class Music : NadekoModule { await _service.SetMusicChannelAsync(ctx.Guild.Id, ctx.Channel.Id); - await ReplyConfirmLocalizedAsync(strs.set_music_channel); + await Response().Confirm(strs.set_music_channel).SendAsync(); } [Cmd] @@ -682,7 +682,7 @@ public sealed partial class Music : NadekoModule { await _service.SetMusicChannelAsync(ctx.Guild.Id, null); - await ReplyConfirmLocalizedAsync(strs.unset_music_channel); + await Response().Confirm(strs.unset_music_channel).SendAsync(); } [Cmd] @@ -692,9 +692,9 @@ public sealed partial class Music : NadekoModule var newState = await _service.ToggleAutoDisconnectAsync(ctx.Guild.Id); if (newState) - await ReplyConfirmLocalizedAsync(strs.autodc_enable); + await Response().Confirm(strs.autodc_enable).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.autodc_disable); + await Response().Confirm(strs.autodc_disable).SendAsync(); } [Cmd] @@ -703,7 +703,7 @@ public sealed partial class Music : NadekoModule public async Task MusicQuality() { var quality = await _service.GetMusicQualityAsync(ctx.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.current_music_quality(Format.Bold(quality.ToString()))); + await Response().Confirm(strs.current_music_quality(Format.Bold(quality.ToString()))).SendAsync(); } [Cmd] @@ -712,7 +712,7 @@ public sealed partial class Music : NadekoModule public async Task MusicQuality(QualityPreset preset) { await _service.SetMusicQualityAsync(ctx.Guild.Id, preset); - await ReplyConfirmLocalizedAsync(strs.music_quality_set(Format.Bold(preset.ToString()))); + await Response().Confirm(strs.music_quality_set(Format.Bold(preset.ToString()))).SendAsync(); } [Cmd] @@ -721,9 +721,9 @@ public sealed partial class Music : NadekoModule { var newValue = await _service.ToggleQueueAutoPlayAsync(ctx.Guild.Id); if (newValue) - await ReplyConfirmLocalizedAsync(strs.music_autoplay_on); + await Response().Confirm(strs.music_autoplay_on).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.music_autoplay_off); + await Response().Confirm(strs.music_autoplay_off).SendAsync(); } [Cmd] @@ -732,8 +732,8 @@ public sealed partial class Music : NadekoModule { var newValue = await _service.FairplayAsync(ctx.Guild.Id); if (newValue) - await ReplyConfirmLocalizedAsync(strs.music_fairplay); + await Response().Confirm(strs.music_fairplay).SendAsync(); else - await ReplyErrorLocalizedAsync(strs.no_player); + await Response().Error(strs.no_player).SendAsync(); } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Music/PlaylistCommands.cs b/src/NadekoBot/Modules/Music/PlaylistCommands.cs index 5ef929d7e..1a60dc1d0 100644 --- a/src/NadekoBot/Modules/Music/PlaylistCommands.cs +++ b/src/NadekoBot/Modules/Music/PlaylistCommands.cs @@ -50,13 +50,13 @@ public sealed partial class Music playlists = uow.Set().GetPlaylistsOnPage(num); } - var embed = _eb.Create(ctx) + var embed = new EmbedBuilder() .WithAuthor(GetText(strs.playlists_page(num)), MUSIC_ICON_URL) .WithDescription(string.Join("\n", playlists.Select(r => GetText(strs.playlists(r.Id, r.Name, r.Author, r.Songs.Count))))) .WithOkColor(); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -85,9 +85,9 @@ public sealed partial class Music } if (!success) - await ReplyErrorLocalizedAsync(strs.playlist_delete_fail); + await Response().Error(strs.playlist_delete_fail).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.playlist_deleted); + await Response().Confirm(strs.playlist_deleted).SendAsync(); } [Cmd] @@ -111,7 +111,7 @@ public sealed partial class Music mpl.Songs.Skip(cur * 20) .Take(20) .Select(x => $"`{++i}.` [{x.Title.TrimTo(45)}]({x.Query}) `{x.Provider}`")); - return _eb.Create().WithTitle($"\"{mpl.Name}\" by {mpl.Author}").WithOkColor().WithDescription(str); + return new EmbedBuilder().WithTitle($"\"{mpl.Name}\" by {mpl.Author}").WithOkColor().WithDescription(str); }, mpl.Songs.Count, 20); @@ -123,7 +123,7 @@ public sealed partial class Music { if (!_service.TryGetMusicPlayer(ctx.Guild.Id, out var mp)) { - await ReplyErrorLocalizedAsync(strs.no_player); + await Response().Error(strs.no_player).SendAsync(); return; } @@ -151,11 +151,11 @@ public sealed partial class Music await uow.SaveChangesAsync(); } - await EmbedAsync(_eb.Create() + await Response().Embed(new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.playlist_saved)) .AddField(GetText(strs.name), name) - .AddField(GetText(strs.id), playlist.Id.ToString())); + .AddField(GetText(strs.id), playlist.Id.ToString())).SendAsync(); } [Cmd] @@ -171,7 +171,7 @@ public sealed partial class Music if (voiceChannelId is null) { - await ReplyErrorLocalizedAsync(strs.must_be_in_voice); + await Response().Error(strs.must_be_in_voice).SendAsync(); return; } @@ -182,14 +182,14 @@ public sealed partial class Music if (botUser.VoiceChannel?.Id != voiceChannelId) { - await ReplyErrorLocalizedAsync(strs.not_with_bot_in_voice); + await Response().Error(strs.not_with_bot_in_voice).SendAsync(); return; } var mp = await _service.GetOrCreateMusicPlayerAsync((ITextChannel)ctx.Channel); if (mp is null) { - await ReplyErrorLocalizedAsync(strs.no_player); + await Response().Error(strs.no_player).SendAsync(); return; } @@ -201,7 +201,7 @@ public sealed partial class Music if (mpl is null) { - await ReplyErrorLocalizedAsync(strs.playlist_id_not_found); + await Response().Error(strs.playlist_id_not_found).SendAsync(); return; } diff --git a/src/NadekoBot/Modules/Music/Services/IMusicService.cs b/src/NadekoBot/Modules/Music/Services/IMusicService.cs index 3c647e168..186bcfd6a 100644 --- a/src/NadekoBot/Modules/Music/Services/IMusicService.cs +++ b/src/NadekoBot/Modules/Music/Services/IMusicService.cs @@ -22,7 +22,7 @@ public interface IMusicService : IPlaceholderProvider bool TryGetMusicPlayer(ulong guildId, [MaybeNullWhen(false)] out IMusicPlayer musicPlayer); Task EnqueueYoutubePlaylistAsync(IMusicPlayer mp, string playlistId, string queuer); Task EnqueueDirectoryAsync(IMusicPlayer mp, string dirPath, string queuer); - Task SendToOutputAsync(ulong guildId, IEmbedBuilder embed); + Task SendToOutputAsync(ulong guildId, EmbedBuilder embed); Task PlayAsync(ulong guildId, ulong voiceChannelId); Task> SearchVideosAsync(string query); Task SetMusicChannelAsync(ulong guildId, ulong? channelId); diff --git a/src/NadekoBot/Modules/Music/Services/MusicService.cs b/src/NadekoBot/Modules/Music/Services/MusicService.cs index 60acfd458..77182d108 100644 --- a/src/NadekoBot/Modules/Music/Services/MusicService.cs +++ b/src/NadekoBot/Modules/Music/Services/MusicService.cs @@ -159,7 +159,7 @@ public sealed class MusicService : IMusicService return mp; } - public async Task SendToOutputAsync(ulong guildId, IEmbedBuilder embed) + public async Task SendToOutputAsync(ulong guildId, EmbedBuilder embed) { if (_outputChannels.TryGetValue(guildId, out var chan)) { @@ -176,7 +176,7 @@ public sealed class MusicService : IMusicService return async (mp, trackInfo) => { _ = lastFinishedMessage?.DeleteAsync(); - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithAuthor(GetText(guildId, strs.finished_track), Music.MUSIC_ICON_URL) .WithDescription(trackInfo.PrettyName()) @@ -192,7 +192,7 @@ public sealed class MusicService : IMusicService return async (mp, trackInfo, index) => { _ = lastPlayingMessage?.DeleteAsync(); - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithAuthor(GetText(guildId, strs.playing_track(index + 1)), Music.MUSIC_ICON_URL) .WithDescription(trackInfo.PrettyName()) diff --git a/src/NadekoBot/Modules/Patronage/CurrencyRewardService.cs b/src/NadekoBot/Modules/Patronage/CurrencyRewardService.cs index cf670cf93..4f8788103 100644 --- a/src/NadekoBot/Modules/Patronage/CurrencyRewardService.cs +++ b/src/NadekoBot/Modules/Patronage/CurrencyRewardService.cs @@ -171,7 +171,7 @@ public sealed class CurrencyRewardService : INService, IDisposable if (user is null) return; - var eb = _eb.Create() + var eb = new EmbedBuilder() .WithOkColor() .WithDescription(message); diff --git a/src/NadekoBot/Modules/Patronage/PatronageCommands.cs b/src/NadekoBot/Modules/Patronage/PatronageCommands.cs index cd7c8e254..3015a16be 100644 --- a/src/NadekoBot/Modules/Patronage/PatronageCommands.cs +++ b/src/NadekoBot/Modules/Patronage/PatronageCommands.cs @@ -31,10 +31,10 @@ public partial class Patronage : NadekoModule _ = ctx.Channel.TriggerTypingAsync(); var result = await _service.SendMessageToPatronsAsync(tierAndHigher, message); - await ReplyConfirmLocalizedAsync(strs.patron_msg_sent( + await Response().Confirm(strs.patron_msg_sent( Format.Code(tierAndHigher.ToString()), Format.Bold(result.Success.ToString()), - Format.Bold(result.Failed.ToString()))); + Format.Bold(result.Failed.ToString()))).SendAsync(); } // [OwnerOnly] @@ -47,12 +47,12 @@ public partial class Patronage : NadekoModule // // var patron = _service.GiftPatronAsync(user, amount); // - // var eb = _eb.Create(ctx); + // var eb = new EmbedBuilder(); // - // await EmbedAsync(eb.WithDescription($"Added **{days}** days of Patron benefits to {user.Mention}!") + // await Response().Embed(eb.WithDescription($"Added **{days}** days of Patron benefits to {user.Mention}!") // .AddField("Tier", Format.Bold(patron.Tier.ToString()), true) // .AddField("Amount", $"**{patron.Amount / 100.0f:N1}$**", true) - // .AddField("Until", TimestampTag.FromDateTime(patron.ValidThru.AddDays(1)))); + // .AddField("Until", TimestampTag.FromDateTime(patron.ValidThru.AddDays(1)))).SendAsync(); // // // } @@ -61,14 +61,14 @@ public partial class Patronage : NadekoModule { if (!_pConf.Data.IsEnabled) { - await ReplyErrorLocalizedAsync(strs.patron_not_enabled); + await Response().Error(strs.patron_not_enabled).SendAsync(); return; } var patron = await _service.GetPatronAsync(user.Id); var quotaStats = await _service.GetUserQuotaStatistic(user.Id); - var eb = _eb.Create(ctx) + var eb = new EmbedBuilder() .WithAuthor(user) .WithTitle(GetText(strs.patron_info)) .WithOkColor(); @@ -119,7 +119,7 @@ public partial class Patronage : NadekoModule } catch { - await ReplyErrorLocalizedAsync(strs.cant_dm); + await Response().Error(strs.cant_dm).SendAsync(); } } diff --git a/src/NadekoBot/Modules/Patronage/PatronageService.cs b/src/NadekoBot/Modules/Patronage/PatronageService.cs index 559b316f4..46c98fa41 100644 --- a/src/NadekoBot/Modules/Patronage/PatronageService.cs +++ b/src/NadekoBot/Modules/Patronage/PatronageService.cs @@ -30,11 +30,13 @@ public sealed class PatronageService private readonly DiscordSocketClient _client; private readonly ISubscriptionHandler _subsHandler; private readonly IEmbedBuilderService _eb; - private static readonly TypedKey _quotaKey + + private static readonly TypedKey _quotaKey = new($"quota:last_hourly_reset"); private readonly IBotCache _cache; private readonly IBotCredsProvider _creds; + private readonly IMessageSenderService _sender; public PatronageService( PatronageConfig pConf, @@ -42,8 +44,9 @@ public sealed class PatronageService DiscordSocketClient client, ISubscriptionHandler subsHandler, IEmbedBuilderService eb, - IBotCache cache, - IBotCredsProvider creds) + IBotCache cache, + IBotCredsProvider creds, + IMessageSenderService sender) { _pConf = pConf; _db = db; @@ -52,6 +55,7 @@ public sealed class PatronageService _eb = eb; _cache = cache; _creds = creds; + _sender = sender; } public Task OnReadyAsync() @@ -167,7 +171,7 @@ public sealed class PatronageService { if (subscriber.LastCharge is null) continue; - + var lastChargeUtc = subscriber.LastCharge.Value.ToUniversalTime(); var dateInOneMonth = lastChargeUtc.Date.AddMonths(1); // await using var tran = await ctx.Database.BeginTransactionAsync(); @@ -176,7 +180,7 @@ public sealed class PatronageService var dbPatron = await ctx.GetTable() .FirstOrDefaultAsync(x => x.UniquePlatformUserId == subscriber.UniquePlatformUserId); - + if (dbPatron is null) { // if the user is not in the database alrady @@ -189,16 +193,17 @@ public sealed class PatronageService LastCharge = lastChargeUtc, ValidThru = dateInOneMonth, }); - + // await tran.CommitAsync(); - + var newPatron = PatronUserToPatron(dbPatron); _ = SendWelcomeMessage(newPatron); await OnNewPatronPayment(newPatron); } else { - if (dbPatron.LastCharge.Month < lastChargeUtc.Month || dbPatron.LastCharge.Year < lastChargeUtc.Year) + if (dbPatron.LastCharge.Month < lastChargeUtc.Month + || dbPatron.LastCharge.Year < lastChargeUtc.Year) { // user is charged again for this month // if his sub would end in teh future, extend it by one month. @@ -215,16 +220,16 @@ public sealed class PatronageService ? old.ValidThru.AddMonths(1) : dateInOneMonth, }); - + // this should never happen if (count == 0) { // await tran.RollbackAsync(); continue; } - + // await tran.CommitAsync(); - + await OnNewPatronPayment(PatronUserToPatron(dbPatron)); } else if (dbPatron.AmountCents != subscriber.Cents // if user changed the amount @@ -245,7 +250,7 @@ public sealed class PatronageService var newPatron = dbPatron.Clone(); newPatron.AmountCents = cents; newPatron.UserId = subscriber.UserId; - + // idk what's going on but UpdateWithOutputAsync doesn't work properly here // nor does firstordefault after update. I'm not seeing something obvious await OnPatronUpdated( @@ -261,31 +266,32 @@ public sealed class PatronageService subscriber.UserId); } } - + var expiredDate = DateTime.MinValue; foreach (var patron in subscribers.Where(x => x.ChargeStatus == SubscriptionChargeStatus.Refunded)) { // if the subscription is refunded, Disable user's valid thru var changedCount = await ctx.GetTable() - .Where(x => x.UniquePlatformUserId == patron.UniquePlatformUserId - && x.ValidThru != expiredDate) - .UpdateAsync(old => new() - { - ValidThru = expiredDate - }); - + .Where(x => x.UniquePlatformUserId == patron.UniquePlatformUserId + && x.ValidThru != expiredDate) + .UpdateAsync(old => new() + { + ValidThru = expiredDate + }); + if (changedCount == 0) continue; var updated = await ctx.GetTable() - .Where(x => x.UniquePlatformUserId == patron.UniquePlatformUserId) - .FirstAsync(); - + .Where(x => x.UniquePlatformUserId == patron.UniquePlatformUserId) + .FirstAsync(); + await OnPatronRefunded(PatronUserToPatron(updated)); } } - public async Task ExecPreCommandAsync(ICommandContext ctx, + public async Task ExecPreCommandAsync( + ICommandContext ctx, string moduleName, CommandInfo command) { @@ -303,7 +309,7 @@ public sealed class PatronageService _ => false, ins => { - var eb = _eb.Create(ctx) + var eb = new EmbedBuilder() .WithPendingColor() .WithTitle("Insufficient Patron Tier") .AddField("For", $"{ins.FeatureType}: `{ins.Feature}`", true) @@ -322,7 +328,10 @@ public sealed class PatronageService _ = ctx.WarningAsync(); if (ctx.Guild?.OwnerId == ctx.User.Id) - _ = ctx.Channel.EmbedAsync(eb, replyTo: ctx.Message); + _ = _sender.Response(ctx) + .Context(ctx) + .Embed(eb) + .SendAsync(); else _ = ctx.User.EmbedAsync(eb); @@ -330,7 +339,7 @@ public sealed class PatronageService }, quota => { - var eb = _eb.Create(ctx) + var eb = new EmbedBuilder() .WithPendingColor() .WithTitle("Quota Limit Reached"); @@ -356,7 +365,9 @@ public sealed class PatronageService // send the message in the server in case it's the owner if (ctx.Guild?.OwnerId == ctx.User.Id) - _ = ctx.Channel.EmbedAsync(eb, replyTo: ctx.Message); + _ = _sender.Response(ctx) + .Embed(eb) + .SendAsync(); else _ = ctx.User.EmbedAsync(eb); @@ -386,7 +397,8 @@ public sealed class PatronageService /// /// Returns either the current usage counter if limit wasn't reached, or QuotaLimit if it is. /// - public async ValueTask> TryIncrementQuotaCounterAsync(ulong userId, + public async ValueTask> TryIncrementQuotaCounterAsync( + ulong userId, bool isSelf, FeatureType featureType, string featureName, @@ -698,8 +710,8 @@ public sealed class PatronageService Quota = defaultValue, IsPatronLimit = false }; - - + + if (!conf.Quotas.Features.TryGetValue(key.Key, out var data)) return new() { @@ -769,7 +781,7 @@ public sealed class PatronageService if (user is null) return; - var eb = _eb.Create() + var eb = new EmbedBuilder() .WithOkColor() .WithTitle("❤️ Thank you for supporting NadekoBot! ❤️") .WithDescription( @@ -782,15 +794,15 @@ public sealed class PatronageService true) .AddField("Instructions", """ - *- Within the next **1-2 minutes** you will have all of the benefits of the Tier you've subscribed to.* - *- You can check your benefits on * - *- You can use the `.patron` command in this chat to check your current quota usage for the Patron-only commands* - *- **ALL** of the servers that you **own** will enjoy your Patron benefits.* - *- You can use any of the commands available in your tier on any server (assuming you have sufficient permissions to run those commands)* - *- Any user in any of your servers can use Patron-only commands, but they will spend **your quota**, which is why it's recommended to use Nadeko's command cooldown system (.h .cmdcd) or permission system to limit the command usage for your server members.* - *- Permission guide can be found here if you're not familiar with it: * - """, - isInline: false) + *- Within the next **1-2 minutes** you will have all of the benefits of the Tier you've subscribed to.* + *- You can check your benefits on * + *- You can use the `.patron` command in this chat to check your current quota usage for the Patron-only commands* + *- **ALL** of the servers that you **own** will enjoy your Patron benefits.* + *- You can use any of the commands available in your tier on any server (assuming you have sufficient permissions to run those commands)* + *- Any user in any of your servers can use Patron-only commands, but they will spend **your quota**, which is why it's recommended to use Nadeko's command cooldown system (.h .cmdcd) or permission system to limit the command usage for your server members.* + *- Permission guide can be found here if you're not familiar with it: * + """, + inline: false) .WithFooter($"platform id: {patron.UniquePlatformUserId}"); await user.EmbedAsync(eb); @@ -806,11 +818,11 @@ public sealed class PatronageService await using var ctx = _db.GetDbContext(); var patrons = await ctx.GetTable() - .Where(x => x.ValidThru > DateTime.UtcNow) - .ToArrayAsync(); + .Where(x => x.ValidThru > DateTime.UtcNow) + .ToArrayAsync(); var text = SmartText.CreateFrom(message); - + var succ = 0; var fail = 0; foreach (var patron in patrons) @@ -828,7 +840,7 @@ public sealed class PatronageService await Task.Delay(1000); } - + return (succ, fail); } diff --git a/src/NadekoBot/Modules/Permissions/Blacklist/BlacklistCommands.cs b/src/NadekoBot/Modules/Permissions/Blacklist/BlacklistCommands.cs index 3a4938b5e..270ea4bb0 100644 --- a/src/NadekoBot/Modules/Permissions/Blacklist/BlacklistCommands.cs +++ b/src/NadekoBot/Modules/Permissions/Blacklist/BlacklistCommands.cs @@ -58,9 +58,9 @@ public partial class Permissions var pageItems = items.Skip(10 * curPage).Take(10).ToList(); if (pageItems.Count == 0) - return _eb.Create().WithOkColor().WithTitle(title).WithDescription(GetText(strs.empty_page)); + return new EmbedBuilder().WithOkColor().WithTitle(title).WithDescription(GetText(strs.empty_page)); - return _eb.Create().WithTitle(title).WithDescription(pageItems.Join('\n')).WithOkColor(); + return new EmbedBuilder().WithTitle(title).WithDescription(pageItems.Join('\n')).WithOkColor(); }, items.Length, 10); @@ -130,13 +130,13 @@ public partial class Permissions if (action == AddRemove.Add) { - await ReplyConfirmLocalizedAsync(strs.blacklisted(Format.Code(type.ToString()), - Format.Code(id.ToString()))); + await Response().Confirm(strs.blacklisted(Format.Code(type.ToString()), + Format.Code(id.ToString()))).SendAsync(); } else { - await ReplyConfirmLocalizedAsync(strs.unblacklisted(Format.Code(type.ToString()), - Format.Code(id.ToString()))); + await Response().Confirm(strs.unblacklisted(Format.Code(type.ToString()), + Format.Code(id.ToString()))).SendAsync(); } } } diff --git a/src/NadekoBot/Modules/Permissions/CommandCooldown/CmdCdsCommands.cs b/src/NadekoBot/Modules/Permissions/CommandCooldown/CmdCdsCommands.cs index 369abb394..a8cf4e8bd 100644 --- a/src/NadekoBot/Modules/Permissions/CommandCooldown/CmdCdsCommands.cs +++ b/src/NadekoBot/Modules/Permissions/CommandCooldown/CmdCdsCommands.cs @@ -27,7 +27,7 @@ public partial class Permissions var channel = (ITextChannel)ctx.Channel; if (secs is < 0 or > 3600) { - await ReplyErrorLocalizedAsync(strs.invalid_second_param_between(0, 3600)); + await Response().Error(strs.invalid_second_param_between(0, 3600)).SendAsync(); return; } @@ -56,10 +56,10 @@ public partial class Permissions if (secs == 0) { _service.ClearCooldowns(ctx.Guild.Id, cmdName); - await ReplyConfirmLocalizedAsync(strs.cmdcd_cleared(Format.Bold(name))); + await Response().Confirm(strs.cmdcd_cleared(Format.Bold(name))).SendAsync(); } else - await ReplyConfirmLocalizedAsync(strs.cmdcd_add(Format.Bold(name), Format.Bold(secs.ToString()))); + await Response().Confirm(strs.cmdcd_add(Format.Bold(name), Format.Bold(secs.ToString()))).SendAsync(); } [Cmd] @@ -85,7 +85,7 @@ public partial class Permissions var localSet = _service.GetCommandCooldowns(ctx.Guild.Id); if (!localSet.Any()) - await ReplyConfirmLocalizedAsync(strs.cmdcd_none); + await Response().Confirm(strs.cmdcd_none).SendAsync(); else { await ctx.SendPaginatedConfirmAsync(page, curPage => @@ -94,7 +94,7 @@ public partial class Permissions .Take(15) .Select(x => $"{Format.Code(x.CommandName)}: {x.Seconds.Seconds().Humanize(maxUnit: TimeUnit.Second, culture: Culture)}"); - return _eb.Create(ctx) + return new EmbedBuilder() .WithOkColor() .WithDescription(items.Join("\n")); diff --git a/src/NadekoBot/Modules/Permissions/Filter/FilterCommands.cs b/src/NadekoBot/Modules/Permissions/Filter/FilterCommands.cs index 537dca5d3..0da25e953 100644 --- a/src/NadekoBot/Modules/Permissions/Filter/FilterCommands.cs +++ b/src/NadekoBot/Modules/Permissions/Filter/FilterCommands.cs @@ -22,14 +22,14 @@ public partial class Permissions public async Task FwClear() { _service.ClearFilteredWords(ctx.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.fw_cleared); + await Response().Confirm(strs.fw_cleared).SendAsync(); } [Cmd] [RequireContext(ContextType.Guild)] public async Task FilterList() { - var embed = _eb.Create(ctx) + var embed = new EmbedBuilder() .WithOkColor() .WithTitle("Server filter settings"); @@ -63,7 +63,7 @@ public partial class Permissions embed.AddField($"{GetEnabledEmoji(config.FilterInvitesEnabled)} Filter Invites", await GetChannelListAsync(config.FilterInvitesChannels)); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -83,12 +83,12 @@ public partial class Permissions if (enabled) { _service.InviteFilteringServers.Add(channel.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.invite_filter_server_on); + await Response().Confirm(strs.invite_filter_server_on).SendAsync(); } else { _service.InviteFilteringServers.TryRemove(channel.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.invite_filter_server_off); + await Response().Confirm(strs.invite_filter_server_off).SendAsync(); } } @@ -119,12 +119,12 @@ public partial class Permissions if (removed is null) { _service.InviteFilteringChannels.Add(channel.Id); - await ReplyConfirmLocalizedAsync(strs.invite_filter_channel_on); + await Response().Confirm(strs.invite_filter_channel_on).SendAsync(); } else { _service.InviteFilteringChannels.TryRemove(channel.Id); - await ReplyConfirmLocalizedAsync(strs.invite_filter_channel_off); + await Response().Confirm(strs.invite_filter_channel_off).SendAsync(); } } @@ -145,12 +145,12 @@ public partial class Permissions if (enabled) { _service.LinkFilteringServers.Add(channel.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.link_filter_server_on); + await Response().Confirm(strs.link_filter_server_on).SendAsync(); } else { _service.LinkFilteringServers.TryRemove(channel.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.link_filter_server_off); + await Response().Confirm(strs.link_filter_server_off).SendAsync(); } } @@ -181,12 +181,12 @@ public partial class Permissions if (removed is null) { _service.LinkFilteringChannels.Add(channel.Id); - await ReplyConfirmLocalizedAsync(strs.link_filter_channel_on); + await Response().Confirm(strs.link_filter_channel_on).SendAsync(); } else { _service.LinkFilteringChannels.TryRemove(channel.Id); - await ReplyConfirmLocalizedAsync(strs.link_filter_channel_off); + await Response().Confirm(strs.link_filter_channel_off).SendAsync(); } } @@ -207,12 +207,12 @@ public partial class Permissions if (enabled) { _service.WordFilteringServers.Add(channel.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.word_filter_server_on); + await Response().Confirm(strs.word_filter_server_on).SendAsync(); } else { _service.WordFilteringServers.TryRemove(channel.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.word_filter_server_off); + await Response().Confirm(strs.word_filter_server_off).SendAsync(); } } @@ -243,12 +243,12 @@ public partial class Permissions if (removed is null) { _service.WordFilteringChannels.Add(channel.Id); - await ReplyConfirmLocalizedAsync(strs.word_filter_channel_on); + await Response().Confirm(strs.word_filter_channel_on).SendAsync(); } else { _service.WordFilteringChannels.TryRemove(channel.Id); - await ReplyConfirmLocalizedAsync(strs.word_filter_channel_off); + await Response().Confirm(strs.word_filter_channel_off).SendAsync(); } } @@ -289,12 +289,12 @@ public partial class Permissions if (removed is null) { filteredWords.Add(word); - await ReplyConfirmLocalizedAsync(strs.filter_word_add(Format.Code(word))); + await Response().Confirm(strs.filter_word_add(Format.Code(word))).SendAsync(); } else { filteredWords.TryRemove(word); - await ReplyConfirmLocalizedAsync(strs.filter_word_remove(Format.Code(word))); + await Response().Confirm(strs.filter_word_remove(Format.Code(word))).SendAsync(); } } @@ -313,7 +313,7 @@ public partial class Permissions var fws = fwHash.ToArray(); await ctx.SendPaginatedConfirmAsync(page, - curPage => _eb.Create() + curPage => new EmbedBuilder() .WithTitle(GetText(strs.filter_word_list)) .WithDescription(string.Join("\n", fws.Skip(curPage * 10).Take(10))) .WithOkColor(), diff --git a/src/NadekoBot/Modules/Permissions/GlobalPermissions/GlobalPermissionCommands.cs b/src/NadekoBot/Modules/Permissions/GlobalPermissions/GlobalPermissionCommands.cs index 9625fd658..faa159728 100644 --- a/src/NadekoBot/Modules/Permissions/GlobalPermissions/GlobalPermissionCommands.cs +++ b/src/NadekoBot/Modules/Permissions/GlobalPermissions/GlobalPermissionCommands.cs @@ -26,11 +26,11 @@ public partial class Permissions var blockedCommands = _service.BlockedCommands; if (!blockedModule.Any() && !blockedCommands.Any()) { - await ReplyErrorLocalizedAsync(strs.lgp_none); + await Response().Error(strs.lgp_none).SendAsync(); return; } - var embed = _eb.Create().WithOkColor(); + var embed = new EmbedBuilder().WithOkColor(); if (blockedModule.Any()) embed.AddField(GetText(strs.blocked_modules), string.Join("\n", _service.BlockedModules)); @@ -38,7 +38,7 @@ public partial class Permissions if (blockedCommands.Any()) embed.AddField(GetText(strs.blocked_commands), string.Join("\n", _service.BlockedCommands)); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -51,11 +51,11 @@ public partial class Permissions if (added) { - await ReplyConfirmLocalizedAsync(strs.gmod_add(Format.Bold(module.Name))); + await Response().Confirm(strs.gmod_add(Format.Bold(module.Name))).SendAsync(); return; } - await ReplyConfirmLocalizedAsync(strs.gmod_remove(Format.Bold(module.Name))); + await Response().Confirm(strs.gmod_remove(Format.Bold(module.Name))).SendAsync(); } [Cmd] @@ -67,11 +67,11 @@ public partial class Permissions if (added) { - await ReplyConfirmLocalizedAsync(strs.gcmd_add(Format.Bold(cmd.Name))); + await Response().Confirm(strs.gcmd_add(Format.Bold(cmd.Name))).SendAsync(); return; } - await ReplyConfirmLocalizedAsync(strs.gcmd_remove(Format.Bold(cmd.Name))); + await Response().Confirm(strs.gcmd_remove(Format.Bold(cmd.Name))).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Permissions/Permissions.cs b/src/NadekoBot/Modules/Permissions/Permissions.cs index 91aeb61d1..a8e4f82cb 100644 --- a/src/NadekoBot/Modules/Permissions/Permissions.cs +++ b/src/NadekoBot/Modules/Permissions/Permissions.cs @@ -32,9 +32,9 @@ public partial class Permissions : NadekoModule } if (action.Value) - await ReplyConfirmLocalizedAsync(strs.verbose_true); + await Response().Confirm(strs.verbose_true).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.verbose_false); + await Response().Confirm(strs.verbose_false).SendAsync(); } [Cmd] @@ -51,9 +51,9 @@ public partial class Permissions : NadekoModule var cache = _service.GetCacheFor(ctx.Guild.Id); if (!ulong.TryParse(cache.PermRole, out var roleId) || (role = ((SocketGuild)ctx.Guild).GetRole(roleId)) is null) - await ReplyConfirmLocalizedAsync(strs.permrole_not_set); + await Response().Confirm(strs.permrole_not_set).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.permrole(Format.Bold(role.ToString()))); + await Response().Confirm(strs.permrole(Format.Bold(role.ToString()))).SendAsync(); return; } @@ -65,7 +65,7 @@ public partial class Permissions : NadekoModule _service.UpdateCache(config); } - await ReplyConfirmLocalizedAsync(strs.permrole_changed(Format.Bold(role.Name))); + await Response().Confirm(strs.permrole_changed(Format.Bold(role.Name))).SendAsync(); } [Cmd] @@ -82,7 +82,7 @@ public partial class Permissions : NadekoModule _service.UpdateCache(config); } - await ReplyConfirmLocalizedAsync(strs.permrole_reset); + await Response().Confirm(strs.permrole_reset).SendAsync(); } [Cmd] @@ -115,7 +115,7 @@ public partial class Permissions : NadekoModule return str; })); - await SendConfirmAsync(toSend); + await Response().Confirm(toSend).SendAsync(); } [Cmd] @@ -139,12 +139,14 @@ public partial class Permissions : NadekoModule _service.UpdateCache(config); } - await ReplyConfirmLocalizedAsync(strs.removed(index + 1, - Format.Code(p.GetCommand(prefix, (SocketGuild)ctx.Guild)))); + await Response() + .Confirm(strs.removed(index + 1, + Format.Code(p.GetCommand(prefix, (SocketGuild)ctx.Guild)))) + .SendAsync(); } catch (IndexOutOfRangeException) { - await ReplyErrorLocalizedAsync(strs.perm_out_of_range); + await Response().Error(strs.perm_out_of_range).SendAsync(); } } @@ -164,33 +166,35 @@ public partial class Permissions : NadekoModule var config = uow.GcWithPermissionsFor(ctx.Guild.Id); var permsCol = new PermissionsCollection(config.Permissions); - var fromFound = @from < permsCol.Count; + var fromFound = from < permsCol.Count; var toFound = to < permsCol.Count; if (!fromFound) { - await ReplyErrorLocalizedAsync(strs.perm_not_found(++@from)); + await Response().Error(strs.perm_not_found(++from)).SendAsync(); return; } if (!toFound) { - await ReplyErrorLocalizedAsync(strs.perm_not_found(++to)); + await Response().Error(strs.perm_not_found(++to)).SendAsync(); return; } - fromPerm = permsCol[@from]; + fromPerm = permsCol[from]; - permsCol.RemoveAt(@from); + permsCol.RemoveAt(from); permsCol.Insert(to, fromPerm); await uow.SaveChangesAsync(); _service.UpdateCache(config); } - await ReplyConfirmLocalizedAsync(strs.moved_permission( - Format.Code(fromPerm.GetCommand(prefix, (SocketGuild)ctx.Guild)), - ++@from, - ++to)); + await Response() + .Confirm(strs.moved_permission( + Format.Code(fromPerm.GetCommand(prefix, (SocketGuild)ctx.Guild)), + ++from, + ++to)) + .SendAsync(); return; } @@ -199,7 +203,7 @@ public partial class Permissions : NadekoModule } } - await ReplyConfirmLocalizedAsync(strs.perm_out_of_range); + await Response().Confirm(strs.perm_out_of_range).SendAsync(); } [Cmd] @@ -218,9 +222,9 @@ public partial class Permissions : NadekoModule }); if (action.Value) - await ReplyConfirmLocalizedAsync(strs.sx_enable(Format.Code(command.Name), GetText(strs.of_command))); + await Response().Confirm(strs.sx_enable(Format.Code(command.Name), GetText(strs.of_command))).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.sx_disable(Format.Code(command.Name), GetText(strs.of_command))); + await Response().Confirm(strs.sx_disable(Format.Code(command.Name), GetText(strs.of_command))).SendAsync(); } [Cmd] @@ -238,9 +242,9 @@ public partial class Permissions : NadekoModule }); if (action.Value) - await ReplyConfirmLocalizedAsync(strs.sx_enable(Format.Code(module.Name), GetText(strs.of_module))); + await Response().Confirm(strs.sx_enable(Format.Code(module.Name), GetText(strs.of_module))).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.sx_disable(Format.Code(module.Name), GetText(strs.of_module))); + await Response().Confirm(strs.sx_disable(Format.Code(module.Name), GetText(strs.of_module))).SendAsync(); } [Cmd] @@ -260,15 +264,19 @@ public partial class Permissions : NadekoModule if (action.Value) { - await ReplyConfirmLocalizedAsync(strs.ux_enable(Format.Code(command.Name), - GetText(strs.of_command), - Format.Code(user.ToString()))); + await Response() + .Confirm(strs.ux_enable(Format.Code(command.Name), + GetText(strs.of_command), + Format.Code(user.ToString()))) + .SendAsync(); } else { - await ReplyConfirmLocalizedAsync(strs.ux_disable(Format.Code(command.Name), - GetText(strs.of_command), - Format.Code(user.ToString()))); + await Response() + .Confirm(strs.ux_disable(Format.Code(command.Name), + GetText(strs.of_command), + Format.Code(user.ToString()))) + .SendAsync(); } } @@ -288,15 +296,19 @@ public partial class Permissions : NadekoModule if (action.Value) { - await ReplyConfirmLocalizedAsync(strs.ux_enable(Format.Code(module.Name), - GetText(strs.of_module), - Format.Code(user.ToString()))); + await Response() + .Confirm(strs.ux_enable(Format.Code(module.Name), + GetText(strs.of_module), + Format.Code(user.ToString()))) + .SendAsync(); } else { - await ReplyConfirmLocalizedAsync(strs.ux_disable(Format.Code(module.Name), - GetText(strs.of_module), - Format.Code(user.ToString()))); + await Response() + .Confirm(strs.ux_disable(Format.Code(module.Name), + GetText(strs.of_module), + Format.Code(user.ToString()))) + .SendAsync(); } } @@ -320,15 +332,19 @@ public partial class Permissions : NadekoModule if (action.Value) { - await ReplyConfirmLocalizedAsync(strs.rx_enable(Format.Code(command.Name), - GetText(strs.of_command), - Format.Code(role.Name))); + await Response() + .Confirm(strs.rx_enable(Format.Code(command.Name), + GetText(strs.of_command), + Format.Code(role.Name))) + .SendAsync(); } else { - await ReplyConfirmLocalizedAsync(strs.rx_disable(Format.Code(command.Name), - GetText(strs.of_command), - Format.Code(role.Name))); + await Response() + .Confirm(strs.rx_disable(Format.Code(command.Name), + GetText(strs.of_command), + Format.Code(role.Name))) + .SendAsync(); } } @@ -352,15 +368,19 @@ public partial class Permissions : NadekoModule if (action.Value) { - await ReplyConfirmLocalizedAsync(strs.rx_enable(Format.Code(module.Name), - GetText(strs.of_module), - Format.Code(role.Name))); + await Response() + .Confirm(strs.rx_enable(Format.Code(module.Name), + GetText(strs.of_module), + Format.Code(role.Name))) + .SendAsync(); } else { - await ReplyConfirmLocalizedAsync(strs.rx_disable(Format.Code(module.Name), - GetText(strs.of_module), - Format.Code(role.Name))); + await Response() + .Confirm(strs.rx_disable(Format.Code(module.Name), + GetText(strs.of_module), + Format.Code(role.Name))) + .SendAsync(); } } @@ -381,15 +401,19 @@ public partial class Permissions : NadekoModule if (action.Value) { - await ReplyConfirmLocalizedAsync(strs.cx_enable(Format.Code(command.Name), - GetText(strs.of_command), - Format.Code(chnl.Name))); + await Response() + .Confirm(strs.cx_enable(Format.Code(command.Name), + GetText(strs.of_command), + Format.Code(chnl.Name))) + .SendAsync(); } else { - await ReplyConfirmLocalizedAsync(strs.cx_disable(Format.Code(command.Name), - GetText(strs.of_command), - Format.Code(chnl.Name))); + await Response() + .Confirm(strs.cx_disable(Format.Code(command.Name), + GetText(strs.of_command), + Format.Code(chnl.Name))) + .SendAsync(); } } @@ -409,15 +433,19 @@ public partial class Permissions : NadekoModule if (action.Value) { - await ReplyConfirmLocalizedAsync(strs.cx_enable(Format.Code(module.Name), - GetText(strs.of_module), - Format.Code(chnl.Name))); + await Response() + .Confirm(strs.cx_enable(Format.Code(module.Name), + GetText(strs.of_module), + Format.Code(chnl.Name))) + .SendAsync(); } else { - await ReplyConfirmLocalizedAsync(strs.cx_disable(Format.Code(module.Name), - GetText(strs.of_module), - Format.Code(chnl.Name))); + await Response() + .Confirm(strs.cx_disable(Format.Code(module.Name), + GetText(strs.of_module), + Format.Code(chnl.Name))) + .SendAsync(); } } @@ -436,9 +464,9 @@ public partial class Permissions : NadekoModule }); if (action.Value) - await ReplyConfirmLocalizedAsync(strs.acm_enable(Format.Code(chnl.Name))); + await Response().Confirm(strs.acm_enable(Format.Code(chnl.Name))).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.acm_disable(Format.Code(chnl.Name))); + await Response().Confirm(strs.acm_disable(Format.Code(chnl.Name))).SendAsync(); } [Cmd] @@ -459,9 +487,9 @@ public partial class Permissions : NadekoModule }); if (action.Value) - await ReplyConfirmLocalizedAsync(strs.arm_enable(Format.Code(role.Name))); + await Response().Confirm(strs.arm_enable(Format.Code(role.Name))).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.arm_disable(Format.Code(role.Name))); + await Response().Confirm(strs.arm_disable(Format.Code(role.Name))).SendAsync(); } [Cmd] @@ -479,9 +507,9 @@ public partial class Permissions : NadekoModule }); if (action.Value) - await ReplyConfirmLocalizedAsync(strs.aum_enable(Format.Code(user.ToString()))); + await Response().Confirm(strs.aum_enable(Format.Code(user.ToString()))).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.aum_disable(Format.Code(user.ToString()))); + await Response().Confirm(strs.aum_disable(Format.Code(user.ToString()))).SendAsync(); } [Cmd] @@ -509,8 +537,8 @@ public partial class Permissions : NadekoModule await _service.AddPermissions(ctx.Guild.Id, newPerm, allowUser); if (action.Value) - await ReplyConfirmLocalizedAsync(strs.asm_enable); + await Response().Confirm(strs.asm_enable).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.asm_disable); + await Response().Confirm(strs.asm_disable).SendAsync(); } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Permissions/PermissionsService.cs b/src/NadekoBot/Modules/Permissions/PermissionsService.cs index 240350a50..3db96b746 100644 --- a/src/NadekoBot/Modules/Permissions/PermissionsService.cs +++ b/src/NadekoBot/Modules/Permissions/PermissionsService.cs @@ -18,18 +18,21 @@ public class PermissionService : IExecPreCommand, INService private readonly CommandHandler _cmd; private readonly IBotStrings _strings; private readonly IEmbedBuilderService _eb; + private readonly IMessageSenderService _sender; public PermissionService( DiscordSocketClient client, DbService db, CommandHandler cmd, IBotStrings strings, - IEmbedBuilderService eb) + IEmbedBuilderService eb, + IMessageSenderService sender) { _db = db; _cmd = cmd; _strings = strings; _eb = eb; + _sender = sender; using var uow = _db.GetDbContext(); foreach (var x in uow.Set().PermissionsForAll(client.Guilds.ToArray().Select(x => x.Id).ToList())) @@ -115,11 +118,12 @@ public class PermissionService : IExecPreCommand, INService { try { - await channel.SendErrorAsync(_eb, - _strings.GetText(strs.perm_prevent(index + 1, - Format.Bold(pc.Permissions[index] - .GetCommand(_cmd.GetPrefix(guild), (SocketGuild)guild))), - guild.Id)); + await _sender.Response(channel) + .Error(_strings.GetText(strs.perm_prevent(index + 1, + Format.Bold(pc.Permissions[index] + .GetCommand(_cmd.GetPrefix(guild), (SocketGuild)guild))), + guild.Id)) + .SendAsync(); } catch { @@ -148,7 +152,7 @@ public class PermissionService : IExecPreCommand, INService returnMsg = "You need Admin permissions in order to use permission commands."; if (pc.Verbose) { - try { await channel.SendErrorAsync(_eb, returnMsg); } + try { await _sender.Response(channel).Error(returnMsg).SendAsync(); } catch { } } @@ -160,7 +164,7 @@ public class PermissionService : IExecPreCommand, INService returnMsg = $"You need the {Format.Bold(role.Name)} role in order to use permission commands."; if (pc.Verbose) { - try { await channel.SendErrorAsync(_eb, returnMsg); } + try { await _sender.Response(channel).Error(returnMsg).SendAsync(); } catch { } } diff --git a/src/NadekoBot/Modules/Permissions/ResetPermissionsCommands.cs b/src/NadekoBot/Modules/Permissions/ResetPermissionsCommands.cs index 153345dec..44cc1473d 100644 --- a/src/NadekoBot/Modules/Permissions/ResetPermissionsCommands.cs +++ b/src/NadekoBot/Modules/Permissions/ResetPermissionsCommands.cs @@ -23,7 +23,7 @@ public partial class Permissions public async Task ResetPerms() { await _perms.Reset(ctx.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.perms_reset); + await Response().Confirm(strs.perms_reset).SendAsync(); } [Cmd] @@ -31,7 +31,7 @@ public partial class Permissions public async Task ResetGlobalPerms() { await _gps.Reset(); - await ReplyConfirmLocalizedAsync(strs.global_perms_reset); + await Response().Confirm(strs.global_perms_reset).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Searches/Anime/AnimeSearchCommands.cs b/src/NadekoBot/Modules/Searches/Anime/AnimeSearchCommands.cs index 6c3a6f7bf..fb5582bb9 100644 --- a/src/NadekoBot/Modules/Searches/Anime/AnimeSearchCommands.cs +++ b/src/NadekoBot/Modules/Searches/Anime/AnimeSearchCommands.cs @@ -20,11 +20,11 @@ public partial class Searches // // if (novelData is null) // { - // await ReplyErrorLocalizedAsync(strs.failed_finding_novel); + // await Response().Error(strs.failed_finding_novel).SendAsync(); // return; // } // - // var embed = _eb.Create() + // var embed = new EmbedBuilder() // .WithOkColor() // .WithDescription(novelData.Description.Replace("
", Environment.NewLine, StringComparison.InvariantCulture)) // .WithTitle(novelData.Title) @@ -35,7 +35,7 @@ public partial class Searches // .AddField(GetText(strs.genres), string.Join(" ", novelData.Genres.Any() ? novelData.Genres : new[] { "none" }), true) // .WithFooter($"{GetText(strs.score)} {novelData.Score}"); // - // await EmbedAsync(embed); + // await Response().Embed(embed).SendAsync(); // } [Cmd] @@ -86,7 +86,7 @@ public partial class Searches .Select(x => x.TextContent.Split(':').Select(y => y.Trim()).ToArray()) .ToArray(); - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.mal_profile(name))) .AddField("💚 " + GetText(strs.watching), stats[0], true) @@ -110,7 +110,7 @@ public partial class Searches .WithUrl(fullQueryLink) .WithImageUrl(imageUrl); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } private static string MalInfoToEmoji(string info) @@ -147,11 +147,11 @@ public partial class Searches if (animeData is null) { - await ReplyErrorLocalizedAsync(strs.failed_finding_anime); + await Response().Error(strs.failed_finding_anime).SendAsync(); return; } - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithDescription(animeData.Synopsis.Replace("
", Environment.NewLine, @@ -165,7 +165,7 @@ public partial class Searches string.Join(",\n", animeData.Genres.Any() ? animeData.Genres : new[] { "none" }), true) .WithFooter($"{GetText(strs.score)} {animeData.AverageScore} / 100"); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -179,11 +179,11 @@ public partial class Searches if (mangaData is null) { - await ReplyErrorLocalizedAsync(strs.failed_finding_manga); + await Response().Error(strs.failed_finding_manga).SendAsync(); return; } - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithDescription(mangaData.Synopsis.Replace("
", Environment.NewLine, @@ -198,7 +198,7 @@ public partial class Searches true) .WithFooter($"{GetText(strs.score)} {mangaData.AverageScore} / 100"); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Searches/Crypto/CryptoCommands.cs b/src/NadekoBot/Modules/Searches/Crypto/CryptoCommands.cs index ea3c3960c..d6a50f09c 100644 --- a/src/NadekoBot/Modules/Searches/Crypto/CryptoCommands.cs +++ b/src/NadekoBot/Modules/Searches/Crypto/CryptoCommands.cs @@ -30,12 +30,12 @@ public partial class Searches if (symbols.Count == 0) { - await ReplyErrorLocalizedAsync(strs.not_found); + await Response().Error(strs.not_found).SendAsync(); return; } var symbol = symbols.First(); - var promptEmbed = _eb.Create() + var promptEmbed = new EmbedBuilder() .WithDescription(symbol.Description) .WithTitle(GetText(strs.did_you_mean(symbol.Symbol))); @@ -47,7 +47,7 @@ public partial class Searches if (stock is null) { - await ReplyErrorLocalizedAsync(strs.not_found); + await Response().Error(strs.not_found).SendAsync(); return; } } @@ -79,7 +79,7 @@ public partial class Searches var price = stock.Price.ToString("C2", localCulture); - var eb = _eb.Create() + var eb = new EmbedBuilder() .WithOkColor() .WithAuthor(stock.Symbol) .WithUrl($"https://www.tradingview.com/chart/?symbol={stock.Symbol}") @@ -92,7 +92,7 @@ public partial class Searches // .AddField("Change 200d", $"{sign200}{change200}", true) .WithFooter(stock.Exchange); - var message = await EmbedAsync(eb); + var message = await Response().Embed(eb).SendAsync(); await using var imageData = await stockImageTask; if (imageData is null) return; @@ -127,7 +127,7 @@ public partial class Searches if (nearest is not null) { - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithTitle(GetText(strs.crypto_not_found)) .WithDescription( GetText(strs.did_you_mean(Format.Bold($"{nearest.Name} ({nearest.Symbol})")))); @@ -138,7 +138,7 @@ public partial class Searches if (crypto is null) { - await ReplyErrorLocalizedAsync(strs.crypto_not_found); + await Response().Error(strs.crypto_not_found).SendAsync(); return; } @@ -160,7 +160,7 @@ public partial class Searches await using var sparkline = await _service.GetSparklineAsync(crypto.Id, usd.PercentChange7d >= 0); var fileName = $"{crypto.Slug}_7d.png"; - var toSend = _eb.Create() + var toSend = new EmbedBuilder() .WithOkColor() .WithAuthor($"#{crypto.CmcRank}") .WithTitle($"{crypto.Name} ({crypto.Symbol})") diff --git a/src/NadekoBot/Modules/Searches/Feeds/FeedCommands.cs b/src/NadekoBot/Modules/Searches/Feeds/FeedCommands.cs index 98132d77c..897affa1e 100644 --- a/src/NadekoBot/Modules/Searches/Feeds/FeedCommands.cs +++ b/src/NadekoBot/Modules/Searches/Feeds/FeedCommands.cs @@ -28,7 +28,7 @@ public partial class Searches { var m = _ytChannelRegex.Match(url); if (!m.Success) - return ReplyErrorLocalizedAsync(strs.invalid_input); + return Response().Error(strs.invalid_input).SendAsync(); if (!((IGuildUser)ctx.User).GetPermissions(channel).MentionEveryone) message = message?.SanitizeAllMentions(); @@ -55,7 +55,7 @@ public partial class Searches if (!Uri.TryCreate(url, UriKind.Absolute, out var uri) || (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps)) { - await ReplyErrorLocalizedAsync(strs.feed_invalid_url); + await Response().Error(strs.feed_invalid_url).SendAsync(); return; } @@ -70,7 +70,7 @@ public partial class Searches catch (Exception ex) { Log.Information(ex, "Unable to get feeds from that url"); - await ReplyErrorLocalizedAsync(strs.feed_cant_parse); + await Response().Error(strs.feed_cant_parse).SendAsync(); return; } @@ -80,19 +80,19 @@ public partial class Searches var result = _service.AddFeed(ctx.Guild.Id, channel.Id, url, message); if (result == FeedAddResult.Success) { - await ReplyConfirmLocalizedAsync(strs.feed_added); + await Response().Confirm(strs.feed_added).SendAsync(); return; } if (result == FeedAddResult.Duplicate) { - await ReplyErrorLocalizedAsync(strs.feed_duplicate); + await Response().Error(strs.feed_duplicate).SendAsync(); return; } if (result == FeedAddResult.LimitReached) { - await ReplyErrorLocalizedAsync(strs.feed_limit_reached); + await Response().Error(strs.feed_limit_reached).SendAsync(); return; } } @@ -103,9 +103,9 @@ public partial class Searches public async Task FeedRemove(int index) { if (_service.RemoveFeed(ctx.Guild.Id, --index)) - await ReplyConfirmLocalizedAsync(strs.feed_removed); + await Response().Confirm(strs.feed_removed).SendAsync(); else - await ReplyErrorLocalizedAsync(strs.feed_out_of_range); + await Response().Error(strs.feed_out_of_range).SendAsync(); } [Cmd] @@ -117,14 +117,14 @@ public partial class Searches if (!feeds.Any()) { - await EmbedAsync(_eb.Create().WithOkColor().WithDescription(GetText(strs.feed_no_feed))); + await Response().Embed(new EmbedBuilder().WithOkColor().WithDescription(GetText(strs.feed_no_feed))).SendAsync(); return; } await ctx.SendPaginatedConfirmAsync(0, cur => { - var embed = _eb.Create().WithOkColor(); + var embed = new EmbedBuilder().WithOkColor(); var i = 0; var fs = string.Join("\n", feeds.Skip(cur * 10).Take(10).Select(x => $"`{(cur * 10) + ++i}.` <#{x.ChannelId}> {x.Url}")); diff --git a/src/NadekoBot/Modules/Searches/Feeds/FeedsService.cs b/src/NadekoBot/Modules/Searches/Feeds/FeedsService.cs index 84f45d9f0..9dce27ef5 100644 --- a/src/NadekoBot/Modules/Searches/Feeds/FeedsService.cs +++ b/src/NadekoBot/Modules/Searches/Feeds/FeedsService.cs @@ -115,7 +115,7 @@ public class FeedsService : INService if (itemUpdateDate <= lastFeedUpdate) continue; - var embed = _eb.Create().WithFooter(rssUrl); + var embed = new EmbedBuilder().WithFooter(rssUrl); _lastPosts[kvp.Key] = itemUpdateDate; diff --git a/src/NadekoBot/Modules/Searches/JokeCommands.cs b/src/NadekoBot/Modules/Searches/JokeCommands.cs index a0229726f..ccdba0b9d 100644 --- a/src/NadekoBot/Modules/Searches/JokeCommands.cs +++ b/src/NadekoBot/Modules/Searches/JokeCommands.cs @@ -10,30 +10,30 @@ public partial class Searches { [Cmd] public async Task Yomama() - => await SendConfirmAsync(await _service.GetYomamaJoke()); + => await Response().Confirm(await _service.GetYomamaJoke()).SendAsync(); [Cmd] public async Task Randjoke() { var (setup, punchline) = await _service.GetRandomJoke(); - await SendConfirmAsync(setup, punchline); + await Response().Confirm(setup, punchline).SendAsync(); } [Cmd] public async Task ChuckNorris() - => await SendConfirmAsync(await _service.GetChuckNorrisJoke()); + => await Response().Confirm(await _service.GetChuckNorrisJoke()).SendAsync(); [Cmd] public async Task WowJoke() { if (!_service.WowJokes.Any()) { - await ReplyErrorLocalizedAsync(strs.jokes_not_loaded); + await Response().Error(strs.jokes_not_loaded).SendAsync(); return; } var joke = _service.WowJokes[new NadekoRandom().Next(0, _service.WowJokes.Count)]; - await SendConfirmAsync(joke.Question, joke.Answer); + await Response().Confirm(joke.Question, joke.Answer).SendAsync(); } [Cmd] @@ -41,13 +41,13 @@ public partial class Searches { if (!_service.MagicItems.Any()) { - await ReplyErrorLocalizedAsync(strs.magicitems_not_loaded); + await Response().Error(strs.magicitems_not_loaded).SendAsync(); return; } var item = _service.MagicItems[new NadekoRandom().Next(0, _service.MagicItems.Count)]; - await SendConfirmAsync("✨" + item.Name, item.Description); + await Response().Confirm("✨" + item.Name, item.Description).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Searches/MemegenCommands.cs b/src/NadekoBot/Modules/Searches/MemegenCommands.cs index f030be2e0..017903e43 100644 --- a/src/NadekoBot/Modules/Searches/MemegenCommands.cs +++ b/src/NadekoBot/Modules/Searches/MemegenCommands.cs @@ -46,7 +46,7 @@ public partial class Searches var templates = string.Empty; foreach (var template in data.Skip(curPage * 15).Take(15)) templates += $"**{template.Name}:**\n key: `{template.Id}`\n"; - var embed = _eb.Create().WithOkColor().WithDescription(templates); + var embed = new EmbedBuilder().WithOkColor().WithDescription(templates); return embed; }, diff --git a/src/NadekoBot/Modules/Searches/OsuCommands.cs b/src/NadekoBot/Modules/Searches/OsuCommands.cs index 5f9c98e28..7acd254cb 100644 --- a/src/NadekoBot/Modules/Searches/OsuCommands.cs +++ b/src/NadekoBot/Modules/Searches/OsuCommands.cs @@ -31,7 +31,7 @@ public partial class Searches { if (string.IsNullOrWhiteSpace(_creds.OsuApiKey)) { - await ReplyErrorLocalizedAsync(strs.osu_api_key); + await Response().Error(strs.osu_api_key).SendAsync(); return; } @@ -42,14 +42,14 @@ public partial class Searches if (objs.Count == 0) { - await ReplyErrorLocalizedAsync(strs.osu_user_not_found); + await Response().Error(strs.osu_user_not_found).SendAsync(); return; } var obj = objs[0]; var userId = obj.UserId; - await EmbedAsync(_eb.Create() + await Response().Embed(new EmbedBuilder() .WithOkColor() .WithTitle($"osu! {smode} profile for {user}") .WithThumbnailUrl($"https://a.ppy.sh/{userId}") @@ -61,15 +61,15 @@ public partial class Searches .AddField("Total PP", Math.Round(obj.PpRaw, 2), true) .AddField("Accuracy", Math.Round(obj.Accuracy, 2) + "%", true) .AddField("Playcount", obj.Playcount, true) - .AddField("Level", Math.Round(obj.Level), true)); + .AddField("Level", Math.Round(obj.Level), true)).SendAsync(); } catch (ArgumentOutOfRangeException) { - await ReplyErrorLocalizedAsync(strs.osu_user_not_found); + await Response().Error(strs.osu_user_not_found).SendAsync(); } catch (Exception ex) { - await ReplyErrorLocalizedAsync(strs.osu_failed); + await Response().Error(strs.osu_failed).SendAsync(); Log.Warning(ex, "Osu command failed"); } } @@ -86,7 +86,7 @@ public partial class Searches var statsResponse = JsonConvert.DeserializeObject(resString); if (statsResponse.Code != 200 || statsResponse.Stats.Id == 0) { - await ReplyErrorLocalizedAsync(strs.osu_user_not_found); + await Response().Error(strs.osu_user_not_found).SendAsync(); return; } @@ -95,7 +95,7 @@ public partial class Searches var userData = JsonConvert.DeserializeObject(usrResString).Users[0]; var userStats = statsResponse.Stats; - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle($"osu!Gatari {modeStr} profile for {user}") .WithThumbnailUrl($"https://a.gatari.pw/{userStats.Id}") @@ -109,7 +109,7 @@ public partial class Searches .AddField("Playcount", userStats.Playcount, true) .AddField("Level", userStats.Level, true); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -117,13 +117,13 @@ public partial class Searches { if (string.IsNullOrWhiteSpace(_creds.OsuApiKey)) { - await SendErrorAsync("An osu! API key is required."); + await Response().Error("An osu! API key is required.").SendAsync(); return; } if (string.IsNullOrWhiteSpace(user)) { - await SendErrorAsync("Please provide a username."); + await Response().Error("Please provide a username.").SendAsync(); return; } @@ -166,13 +166,13 @@ public partial class Searches return (title, desc); }); - var eb = _eb.Create().WithOkColor().WithTitle($"Top 5 plays for {user}"); + var eb = new EmbedBuilder().WithOkColor().WithTitle($"Top 5 plays for {user}"); var mapData = await mapTasks.WhenAll(); foreach (var (title, desc) in mapData.Where(x => x != default)) eb.AddField(title, desc); - await EmbedAsync(eb); + await Response().Embed(eb).SendAsync(); } //https://osu.ppy.sh/wiki/Accuracy diff --git a/src/NadekoBot/Modules/Searches/PathOfExileCommands.cs b/src/NadekoBot/Modules/Searches/PathOfExileCommands.cs index 18ee403b1..cdb07f32a 100644 --- a/src/NadekoBot/Modules/Searches/PathOfExileCommands.cs +++ b/src/NadekoBot/Modules/Searches/PathOfExileCommands.cs @@ -121,7 +121,7 @@ public partial class Searches if (string.IsNullOrWhiteSpace(usr)) { - await SendErrorAsync("Please provide an account name."); + await Response().Error("Please provide an account name.").SendAsync(); return; } @@ -135,9 +135,9 @@ public partial class Searches } catch { - var embed = _eb.Create().WithDescription(GetText(strs.account_not_found)).WithErrorColor(); + var embed = new EmbedBuilder().WithDescription(GetText(strs.account_not_found)).WithErrorColor(); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); return; } @@ -147,7 +147,7 @@ public partial class Searches await ctx.SendPaginatedConfirmAsync(page, curPage => { - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithAuthor($"Characters on {usr}'s account", "https://web.poecdn.com/image/favicon/ogimage.png", $"{PROFILE_URL}{usr}") @@ -190,13 +190,13 @@ public partial class Searches } catch { - var eembed = _eb.Create().WithDescription(GetText(strs.leagues_not_found)).WithErrorColor(); + var eembed = new EmbedBuilder().WithDescription(GetText(strs.leagues_not_found)).WithErrorColor(); - await EmbedAsync(eembed); + await Response().Embed(eembed).SendAsync(); return; } - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithAuthor("Path of Exile Leagues", "https://web.poecdn.com/image/favicon/ogimage.png", "https://www.pathofexile.com") @@ -215,7 +215,7 @@ public partial class Searches embed.WithDescription(sb.ToString()); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -226,13 +226,13 @@ public partial class Searches { if (string.IsNullOrWhiteSpace(leagueName)) { - await SendErrorAsync("Please provide league name."); + await Response().Error("Please provide league name.").SendAsync(); return; } if (string.IsNullOrWhiteSpace(currencyName)) { - await SendErrorAsync("Please provide currency name."); + await Response().Error("Please provide currency name.").SendAsync(); return; } @@ -273,7 +273,7 @@ public partial class Searches CultureInfo.InvariantCulture); } - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithAuthor($"{leagueName} Currency Exchange", "https://web.poecdn.com/image/favicon/ogimage.png", "http://poe.ninja") @@ -281,13 +281,13 @@ public partial class Searches .AddField($"{cleanConvert} Equivalent", chaosEquivalent / conversionEquivalent, true) .WithOkColor(); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } catch { - var embed = _eb.Create().WithDescription(GetText(strs.ninja_not_found)).WithErrorColor(); + var embed = new EmbedBuilder().WithDescription(GetText(strs.ninja_not_found)).WithErrorColor(); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } } diff --git a/src/NadekoBot/Modules/Searches/PokemonSearchCommands.cs b/src/NadekoBot/Modules/Searches/PokemonSearchCommands.cs index d16568366..f51486900 100644 --- a/src/NadekoBot/Modules/Searches/PokemonSearchCommands.cs +++ b/src/NadekoBot/Modules/Searches/PokemonSearchCommands.cs @@ -25,7 +25,7 @@ public partial class Searches if (kvp.Key.ToUpperInvariant() == pokemon.ToUpperInvariant()) { var p = kvp.Value; - await EmbedAsync(_eb.Create() + await Response().Embed(new EmbedBuilder() .WithOkColor() .WithTitle(kvp.Key.ToTitleCase()) .WithDescription(p.BaseStats.ToString()) @@ -37,12 +37,12 @@ public partial class Searches true) .AddField(GetText(strs.abilities), string.Join("\n", p.Abilities.Select(a => a.Value)), - true)); + true)).SendAsync(); return; } } - await ReplyErrorLocalizedAsync(strs.pokemon_none); + await Response().Error(strs.pokemon_none).SendAsync(); } [Cmd] @@ -55,7 +55,7 @@ public partial class Searches { if (kvp.Key.ToUpperInvariant() == ability) { - await EmbedAsync(_eb.Create() + await Response().Embed(new EmbedBuilder() .WithOkColor() .WithTitle(kvp.Value.Name) .WithDescription(string.IsNullOrWhiteSpace(kvp.Value.Desc) @@ -63,12 +63,12 @@ public partial class Searches : kvp.Value.Desc) .AddField(GetText(strs.rating), kvp.Value.Rating.ToString(Culture), - true)); + true)).SendAsync(); return; } } - await ReplyErrorLocalizedAsync(strs.pokemon_ability_none); + await Response().Error(strs.pokemon_ability_none).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Searches/Search/SearchCommands.cs b/src/NadekoBot/Modules/Searches/Search/SearchCommands.cs index 4d5c01bab..1eb97dd7f 100644 --- a/src/NadekoBot/Modules/Searches/Search/SearchCommands.cs +++ b/src/NadekoBot/Modules/Searches/Search/SearchCommands.cs @@ -24,7 +24,7 @@ public partial class Searches if (string.IsNullOrWhiteSpace(query)) { - await ErrorLocalizedAsync(strs.specify_search_params); + await Response().Error(strs.specify_search_params).SendAsync(); return; } @@ -35,7 +35,7 @@ public partial class Searches if (data is null or { Entries: null or { Count: 0 } }) { - await ReplyErrorLocalizedAsync(strs.no_results); + await Response().Error(strs.no_results).SendAsync(); return; } @@ -59,7 +59,7 @@ public partial class Searches descStr = descStr.TrimTo(4096); - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithAuthor(ctx.User) .WithTitle(query.TrimTo(64)!) @@ -68,7 +68,7 @@ public partial class Searches GetText(strs.results_in(data.Info.TotalResults, data.Info.SearchTime)), "https://i.imgur.com/G46fm8J.png"); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -78,7 +78,7 @@ public partial class Searches if (string.IsNullOrWhiteSpace(query)) { - await ErrorLocalizedAsync(strs.specify_search_params); + await Response().Error(strs.specify_search_params).SendAsync(); return; } @@ -89,16 +89,16 @@ public partial class Searches if (data is null or { Entries: null or { Count: 0 } }) { - await ReplyErrorLocalizedAsync(strs.no_search_results); + await Response().Error(strs.no_search_results).SendAsync(); return; } - var embeds = new List(4); + var embeds = new List(4); - IEmbedBuilder CreateEmbed(IImageSearchResultEntry entry) + EmbedBuilder CreateEmbed(IImageSearchResultEntry entry) { - return _eb.Create(ctx) + return new EmbedBuilder() .WithOkColor() .WithAuthor(ctx.User) .WithTitle(query) @@ -121,7 +121,7 @@ public partial class Searches embeds.Add(CreateEmbed(entry)); } - await EmbedAsync(null, embeds: embeds); + await Response().Embeds(embeds).SendAsync(); } private TypedKey GetYtCacheKey(string query) @@ -150,7 +150,7 @@ public partial class Searches if (string.IsNullOrWhiteSpace(query)) { - await ErrorLocalizedAsync(strs.specify_search_params); + await Response().Error(strs.specify_search_params).SendAsync(); return; } @@ -160,7 +160,7 @@ public partial class Searches ?? await _searchFactory.GetYoutubeSearchService().SearchAsync(query); if (maybeResult is not {} result || result is {Url: null}) { - await ReplyErrorLocalizedAsync(strs.no_results); + await Response().Error(strs.no_results).SendAsync(); return; } @@ -180,7 +180,7 @@ public partial class Searches // var data = await _service.DuckDuckGoSearchAsync(query); // if (data is null) // { -// await ReplyErrorLocalizedAsync(strs.no_results); +// await Response().Error(strs.no_results).SendAsync(); // return; // } // @@ -190,13 +190,13 @@ public partial class Searches // // var descStr = string.Join("\n\n", desc); // -// var embed = _eb.Create() +// var embed = new EmbedBuilder() // .WithAuthor(ctx.User.ToString(), // "https://upload.wikimedia.org/wikipedia/en/9/90/The_DuckDuckGo_Duck.png") // .WithDescription($"{GetText(strs.search_for)} **{query}**\n\n" + descStr) // .WithOkColor(); // -// await EmbedAsync(embed); +// await Response().Embed(embed).SendAsync(); // } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 50c5c21ff..00efa8d08 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -54,7 +54,7 @@ public partial class Searches : NadekoModule if (!await ValidateQuery(query)) return; - var embed = _eb.Create(); + var embed = new EmbedBuilder(); var data = await _service.GetWeatherDataAsync(query); if (data is null) @@ -93,7 +93,7 @@ public partial class Searches : NadekoModule $"https://openweathermap.org/img/w/{data.Weather[0].Icon}.png"); } - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -124,22 +124,22 @@ public partial class Searches : NadekoModule break; } - await ReplyErrorLocalizedAsync(errorKey); + await Response().Error(errorKey).SendAsync(); return; } if (string.IsNullOrWhiteSpace(data.TimeZoneName)) { - await ReplyErrorLocalizedAsync(strs.timezone_db_api_key); + await Response().Error(strs.timezone_db_api_key).SendAsync(); return; } - var eb = _eb.Create() - .WithOkColor() - .WithTitle(GetText(strs.time_new)) - .WithDescription(Format.Code(data.Time.ToString(Culture))) - .AddField(GetText(strs.location), string.Join('\n', data.Address.Split(", ")), true) - .AddField(GetText(strs.timezone), data.TimeZoneName, true); + var eb = new EmbedBuilder() + .WithOkColor() + .WithTitle(GetText(strs.time_new)) + .WithDescription(Format.Code(data.Time.ToString(Culture))) + .AddField(GetText(strs.location), string.Join('\n', data.Address.Split(", ")), true) + .AddField(GetText(strs.timezone), data.TimeZoneName, true); await ctx.Channel.SendMessageAsync(embed: eb.Build()); } @@ -155,19 +155,21 @@ public partial class Searches : NadekoModule var movie = await _service.GetMovieDataAsync(query); if (movie is null) { - await ReplyErrorLocalizedAsync(strs.imdb_fail); + await Response().Error(strs.imdb_fail).SendAsync(); return; } - await EmbedAsync(_eb.Create() - .WithOkColor() - .WithTitle(movie.Title) - .WithUrl($"https://www.imdb.com/title/{movie.ImdbId}/") - .WithDescription(movie.Plot.TrimTo(1000)) - .AddField("Rating", movie.ImdbRating, true) - .AddField("Genre", movie.Genre, true) - .AddField("Year", movie.Year, true) - .WithImageUrl(movie.Poster)); + await Response() + .Embed(new EmbedBuilder() + .WithOkColor() + .WithTitle(movie.Title) + .WithUrl($"https://www.imdb.com/title/{movie.ImdbId}/") + .WithDescription(movie.Plot.TrimTo(1000)) + .AddField("Rating", movie.ImdbRating, true) + .AddField("Genre", movie.Genre, true) + .AddField("Year", movie.Year, true) + .WithImageUrl(movie.Poster)) + .SendAsync(); } [Cmd] @@ -189,7 +191,7 @@ public partial class Searches : NadekoModule private Task InternalRandomImage(SearchesService.ImageTag tag) { var url = _service.GetRandomImageUrl(tag); - return EmbedAsync(_eb.Create().WithOkColor().WithImageUrl(url)); + return Response().Embed(new EmbedBuilder().WithOkColor().WithImageUrl(url)).SendAsync(); } [Cmd] @@ -199,7 +201,7 @@ public partial class Searches : NadekoModule return; var shortenedUrl = await _google.ShortenUrl($"https://letmegooglethat.com/?q={Uri.EscapeDataString(ffs)}"); - await SendConfirmAsync($"<{shortenedUrl}>"); + await Response().Confirm($"<{shortenedUrl}>").SendAsync(); } [Cmd] @@ -239,10 +241,12 @@ public partial class Searches : NadekoModule } } - await EmbedAsync(_eb.Create() - .WithOkColor() - .AddField(GetText(strs.original_url), $"<{query}>") - .AddField(GetText(strs.short_url), $"<{shortLink}>")); + await Response() + .Embed(new EmbedBuilder() + .WithOkColor() + .AddField(GetText(strs.original_url), $"<{query}>") + .AddField(GetText(strs.short_url), $"<{shortLink}>")) + .SendAsync(); } [Cmd] @@ -256,20 +260,20 @@ public partial class Searches : NadekoModule if (card is null) { - await ReplyErrorLocalizedAsync(strs.card_not_found); + await Response().Error(strs.card_not_found).SendAsync(); return; } - var embed = _eb.Create() - .WithOkColor() - .WithTitle(card.Name) - .WithDescription(card.Description) - .WithImageUrl(card.ImageUrl) - .AddField(GetText(strs.store_url), card.StoreUrl, true) - .AddField(GetText(strs.cost), card.ManaCost, true) - .AddField(GetText(strs.types), card.Types, true); + var embed = new EmbedBuilder() + .WithOkColor() + .WithTitle(card.Name) + .WithDescription(card.Description) + .WithImageUrl(card.ImageUrl) + .AddField(GetText(strs.store_url), card.StoreUrl, true) + .AddField(GetText(strs.cost), card.ManaCost, true) + .AddField(GetText(strs.types), card.Types, true); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -280,7 +284,7 @@ public partial class Searches : NadekoModule if (string.IsNullOrWhiteSpace(_creds.RapidApiKey)) { - await ReplyErrorLocalizedAsync(strs.mashape_api_missing); + await Response().Error(strs.mashape_api_missing).SendAsync(); return; } @@ -289,16 +293,16 @@ public partial class Searches : NadekoModule if (card is null) { - await ReplyErrorLocalizedAsync(strs.card_not_found); + await Response().Error(strs.card_not_found).SendAsync(); return; } - var embed = _eb.Create().WithOkColor().WithImageUrl(card.Img); + var embed = new EmbedBuilder().WithOkColor().WithImageUrl(card.Img); if (!string.IsNullOrWhiteSpace(card.Flavor)) embed.WithDescription(card.Flavor); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -321,11 +325,11 @@ public partial class Searches : NadekoModule p => { var item = items[p]; - return _eb.Create() - .WithOkColor() - .WithUrl(item.Permalink) - .WithTitle(item.Word) - .WithDescription(item.Definition); + return new EmbedBuilder() + .WithOkColor() + .WithUrl(item.Permalink) + .WithTitle(item.Word) + .WithDescription(item.Definition); }, items.Length, 1); @@ -337,7 +341,7 @@ public partial class Searches : NadekoModule } } - await ReplyErrorLocalizedAsync(strs.ud_error); + await Response().Error(strs.ud_error).SendAsync(); } [Cmd] @@ -361,28 +365,28 @@ public partial class Searches : NadekoModule var data = JsonConvert.DeserializeObject(res); var datas = data.Results - .Where(x => x.Senses is not null - && x.Senses.Count > 0 - && x.Senses[0].Definition is not null) - .Select(x => (Sense: x.Senses[0], x.PartOfSpeech)) - .ToList(); + .Where(x => x.Senses is not null + && x.Senses.Count > 0 + && x.Senses[0].Definition is not null) + .Select(x => (Sense: x.Senses[0], x.PartOfSpeech)) + .ToList(); if (!datas.Any()) { Log.Warning("Definition not found: {Word}", word); - await ReplyErrorLocalizedAsync(strs.define_unknown); + await Response().Error(strs.define_unknown).SendAsync(); } var col = datas.Select(x => ( - Definition: x.Sense.Definition is string - ? x.Sense.Definition.ToString() - : ((JArray)JToken.Parse(x.Sense.Definition.ToString())).First.ToString(), - Example: x.Sense.Examples is null || x.Sense.Examples.Count == 0 - ? string.Empty - : x.Sense.Examples[0].Text, Word: word, - WordType: string.IsNullOrWhiteSpace(x.PartOfSpeech) ? "-" : x.PartOfSpeech)) - .ToList(); + Definition: x.Sense.Definition is string + ? x.Sense.Definition.ToString() + : ((JArray)JToken.Parse(x.Sense.Definition.ToString())).First.ToString(), + Example: x.Sense.Examples is null || x.Sense.Examples.Count == 0 + ? string.Empty + : x.Sense.Examples[0].Text, Word: word, + WordType: string.IsNullOrWhiteSpace(x.PartOfSpeech) ? "-" : x.PartOfSpeech)) + .ToList(); Log.Information("Sending {Count} definition for: {Word}", col.Count, word); @@ -390,12 +394,12 @@ public partial class Searches : NadekoModule page => { var model = col.Skip(page).First(); - var embed = _eb.Create() - .WithDescription(ctx.User.Mention) - .AddField(GetText(strs.word), model.Word, true) - .AddField(GetText(strs._class), model.WordType, true) - .AddField(GetText(strs.definition), model.Definition) - .WithOkColor(); + var embed = new EmbedBuilder() + .WithDescription(ctx.User.Mention) + .AddField(GetText(strs.word), model.Word, true) + .AddField(GetText(strs._class), model.WordType, true) + .AddField(GetText(strs.definition), model.Definition) + .WithOkColor(); if (!string.IsNullOrWhiteSpace(model.Example)) embed.AddField(GetText(strs.example), model.Example); @@ -418,7 +422,7 @@ public partial class Searches : NadekoModule var response = await http.GetStringAsync("https://catfact.ninja/fact"); var fact = JObject.Parse(response)["fact"].ToString(); - await SendConfirmAsync("🐈" + GetText(strs.catfact), fact); + await Response().Confirm("🐈" + GetText(strs.catfact), fact).SendAsync(); } [Cmd] @@ -435,7 +439,7 @@ public partial class Searches : NadekoModule + Uri.EscapeDataString(query)); var data = JsonConvert.DeserializeObject(result); if (data.Query.Pages[0].Missing || string.IsNullOrWhiteSpace(data.Query.Pages[0].FullUrl)) - await ReplyErrorLocalizedAsync(strs.wiki_page_not_found); + await Response().Error(strs.wiki_page_not_found).SendAsync(); else await ctx.Channel.SendMessageAsync(data.Query.Pages[0].FullUrl); } @@ -468,13 +472,14 @@ public partial class Searches : NadekoModule var avatarUrl = usr.RealAvatarUrl(2048); - await EmbedAsync( - _eb.Create() - .WithOkColor() - .AddField("Username", usr.ToString()) - .AddField("Avatar Url", avatarUrl) - .WithThumbnailUrl(avatarUrl.ToString()), - ctx.User.Mention); + await Response() + .Embed( + new EmbedBuilder() + .WithOkColor() + .AddField("Username", usr.ToString()) + .AddField("Avatar Url", avatarUrl) + .WithThumbnailUrl(avatarUrl.ToString())) + .SendAsync(); } [Cmd] @@ -482,7 +487,7 @@ public partial class Searches : NadekoModule { if (string.IsNullOrWhiteSpace(target) || string.IsNullOrWhiteSpace(query)) { - await ReplyErrorLocalizedAsync(strs.wikia_input_error); + await Response().Error(strs.wikia_input_error).SendAsync(); return; } @@ -502,7 +507,7 @@ public partial class Searches : NadekoModule if (string.IsNullOrWhiteSpace(title)) { - await ReplyErrorLocalizedAsync(strs.wikia_error); + await Response().Error(strs.wikia_error).SendAsync(); return; } @@ -513,7 +518,7 @@ public partial class Searches : NadekoModule } catch { - await ReplyErrorLocalizedAsync(strs.wikia_error); + await Response().Error(strs.wikia_error).SendAsync(); } } @@ -532,14 +537,16 @@ public partial class Searches : NadekoModule } if (obj.Error is not null || obj.Verses is null || obj.Verses.Length == 0) - await SendErrorAsync(obj.Error ?? "No verse found."); + await Response().Error(obj.Error ?? "No verse found.").SendAsync(); else { var v = obj.Verses[0]; - await EmbedAsync(_eb.Create() - .WithOkColor() - .WithTitle($"{v.BookName} {v.Chapter}:{v.Verse}") - .WithDescription(v.Text)); + await Response() + .Embed(new EmbedBuilder() + .WithOkColor() + .WithTitle($"{v.BookName} {v.Chapter}:{v.Verse}") + .WithDescription(v.Text)) + .SendAsync(); } } @@ -554,11 +561,11 @@ public partial class Searches : NadekoModule var appId = await _service.GetSteamAppIdByName(query); if (appId == -1) { - await ReplyErrorLocalizedAsync(strs.not_found); + await Response().Error(strs.not_found).SendAsync(); return; } - //var embed = _eb.Create() + //var embed = new EmbedBuilder() // .WithOkColor() // .WithDescription(gameData.ShortDescription) // .WithTitle(gameData.Name) @@ -576,12 +583,13 @@ public partial class Searches : NadekoModule if (!string.IsNullOrWhiteSpace(query)) return true; - await ErrorLocalizedAsync(strs.specify_search_params); + await Response().Error(strs.specify_search_params).SendAsync(); return false; } public class ShortenData { - [JsonProperty("result_url")] public string ResultUrl { get; set; } + [JsonProperty("result_url")] + public string ResultUrl { get; set; } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationCommands.cs index 651394f03..c7ce854a6 100644 --- a/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationCommands.cs +++ b/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationCommands.cs @@ -24,12 +24,15 @@ public partial class Searches var data = await _service.FollowStream(ctx.Guild.Id, ctx.Channel.Id, link); if (data is null) { - await ReplyErrorLocalizedAsync(strs.stream_not_added); + await Response().Error(strs.stream_not_added).SendAsync(); return; } var embed = _service.GetEmbed(ctx.Guild.Id, data); - await EmbedAsync(embed, GetText(strs.stream_tracked)); + await Response() + .Embed(embed) + .Text(strs.stream_tracked) + .SendAsync(); } [Cmd] @@ -44,11 +47,11 @@ public partial class Searches var fs = await _service.UnfollowStreamAsync(ctx.Guild.Id, index); if (fs is null) { - await ReplyErrorLocalizedAsync(strs.stream_no); + await Response().Error(strs.stream_no).SendAsync(); return; } - await ReplyConfirmLocalizedAsync(strs.stream_removed(Format.Bold(fs.Username), fs.Type)); + await Response().Confirm(strs.stream_removed(Format.Bold(fs.Username), fs.Type)).SendAsync(); } [Cmd] @@ -57,7 +60,7 @@ public partial class Searches public async Task StreamsClear() { await _service.ClearAllStreams(ctx.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.streams_cleared); + await Response().Confirm(strs.streams_cleared).SendAsync(); } [Cmd] @@ -93,9 +96,9 @@ public partial class Searches .ToList(); if (elements.Count == 0) - return _eb.Create().WithDescription(GetText(strs.streams_none)).WithErrorColor(); + return new EmbedBuilder().WithDescription(GetText(strs.streams_none)).WithErrorColor(); - var eb = _eb.Create().WithTitle(GetText(strs.streams_follow_title)).WithOkColor(); + var eb = new EmbedBuilder().WithTitle(GetText(strs.streams_follow_title)).WithOkColor(); for (var index = 0; index < elements.Count; index++) { var elem = elements[index]; @@ -117,11 +120,11 @@ public partial class Searches { var newValue = _service.ToggleStreamOffline(ctx.Guild.Id); if (newValue) - await ReplyConfirmLocalizedAsync(strs.stream_off_enabled); + await Response().Confirm(strs.stream_off_enabled).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.stream_off_disabled); + await Response().Confirm(strs.stream_off_disabled).SendAsync(); } - + [Cmd] [RequireContext(ContextType.Guild)] [UserPerm(GuildPerm.ManageMessages)] @@ -129,9 +132,9 @@ public partial class Searches { var newValue = _service.ToggleStreamOnlineDelete(ctx.Guild.Id); if (newValue) - await ReplyConfirmLocalizedAsync(strs.stream_online_delete_enabled); + await Response().Confirm(strs.stream_online_delete_enabled).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.stream_online_delete_disabled); + await Response().Confirm(strs.stream_online_delete_disabled).SendAsync(); } [Cmd] @@ -144,14 +147,14 @@ public partial class Searches if (!_service.SetStreamMessage(ctx.Guild.Id, index, message, out var fs)) { - await ReplyConfirmLocalizedAsync(strs.stream_not_following); + await Response().Confirm(strs.stream_not_following).SendAsync(); return; } if (string.IsNullOrWhiteSpace(message)) - await ReplyConfirmLocalizedAsync(strs.stream_message_reset(Format.Bold(fs.Username))); + await Response().Confirm(strs.stream_message_reset(Format.Bold(fs.Username))).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.stream_message_set(Format.Bold(fs.Username))); + await Response().Confirm(strs.stream_message_set(Format.Bold(fs.Username))).SendAsync(); } [Cmd] @@ -163,11 +166,11 @@ public partial class Searches if (count == 0) { - await ReplyConfirmLocalizedAsync(strs.stream_not_following_any); + await Response().Confirm(strs.stream_not_following_any).SendAsync(); return; } - await ReplyConfirmLocalizedAsync(strs.stream_message_set_all(count)); + await Response().Confirm(strs.stream_message_set_all(count)).SendAsync(); } [Cmd] @@ -179,21 +182,23 @@ public partial class Searches var data = await _service.GetStreamDataAsync(url); if (data is null) { - await ReplyErrorLocalizedAsync(strs.no_channel_found); + await Response().Error(strs.no_channel_found).SendAsync(); return; } if (data.IsLive) { - await ReplyConfirmLocalizedAsync(strs.streamer_online(Format.Bold(data.Name), - Format.Bold(data.Viewers.ToString()))); + await Response() + .Confirm(strs.streamer_online(Format.Bold(data.Name), + Format.Bold(data.Viewers.ToString()))) + .SendAsync(); } else - await ReplyConfirmLocalizedAsync(strs.streamer_offline(data.Name)); + await Response().Confirm(strs.streamer_offline(data.Name)).SendAsync(); } catch { - await ReplyErrorLocalizedAsync(strs.no_channel_found); + await Response().Error(strs.no_channel_found).SendAsync(); } } } diff --git a/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs b/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs index 7a37fa1cc..a804de44b 100644 --- a/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs +++ b/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs @@ -479,9 +479,9 @@ public sealed class StreamNotificationService : INService, IReadyExecutor return data; } - public IEmbedBuilder GetEmbed(ulong guildId, StreamData status, bool showViewers = true) + public EmbedBuilder GetEmbed(ulong guildId, StreamData status, bool showViewers = true) { - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithTitle(status.Name) .WithUrl(status.StreamUrl) .WithDescription(status.StreamUrl) diff --git a/src/NadekoBot/Modules/Searches/Translate/TranslateService.cs b/src/NadekoBot/Modules/Searches/Translate/TranslateService.cs index e2e575109..8c2b691aa 100644 --- a/src/NadekoBot/Modules/Searches/Translate/TranslateService.cs +++ b/src/NadekoBot/Modules/Searches/Translate/TranslateService.cs @@ -69,7 +69,7 @@ public sealed class TranslateService : ITranslateService, IExecNoCommand, IReady || msg.Content.Equals(output, StringComparison.InvariantCultureIgnoreCase)) return; - var embed = _eb.Create().WithOkColor(); + var embed = new EmbedBuilder().WithOkColor(); if (autoDelete) { diff --git a/src/NadekoBot/Modules/Searches/Translate/TranslatorCommands.cs b/src/NadekoBot/Modules/Searches/Translate/TranslatorCommands.cs index 310787c44..818676f40 100644 --- a/src/NadekoBot/Modules/Searches/Translate/TranslatorCommands.cs +++ b/src/NadekoBot/Modules/Searches/Translate/TranslatorCommands.cs @@ -20,13 +20,13 @@ public partial class Searches await ctx.Channel.TriggerTypingAsync(); var translation = await _service.Translate(from, to, text); - var embed = _eb.Create(ctx).WithOkColor().AddField(from, text).AddField(to, translation); + var embed = new EmbedBuilder().WithOkColor().AddField(from, text).AddField(to, translation); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } catch { - await ReplyErrorLocalizedAsync(strs.bad_input_format); + await Response().Error(strs.bad_input_format).SendAsync(); } } @@ -40,9 +40,9 @@ public partial class Searches var toggle = await _service.ToggleAtl(ctx.Guild.Id, ctx.Channel.Id, autoDelete == AutoDeleteAutoTranslate.Del); if (toggle) - await ReplyConfirmLocalizedAsync(strs.atl_started); + await Response().Confirm(strs.atl_started).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.atl_stopped); + await Response().Confirm(strs.atl_stopped).SendAsync(); } [Cmd] @@ -50,7 +50,7 @@ public partial class Searches public async Task AutoTransLang() { if (await _service.UnregisterUser(ctx.Channel.Id, ctx.User.Id)) - await ReplyConfirmLocalizedAsync(strs.atl_removed); + await Response().Confirm(strs.atl_removed).SendAsync(); } [Cmd] @@ -61,17 +61,17 @@ public partial class Searches if (succ is null) { - await ReplyErrorLocalizedAsync(strs.atl_not_enabled); + await Response().Error(strs.atl_not_enabled).SendAsync(); return; } if (succ is false) { - await ReplyErrorLocalizedAsync(strs.invalid_lang); + await Response().Error(strs.invalid_lang).SendAsync(); return; } - await ReplyConfirmLocalizedAsync(strs.atl_set(from, to)); + await Response().Confirm(strs.atl_set(from, to)).SendAsync(); } [Cmd] @@ -80,16 +80,16 @@ public partial class Searches { var langs = _service.GetLanguages().ToList(); - var eb = _eb.Create() + var eb = new EmbedBuilder() .WithTitle(GetText(strs.supported_languages)) .WithOkColor(); foreach (var chunk in langs.Chunk(15)) { - eb.AddField("󠀁", chunk.Join("\n"), isInline: true); + eb.AddField("󠀁", chunk.Join("\n"), inline: true); } - await EmbedAsync(eb); + await Response().Embed(eb).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Searches/XkcdCommands.cs b/src/NadekoBot/Modules/Searches/XkcdCommands.cs index 24d14b8bf..bc19ebb60 100644 --- a/src/NadekoBot/Modules/Searches/XkcdCommands.cs +++ b/src/NadekoBot/Modules/Searches/XkcdCommands.cs @@ -25,13 +25,13 @@ public partial class Searches using var http = _httpFactory.CreateClient(); var res = await http.GetStringAsync($"{XKCD_URL}/info.0.json"); var comic = JsonConvert.DeserializeObject(res); - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithImageUrl(comic.ImageLink) .WithAuthor(comic.Title, "https://xkcd.com/s/919f27.ico", $"{XKCD_URL}/{comic.Num}") .AddField(GetText(strs.comic_number), comic.Num.ToString(), true) .AddField(GetText(strs.date), $"{comic.Month}/{comic.Year}", true); - var sent = await EmbedAsync(embed); + var sent = await Response().Embed(embed).SendAsync(); await Task.Delay(10000); @@ -39,7 +39,7 @@ public partial class Searches } catch (HttpRequestException) { - await ReplyErrorLocalizedAsync(strs.comic_not_found); + await Response().Error(strs.comic_not_found).SendAsync(); } return; @@ -60,14 +60,14 @@ public partial class Searches var res = await http.GetStringAsync($"{XKCD_URL}/{num}/info.0.json"); var comic = JsonConvert.DeserializeObject(res); - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithImageUrl(comic.ImageLink) .WithAuthor(comic.Title, "https://xkcd.com/s/919f27.ico", $"{XKCD_URL}/{num}") .AddField(GetText(strs.comic_number), comic.Num.ToString(), true) .AddField(GetText(strs.date), $"{comic.Month}/{comic.Year}", true); - var sent = await EmbedAsync(embed); + var sent = await Response().Embed(embed).SendAsync(); await Task.Delay(10000); @@ -75,7 +75,7 @@ public partial class Searches } catch (HttpRequestException) { - await ReplyErrorLocalizedAsync(strs.comic_not_found); + await Response().Error(strs.comic_not_found).SendAsync(); } } } diff --git a/src/NadekoBot/Modules/Searches/YoutubeTrack/YtUploadCommands.cs b/src/NadekoBot/Modules/Searches/YoutubeTrack/YtUploadCommands.cs index 880222c68..9563e0d09 100644 --- a/src/NadekoBot/Modules/Searches/YoutubeTrack/YtUploadCommands.cs +++ b/src/NadekoBot/Modules/Searches/YoutubeTrack/YtUploadCommands.cs @@ -13,11 +13,11 @@ public partial class Searches // var succ = await _service.ToggleChannelFollowAsync(ctx.Guild.Id, ctx.Channel.Id, ytChannelId, uploadMessage); // if(succ) // { - // await ReplyConfirmLocalizedAsync(strs.yt_follow_added); + // await Response().Confirm(strs.yt_follow_added).SendAsync(); // } // else // { - // await ReplyConfirmLocalizedAsync(strs.yt_follow_fail); + // await Response().Confirm(strs.yt_follow_fail).SendAsync(); // } // } // @@ -28,11 +28,11 @@ public partial class Searches // //var succ = await _service.ToggleChannelTrackingAsync(ctx.Guild.Id, ctx.Channel.Id, ytChannelId, uploadMessage); // //if (succ) // //{ - // // await ReplyConfirmLocalizedAsync(strs.yt_track_added); + // // await Response().Confirm(strs.yt_track_added).SendAsync(); // //} // //else // //{ - // // await ReplyConfirmLocalizedAsync(strs.yt_track_fail); + // // await Response().Confirm(strs.yt_track_fail).SendAsync(); // //} // } // @@ -43,11 +43,11 @@ public partial class Searches // //var succ = await _service.ToggleChannelTrackingAsync(ctx.Guild.Id, ctx.Channel.Id, ytChannelId, uploadMessage); // //if (succ) // //{ - // // await ReplyConfirmLocalizedAsync(strs.yt_track_added); + // // await Response().Confirm(strs.yt_track_added).SendAsync(); // //} // //else // //{ - // // await ReplyConfirmLocalizedAsync(strs.yt_track_fail); + // // await Response().Confirm(strs.yt_track_fail).SendAsync(); // //} // } // } diff --git a/src/NadekoBot/Modules/Utility/Alias/AliasCommands.cs b/src/NadekoBot/Modules/Utility/Alias/AliasCommands.cs index 8ad0402e0..d6c67f9cc 100644 --- a/src/NadekoBot/Modules/Utility/Alias/AliasCommands.cs +++ b/src/NadekoBot/Modules/Utility/Alias/AliasCommands.cs @@ -26,7 +26,7 @@ public partial class Utility public async Task AliasesClear() { var count = _service.ClearAliases(ctx.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.aliases_cleared(count)); + await Response().Confirm(strs.aliases_cleared(count)).SendAsync(); } [Cmd] @@ -43,7 +43,7 @@ public partial class Utility { if (!_service.AliasMaps.TryGetValue(ctx.Guild.Id, out var maps) || !maps.TryRemove(trigger, out _)) { - await ReplyErrorLocalizedAsync(strs.alias_remove_fail(Format.Code(trigger))); + await Response().Error(strs.alias_remove_fail(Format.Code(trigger))).SendAsync(); return; } @@ -56,7 +56,7 @@ public partial class Utility uow.SaveChanges(); } - await ReplyConfirmLocalizedAsync(strs.alias_removed(Format.Code(trigger))); + await Response().Confirm(strs.alias_removed(Format.Code(trigger))).SendAsync(); return; } @@ -100,7 +100,7 @@ public partial class Utility return map; }); - await ReplyConfirmLocalizedAsync(strs.alias_added(Format.Code(trigger), Format.Code(mapping))); + await Response().Confirm(strs.alias_added(Format.Code(trigger), Format.Code(mapping))).SendAsync(); } @@ -115,7 +115,7 @@ public partial class Utility if (!_service.AliasMaps.TryGetValue(ctx.Guild.Id, out var maps) || !maps.Any()) { - await ReplyErrorLocalizedAsync(strs.aliases_none); + await Response().Error(strs.aliases_none).SendAsync(); return; } @@ -124,7 +124,7 @@ public partial class Utility await ctx.SendPaginatedConfirmAsync(page, curPage => { - return _eb.Create() + return new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.alias_list)) .WithDescription(string.Join("\n", diff --git a/src/NadekoBot/Modules/Utility/Alias/AliasService.cs b/src/NadekoBot/Modules/Utility/Alias/AliasService.cs index 7bc6e0539..a33a7cd9b 100644 --- a/src/NadekoBot/Modules/Utility/Alias/AliasService.cs +++ b/src/NadekoBot/Modules/Utility/Alias/AliasService.cs @@ -9,13 +9,16 @@ namespace NadekoBot.Modules.Utility.Services; public class AliasService : IInputTransformer, INService { public ConcurrentDictionary> AliasMaps { get; } = new(); - private readonly IEmbedBuilderService _eb; private readonly DbService _db; + private readonly IMessageSenderService _sender; - public AliasService(DiscordSocketClient client, DbService db, IEmbedBuilderService eb) + public AliasService( + DiscordSocketClient client, + DbService db, + IMessageSenderService sender) { - _eb = eb; + _sender = sender; using var uow = db.GetDbContext(); var guildIds = client.Guilds.Select(x => x.Id).ToList(); @@ -53,7 +56,7 @@ public class AliasService : IInputTransformer, INService { if (guild is null || string.IsNullOrWhiteSpace(input)) return null; - + if (AliasMaps.TryGetValue(guild.Id, out var maps)) { string newInput = null; @@ -75,7 +78,9 @@ public class AliasService : IInputTransformer, INService { try { - var toDelete = await channel.SendConfirmAsync(_eb, $"{input} => {newInput}"); + var toDelete = await _sender.Response(channel) + .Confirm($"{input} => {newInput}") + .SendAsync(); toDelete.DeleteAfter(1.5f); } catch diff --git a/src/NadekoBot/Modules/Utility/Calc/CalcCommands.cs b/src/NadekoBot/Modules/Utility/Calc/CalcCommands.cs index fb0c1126a..4ff15289b 100644 --- a/src/NadekoBot/Modules/Utility/Calc/CalcCommands.cs +++ b/src/NadekoBot/Modules/Utility/Calc/CalcCommands.cs @@ -16,9 +16,9 @@ public partial class Utility expr.EvaluateParameter += Expr_EvaluateParameter; var result = expr.Evaluate(); if (!expr.HasErrors()) - await SendConfirmAsync("⚙ " + GetText(strs.result), result.ToString()); + await Response().Confirm("⚙ " + GetText(strs.result), result.ToString()).SendAsync(); else - await SendErrorAsync("⚙ " + GetText(strs.error), expr.Error); + await Response().Error("⚙ " + GetText(strs.error), expr.Error).SendAsync(); } private static void Expr_EvaluateParameter(string name, ParameterArgs args) @@ -42,7 +42,7 @@ public partial class Utility .DistinctBy(x => x.Name) .Select(x => x.Name) .Except(new[] { "ToString", "Equals", "GetHashCode", "GetType" }); - await SendConfirmAsync(GetText(strs.calcops(prefix)), string.Join(", ", selection)); + await Response().Confirm(GetText(strs.calcops(prefix)), string.Join(", ", selection)).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Utility/ConfigCommands.cs b/src/NadekoBot/Modules/Utility/ConfigCommands.cs index 04da91fce..cf409cd3d 100644 --- a/src/NadekoBot/Modules/Utility/ConfigCommands.cs +++ b/src/NadekoBot/Modules/Utility/ConfigCommands.cs @@ -20,12 +20,12 @@ public partial class Utility if (setting is null) { var configNames = _settingServices.Select(x => x.Name); - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithErrorColor() .WithDescription(GetText(strs.config_not_found(Format.Code(name)))) .AddField(GetText(strs.config_list), string.Join("\n", configNames)); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); return; } @@ -43,12 +43,12 @@ public partial class Utility name = name?.ToLowerInvariant(); if (string.IsNullOrWhiteSpace(name)) { - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.config_list)) .WithDescription(string.Join("\n", configNames)); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); return; } @@ -58,12 +58,12 @@ public partial class Utility // if config name is not found, print error and the list of configs if (setting is null) { - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithErrorColor() .WithDescription(GetText(strs.config_not_found(Format.Code(name)))) .AddField(GetText(strs.config_list), string.Join("\n", configNames)); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); return; } @@ -75,10 +75,10 @@ public partial class Utility if (string.IsNullOrWhiteSpace(prop)) { var propStrings = GetPropsAndValuesString(setting, propNames); - var embed = _eb.Create().WithOkColor().WithTitle($"⚙️ {setting.Name}").WithDescription(propStrings); + var embed = new EmbedBuilder().WithOkColor().WithTitle($"⚙️ {setting.Name}").WithDescription(propStrings); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); return; } // if the prop is invalid -> print error and list of @@ -88,13 +88,13 @@ public partial class Utility if (!exists) { var propStrings = GetPropsAndValuesString(setting, propNames); - var propErrorEmbed = _eb.Create() + var propErrorEmbed = new EmbedBuilder() .WithErrorColor() .WithDescription(GetText( strs.config_prop_not_found(Format.Code(prop), Format.Code(name)))) .AddField($"⚙️ {setting.Name}", propStrings); - await EmbedAsync(propErrorEmbed); + await Response().Embed(propErrorEmbed).SendAsync(); return; } @@ -110,7 +110,7 @@ public partial class Utility if (prop != "currency.sign") value = Format.Code(Format.Sanitize(value.TrimTo(1000)), "json"); - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .AddField("Config", Format.Code(setting.Name), true) .AddField("Prop", Format.Code(prop), true) @@ -120,7 +120,7 @@ public partial class Utility if (!string.IsNullOrWhiteSpace(comment)) embed.AddField("Comment", comment); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); return; } @@ -128,7 +128,7 @@ public partial class Utility if (!success) { - await ReplyErrorLocalizedAsync(strs.config_edit_fail(Format.Code(prop), Format.Code(value))); + await Response().Error(strs.config_edit_fail(Format.Code(prop), Format.Code(value))).SendAsync(); return; } diff --git a/src/NadekoBot/Modules/Utility/Giveaway/GiveawayCommands.cs b/src/NadekoBot/Modules/Utility/Giveaway/GiveawayCommands.cs index 66d076da2..929716e4d 100644 --- a/src/NadekoBot/Modules/Utility/Giveaway/GiveawayCommands.cs +++ b/src/NadekoBot/Modules/Utility/Giveaway/GiveawayCommands.cs @@ -13,16 +13,16 @@ public partial class Utility { if (duration > TimeSpan.FromDays(30)) { - await ReplyErrorLocalizedAsync(strs.giveaway_duration_invalid); + await Response().Error(strs.giveaway_duration_invalid).SendAsync(); return; } - var eb = _eb.Create(ctx) + var eb = new EmbedBuilder() .WithPendingColor() .WithTitle(GetText(strs.giveaway_starting)) .WithDescription(message); - var startingMsg = await EmbedAsync(eb); + var startingMsg = await Response().Embed(eb).SendAsync(); var maybeId = await _service.StartGiveawayAsync(ctx.Guild.Id, ctx.Channel.Id, startingMsg.Id, duration, message); @@ -31,7 +31,7 @@ public partial class Utility if (maybeId is not int id) { await startingMsg.DeleteAsync(); - await ReplyErrorLocalizedAsync(strs.giveaway_max_amount_reached); + await Response().Error(strs.giveaway_max_amount_reached).SendAsync(); return; } @@ -52,7 +52,7 @@ public partial class Utility if(!success) { - await ReplyErrorLocalizedAsync(strs.giveaway_not_found); + await Response().Error(strs.giveaway_not_found).SendAsync(); return; } @@ -67,7 +67,7 @@ public partial class Utility var success = await _service.RerollGiveawayAsync(ctx.Guild.Id, id); if (!success) { - await ReplyErrorLocalizedAsync(strs.giveaway_not_found); + await Response().Error(strs.giveaway_not_found).SendAsync(); return; } @@ -84,11 +84,11 @@ public partial class Utility if (!success) { - await ReplyConfirmLocalizedAsync(strs.giveaway_not_found); + await Response().Confirm(strs.giveaway_not_found).SendAsync(); return; } - await ReplyConfirmLocalizedAsync(strs.giveaway_cancelled); + await Response().Confirm(strs.giveaway_cancelled).SendAsync(); } [Cmd] @@ -99,11 +99,11 @@ public partial class Utility if (!giveaways.Any()) { - await ReplyErrorLocalizedAsync(strs.no_givaways); + await Response().Error(strs.no_givaways).SendAsync(); return; } - var eb = _eb.Create(ctx) + var eb = new EmbedBuilder() .WithTitle(GetText(strs.giveaway_list)) .WithOkColor(); @@ -112,7 +112,7 @@ public partial class Utility eb.AddField($"id: {new kwum(g.Id)}", g.Message, true); } - await EmbedAsync(eb); + await Response().Embed(eb).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Utility/Info/InfoCommands.cs b/src/NadekoBot/Modules/Utility/Info/InfoCommands.cs index 4cdde2f77..4767c923b 100644 --- a/src/NadekoBot/Modules/Utility/Info/InfoCommands.cs +++ b/src/NadekoBot/Modules/Utility/Info/InfoCommands.cs @@ -54,7 +54,7 @@ public partial class Utility if (string.IsNullOrWhiteSpace(features)) features = "-"; - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithAuthor(GetText(strs.server_info)) .WithTitle(guild.Name) .AddField(GetText(strs.id), guild.Id.ToString(), true) @@ -75,7 +75,7 @@ public partial class Utility string.Join(" ", guild.Emotes.Shuffle().Take(20).Select(e => $"{e.Name} {e}")).TrimTo(1020)); } - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -87,14 +87,14 @@ public partial class Utility return; var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(ch.Id >> 22); var usercount = (await ch.GetUsersAsync().FlattenAsync()).Count(); - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithTitle(ch.Name) .WithDescription(ch.Topic?.SanitizeMentions(true)) .AddField(GetText(strs.id), ch.Id.ToString(), true) .AddField(GetText(strs.created_at), $"{createdAt:dd.MM.yyyy HH:mm}", true) .AddField(GetText(strs.users), usercount.ToString(), true) .WithOkColor(); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -107,7 +107,7 @@ public partial class Utility var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc) .AddMilliseconds(role.Id >> 22); var usercount = role.Members.LongCount(); - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithTitle(role.Name.TrimTo(128)) .WithDescription(role.Permissions.ToList().Join(" | ")) .AddField(GetText(strs.id), role.Id.ToString(), true) @@ -121,7 +121,7 @@ public partial class Utility if (!string.IsNullOrWhiteSpace(role.GetIconUrl())) embed = embed.WithThumbnailUrl(role.GetIconUrl()); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -133,7 +133,7 @@ public partial class Utility if (user is null) return; - var embed = _eb.Create().AddField(GetText(strs.name), $"**{user.Username}**#{user.Discriminator}", true); + var embed = new EmbedBuilder().AddField(GetText(strs.name), $"**{user.Username}**#{user.Discriminator}", true); if (!string.IsNullOrWhiteSpace(user.Nickname)) embed.AddField(GetText(strs.nickname), user.Nickname, true); @@ -165,7 +165,7 @@ public partial class Utility if (av.IsAbsoluteUri) embed.WithThumbnailUrl(av.ToString()); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } private DateTimeOffset? GetJoinedAt(IGuildUser user) @@ -204,12 +204,12 @@ public partial class Utility kvp.Value))); } - await EmbedAsync(_eb.Create() + await Response().Embed(new EmbedBuilder() .WithTitle(GetText(strs.activity_page(page + 1))) .WithOkColor() .WithFooter(GetText( strs.activity_users_total(_cmdHandler.UserMessagesSent.Count))) - .WithDescription(str.ToString())); + .WithDescription(str.ToString())).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Utility/Info/InviteCommands.cs b/src/NadekoBot/Modules/Utility/Info/InviteCommands.cs index 38ab1c708..cbbf0575f 100644 --- a/src/NadekoBot/Modules/Utility/Info/InviteCommands.cs +++ b/src/NadekoBot/Modules/Utility/Info/InviteCommands.cs @@ -22,7 +22,7 @@ public partial class Utility var ch = (ITextChannel)ctx.Channel; var invite = await ch.CreateInviteAsync(opts.Expire, opts.MaxUses, opts.Temporary, opts.Unique); - await SendConfirmAsync($"{ctx.User.Mention} https://discord.gg/{invite.Code}"); + await Response().Confirm($"{ctx.User.Mention} https://discord.gg/{invite.Code}").SendAsync(); } [Cmd] @@ -44,9 +44,9 @@ public partial class Utility var invs = invites.Skip(cur * 9).Take(9).ToList(); if (!invs.Any()) - return _eb.Create().WithErrorColor().WithDescription(GetText(strs.no_invites)); + return new EmbedBuilder().WithErrorColor().WithDescription(GetText(strs.no_invites)); - var embed = _eb.Create().WithOkColor(); + var embed = new EmbedBuilder().WithOkColor(); foreach (var inv in invites) { var expiryString = inv.MaxAge is null or 0 || inv.CreatedAt is null diff --git a/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs index 149c423e0..d30f0da08 100644 --- a/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs @@ -14,24 +14,24 @@ public partial class Utility { private const string PREPEND_EXPORT = """ - # Keys are keywords, Each key has a LIST of quotes in the following format: - # - id: Alphanumeric id used for commands related to the quote. (Note, when using .quotesimport, a new id will be generated.) - # an: Author name - # aid: Author id - # txt: Quote text + # Keys are keywords, Each key has a LIST of quotes in the following format: + # - id: Alphanumeric id used for commands related to the quote. (Note, when using .quotesimport, a new id will be generated.) + # an: Author name + # aid: Author id + # txt: Quote text - """; + """; private static readonly ISerializer _exportSerializer = new SerializerBuilder() - .WithEventEmitter(args - => new MultilineScalarFlowStyleEmitter(args)) - .WithNamingConvention( - CamelCaseNamingConvention.Instance) - .WithIndentedSequences() - .ConfigureDefaultValuesHandling(DefaultValuesHandling - .OmitDefaults) - .DisableAliases() - .Build(); + .WithEventEmitter(args + => new MultilineScalarFlowStyleEmitter(args)) + .WithNamingConvention( + CamelCaseNamingConvention.Instance) + .WithIndentedSequences() + .ConfigureDefaultValuesHandling(DefaultValuesHandling + .OmitDefaults) + .DisableAliases() + .Build(); private readonly DbService _db; private readonly IHttpClientFactory _http; @@ -67,13 +67,15 @@ public partial class Utility if (quotes.Any()) { - await SendConfirmAsync(GetText(strs.quotes_page(page + 1)), - string.Join("\n", - quotes.Select(q - => $"`#{q.Id}` {Format.Bold(q.Keyword.SanitizeAllMentions()),-20} by {q.AuthorName.SanitizeAllMentions()}"))); + await Response() + .Confirm(GetText(strs.quotes_page(page + 1)), + string.Join("\n", + quotes.Select(q + => $"`#{q.Id}` {Format.Bold(q.Keyword.SanitizeAllMentions()),-20} by {q.AuthorName.SanitizeAllMentions()}"))) + .SendAsync(); } else - await ReplyErrorLocalizedAsync(strs.quotes_page_none); + await Response().Error(strs.quotes_page_none).SendAsync(); } [Cmd] @@ -121,7 +123,7 @@ public partial class Utility if (quote is null) { - await ReplyErrorLocalizedAsync(strs.quotes_notfound); + await Response().Error(strs.quotes_notfound).SendAsync(); return; } @@ -130,26 +132,26 @@ public partial class Utility private async Task ShowQuoteData(Quote data) { - var eb = _eb.Create(ctx) - .WithOkColor() - .WithTitle($"{GetText(strs.quote_id($"#{data.Id}"))} | {GetText(strs.response)}:") - .WithDescription(Format.Sanitize(data.Text).Replace("](", "]\\(").TrimTo(4096)) - .AddField(GetText(strs.trigger), data.Keyword) - .WithFooter( - GetText(strs.created_by($"{data.AuthorName} ({data.AuthorId})"))) - .Build(); + var eb = new EmbedBuilder() + .WithOkColor() + .WithTitle($"{GetText(strs.quote_id($"#{data.Id}"))} | {GetText(strs.response)}:") + .WithDescription(Format.Sanitize(data.Text).Replace("](", "]\\(").TrimTo(4096)) + .AddField(GetText(strs.trigger), data.Keyword) + .WithFooter( + GetText(strs.created_by($"{data.AuthorName} ({data.AuthorId})"))) + .Build(); if (!(data.Text.Length > 4096)) { await ctx.Channel.SendMessageAsync(embed: eb); return; } - + await ctx.Channel.SendFileAsync( attachment: new FileAttachment(await data.Text.ToStream(), "quote.txt"), embed: eb); } - + private async Task QuoteSearchinternalAsync(string? keyword, string textOrAuthor) { if (string.IsNullOrWhiteSpace(textOrAuthor)) @@ -177,7 +179,7 @@ public partial class Utility [Priority(0)] public Task QuoteSearch(string textOrAuthor) => QuoteSearchinternalAsync(null, textOrAuthor); - + [Cmd] [RequireContext(ContextType.Guild)] [Priority(1)] @@ -202,7 +204,7 @@ public partial class Utility if (quote is null || quote.GuildId != ctx.Guild.Id) { - await SendErrorAsync(GetText(strs.quotes_notfound)); + await Response().Error(GetText(strs.quotes_notfound)).SendAsync(); return; } @@ -228,18 +230,19 @@ public partial class Utility Quote q; await using (var uow = _db.GetDbContext()) { - uow.Set().Add(q = new() - { - AuthorId = ctx.Message.Author.Id, - AuthorName = ctx.Message.Author.Username, - GuildId = ctx.Guild.Id, - Keyword = keyword, - Text = text - }); + uow.Set() + .Add(q = new() + { + AuthorId = ctx.Message.Author.Id, + AuthorName = ctx.Message.Author.Username, + GuildId = ctx.Guild.Id, + Keyword = keyword, + Text = text + }); await uow.SaveChangesAsync(); } - await ReplyConfirmLocalizedAsync(strs.quote_added_new(Format.Code(q.Id.ToString()))); + await Response().Confirm(strs.quote_added_new(Format.Code(q.Id.ToString()))).SendAsync(); } [Cmd] @@ -266,16 +269,16 @@ public partial class Utility } if (success) - await SendConfirmAsync(response); + await Response().Confirm(response).SendAsync(); else - await SendErrorAsync(response); + await Response().Error(response).SendAsync(); } [Cmd] [RequireContext(ContextType.Guild)] public Task QuoteDeleteAuthor(IUser user) => QuoteDeleteAuthor(user.Id); - + [Cmd] [RequireContext(ContextType.Guild)] public async Task QuoteDeleteAuthor(ulong userId) @@ -285,11 +288,11 @@ public partial class Utility if (userId == ctx.User.Id || hasManageMessages) { var deleted = await _qs.DeleteAllAuthorQuotesAsync(ctx.Guild.Id, userId); - await ReplyConfirmLocalizedAsync(strs.quotes_deleted_count(deleted)); + await Response().Confirm(strs.quotes_deleted_count(deleted)).SendAsync(); } else { - await ReplyErrorLocalizedAsync(strs.insuf_perms_u); + await Response().Error(strs.insuf_perms_u).SendAsync(); } } @@ -310,7 +313,7 @@ public partial class Utility await uow.SaveChangesAsync(); } - await ReplyConfirmLocalizedAsync(strs.quotes_deleted(Format.Bold(keyword.SanitizeAllMentions()))); + await Response().Confirm(strs.quotes_deleted(Format.Bold(keyword.SanitizeAllMentions()))).SendAsync(); } [Cmd] @@ -325,7 +328,7 @@ public partial class Utility } var exprsDict = quotes.GroupBy(x => x.Keyword) - .ToDictionary(x => x.Key, x => x.Select(ExportedQuote.FromModel)); + .ToDictionary(x => x.Key, x => x.Select(ExportedQuote.FromModel)); var text = PREPEND_EXPORT + _exportSerializer.Serialize(exprsDict).UnescapeUnicodeCodePoints(); @@ -351,7 +354,7 @@ public partial class Utility var attachment = ctx.Message.Attachments.FirstOrDefault(); if (attachment is null) { - await ReplyErrorLocalizedAsync(strs.expr_import_no_input); + await Response().Error(strs.expr_import_no_input).SendAsync(); return; } @@ -360,7 +363,7 @@ public partial class Utility if (string.IsNullOrWhiteSpace(input)) { - await ReplyErrorLocalizedAsync(strs.expr_import_no_input); + await Response().Error(strs.expr_import_no_input).SendAsync(); return; } } @@ -368,7 +371,7 @@ public partial class Utility var succ = await ImportExprsAsync(ctx.Guild.Id, input); if (!succ) { - await ReplyErrorLocalizedAsync(strs.expr_import_invalid_data); + await Response().Error(strs.expr_import_invalid_data).SendAsync(); return; } @@ -393,15 +396,16 @@ public partial class Utility foreach (var entry in data) { var keyword = entry.Key; - await uow.Set().AddRangeAsync(entry.Value.Where(quote => !string.IsNullOrWhiteSpace(quote.Txt)) - .Select(quote => new Quote - { - GuildId = guildId, - Keyword = keyword, - Text = quote.Txt, - AuthorId = quote.Aid, - AuthorName = quote.An - })); + await uow.Set() + .AddRangeAsync(entry.Value.Where(quote => !string.IsNullOrWhiteSpace(quote.Txt)) + .Select(quote => new Quote + { + GuildId = guildId, + Keyword = keyword, + Text = quote.Txt, + AuthorId = quote.Aid, + AuthorName = quote.An + })); } await uow.SaveChangesAsync(); diff --git a/src/NadekoBot/Modules/Utility/Remind/RemindCommands.cs b/src/NadekoBot/Modules/Utility/Remind/RemindCommands.cs index 0365dd577..1b1239bde 100644 --- a/src/NadekoBot/Modules/Utility/Remind/RemindCommands.cs +++ b/src/NadekoBot/Modules/Utility/Remind/RemindCommands.cs @@ -41,10 +41,10 @@ public partial class Utility { if (!_service.TryParseRemindMessage(remindString, out var remindData)) { - await ReplyErrorLocalizedAsync(strs.remind_invalid); + await Response().Error(strs.remind_invalid).SendAsync(); return; } - + ulong target; target = meorhere == MeOrHere.Me ? ctx.User.Id : ctx.Channel.Id; if (!await RemindInternal(target, @@ -52,7 +52,7 @@ public partial class Utility remindData.Time, remindData.What, ReminderType.User)) - await ReplyErrorLocalizedAsync(strs.remind_too_long); + await Response().Error(strs.remind_too_long).SendAsync(); } [Cmd] @@ -64,19 +64,19 @@ public partial class Utility var perms = ((IGuildUser)ctx.User).GetPermissions(channel); if (!perms.SendMessages || !perms.ViewChannel) { - await ReplyErrorLocalizedAsync(strs.cant_read_or_send); + await Response().Error(strs.cant_read_or_send).SendAsync(); return; } if (!_service.TryParseRemindMessage(remindString, out var remindData)) { - await ReplyErrorLocalizedAsync(strs.remind_invalid); + await Response().Error(strs.remind_invalid).SendAsync(); return; } if (!await RemindInternal(channel.Id, false, remindData.Time, remindData.What, ReminderType.User)) - await ReplyErrorLocalizedAsync(strs.remind_too_long); + await Response().Error(strs.remind_too_long).SendAsync(); } [Cmd] @@ -96,7 +96,7 @@ public partial class Utility if (--page < 0) return; - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle(GetText(isServer ? strs.reminder_server_list : strs.reminder_list)); @@ -128,7 +128,7 @@ public partial class Utility embed.WithDescription(GetText(strs.reminders_none)); embed.AddPaginatedFooter(page + 1, null); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -165,9 +165,9 @@ public partial class Utility } if (rem is null) - await ReplyErrorLocalizedAsync(strs.reminder_not_exist); + await Response().Error(strs.reminder_not_exist).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.reminder_deleted(index + 1)); + await Response().Confirm(strs.reminder_deleted(index + 1)).SendAsync(); } private async Task RemindInternal( @@ -208,13 +208,14 @@ public partial class Utility var gTime = ctx.Guild is null ? time : TimeZoneInfo.ConvertTime(time, _tz.GetTimeZoneOrUtc(ctx.Guild.Id)); try { - await SendConfirmAsync("⏰ " - + GetText(strs.remind( - Format.Bold(!isPrivate ? $"<#{targetId}>" : ctx.User.Username), - Format.Bold(message), - ts.Humanize(3, minUnit: TimeUnit.Second, culture: Culture), - gTime, - gTime))); + await Response() + .Confirm($"\u23f0 {GetText(strs.remind( + Format.Bold(!isPrivate ? $"<#{targetId}>" : ctx.User.Username), + Format.Bold(message), + ts.Humanize(3, minUnit: TimeUnit.Second, culture: Culture), + gTime, + gTime))}") + .SendAsync(); } catch { diff --git a/src/NadekoBot/Modules/Utility/Remind/RemindService.cs b/src/NadekoBot/Modules/Utility/Remind/RemindService.cs index 7b1604542..7a36adf1a 100644 --- a/src/NadekoBot/Modules/Utility/Remind/RemindService.cs +++ b/src/NadekoBot/Modules/Utility/Remind/RemindService.cs @@ -205,7 +205,7 @@ public class RemindService : INService, IReadyExecutor, IRemindService } else { - await ch.EmbedAsync(_eb.Create() + await ch.EmbedAsync(new EmbedBuilder() .WithOkColor() .WithTitle("Reminder") .AddField("Created At", diff --git a/src/NadekoBot/Modules/Utility/Repeater/RepeatCommands.cs b/src/NadekoBot/Modules/Utility/Repeater/RepeatCommands.cs index 56b2df992..f3e9485c8 100644 --- a/src/NadekoBot/Modules/Utility/Repeater/RepeatCommands.cs +++ b/src/NadekoBot/Modules/Utility/Repeater/RepeatCommands.cs @@ -21,17 +21,17 @@ public partial class Utility if (result is null) { - await ReplyErrorLocalizedAsync(strs.index_out_of_range); + await Response().Error(strs.index_out_of_range).SendAsync(); return; } if (result is true) { - await ReplyConfirmLocalizedAsync(strs.repeater_skip_next); + await Response().Confirm(strs.repeater_skip_next).SendAsync(); } else { - await ReplyConfirmLocalizedAsync(strs.repeater_dont_skip_next); + await Response().Confirm(strs.repeater_dont_skip_next).SendAsync(); } } @@ -45,7 +45,7 @@ public partial class Utility var success = await _service.TriggerExternal(ctx.Guild.Id, index); if (!success) - await ReplyErrorLocalizedAsync(strs.repeat_invoke_none); + await Response().Error(strs.repeat_invoke_none).SendAsync(); } [Cmd] @@ -59,15 +59,15 @@ public partial class Utility var removed = await _service.RemoveByIndexAsync(ctx.Guild.Id, index); if (removed is null) { - await ReplyErrorLocalizedAsync(strs.repeater_remove_fail); + await Response().Error(strs.repeater_remove_fail).SendAsync(); return; } var description = GetRepeaterInfoString(removed); - await EmbedAsync(_eb.Create() + await Response().Embed(new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.repeater_removed(index + 1))) - .WithDescription(description)); + .WithDescription(description)).SendAsync(); } [Cmd] @@ -82,14 +82,14 @@ public partial class Utility if (result is null) { - await ReplyErrorLocalizedAsync(strs.index_out_of_range); + await Response().Error(strs.index_out_of_range).SendAsync(); return; } if (result.Value) - await ReplyErrorLocalizedAsync(strs.repeater_redundant_no(index + 1)); + await Response().Error(strs.repeater_redundant_no(index + 1)).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.repeater_redundant_yes(index + 1)); + await Response().Confirm(strs.repeater_redundant_yes(index + 1)).SendAsync(); } [Cmd] @@ -182,15 +182,15 @@ public partial class Utility if (runner is null) { - await ReplyErrorLocalizedAsync(strs.repeater_exceed_limit(5)); + await Response().Error(strs.repeater_exceed_limit(5)).SendAsync(); return; } var description = GetRepeaterInfoString(runner); - await EmbedAsync(_eb.Create() + await Response().Embed(new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.repeater_created)) - .WithDescription(description)); + .WithDescription(description)).SendAsync(); } [Cmd] @@ -201,11 +201,11 @@ public partial class Utility var repeaters = _service.GetRepeaters(ctx.Guild.Id); if (repeaters.Count == 0) { - await ReplyConfirmLocalizedAsync(strs.repeaters_none); + await Response().Confirm(strs.repeaters_none).SendAsync(); return; } - var embed = _eb.Create().WithTitle(GetText(strs.list_of_repeaters)).WithOkColor(); + var embed = new EmbedBuilder().WithTitle(GetText(strs.list_of_repeaters)).WithOkColor(); var i = 0; foreach (var runner in repeaters.OrderBy(r => r.Repeater.Id)) @@ -215,7 +215,7 @@ public partial class Utility embed.AddField(name, description); } - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } private string GetRepeaterInfoString(RunningRepeater runner) diff --git a/src/NadekoBot/Modules/Utility/StreamRole/StreamRoleCommands.cs b/src/NadekoBot/Modules/Utility/StreamRole/StreamRoleCommands.cs index 25c3710c0..b3c5e6fee 100644 --- a/src/NadekoBot/Modules/Utility/StreamRole/StreamRoleCommands.cs +++ b/src/NadekoBot/Modules/Utility/StreamRole/StreamRoleCommands.cs @@ -16,8 +16,8 @@ public partial class Utility { await _service.SetStreamRole(fromRole, addRole); - await ReplyConfirmLocalizedAsync(strs.stream_role_enabled(Format.Bold(fromRole.ToString()), - Format.Bold(addRole.ToString()))); + await Response().Confirm(strs.stream_role_enabled(Format.Bold(fromRole.ToString()), + Format.Bold(addRole.ToString()))).SendAsync(); } [Cmd] @@ -27,7 +27,7 @@ public partial class Utility public async Task StreamRole() { await _service.StopStreamRole(ctx.Guild); - await ReplyConfirmLocalizedAsync(strs.stream_role_disabled); + await Response().Confirm(strs.stream_role_disabled).SendAsync(); } [Cmd] @@ -39,9 +39,9 @@ public partial class Utility var kw = await _service.SetKeyword(ctx.Guild, keyword); if (string.IsNullOrWhiteSpace(keyword)) - await ReplyConfirmLocalizedAsync(strs.stream_role_kw_reset); + await Response().Confirm(strs.stream_role_kw_reset).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.stream_role_kw_set(Format.Bold(kw))); + await Response().Confirm(strs.stream_role_kw_set(Format.Bold(kw))).SendAsync(); } [Cmd] @@ -59,14 +59,14 @@ public partial class Utility if (action == AddRemove.Add) { if (success) - await ReplyConfirmLocalizedAsync(strs.stream_role_bl_add(Format.Bold(user.ToString()))); + await Response().Confirm(strs.stream_role_bl_add(Format.Bold(user.ToString()))).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.stream_role_bl_add_fail(Format.Bold(user.ToString()))); + await Response().Confirm(strs.stream_role_bl_add_fail(Format.Bold(user.ToString()))).SendAsync(); } else if (success) - await ReplyConfirmLocalizedAsync(strs.stream_role_bl_rem(Format.Bold(user.ToString()))); + await Response().Confirm(strs.stream_role_bl_rem(Format.Bold(user.ToString()))).SendAsync(); else - await ReplyErrorLocalizedAsync(strs.stream_role_bl_rem_fail(Format.Bold(user.ToString()))); + await Response().Error(strs.stream_role_bl_rem_fail(Format.Bold(user.ToString()))).SendAsync(); } [Cmd] @@ -84,14 +84,14 @@ public partial class Utility if (action == AddRemove.Add) { if (success) - await ReplyConfirmLocalizedAsync(strs.stream_role_wl_add(Format.Bold(user.ToString()))); + await Response().Confirm(strs.stream_role_wl_add(Format.Bold(user.ToString()))).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.stream_role_wl_add_fail(Format.Bold(user.ToString()))); + await Response().Confirm(strs.stream_role_wl_add_fail(Format.Bold(user.ToString()))).SendAsync(); } else if (success) - await ReplyConfirmLocalizedAsync(strs.stream_role_wl_rem(Format.Bold(user.ToString()))); + await Response().Confirm(strs.stream_role_wl_rem(Format.Bold(user.ToString()))).SendAsync(); else - await ReplyErrorLocalizedAsync(strs.stream_role_wl_rem_fail(Format.Bold(user.ToString()))); + await Response().Error(strs.stream_role_wl_rem_fail(Format.Bold(user.ToString()))).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Utility/Todo/TodoCommands.cs b/src/NadekoBot/Modules/Utility/Todo/TodoCommands.cs index 1526b789f..28116930b 100644 --- a/src/NadekoBot/Modules/Utility/Todo/TodoCommands.cs +++ b/src/NadekoBot/Modules/Utility/Todo/TodoCommands.cs @@ -13,7 +13,7 @@ public partial class Utility var result = await _service.AddAsync(ctx.User.Id, todo); if (result == TodoAddResult.MaxLimitReached) { - await ReplyErrorLocalizedAsync(strs.todo_add_max_limit); + await Response().Error(strs.todo_add_max_limit).SendAsync(); return; } @@ -25,7 +25,7 @@ public partial class Utility { if (!await _service.EditAsync(ctx.User.Id, todoId, newMessage)) { - await ReplyErrorLocalizedAsync(strs.todo_not_found); + await Response().Error(strs.todo_not_found).SendAsync(); return; } @@ -39,7 +39,7 @@ public partial class Utility if (todos.Length == 0) { - await ReplyErrorLocalizedAsync(strs.todo_list_empty); + await Response().Error(strs.todo_list_empty).SendAsync(); return; } @@ -52,7 +52,7 @@ public partial class Utility { if (!await _service.CompleteTodoAsync(ctx.User.Id, todoId)) { - await ReplyErrorLocalizedAsync(strs.todo_not_found); + await Response().Error(strs.todo_not_found).SendAsync(); return; } @@ -64,7 +64,7 @@ public partial class Utility { if (!await _service.DeleteTodoAsync(ctx.User.Id, todoId)) { - await ReplyErrorLocalizedAsync(strs.todo_not_found); + await Response().Error(strs.todo_not_found).SendAsync(); return; } @@ -76,7 +76,7 @@ public partial class Utility { await _service.ClearTodosAsync(ctx.User.Id); - await ReplyConfirmLocalizedAsync(strs.todo_cleared); + await Response().Confirm(strs.todo_cleared).SendAsync(); } @@ -85,7 +85,7 @@ public partial class Utility await ctx.SendPaginatedConfirmAsync(0, (curPage) => { - var eb = _eb.Create() + var eb = new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.todo_list)); @@ -97,7 +97,7 @@ public partial class Utility 9); } - private static void ShowTodoItem(IReadOnlyCollection todos, int curPage, IEmbedBuilder eb) + private static void ShowTodoItem(IReadOnlyCollection todos, int curPage, EmbedBuilder eb) { foreach (var todo in todos.Skip(curPage * 9).Take(9)) { @@ -119,13 +119,13 @@ public partial class Utility var result = await _service.ArchiveTodosAsync(ctx.User.Id, name); if (result == ArchiveTodoResult.NoTodos) { - await ReplyErrorLocalizedAsync(strs.todo_no_todos); + await Response().Error(strs.todo_no_todos).SendAsync(); return; } if (result == ArchiveTodoResult.MaxLimitReached) { - await ReplyErrorLocalizedAsync(strs.todo_archive_max_limit); + await Response().Error(strs.todo_archive_max_limit).SendAsync(); return; } @@ -142,14 +142,14 @@ public partial class Utility if (archivedTodoLists.Count == 0) { - await ReplyErrorLocalizedAsync(strs.todo_archive_empty); + await Response().Error(strs.todo_archive_empty).SendAsync(); return; } await ctx.SendPaginatedConfirmAsync(page, (curPage) => { - var eb = _eb.Create() + var eb = new EmbedBuilder() .WithTitle(GetText(strs.todo_archive_list)) .WithOkColor(); @@ -171,14 +171,14 @@ public partial class Utility var list = await _service.GetArchivedTodoListAsync(ctx.User.Id, id); if (list == null || list.Items.Count == 0) { - await ReplyErrorLocalizedAsync(strs.todo_archive_not_found); + await Response().Error(strs.todo_archive_not_found).SendAsync(); return; } await ctx.SendPaginatedConfirmAsync(0, (curPage) => { - var eb = _eb.Create() + var eb = new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.todo_list)); diff --git a/src/NadekoBot/Modules/Utility/UnitConversion/UnitConversionCommands.cs b/src/NadekoBot/Modules/Utility/UnitConversion/UnitConversionCommands.cs index e3d92d158..b1178ac6e 100644 --- a/src/NadekoBot/Modules/Utility/UnitConversion/UnitConversionCommands.cs +++ b/src/NadekoBot/Modules/Utility/UnitConversion/UnitConversionCommands.cs @@ -13,7 +13,7 @@ public partial class Utility { var units = await _service.GetUnitsAsync(); - var embed = _eb.Create().WithTitle(GetText(strs.convertlist)).WithOkColor(); + var embed = new EmbedBuilder().WithTitle(GetText(strs.convertlist)).WithOkColor(); foreach (var g in units.GroupBy(x => x.UnitType)) @@ -22,7 +22,7 @@ public partial class Utility string.Join(", ", g.Select(x => x.Triggers.FirstOrDefault()).OrderBy(x => x))); } - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -36,14 +36,16 @@ public partial class Utility => x.Triggers.Select(y => y.ToUpperInvariant()).Contains(target.ToUpperInvariant())); if (originUnit is null || targetUnit is null) { - await ReplyErrorLocalizedAsync(strs.convert_not_found(Format.Bold(origin), Format.Bold(target))); + await Response().Error(strs.convert_not_found(Format.Bold(origin), Format.Bold(target))).SendAsync(); return; } if (originUnit.UnitType != targetUnit.UnitType) { - await ReplyErrorLocalizedAsync(strs.convert_type_error(Format.Bold(originUnit.Triggers.First()), - Format.Bold(targetUnit.Triggers.First()))); + await Response() + .Error(strs.convert_type_error(Format.Bold(originUnit.Triggers.First()), + Format.Bold(targetUnit.Triggers.First()))) + .SendAsync(); return; } @@ -87,10 +89,12 @@ public partial class Utility res = Math.Round(res, 4); - await SendConfirmAsync(GetText(strs.convert(value, - originUnit.Triggers.Last(), - res, - targetUnit.Triggers.Last()))); + await Response() + .Confirm(GetText(strs.convert(value, + originUnit.Triggers.Last(), + res, + targetUnit.Triggers.Last()))) + .SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 6768a5416..61839723a 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -70,13 +70,13 @@ public partial class Utility : NadekoModule { if (!((IGuildUser)ctx.User).GetPermissions(channel).SendMessages) { - await ReplyErrorLocalizedAsync(strs.insuf_perms_u); + await Response().Error(strs.insuf_perms_u).SendAsync(); return; } if (!((ctx.Guild as SocketGuild)?.CurrentUser.GetPermissions(channel).SendMessages ?? false)) { - await ReplyErrorLocalizedAsync(strs.insuf_perms_i); + await Response().Error(strs.insuf_perms_i).SendAsync(); return; } @@ -122,14 +122,16 @@ public partial class Utility : NadekoModule var i = 0; if (arr.Length == 0) - await ReplyErrorLocalizedAsync(strs.nobody_playing_game); + await Response().Error(strs.nobody_playing_game).SendAsync(); else { - await SendConfirmAsync("```css\n" - + string.Join("\n", - arr.GroupBy(_ => i++ / 2) - .Select(ig => string.Concat(ig.Select(el => $"• {el,-27}")))) - + "\n```"); + await Response() + .Confirm("```css\n" + + string.Join("\n", + arr.GroupBy(_ => i++ / 2) + .Select(ig => string.Concat(ig.Select(el => $"• {el,-27}")))) + + "\n```") + .SendAsync(); } } @@ -158,9 +160,9 @@ public partial class Utility : NadekoModule var pageUsers = roleUsers.Skip(cur * 20).Take(20).ToList(); if (pageUsers.Count == 0) - return _eb.Create().WithOkColor().WithDescription(GetText(strs.no_user_on_this_page)); + return new EmbedBuilder().WithOkColor().WithDescription(GetText(strs.no_user_on_this_page)); - return _eb.Create() + return new EmbedBuilder() .WithOkColor() .WithTitle(GetText(strs.inrole_list(Format.Bold(role?.Name ?? "No Role"), roleUsers.Length))) .WithDescription(string.Join("\n", pageUsers)); @@ -192,7 +194,7 @@ public partial class Utility : NadekoModule return !method.GetParameters().Any(); })) builder.AppendLine($"{p.Name} : {p.GetValue(perms, null)}"); - await SendConfirmAsync(builder.ToString()); + await Response().Confirm(builder.ToString()).SendAsync(); } [Cmd] @@ -200,26 +202,30 @@ public partial class Utility : NadekoModule public async Task UserId([Leftover] IGuildUser target = null) { var usr = target ?? ctx.User; - await ReplyConfirmLocalizedAsync(strs.userid("🆔", - Format.Bold(usr.ToString()), - Format.Code(usr.Id.ToString()))); + await Response() + .Confirm(strs.userid("🆔", + Format.Bold(usr.ToString()), + Format.Code(usr.Id.ToString()))) + .SendAsync(); } [Cmd] [RequireContext(ContextType.Guild)] public async Task RoleId([Leftover] IRole role) - => await ReplyConfirmLocalizedAsync(strs.roleid("🆔", - Format.Bold(role.ToString()), - Format.Code(role.Id.ToString()))); + => await Response() + .Confirm(strs.roleid("🆔", + Format.Bold(role.ToString()), + Format.Code(role.Id.ToString()))) + .SendAsync(); [Cmd] public async Task ChannelId() - => await ReplyConfirmLocalizedAsync(strs.channelid("🆔", Format.Code(ctx.Channel.Id.ToString()))); + => await Response().Confirm(strs.channelid("🆔", Format.Code(ctx.Channel.Id.ToString()))).SendAsync(); [Cmd] [RequireContext(ContextType.Guild)] public async Task ServerId() - => await ReplyConfirmLocalizedAsync(strs.serverid("🆔", Format.Code(ctx.Guild.Id.ToString()))); + => await Response().Confirm(strs.serverid("🆔", Format.Code(ctx.Guild.Id.ToString()))).SendAsync(); [Cmd] [RequireContext(ContextType.Guild)] @@ -241,11 +247,13 @@ public partial class Utility : NadekoModule .Take(rolesPerPage) .ToArray(); if (!roles.Any()) - await ReplyErrorLocalizedAsync(strs.no_roles_on_page); + await Response().Error(strs.no_roles_on_page).SendAsync(); else { - await SendConfirmAsync(GetText(strs.roles_page(page, Format.Bold(target.ToString()))), - "\n• " + string.Join("\n• ", (IEnumerable)roles).SanitizeMentions(true)); + await Response() + .Confirm(GetText(strs.roles_page(page, Format.Bold(target.ToString()))), + "\n• " + string.Join("\n• ", (IEnumerable)roles)) + .SendAsync(); } } else @@ -256,11 +264,13 @@ public partial class Utility : NadekoModule .Take(rolesPerPage) .ToArray(); if (!roles.Any()) - await ReplyErrorLocalizedAsync(strs.no_roles_on_page); + await Response().Error(strs.no_roles_on_page).SendAsync(); else { - await SendConfirmAsync(GetText(strs.roles_all_page(page)), - "\n• " + string.Join("\n• ", (IEnumerable)roles).SanitizeMentions(true)); + await Response() + .Confirm(GetText(strs.roles_all_page(page)), + "\n• " + string.Join("\n• ", (IEnumerable)roles).SanitizeMentions(true)) + .SendAsync(); } } } @@ -279,9 +289,9 @@ public partial class Utility : NadekoModule var topic = channel.Topic; if (string.IsNullOrWhiteSpace(topic)) - await ReplyErrorLocalizedAsync(strs.no_topic_set); + await Response().Error(strs.no_topic_set).SendAsync(); else - await SendConfirmAsync(GetText(strs.channel_topic), topic); + await Response().Confirm(GetText(strs.channel_topic), topic).SendAsync(); } [Cmd] @@ -291,7 +301,7 @@ public partial class Utility : NadekoModule if (string.IsNullOrWhiteSpace(ownerIds)) ownerIds = "-"; - await EmbedAsync(_eb.Create() + await Response().Embed(new EmbedBuilder() .WithOkColor() .WithAuthor($"NadekoBot v{StatsService.BotVersion}", "https://nadeko-pictures.nyc3.digitaloceanspaces.com/other/avatar.png", @@ -314,7 +324,7 @@ public partial class Utility : NadekoModule GetText(strs.presence_txt(_coord.GetGuildCount(), _stats.TextChannels, _stats.VoiceChannels)), - true)); + true)).SendAsync(); } [Cmd] @@ -325,7 +335,7 @@ public partial class Utility : NadekoModule var result = string.Join("\n", tags.Select(m => GetText(strs.showemojis(m, m.Url)))); if (string.IsNullOrWhiteSpace(result)) - await ReplyErrorLocalizedAsync(strs.showemojis_none); + await Response().Error(strs.showemojis_none).SendAsync(); else await ctx.Channel.SendMessageAsync(result.TrimTo(2000)); } @@ -364,7 +374,7 @@ public partial class Utility : NadekoModule using var res = await http.GetAsync(url, HttpCompletionOption.ResponseHeadersRead); if (!res.IsImage() || res.GetContentLength() > 262_144) { - await ReplyErrorLocalizedAsync(strs.invalid_emoji_link); + await Response().Error(strs.invalid_emoji_link).SendAsync(); return; } @@ -378,11 +388,11 @@ public partial class Utility : NadekoModule { Log.Warning(ex, "Error adding emoji on server {GuildId}", ctx.Guild.Id); - await ReplyErrorLocalizedAsync(strs.emoji_add_error); + await Response().Error(strs.emoji_add_error).SendAsync(); return; } - await ConfirmLocalizedAsync(strs.emoji_added(em.ToString())); + await Response().Confirm(strs.emoji_added(em.ToString())).SendAsync(); } [Cmd] @@ -413,7 +423,7 @@ public partial class Utility : NadekoModule if (fails.Count > 0) { - await ReplyPendingLocalizedAsync(strs.emoji_not_removed(fails.Select(x => x.ToString()).Join(" "))); + await Response().Pending(strs.emoji_not_removed(fails.Select(x => x.ToString()).Join(" "))).SendAsync(); return; } @@ -442,7 +452,7 @@ public partial class Utility : NadekoModule } else { - await ReplyErrorLocalizedAsync(strs.sticker_error); + await Response().Error(strs.sticker_error).SendAsync(); return; } @@ -464,7 +474,7 @@ public partial class Utility : NadekoModule catch (Exception ex) { Log.Warning(ex, "Error occurred while adding a sticker: {Message}", ex.Message); - await ReplyErrorLocalizedAsync(strs.error_occured); + await Response().Error(strs.error_occured).SendAsync(); } finally { @@ -503,15 +513,15 @@ public partial class Utility : NadekoModule if (!guilds.Any()) { - await ReplyErrorLocalizedAsync(strs.listservers_none); + await Response().Error(strs.listservers_none).SendAsync(); return; } - var embed = _eb.Create().WithOkColor(); + var embed = new EmbedBuilder().WithOkColor(); foreach (var guild in guilds) embed.AddField(guild.Name, GetText(strs.listservers(guild.Id, guild.MemberCount, guild.OwnerId))); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -527,20 +537,20 @@ public partial class Utility : NadekoModule var perms = user.GetPermissions(ch); if (!perms.ReadMessageHistory || !perms.ViewChannel) { - await ReplyErrorLocalizedAsync(strs.insuf_perms_u); + await Response().Error(strs.insuf_perms_u).SendAsync(); return; } var msg = await ch.GetMessageAsync(messageId); if (msg is null) { - await ReplyErrorLocalizedAsync(strs.msg_not_found); + await Response().Error(strs.msg_not_found).SendAsync(); return; } if (!msg.Embeds.Any()) { - await ReplyErrorLocalizedAsync(strs.not_found); + await Response().Error(strs.not_found).SendAsync(); return; } @@ -551,7 +561,7 @@ public partial class Utility : NadekoModule .Map(x => new SmartEmbedArrayElementText(x)) }.ToJson(_showEmbedSerializerOptions); - await SendConfirmAsync(Format.Code(json, "json").Replace("](", "]\\(")); + await Response().Confirm(Format.Code(json, "json").Replace("](", "]\\(")).SendAsync(); } [Cmd] @@ -607,7 +617,9 @@ public partial class Utility : NadekoModule sw.Stop(); msg.DeleteAfter(0); - await SendConfirmAsync($"{Format.Bold(ctx.User.ToString())} 🏓 {(int)sw.Elapsed.TotalMilliseconds}ms"); + await Response() + .Confirm($"{Format.Bold(ctx.User.ToString())} 🏓 {(int)sw.Elapsed.TotalMilliseconds}ms") + .SendAsync(); } finally { @@ -623,9 +635,9 @@ public partial class Utility : NadekoModule var state = _veService.ToggleVerboseErrors(ctx.Guild.Id, newstate); if (state) - await ReplyConfirmLocalizedAsync(strs.verbose_errors_enabled); + await Response().Confirm(strs.verbose_errors_enabled).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.verbose_errors_disabled); + await Response().Confirm(strs.verbose_errors_disabled).SendAsync(); } [Cmd] @@ -671,17 +683,17 @@ public partial class Utility : NadekoModule var output = result.ReturnValue?.ToString(); if (!string.IsNullOrWhiteSpace(output)) { - var eb = _eb.Create(ctx) + var eb = new EmbedBuilder() .WithOkColor() .AddField("Code", scriptText) .AddField("Output", output.TrimTo(512)!); - _ = EmbedAsync(eb); + _ = Response().Embed(eb).SendAsync(); } } catch (Exception ex) { - await SendErrorAsync(ex.Message); + await Response().Error(ex.Message).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Xp/Club/Club.cs b/src/NadekoBot/Modules/Xp/Club/Club.cs index 20333edc4..ed8046592 100644 --- a/src/NadekoBot/Modules/Xp/Club/Club.cs +++ b/src/NadekoBot/Modules/Xp/Club/Club.cs @@ -23,18 +23,18 @@ public partial class Xp if (!result.TryPickT0(out var club, out var error)) { if (error == ClubTransferError.NotOwner) - await ReplyErrorLocalizedAsync(strs.club_owner_only); + await Response().Error(strs.club_owner_only).SendAsync(); else - await ReplyErrorLocalizedAsync(strs.club_target_not_member); + await Response().Error(strs.club_target_not_member).SendAsync(); } else { - await ReplyConfirmLocalizedAsync( + await Response().Confirm( strs.club_transfered( Format.Bold(club.Name), Format.Bold(newOwner.ToString()) ) - ); + ).SendAsync(); } } @@ -44,15 +44,15 @@ public partial class Xp var result = await _service.ToggleAdminAsync(ctx.User, toAdmin); if (result == ToggleAdminResult.AddedAdmin) - await ReplyConfirmLocalizedAsync(strs.club_admin_add(Format.Bold(toAdmin.ToString()))); + await Response().Confirm(strs.club_admin_add(Format.Bold(toAdmin.ToString()))).SendAsync(); else if (result == ToggleAdminResult.RemovedAdmin) - await ReplyConfirmLocalizedAsync(strs.club_admin_remove(Format.Bold(toAdmin.ToString()))); + await Response().Confirm(strs.club_admin_remove(Format.Bold(toAdmin.ToString()))).SendAsync(); else if (result == ToggleAdminResult.NotOwner) - await ReplyErrorLocalizedAsync(strs.club_owner_only); + await Response().Error(strs.club_owner_only).SendAsync(); else if (result == ToggleAdminResult.CantTargetThyself) - await ReplyErrorLocalizedAsync(strs.club_admin_invalid_target); + await Response().Error(strs.club_admin_invalid_target).SendAsync(); else if (result == ToggleAdminResult.TargetNotMember) - await ReplyErrorLocalizedAsync(strs.club_target_not_member); + await Response().Error(strs.club_target_not_member).SendAsync(); } [Cmd] @@ -62,29 +62,29 @@ public partial class Xp if (result == ClubCreateResult.NameTooLong) { - await ReplyErrorLocalizedAsync(strs.club_name_too_long); + await Response().Error(strs.club_name_too_long).SendAsync(); return; } if (result == ClubCreateResult.NameTaken) { - await ReplyErrorLocalizedAsync(strs.club_name_taken); + await Response().Error(strs.club_name_taken).SendAsync(); return; } if (result == ClubCreateResult.InsufficientLevel) { - await ReplyErrorLocalizedAsync(strs.club_create_insuff_lvl); + await Response().Error(strs.club_create_insuff_lvl).SendAsync(); return; } if (result == ClubCreateResult.AlreadyInAClub) { - await ReplyErrorLocalizedAsync(strs.club_already_in); + await Response().Error(strs.club_already_in).SendAsync(); return; } - await ReplyConfirmLocalizedAsync(strs.club_created(Format.Bold(clubName))); + await Response().Confirm(strs.club_created(Format.Bold(clubName))).SendAsync(); } [Cmd] @@ -92,19 +92,19 @@ public partial class Xp { if ((!Uri.IsWellFormedUriString(url, UriKind.Absolute) && url is not null)) { - await ReplyErrorLocalizedAsync(strs.club_icon_url_format); + await Response().Error(strs.club_icon_url_format).SendAsync(); return; } var result = await _service.SetClubIconAsync(ctx.User.Id, url); if (result == SetClubIconResult.Success) - await ReplyConfirmLocalizedAsync(strs.club_icon_set); + await Response().Confirm(strs.club_icon_set).SendAsync(); else if (result == SetClubIconResult.NotOwner) - await ReplyErrorLocalizedAsync(strs.club_owner_only); + await Response().Error(strs.club_owner_only).SendAsync(); else if (result == SetClubIconResult.TooLarge) - await ReplyErrorLocalizedAsync(strs.club_icon_too_large); + await Response().Error(strs.club_icon_too_large).SendAsync(); else if (result == SetClubIconResult.InvalidFileType) - await ReplyErrorLocalizedAsync(strs.club_icon_invalid_filetype); + await Response().Error(strs.club_icon_invalid_filetype).SendAsync(); } private async Task InternalClubInfoAsync(ClubInfo club) @@ -123,7 +123,7 @@ public partial class Xp await ctx.SendPaginatedConfirmAsync(0, page => { - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithOkColor() .WithTitle($"{club}") .WithDescription(GetText(strs.level_x(lvl.Level + $" ({club.Xp} xp)"))) @@ -163,7 +163,7 @@ public partial class Xp var club = _service.GetClubByMember(user); if (club is null) { - await ErrorLocalizedAsync(strs.club_user_not_in_club(Format.Bold(user.ToString()))); + await Response().Error(strs.club_user_not_in_club(Format.Bold(user.ToString()))).SendAsync(); return; } @@ -182,7 +182,7 @@ public partial class Xp if (!_service.GetClubByName(clubName, out var club)) { - await ReplyErrorLocalizedAsync(strs.club_not_exists); + await Response().Error(strs.club_not_exists).SendAsync(); return; } @@ -197,7 +197,7 @@ public partial class Xp var club = _service.GetClubWithBansAndApplications(ctx.User.Id); if (club is null) - return ReplyErrorLocalizedAsync(strs.club_admin_perms); + return Response().Error(strs.club_admin_perms).SendAsync(); var bans = club.Bans.Select(x => x.User).ToArray(); @@ -208,7 +208,7 @@ public partial class Xp .Skip(page * 10).Take(10) .Select(x => x.ToString())); - return _eb.Create() + return new EmbedBuilder() .WithTitle(GetText(strs.club_bans_for(club.ToString()))) .WithDescription(toShow) .WithOkColor(); @@ -225,7 +225,7 @@ public partial class Xp var club = _service.GetClubWithBansAndApplications(ctx.User.Id); if (club is null) - return ReplyErrorLocalizedAsync(strs.club_admin_perms); + return Response().Error(strs.club_admin_perms).SendAsync(); var apps = club.Applicants.Select(x => x.User).ToArray(); @@ -234,7 +234,7 @@ public partial class Xp { var toShow = string.Join("\n", apps.Skip(page * 10).Take(10).Select(x => x.ToString())); - return _eb.Create() + return new EmbedBuilder() .WithTitle(GetText(strs.club_apps_for(club.ToString()))) .WithDescription(toShow) .WithOkColor(); @@ -251,19 +251,19 @@ public partial class Xp if (!_service.GetClubByName(clubName, out var club)) { - await ReplyErrorLocalizedAsync(strs.club_not_exists); + await Response().Error(strs.club_not_exists).SendAsync(); return; } var result = _service.ApplyToClub(ctx.User, club); if (result == ClubApplyResult.Success) - await ReplyConfirmLocalizedAsync(strs.club_applied(Format.Bold(club.ToString()))); + await Response().Confirm(strs.club_applied(Format.Bold(club.ToString()))).SendAsync(); else if (result == ClubApplyResult.Banned) - await ReplyErrorLocalizedAsync(strs.club_join_banned); + await Response().Error(strs.club_join_banned).SendAsync(); else if (result == ClubApplyResult.AlreadyApplied) - await ReplyErrorLocalizedAsync(strs.club_already_applied); + await Response().Error(strs.club_already_applied).SendAsync(); else if (result == ClubApplyResult.AlreadyInAClub) - await ReplyErrorLocalizedAsync(strs.club_already_in); + await Response().Error(strs.club_already_in).SendAsync(); } [Cmd] @@ -277,11 +277,11 @@ public partial class Xp { var result = _service.AcceptApplication(ctx.User.Id, userName, out var discordUser); if (result == ClubAcceptResult.Accepted) - await ReplyConfirmLocalizedAsync(strs.club_accepted(Format.Bold(discordUser.ToString()))); + await Response().Confirm(strs.club_accepted(Format.Bold(discordUser.ToString()))).SendAsync(); else if (result == ClubAcceptResult.NoSuchApplicant) - await ReplyErrorLocalizedAsync(strs.club_accept_invalid_applicant); + await Response().Error(strs.club_accept_invalid_applicant).SendAsync(); else if (result == ClubAcceptResult.NotOwnerOrAdmin) - await ReplyErrorLocalizedAsync(strs.club_admin_perms); + await Response().Error(strs.club_admin_perms).SendAsync(); } [Cmd] @@ -295,11 +295,11 @@ public partial class Xp { var result = _service.RejectApplication(ctx.User.Id, userName, out var discordUser); if (result == ClubDenyResult.Rejected) - await ReplyConfirmLocalizedAsync(strs.club_rejected(Format.Bold(discordUser.ToString()))); + await Response().Confirm(strs.club_rejected(Format.Bold(discordUser.ToString()))).SendAsync(); else if(result == ClubDenyResult.NoSuchApplicant) - await ReplyErrorLocalizedAsync(strs.club_accept_invalid_applicant); + await Response().Error(strs.club_accept_invalid_applicant).SendAsync(); else if(result == ClubDenyResult.NotOwnerOrAdmin) - await ReplyErrorLocalizedAsync(strs.club_admin_perms); + await Response().Error(strs.club_admin_perms).SendAsync(); } [Cmd] @@ -308,11 +308,11 @@ public partial class Xp var res = _service.LeaveClub(ctx.User); if (res == ClubLeaveResult.Success) - await ReplyConfirmLocalizedAsync(strs.club_left); + await Response().Confirm(strs.club_left).SendAsync(); else if (res == ClubLeaveResult.NotInAClub) - await ReplyErrorLocalizedAsync(strs.club_not_in_a_club); + await Response().Error(strs.club_not_in_a_club).SendAsync(); else - await ReplyErrorLocalizedAsync(strs.club_owner_cant_leave); + await Response().Error(strs.club_owner_cant_leave).SendAsync(); } [Cmd] @@ -327,17 +327,17 @@ public partial class Xp var result = _service.Kick(ctx.User.Id, userName, out var club); if (result == ClubKickResult.Success) { - return ReplyConfirmLocalizedAsync(strs.club_user_kick(Format.Bold(userName), - Format.Bold(club.ToString()))); + return Response().Confirm(strs.club_user_kick(Format.Bold(userName), + Format.Bold(club.ToString()))).SendAsync(); } if (result == ClubKickResult.Hierarchy) - return ReplyErrorLocalizedAsync(strs.club_kick_hierarchy); + return Response().Error(strs.club_kick_hierarchy).SendAsync(); if (result == ClubKickResult.NotOwnerOrAdmin) - return ReplyErrorLocalizedAsync(strs.club_admin_perms); + return Response().Error(strs.club_admin_perms).SendAsync(); - return ReplyErrorLocalizedAsync(strs.club_target_not_member); + return Response().Error(strs.club_target_not_member).SendAsync(); } [Cmd] @@ -352,17 +352,17 @@ public partial class Xp var result = _service.Ban(ctx.User.Id, userName, out var club); if (result == ClubBanResult.Success) { - return ReplyConfirmLocalizedAsync(strs.club_user_banned(Format.Bold(userName), - Format.Bold(club.ToString()))); + return Response().Confirm(strs.club_user_banned(Format.Bold(userName), + Format.Bold(club.ToString()))).SendAsync(); } if (result == ClubBanResult.Unbannable) - return ReplyErrorLocalizedAsync(strs.club_ban_fail_unbannable); + return Response().Error(strs.club_ban_fail_unbannable).SendAsync(); if (result == ClubBanResult.WrongUser) - return ReplyErrorLocalizedAsync(strs.club_ban_fail_user_not_found); + return Response().Error(strs.club_ban_fail_user_not_found).SendAsync(); - return ReplyErrorLocalizedAsync(strs.club_admin_perms); + return Response().Error(strs.club_admin_perms).SendAsync(); } [Cmd] @@ -378,16 +378,16 @@ public partial class Xp if (result == ClubUnbanResult.Success) { - return ReplyConfirmLocalizedAsync(strs.club_user_unbanned(Format.Bold(userName), - Format.Bold(club.ToString()))); + return Response().Confirm(strs.club_user_unbanned(Format.Bold(userName), + Format.Bold(club.ToString()))).SendAsync(); } if (result == ClubUnbanResult.WrongUser) { - return ReplyErrorLocalizedAsync(strs.club_unban_fail_user_not_found); + return Response().Error(strs.club_unban_fail_user_not_found).SendAsync(); } - return ReplyErrorLocalizedAsync(strs.club_admin_perms); + return Response().Error(strs.club_admin_perms).SendAsync(); } [Cmd] @@ -399,17 +399,17 @@ public partial class Xp ? "-" : desc; - var eb = _eb.Create(ctx) + var eb = new EmbedBuilder() .WithAuthor(ctx.User) .WithTitle(GetText(strs.club_desc_update)) .WithOkColor() .WithDescription(desc); - await EmbedAsync(eb); + await Response().Embed(eb).SendAsync(); } else { - await ReplyErrorLocalizedAsync(strs.club_desc_update_failed); + await Response().Error(strs.club_desc_update_failed).SendAsync(); } } @@ -417,9 +417,9 @@ public partial class Xp public async Task ClubDisband() { if (_service.Disband(ctx.User.Id, out var club)) - await ReplyConfirmLocalizedAsync(strs.club_disbanded(Format.Bold(club.Name))); + await Response().Confirm(strs.club_disbanded(Format.Bold(club.Name))).SendAsync(); else - await ReplyErrorLocalizedAsync(strs.club_disband_error); + await Response().Error(strs.club_disband_error).SendAsync(); } [Cmd] @@ -430,13 +430,13 @@ public partial class Xp var clubs = _service.GetClubLeaderboardPage(page); - var embed = _eb.Create().WithTitle(GetText(strs.club_leaderboard(page + 1))).WithOkColor(); + var embed = new EmbedBuilder().WithTitle(GetText(strs.club_leaderboard(page + 1))).WithOkColor(); var i = page * 9; foreach (var club in clubs) embed.AddField($"#{++i} " + club, club.Xp + " xp"); - return EmbedAsync(embed); + return Response().Embed(embed).SendAsync(); } [Cmd] @@ -447,19 +447,19 @@ public partial class Xp switch (res) { case ClubRenameResult.NameTooLong: - await ReplyErrorLocalizedAsync(strs.club_name_too_long); + await Response().Error(strs.club_name_too_long).SendAsync(); return; case ClubRenameResult.Success: { - var embed = _eb.Create().WithTitle(GetText(strs.club_renamed(clubName))).WithOkColor(); - await EmbedAsync(embed); + var embed = new EmbedBuilder().WithTitle(GetText(strs.club_renamed(clubName))).WithOkColor(); + await Response().Embed(embed).SendAsync(); return; } case ClubRenameResult.NameTaken: - await ReplyErrorLocalizedAsync(strs.club_name_taken); + await Response().Error(strs.club_name_taken).SendAsync(); return; case ClubRenameResult.NotOwnerOrAdmin: - await ReplyErrorLocalizedAsync(strs.club_admin_perms); + await Response().Error(strs.club_admin_perms).SendAsync(); return; default: return; diff --git a/src/NadekoBot/Modules/Xp/Club/ClubService.cs b/src/NadekoBot/Modules/Xp/Club/ClubService.cs index fe0df6f61..b7c52d7b1 100644 --- a/src/NadekoBot/Modules/Xp/Club/ClubService.cs +++ b/src/NadekoBot/Modules/Xp/Club/ClubService.cs @@ -57,7 +57,7 @@ public class ClubService : INService, IClubService public OneOf TransferClub(IUser from, IUser newOwner) { using var uow = _db.GetDbContext(); - var club = uow.Set().GetByOwner(@from.Id); + var club = uow.Set().GetByOwner(from.Id); var newOwnerUser = uow.GetOrCreateUser(newOwner); if (club is null || club.Owner.UserId != from.Id) diff --git a/src/NadekoBot/Modules/Xp/Xp.cs b/src/NadekoBot/Modules/Xp/Xp.cs index 881238688..9eed1ba5a 100644 --- a/src/NadekoBot/Modules/Xp/Xp.cs +++ b/src/NadekoBot/Modules/Xp/Xp.cs @@ -59,12 +59,12 @@ public partial class Xp : NadekoModule var globalSetting = _service.GetNotificationType(ctx.User); var serverSetting = _service.GetNotificationType(ctx.User.Id, ctx.Guild.Id); - var embed = _eb.Create() - .WithOkColor() - .AddField(GetText(strs.xpn_setting_global), GetNotifLocationString(globalSetting)) - .AddField(GetText(strs.xpn_setting_server), GetNotifLocationString(serverSetting)); + var embed = new EmbedBuilder() + .WithOkColor() + .AddField(GetText(strs.xpn_setting_global), GetNotifLocationString(globalSetting)) + .AddField(GetText(strs.xpn_setting_server), GetNotifLocationString(serverSetting)); - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -87,9 +87,9 @@ public partial class Xp : NadekoModule var ex = _service.ToggleExcludeServer(ctx.Guild.Id); if (ex) - await ReplyConfirmLocalizedAsync(strs.excluded(Format.Bold(ctx.Guild.ToString()))); + await Response().Confirm(strs.excluded(Format.Bold(ctx.Guild.ToString()))).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.not_excluded(Format.Bold(ctx.Guild.ToString()))); + await Response().Confirm(strs.not_excluded(Format.Bold(ctx.Guild.ToString()))).SendAsync(); } [Cmd] @@ -100,9 +100,9 @@ public partial class Xp : NadekoModule var ex = _service.ToggleExcludeRole(ctx.Guild.Id, role.Id); if (ex) - await ReplyConfirmLocalizedAsync(strs.excluded(Format.Bold(role.ToString()))); + await Response().Confirm(strs.excluded(Format.Bold(role.ToString()))).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.not_excluded(Format.Bold(role.ToString()))); + await Response().Confirm(strs.not_excluded(Format.Bold(role.ToString()))).SendAsync(); } [Cmd] @@ -116,9 +116,9 @@ public partial class Xp : NadekoModule var ex = _service.ToggleExcludeChannel(ctx.Guild.Id, channel.Id); if (ex) - await ReplyConfirmLocalizedAsync(strs.excluded(Format.Bold(channel.ToString()))); + await Response().Confirm(strs.excluded(Format.Bold(channel.ToString()))).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.not_excluded(Format.Bold(channel.ToString()))); + await Response().Confirm(strs.not_excluded(Format.Bold(channel.ToString()))).SendAsync(); } [Cmd] @@ -127,16 +127,16 @@ public partial class Xp : NadekoModule { var serverExcluded = _service.IsServerExcluded(ctx.Guild.Id); var roles = _service.GetExcludedRoles(ctx.Guild.Id) - .Select(x => ctx.Guild.GetRole(x)) - .Where(x => x is not null) - .Select(x => $"`role` {x.Mention}") - .ToList(); + .Select(x => ctx.Guild.GetRole(x)) + .Where(x => x is not null) + .Select(x => $"`role` {x.Mention}") + .ToList(); var chans = (await _service.GetExcludedChannels(ctx.Guild.Id) - .Select(x => ctx.Guild.GetChannelAsync(x)) - .WhenAll()).Where(x => x is not null) - .Select(x => $"`channel` <#{x.Id}>") - .ToList(); + .Select(x => ctx.Guild.GetChannelAsync(x)) + .WhenAll()).Where(x => x is not null) + .Select(x => $"`channel` <#{x.Id}>") + .ToList(); var rolesStr = roles.Any() ? string.Join("\n", roles) + "\n" : string.Empty; var chansStr = chans.Count > 0 ? string.Join("\n", chans) + "\n" : string.Empty; @@ -150,10 +150,10 @@ public partial class Xp : NadekoModule await ctx.SendPaginatedConfirmAsync(0, curpage => { - var embed = _eb.Create() - .WithTitle(GetText(strs.exclusion_list)) - .WithDescription(string.Join('\n', lines.Skip(15 * curpage).Take(15))) - .WithOkColor(); + var embed = new EmbedBuilder() + .WithTitle(GetText(strs.exclusion_list)) + .WithDescription(string.Join('\n', lines.Skip(15 * curpage).Take(15))) + .WithOkColor(); return embed; }, @@ -189,14 +189,14 @@ public partial class Xp : NadekoModule await _tracker.EnsureUsersDownloadedAsync(ctx.Guild); allUsers = _service.GetTopUserXps(ctx.Guild.Id, 1000) - .Where(user => socketGuild.GetUser(user.UserId) is not null) - .ToList(); + .Where(user => socketGuild.GetUser(user.UserId) is not null) + .ToList(); } await ctx.SendPaginatedConfirmAsync(page, curPage => { - var embed = _eb.Create().WithTitle(GetText(strs.server_leaderboard)).WithOkColor(); + var embed = new EmbedBuilder().WithTitle(GetText(strs.server_leaderboard)).WithOkColor(); List users; if (opts.Clean) @@ -239,7 +239,7 @@ public partial class Xp : NadekoModule return; var users = _service.GetUserXps(page); - var embed = _eb.Create().WithTitle(GetText(strs.global_leaderboard)).WithOkColor(); + var embed = new EmbedBuilder().WithTitle(GetText(strs.global_leaderboard)).WithOkColor(); if (!users.Any()) embed.WithDescription("-"); @@ -253,7 +253,7 @@ public partial class Xp : NadekoModule } } - await EmbedAsync(embed); + await Response().Embed(embed).SendAsync(); } [Cmd] @@ -269,8 +269,10 @@ public partial class Xp : NadekoModule return; var count = await _service.AddXpToUsersAsync(ctx.Guild.Id, amount, role.Members.Select(x => x.Id).ToArray()); - await ReplyConfirmLocalizedAsync( - strs.xpadd_users(Format.Bold(amount.ToString()), Format.Bold(count.ToString()))); + await Response() + .Confirm( + strs.xpadd_users(Format.Bold(amount.ToString()), Format.Bold(count.ToString()))) + .SendAsync(); } [Cmd] @@ -284,7 +286,7 @@ public partial class Xp : NadekoModule _service.AddXp(userId, ctx.Guild.Id, amount); var usr = ((SocketGuild)ctx.Guild).GetUser(userId)?.ToString() ?? userId.ToString(); - await ReplyConfirmLocalizedAsync(strs.modified(Format.Bold(usr), Format.Bold(amount.ToString()))); + await Response().Confirm(strs.modified(Format.Bold(usr), Format.Bold(amount.ToString()))).SendAsync(); } [Cmd] @@ -301,7 +303,7 @@ public partial class Xp : NadekoModule { _service.ReloadXpTemplate(); await Task.Delay(1000); - await ReplyConfirmLocalizedAsync(strs.template_reloaded); + await Response().Confirm(strs.template_reloaded).SendAsync(); } [Cmd] @@ -315,14 +317,14 @@ public partial class Xp : NadekoModule [UserPerm(GuildPerm.Administrator)] public async Task XpReset(ulong userId) { - var embed = _eb.Create().WithTitle(GetText(strs.reset)).WithDescription(GetText(strs.reset_user_confirm)); + var embed = new EmbedBuilder().WithTitle(GetText(strs.reset)).WithDescription(GetText(strs.reset_user_confirm)); if (!await PromptUserConfirmAsync(embed)) return; _service.XpReset(ctx.Guild.Id, userId); - await ReplyConfirmLocalizedAsync(strs.reset_user(userId)); + await Response().Confirm(strs.reset_user(userId)).SendAsync(); } [Cmd] @@ -330,14 +332,14 @@ public partial class Xp : NadekoModule [UserPerm(GuildPerm.Administrator)] public async Task XpReset() { - var embed = _eb.Create().WithTitle(GetText(strs.reset)).WithDescription(GetText(strs.reset_server_confirm)); + var embed = new EmbedBuilder().WithTitle(GetText(strs.reset)).WithDescription(GetText(strs.reset_server_confirm)); if (!await PromptUserConfirmAsync(embed)) return; _service.XpReset(ctx.Guild.Id); - await ReplyConfirmLocalizedAsync(strs.reset_server); + await Response().Confirm(strs.reset_server).SendAsync(); } public enum XpShopInputType @@ -358,15 +360,19 @@ public partial class Xp : NadekoModule { if (!_service.IsShopEnabled()) { - await ReplyErrorLocalizedAsync(strs.xp_shop_disabled); + await Response().Error(strs.xp_shop_disabled).SendAsync(); return; } - await SendConfirmAsync(GetText(strs.available_commands), - $@"`{prefix}xpshop bgs` -`{prefix}xpshop frames` + await Response() + .Confirm(GetText(strs.available_commands), + $""" + `{prefix}xpshop bgs` + `{prefix}xpshop frames` -*{GetText(strs.xpshop_website)}*"); + *{GetText(strs.xpshop_website)}* + """) + .SendAsync(); } [Cmd] @@ -383,13 +389,13 @@ public partial class Xp : NadekoModule if (items is null) { - await ReplyErrorLocalizedAsync(strs.xp_shop_disabled); + await Response().Error(strs.xp_shop_disabled).SendAsync(); return; } if (items.Count == 0) { - await ReplyErrorLocalizedAsync(strs.not_found); + await Response().Error(strs.not_found).SendAsync(); return; } @@ -398,13 +404,15 @@ public partial class Xp : NadekoModule { var (key, item) = items.Skip(current).First(); - var eb = _eb.Create(ctx) - .WithOkColor() - .WithTitle(item.Name) - .AddField(GetText(strs.price), CurrencyHelper.N(item.Price, Culture, _gss.GetCurrencySign()), true) - .WithImageUrl(string.IsNullOrWhiteSpace(item.Preview) - ? item.Url - : item.Preview); + var eb = new EmbedBuilder() + .WithOkColor() + .WithTitle(item.Name) + .AddField(GetText(strs.price), + CurrencyHelper.N(item.Price, Culture, _gss.GetCurrencySign()), + true) + .WithImageUrl(string.IsNullOrWhiteSpace(item.Preview) + ? item.Url + : item.Preview); if (!string.IsNullOrWhiteSpace(item.Desc)) eb.AddField(GetText(strs.desc), item.Desc); @@ -483,20 +491,24 @@ public partial class Xp : NadekoModule { var _ = result switch { - BuyResult.XpShopDisabled => await ReplyErrorLocalizedAsync(strs.xp_shop_disabled), - BuyResult.InsufficientFunds => await ReplyErrorLocalizedAsync(strs.not_enough(_gss.GetCurrencySign())), + BuyResult.XpShopDisabled => await Response().Error(strs.xp_shop_disabled).SendAsync(), + BuyResult.InsufficientFunds => await Response() + .Error(strs.not_enough(_gss.GetCurrencySign())) + .SendAsync(), BuyResult.AlreadyOwned => - await ReplyErrorLocalizedAsync(strs.xpshop_already_owned, GetUseInteraction()), - BuyResult.UnknownItem => await ReplyErrorLocalizedAsync(strs.xpshop_item_not_found), - BuyResult.InsufficientPatronTier => await ReplyErrorLocalizedAsync(strs.patron_insuff_tier), + await Response().Error(strs.xpshop_already_owned).Interaction(GetUseInteraction()).SendAsync(), + BuyResult.UnknownItem => await Response().Error(strs.xpshop_item_not_found).SendAsync(), + BuyResult.InsufficientPatronTier => await Response().Error(strs.patron_insuff_tier).SendAsync(), _ => throw new ArgumentOutOfRangeException() }; return; } - await ReplyConfirmLocalizedAsync(strs.xpshop_buy_success(type.ToString().ToLowerInvariant(), - key.ToLowerInvariant()), - GetUseInteraction()); + await Response() + .Confirm(strs.xpshop_buy_success(type.ToString().ToLowerInvariant(), + key.ToLowerInvariant())) + .Interaction(GetUseInteraction()) + .SendAsync(); } [Cmd] @@ -506,7 +518,7 @@ public partial class Xp : NadekoModule if (!result) { - await ReplyConfirmLocalizedAsync(strs.xp_shop_item_cant_use); + await Response().Confirm(strs.xp_shop_item_cant_use).SendAsync(); return; } @@ -525,7 +537,7 @@ public partial class Xp : NadekoModule if (!result) { - await ReplyConfirmLocalizedAsync(strs.xp_shop_item_cant_use); + await Response().Confirm(strs.xp_shop_item_cant_use).SendAsync(); } } @@ -540,7 +552,7 @@ public partial class Xp : NadekoModule if (result == BuyResult.InsufficientFunds) { - await ReplyErrorLocalizedAsync(strs.not_enough(_gss.GetCurrencySign())); + await Response().Error(strs.not_enough(_gss.GetCurrencySign())).SendAsync(); } } diff --git a/src/NadekoBot/Modules/Xp/XpRewards.cs b/src/NadekoBot/Modules/Xp/XpRewards.cs index d98983749..bc0cfc43f 100644 --- a/src/NadekoBot/Modules/Xp/XpRewards.cs +++ b/src/NadekoBot/Modules/Xp/XpRewards.cs @@ -16,7 +16,7 @@ public partial class Xp [UserPerm(GuildPerm.Administrator)] public async Task XpRewsReset() { - var promptEmbed = _eb.Create() + var promptEmbed = new EmbedBuilder() .WithPendingColor() .WithDescription(GetText(strs.xprewsreset_confirm)); @@ -69,7 +69,7 @@ public partial class Xp return Context.SendPaginatedConfirmAsync(page, cur => { - var embed = _eb.Create().WithTitle(GetText(strs.level_up_rewards)).WithOkColor(); + var embed = new EmbedBuilder().WithTitle(GetText(strs.level_up_rewards)).WithOkColor(); var localRewards = allRewards.Skip(cur * 9).Take(9).ToList(); @@ -94,7 +94,7 @@ public partial class Xp public async Task XpRoleReward(int level) { _service.ResetRoleReward(ctx.Guild.Id, level); - await ReplyConfirmLocalizedAsync(strs.xp_role_reward_cleared(level)); + await Response().Confirm(strs.xp_role_reward_cleared(level)).SendAsync(); } [Cmd] @@ -109,11 +109,11 @@ public partial class Xp _service.SetRoleReward(ctx.Guild.Id, level, role.Id, action == AddRemove.Remove); if (action == AddRemove.Add) - await ReplyConfirmLocalizedAsync(strs.xp_role_reward_add_role(level, Format.Bold(role.ToString()))); + await Response().Confirm(strs.xp_role_reward_add_role(level, Format.Bold(role.ToString()))).SendAsync(); else { - await ReplyConfirmLocalizedAsync(strs.xp_role_reward_remove_role(Format.Bold(level.ToString()), - Format.Bold(role.ToString()))); + await Response().Confirm(strs.xp_role_reward_remove_role(Format.Bold(level.ToString()), + Format.Bold(role.ToString()))).SendAsync(); } } @@ -127,10 +127,10 @@ public partial class Xp _service.SetCurrencyReward(ctx.Guild.Id, level, amount); if (amount == 0) - await ReplyConfirmLocalizedAsync(strs.cur_reward_cleared(level, _cp.GetCurrencySign())); + await Response().Confirm(strs.cur_reward_cleared(level, _cp.GetCurrencySign())).SendAsync(); else - await ReplyConfirmLocalizedAsync(strs.cur_reward_added(level, - Format.Bold(amount + _cp.GetCurrencySign()))); + await Response().Confirm(strs.cur_reward_added(level, + Format.Bold(amount + _cp.GetCurrencySign()))).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Xp/XpService.cs b/src/NadekoBot/Modules/Xp/XpService.cs index 5456b7490..730defd35 100644 --- a/src/NadekoBot/Modules/Xp/XpService.cs +++ b/src/NadekoBot/Modules/Xp/XpService.cs @@ -22,7 +22,6 @@ namespace NadekoBot.Modules.Xp.Services; public class XpService : INService, IReadyExecutor, IExecNoCommand { - private readonly DbService _db; private readonly IImageCache _images; private readonly IBotStrings _strings; @@ -44,10 +43,11 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand private readonly TypedKey _xpTemplateReloadKey; private readonly IPatronageService _ps; private readonly IBotCache _c; - - + + private readonly QueueRunner _levelUpQueue = new QueueRunner(0, 50); private readonly Channel _xpGainQueue = Channel.CreateUnbounded(); + private readonly IMessageSenderService _sender; public XpService( DiscordSocketClient client, @@ -63,7 +63,8 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand XpConfigService xpConfig, IPubSub pubSub, IEmbedBuilderService eb, - IPatronageService ps) + IPatronageService ps, + IMessageSenderService sender) { _db = db; _images = images; @@ -81,6 +82,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand _xpTemplateReloadKey = new("xp.template.reload"); _ps = ps; _c = c; + _sender = sender; InternalReloadXpTemplate(); @@ -127,7 +129,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand public async Task OnReadyAsync() { _ = Task.Run(() => _levelUpQueue.RunAsync()); - + using var timer = new PeriodicTimer(5.Seconds()); while (await timer.WaitForNextTickAsync()) { @@ -142,12 +144,13 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand public ulong GuildId { get; set; } public ulong UserId { get; set; } } + private async Task UpdateXp() { try { var reader = _xpGainQueue.Reader; - + // sum up all gains into a single UserCacheItem var globalToAdd = new Dictionary(); var guildToAdd = new Dictionary>(); @@ -159,7 +162,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand else ci.XpAmount += item.XpAmount; - + // ad guild xp in these guilds to these users if (!guildToAdd.TryGetValue(item.Guild.Id, out var users)) users = guildToAdd[item.Guild.Id] = new(); @@ -183,77 +186,77 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand await _cs.AddAsync(user.Key, (long)(amount), null); } } - + // update global user xp in batches // group by xp amount and update the same amounts at the same time foreach (var group in globalToAdd.GroupBy(x => x.Value.XpAmount, x => x.Key)) { var items = await ctx.Set() - .Where(x => group.Contains(x.UserId)) - .UpdateWithOutputAsync(old => new() - { - TotalXp = old.TotalXp + group.Key - }, - (_, n) => n); + .Where(x => group.Contains(x.UserId)) + .UpdateWithOutputAsync(old => new() + { + TotalXp = old.TotalXp + group.Key + }, + (_, n) => n); await ctx.Set() - .Where(x => x.Members.Any(m => group.Contains(m.UserId))) - .UpdateAsync(old => new() - { - Xp = old.Xp + (group.Key * old.Members.Count(m => group.Contains(m.UserId))) - }); - + .Where(x => x.Members.Any(m => group.Contains(m.UserId))) + .UpdateAsync(old => new() + { + Xp = old.Xp + (group.Key * old.Members.Count(m => group.Contains(m.UserId))) + }); + dus.AddRange(items); } + // update guild user xp in batches foreach (var (guildId, toAdd) in guildToAdd) { foreach (var group in toAdd.GroupBy(x => x.Value.XpAmount, x => x.Key)) { var items = await ctx - .Set() - .Where(x => x.GuildId == guildId) - .Where(x => group.Contains(x.UserId)) - .UpdateWithOutputAsync(old => new() - { - Xp = old.Xp + group.Key - }, - (_, n) => n); - + .Set() + .Where(x => x.GuildId == guildId) + .Where(x => group.Contains(x.UserId)) + .UpdateWithOutputAsync(old => new() + { + Xp = old.Xp + group.Key + }, + (_, n) => n); + gxps.AddRange(items); - + var missingUserIds = group.Where(userId => !items.Any(x => x.UserId == userId)).ToArray(); foreach (var userId in missingUserIds) { await ctx - .Set() - .ToLinqToDBTable() - .InsertOrUpdateAsync(() => new UserXpStats() - { - UserId = userId, - GuildId = guildId, - Xp = group.Key, - DateAdded = DateTime.UtcNow, - AwardedXp = 0, - NotifyOnLevelUp = XpNotificationLocation.None - }, - _ => new() - { - - }, - () => new() - { - UserId = userId - }); + .Set() + .ToLinqToDBTable() + .InsertOrUpdateAsync(() => new UserXpStats() + { + UserId = userId, + GuildId = guildId, + Xp = group.Key, + DateAdded = DateTime.UtcNow, + AwardedXp = 0, + NotifyOnLevelUp = XpNotificationLocation.None + }, + _ => new() + { + }, + () => new() + { + UserId = userId + }); } if (missingUserIds.Length > 0) { var missingItems = await ctx.Set() - .ToLinqToDBTable() - .Where(x => missingUserIds.Contains(x.UserId)) - .ToArrayAsyncLinqToDB(); - + .ToLinqToDBTable() + .Where(x => missingUserIds.Contains(x.UserId)) + .ToArrayAsyncLinqToDB(); + gxps.AddRange(missingItems); } } @@ -325,7 +328,11 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand await HandleNotifyInternalAsync(guildId, channelId, userId, isServer, newLevel, notifyLoc); }; - private async Task HandleRewardsInternalAsync(ulong guildId, ulong userId, long oldLevel, long newLevel) + private async Task HandleRewardsInternalAsync( + ulong guildId, + ulong userId, + long oldLevel, + long newLevel) { List rrews; List crews; @@ -364,16 +371,17 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand } } - private async Task HandleNotifyInternalAsync(ulong guildId, - ulong channelId, - ulong userId, + private async Task HandleNotifyInternalAsync( + ulong guildId, + ulong channelId, + ulong userId, bool isServer, long newLevel, XpNotificationLocation notifyLoc) { if (notifyLoc == XpNotificationLocation.None) return; - + var guild = _client.GetGuild(guildId); var user = guild?.GetUser(userId); var ch = guild?.GetTextChannel(channelId); @@ -395,10 +403,11 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand { if (ch is not null) { - await ch.SendConfirmAsync(_eb, - _strings.GetText(strs.level_up_channel(user.Mention, - Format.Bold(newLevel.ToString())), - guild.Id)); + await _sender.Response(ch) + .Confirm(_strings.GetText(strs.level_up_channel(user.Mention, + Format.Bold(newLevel.ToString())), + guild.Id)) + .SendAsync(); } } } @@ -414,10 +423,12 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand if (chan is null) return; - await chan.SendConfirmAsync(_eb, - _strings.GetText(strs.level_up_global(user.Mention, - Format.Bold(newLevel.ToString())), - guild.Id)); + await _sender.Response(chan) + .Confirm( + _strings.GetText(strs.level_up_global(user.Mention, + Format.Bold(newLevel.ToString())), + guild.Id)) + .SendAsync(); } } @@ -673,7 +684,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand private TypedKey GetVoiceXpKey(ulong userId) => new($"xp:{_client.CurrentUser.Id}:vc_join:{userId}"); - + private async Task UserJoinedVoiceChannel(SocketGuildUser user) { var value = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); @@ -683,7 +694,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand TimeSpan.FromMinutes(_xpConfig.Data.VoiceMaxMinutes), overwrite: false); } - + // private void UserJoinedVoiceChannel(SocketGuildUser user) // { // var key = $"{_creds.RedisKey()}_user_xp_vc_join_{user.Id}"; @@ -725,7 +736,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand }); } } - + /* * private void UserLeftVoiceChannel(SocketGuildUser user, SocketVoiceChannel channel) { @@ -825,13 +836,13 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand { await using var ctx = _db.GetDbContext(); return await ctx.GetTable() - .Where(x => x.GuildId == guildId && userIds.Contains(x.UserId)) - .UpdateAsync(old => new() - { - Xp = old.Xp + amount - }); + .Where(x => x.GuildId == guildId && userIds.Contains(x.UserId)) + .UpdateAsync(old => new() + { + Xp = old.Xp + amount + }); } - + public void AddXp(ulong userId, ulong guildId, int amount) { using var uow = _db.GetDbContext(); @@ -863,7 +874,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand private TypedKey GetUserRewKey(ulong userId) => new($"xp:{_client.CurrentUser.Id}:user_gain:{userId}"); - + private async Task SetUserRewardedAsync(ulong userId) => await _c.AddAsync(GetUserRewKey(userId), true, @@ -982,7 +993,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand } var outlinePen = new Pen(Color.Black, 1f); - + using var img = Image.Load(bgBytes, out var imageFormat); if (template.User.Name.Show) { @@ -1253,7 +1264,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand { return await _images.GetXpBackgroundImageAsync(); } - + var url = _xpConfig.Data.Shop.GetItemUrl(XpShopItemType.Background, item.ItemKey); if (!string.IsNullOrWhiteSpace(url)) { @@ -1428,13 +1439,13 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand return new(_xpConfig.Data.Shop.Bgs?.Where(x => x.Value.Price >= 0).ToDictionary(x => x.Key, x => x.Value)); } - + public ValueTask?> GetShopFrames() { var data = _xpConfig.Data; if (!data.Shop.IsEnabled) return new(default(Dictionary)); - + return new(_xpConfig.Data.Shop.Frames?.Where(x => x.Value.Price >= 0).ToDictionary(x => x.Key, x => x.Value)); } @@ -1448,7 +1459,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand var req = type == XpShopItemType.Background ? conf.Shop.BgsTierRequirement : conf.Shop.FramesTierRequirement; - + if (req != PatronTier.None && !_creds.IsOwner(userId)) { var patron = await _ps.GetPatronAsync(userId); @@ -1456,12 +1467,13 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand if ((int)patron.Tier < (int)req) return BuyResult.InsufficientPatronTier; } - + await using var ctx = _db.GetDbContext(); // await using var tran = await ctx.Database.BeginTransactionAsync(); try { - if (await ctx.GetTable().AnyAsyncLinqToDB(x => x.UserId == userId && x.ItemKey == key && x.ItemType == type)) + if (await ctx.GetTable() + .AnyAsyncLinqToDB(x => x.UserId == userId && x.ItemKey == key && x.ItemType == type)) return BuyResult.AlreadyOwned; var item = GetShopItem(type, key); @@ -1471,17 +1483,17 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand if (item.Price > 0 && !await _cs.RemoveAsync(userId, item.Price, new("xpshop", "buy", $"Background {key}"))) return BuyResult.InsufficientFunds; - + await ctx.GetTable() - .InsertAsync(() => new XpShopOwnedItem() - { - UserId = userId, - IsUsing = false, - ItemKey = key, - ItemType = type, - DateAdded = DateTime.UtcNow, - }); + .InsertAsync(() => new XpShopOwnedItem() + { + UserId = userId, + IsUsing = false, + ItemKey = key, + ItemType = type, + DateAdded = DateTime.UtcNow, + }); return BuyResult.Success; } @@ -1497,54 +1509,57 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand var data = _xpConfig.Data; if (type == XpShopItemType.Background) { - if (data.Shop.Bgs is {} bgs && bgs.TryGetValue(key, out var item)) + if (data.Shop.Bgs is { } bgs && bgs.TryGetValue(key, out var item)) return item; - + return null; } if (type == XpShopItemType.Frame) { - if (data.Shop.Frames is {} fs && fs.TryGetValue(key, out var item)) + if (data.Shop.Frames is { } fs && fs.TryGetValue(key, out var item)) return item; - + return null; } throw new ArgumentOutOfRangeException(nameof(type)); } - public async Task OwnsItemAsync(ulong userId, + public async Task OwnsItemAsync( + ulong userId, XpShopItemType itemType, string key) { await using var ctx = _db.GetDbContext(); return await ctx.GetTable() - .AnyAsyncLinqToDB(x => x.UserId == userId - && x.ItemType == itemType - && x.ItemKey == key); + .AnyAsyncLinqToDB(x => x.UserId == userId + && x.ItemType == itemType + && x.ItemKey == key); } - - - public async Task GetUserItemAsync(ulong userId, + + + public async Task GetUserItemAsync( + ulong userId, XpShopItemType itemType, string key) { await using var ctx = _db.GetDbContext(); return await ctx.GetTable() - .FirstOrDefaultAsyncLinqToDB(x => x.UserId == userId - && x.ItemType == itemType - && x.ItemKey == key); + .FirstOrDefaultAsyncLinqToDB(x => x.UserId == userId + && x.ItemType == itemType + && x.ItemKey == key); } - - public async Task GetItemInUse(ulong userId, + + public async Task GetItemInUse( + ulong userId, XpShopItemType itemType) { await using var ctx = _db.GetDbContext(); return await ctx.GetTable() - .FirstOrDefaultAsyncLinqToDB(x => x.UserId == userId - && x.ItemType == itemType - && x.IsUsing); + .FirstOrDefaultAsyncLinqToDB(x => x.UserId == userId + && x.ItemType == itemType + && x.IsUsing); } public async Task UseShopItemAsync(ulong userId, XpShopItemType itemType, string key) @@ -1568,11 +1583,11 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand if (await OwnsItemAsync(userId, itemType, key)) { await ctx.GetTable() - .Where(x => x.UserId == userId && x.ItemType == itemType) - .UpdateAsync(old => new() - { - IsUsing = key == old.ItemKey - }); + .Where(x => x.UserId == userId && x.ItemType == itemType) + .UpdateAsync(old => new() + { + IsUsing = key == old.ItemKey + }); return true; } diff --git a/src/NadekoBot/_common/CleanupModuleBase.cs b/src/NadekoBot/_common/CleanupModuleBase.cs index 625020d05..b45daa024 100644 --- a/src/NadekoBot/_common/CleanupModuleBase.cs +++ b/src/NadekoBot/_common/CleanupModuleBase.cs @@ -7,7 +7,7 @@ public abstract class CleanupModuleBase : NadekoModule { try { - var embed = _eb.Create() + var embed = new EmbedBuilder() .WithTitle(GetText(strs.sql_confirm_exec)) .WithDescription(name); @@ -19,7 +19,7 @@ public abstract class CleanupModuleBase : NadekoModule } catch (Exception ex) { - await SendErrorAsync(ex.ToString()); + await Response().Error(ex.ToString()).SendAsync(); } } } \ No newline at end of file diff --git a/src/NadekoBot/_common/Medusa/Common/Adapters/DmContextAdapter.cs b/src/NadekoBot/_common/Medusa/Common/Adapters/DmContextAdapter.cs index 9e520454b..87fcbf8cb 100644 --- a/src/NadekoBot/_common/Medusa/Common/Adapters/DmContextAdapter.cs +++ b/src/NadekoBot/_common/Medusa/Common/Adapters/DmContextAdapter.cs @@ -37,8 +37,8 @@ public sealed class DmContextAdapter : DmContext _localization = new(_services.GetRequiredService()); } - public override IEmbedBuilder Embed() - => _ebs.Value.Create(); + public override EmbedBuilder Embed() + => new EmbedBuilder(); public override string GetText(string key, object[]? args = null) { diff --git a/src/NadekoBot/_common/Medusa/Common/Adapters/GuildContextAdapter.cs b/src/NadekoBot/_common/Medusa/Common/Adapters/GuildContextAdapter.cs index 7a6b2972e..7f5896e15 100644 --- a/src/NadekoBot/_common/Medusa/Common/Adapters/GuildContextAdapter.cs +++ b/src/NadekoBot/_common/Medusa/Common/Adapters/GuildContextAdapter.cs @@ -18,7 +18,7 @@ public sealed class GuildContextAdapter : GuildContext public override IGuildUser User { get; } - public override IEmbedBuilder Embed() + public override EmbedBuilder Embed() => _ebs.Value.Create(); public GuildContextAdapter(ICommandContext ctx, IMedusaStrings strings, IServiceProvider services) diff --git a/src/NadekoBot/_common/NadekoModule.cs b/src/NadekoBot/_common/NadekoModule.cs index 1b6bcb30a..4e6f79c39 100644 --- a/src/NadekoBot/_common/NadekoModule.cs +++ b/src/NadekoBot/_common/NadekoModule.cs @@ -19,6 +19,7 @@ public abstract class NadekoModule : ModuleBase public IEmbedBuilderService _eb { get; set; } public INadekoInteractionService _inter { get; set; } public IReplacementService repSvc { get; set; } + public IMessageSenderService _sender { get; set; } protected string prefix => _cmdHandler.GetPrefix(ctx.Guild); @@ -26,67 +27,23 @@ public abstract class NadekoModule : ModuleBase protected ICommandContext ctx => Context; + public ResponseBuilder Response() + => new ResponseBuilder(Strings, _eb) + .Context(ctx); + protected override void BeforeExecute(CommandInfo command) => Culture = _localization.GetCultureInfo(ctx.Guild?.Id); protected string GetText(in LocStr data) => Strings.GetText(data, Culture); - public Task SendErrorAsync( - string title, - string error, - string url = null, - string footer = null, - NadekoInteraction inter = null) - => ctx.Channel.SendErrorAsync(_eb, title, error, url, footer); - - public Task SendConfirmAsync( - string title, - string text, - string url = null, - string footer = null) - => ctx.Channel.SendConfirmAsync(_eb, title, text, url, footer); - - // public Task SendAsync(SmartText text, NadekoInteraction inter = null, IUserMessage replyTo = null) - // => ctx.Channel.SendAsync(_eb, text, MsgType.Ok, inter, replyTo: replyTo); - - // colored - public Task SendErrorAsync(string text, NadekoInteraction inter = null) - => ctx.Channel.SendAsync(_eb, text, MsgType.Error, inter, replyTo: ctx.Message); - - public Task SendConfirmAsync(string text, NadekoInteraction inter = null) - => ctx.Channel.SendAsync(_eb, text, MsgType.Ok, inter, replyTo: ctx.Message); - - public Task SendPendingAsync(string text, NadekoInteraction inter = null) - => ctx.Channel.SendAsync(_eb, text, MsgType.Pending, inter, replyTo: ctx.Message); - - // localized normal - public Task ErrorLocalizedAsync(LocStr str, NadekoInteraction inter = null) - => SendErrorAsync(GetText(str), inter); - - public Task PendingLocalizedAsync(LocStr str, NadekoInteraction inter = null) - => SendPendingAsync(GetText(str), inter); - - public Task ConfirmLocalizedAsync(LocStr str, NadekoInteraction inter = null) - => SendConfirmAsync(GetText(str), inter); - - // localized replies - public Task ReplyErrorLocalizedAsync(LocStr str, NadekoInteraction inter = null) - => SendErrorAsync($"{Format.Bold(ctx.User.ToString())} {GetText(str)}", inter); - - public Task ReplyPendingLocalizedAsync(LocStr str, NadekoInteraction inter = null) - => SendPendingAsync($"{Format.Bold(ctx.User.ToString())} {GetText(str)}", inter); - - public Task ReplyConfirmLocalizedAsync(LocStr str, NadekoInteraction inter = null) - => SendConfirmAsync($"{Format.Bold(ctx.User.ToString())} {GetText(str)}", inter); - - public async Task PromptUserConfirmAsync(IEmbedBuilder embed) + public async Task PromptUserConfirmAsync(EmbedBuilder embed) { embed.WithPendingColor() - .WithFooter("yes/no"); + .WithFooter("yes/no"); - var msg = await ctx.Channel.EmbedAsync(embed); + var msg = await Response().Embed(embed).SendAsync(); try { var input = await GetUserInputAsync(ctx.User.Id, ctx.Channel.Id); @@ -140,9 +97,6 @@ public abstract class NadekoModule : ModuleBase return Task.CompletedTask; } } - - public Task EmbedAsync(IEmbedBuilder embed, string msg = "", IReadOnlyCollection embeds = null) - => ctx.Channel.EmbedAsync(embed, msg, replyTo: ctx.Message); } public abstract class NadekoModule : NadekoModule diff --git a/src/NadekoBot/_common/Sender/IMessageSenderService.cs b/src/NadekoBot/_common/Sender/IMessageSenderService.cs new file mode 100644 index 000000000..1a3453d4e --- /dev/null +++ b/src/NadekoBot/_common/Sender/IMessageSenderService.cs @@ -0,0 +1,7 @@ +namespace NadekoBot.Extensions; + +public interface IMessageSenderService +{ + ResponseBuilder Response(IMessageChannel channel); + ResponseBuilder Response(ICommandContext hannel); +} \ No newline at end of file diff --git a/src/NadekoBot/_common/_Extensions/IMessageChannelExtensions.cs b/src/NadekoBot/_common/Sender/MessageChannelExtensions.cs similarity index 77% rename from src/NadekoBot/_common/_Extensions/IMessageChannelExtensions.cs rename to src/NadekoBot/_common/Sender/MessageChannelExtensions.cs index 9f43a2ad0..dde83f5cb 100644 --- a/src/NadekoBot/_common/_Extensions/IMessageChannelExtensions.cs +++ b/src/NadekoBot/_common/Sender/MessageChannelExtensions.cs @@ -1,7 +1,11 @@ -namespace NadekoBot.Extensions; +namespace NadekoBot.Extensions; public static class MessageChannelExtensions { + public static ResponseBuilder Response(this IMessageChannel channel, IBotStrings bs, IEmbedBuilderService ebs) + => new ResponseBuilder(bs, ebs) + .Channel(channel); + // main overload that all other send methods reduce to public static Task SendAsync( this IMessageChannel channel, @@ -33,7 +37,7 @@ public static class MessageChannelExtensions if (replyTo.Channel.Id != source.Id) return null; - + return new(replyTo.Id, replyTo.Channel.Id, (replyTo.Channel as ITextChannel)?.GuildId, @@ -86,7 +90,7 @@ public static class MessageChannelExtensions public static Task EmbedAsync( this IMessageChannel ch, - IEmbedBuilder? embed, + EmbedBuilder? embed, string plainText = "", IReadOnlyCollection? embeds = null, NadekoInteraction? inter = null, @@ -96,89 +100,13 @@ public static class MessageChannelExtensions embed: embed?.Build(), embeds: embeds?.Map(x => x.Build()), replyTo: replyTo); - - public static Task SendAsync( - this IMessageChannel ch, - IEmbedBuilderService eb, - string text, - MsgType type, - NadekoInteraction? inter = null, - IUserMessage? replyTo = null) - { - var builder = eb.Create().WithDescription(text); - - builder = (type switch - { - MsgType.Error => builder.WithErrorColor(), - MsgType.Ok => builder.WithOkColor(), - MsgType.Pending => builder.WithPendingColor(), - _ => throw new ArgumentOutOfRangeException(nameof(type)) - }); - - return ch.EmbedAsync(builder, inter: inter, replyTo: replyTo); - } - - public static Task SendConfirmAsync(this IMessageChannel ch, IEmbedBuilderService eb, string text) - => ch.SendAsync(eb, text, MsgType.Ok); - - public static Task SendAsync( - this IMessageChannel ch, - IEmbedBuilderService eb, - MsgType type, - string? title, - string text, - string? url = null, - string? footer = null) - { - var embed = eb.Create() - .WithDescription(text) - .WithTitle(title); - - if (url is not null && Uri.IsWellFormedUriString(url, UriKind.Absolute)) - embed.WithUrl(url); - - if (!string.IsNullOrWhiteSpace(footer)) - embed.WithFooter(footer); - - embed = type switch - { - MsgType.Error => embed.WithErrorColor(), - MsgType.Ok => embed.WithOkColor(), - MsgType.Pending => embed.WithPendingColor(), - _ => throw new ArgumentOutOfRangeException(nameof(type)) - }; - - return ch.EmbedAsync(embed); - } - + // embed title and optional footer overloads - public static Task SendConfirmAsync( - this IMessageChannel ch, - IEmbedBuilderService eb, - string? title, - string text, - string? url = null, - string? footer = null) - => ch.SendAsync(eb, MsgType.Ok, title, text, url, footer); - - public static Task SendErrorAsync( - this IMessageChannel ch, - IEmbedBuilderService eb, - string title, - string text, - string? url = null, - string? footer = null) - => ch.SendAsync(eb, MsgType.Error, title, text, url, footer); - - // regular send overloads - public static Task SendErrorAsync(this IMessageChannel ch, IEmbedBuilderService eb, string text) - => ch.SendAsync(eb, text, MsgType.Error); - public static Task SendPaginatedConfirmAsync( this ICommandContext ctx, int currentPage, - Func pageFunc, + Func pageFunc, int totalElements, int itemsPerPage, bool addPaginatedFooter = true) @@ -197,7 +125,7 @@ public static class MessageChannelExtensions public static Task SendPaginatedConfirmAsync( this ICommandContext ctx, int currentPage, - Func> pageFunc, + Func> pageFunc, int totalElements, int itemsPerPage, bool addPaginatedFooter = true) @@ -211,7 +139,7 @@ public static class MessageChannelExtensions public static async Task SendPaginatedConfirmAsync( this ICommandContext ctx, int currentPage, - Func> pageFunc, + Func> pageFunc, Func?>>? interFactory, int totalElements, int itemsPerPage, diff --git a/src/NadekoBot/_common/Sender/MessageSenderService.cs b/src/NadekoBot/_common/Sender/MessageSenderService.cs new file mode 100644 index 000000000..cc91e926a --- /dev/null +++ b/src/NadekoBot/_common/Sender/MessageSenderService.cs @@ -0,0 +1,24 @@ +using System.Diagnostics.CodeAnalysis; + +namespace NadekoBot.Extensions; + +public sealed class MessageSenderService : IMessageSenderService, INService +{ + private readonly IBotStrings _bs; + private readonly IEmbedBuilderService _ebs; + + public MessageSenderService(IBotStrings bs, IEmbedBuilderService ebs) + { + _bs = bs; + _ebs = ebs; + } + + + public ResponseBuilder Response(IMessageChannel channel) + => new ResponseBuilder(_bs, _ebs) + .Channel(channel); + + public ResponseBuilder Response(ICommandContext ctx) + => new ResponseBuilder(_bs, _ebs) + .Context(ctx); +} \ No newline at end of file diff --git a/src/NadekoBot/_common/Sender/ResponseBuilder.cs b/src/NadekoBot/_common/Sender/ResponseBuilder.cs new file mode 100644 index 000000000..cff737fb3 --- /dev/null +++ b/src/NadekoBot/_common/Sender/ResponseBuilder.cs @@ -0,0 +1,252 @@ +namespace NadekoBot.Extensions; + +public sealed class ResponseBuilder +{ + private ICommandContext? ctx = null; + private IMessageChannel? channel = null; + private Embed? embed = null; + private string? plainText = null; + private IReadOnlyCollection? embeds = null; + private IUserMessage? msg = null; + private IUser? user = null; + private bool sanitizeMentions = true; + private LocStr? locTxt; + private object[] locParams = []; + private bool shouldReply = true; + private readonly IBotStrings _bs; + private readonly IEmbedBuilderService _ebs; + private EmbedBuilder? embedBuilder = null; + + public ResponseBuilder(IBotStrings bs, IEmbedBuilderService ebs) + { + _bs = bs; + _ebs = ebs; + } + + private MessageReference? CreateMessageReference(IMessageChannel targetChannel) + { + if (!shouldReply) + return null; + + var replyTo = msg ?? ctx?.Message; + // what message are we replying to + if (replyTo is null) + return null; + + // we have to have a channel where we are sending the message in order to know whether we can reply to it + if (targetChannel.Id != replyTo.Channel.Id) + return null; + + return new(replyTo.Id, + replyTo.Channel.Id, + (replyTo.Channel as ITextChannel)?.GuildId, + failIfNotExists: false); + } + + public async Task SendAsync() + { + var targetChannel = InternalResolveChannel() ?? throw new ArgumentNullException(nameof(channel)); + var msgReference = CreateMessageReference(targetChannel); + + var txt = GetText(locTxt); + + if (sanitizeMentions) + txt = txt?.SanitizeMentions(true); + + return await targetChannel.SendMessageAsync( + txt, + embed: embed ?? embedBuilder?.Build(), + embeds: embeds?.Map(x => x.Build()), + components: null, + allowedMentions: sanitizeMentions ? new(AllowedMentionTypes.Users) : AllowedMentions.All, + messageReference: msgReference); + } + + private ulong? InternalResolveGuildId(IMessageChannel? targetChannel) + => ctx?.Guild?.Id ?? (targetChannel as ITextChannel)?.GuildId; + + private IMessageChannel? InternalResolveChannel() + => channel ?? ctx?.Channel ?? msg?.Channel; + + private string? GetText(LocStr? locStr) + { + var targetChannel = InternalResolveChannel(); + var guildId = InternalResolveGuildId(targetChannel); + return locStr is LocStr ls ? _bs.GetText(ls.Key, guildId, locParams) : plainText; + } + + private string GetText(LocStr locStr) + { + var targetChannel = InternalResolveChannel(); + var guildId = InternalResolveGuildId(targetChannel); + return _bs.GetText(locStr.Key, guildId, locStr.Params); + } + + public ResponseBuilder Text(LocStr str) + { + locTxt = str; + return this; + } + + public ResponseBuilder Text(SmartText text) + { + if (text is SmartPlainText spt) + plainText = spt.Text; + else if (text is SmartEmbedText set) + embed = set.GetEmbed().Build(); + else if (text is SmartEmbedTextArray ser) + embeds = ser.GetEmbedBuilders(); + + return this; + } + + private ResponseBuilder InternalColoredText(string text, EmbedColor color) + { + embed = new EmbedBuilder() + .WithColor(color) + .WithDescription(text) + .Build(); + + return this; + } + + private EmbedBuilder CreateEmbedInternal( + string? title, + string? text, + string? url, + string? footer = null) + { + var embed = new EmbedBuilder() + .WithTitle(title) + .WithDescription(text); + + if (!string.IsNullOrWhiteSpace(url)) + embed = embed.WithUrl(url); + + if (!string.IsNullOrWhiteSpace(footer)) + embed = embed.WithFooter(footer); + + return embed; + } + + private EmbedBuilder PaintEmbedInternal(EmbedBuilder eb, EmbedColor color) + => color switch + { + EmbedColor.Ok => eb.WithOkColor(), + EmbedColor.Pending => eb.WithPendingColor(), + EmbedColor.Error => eb.WithErrorColor(), + }; + + public ResponseBuilder Error( + string? title, + string? text, + string? url = null, + string? footer = null) + { + var eb = CreateEmbedInternal(title, text, url, footer); + embed = PaintEmbedInternal(eb, EmbedColor.Error).Build(); + return this; + } + + + public ResponseBuilder Confirm( + string? title, + string? text, + string? url = null, + string? footer = null) + { + var eb = CreateEmbedInternal(title, text, url, footer); + embed = PaintEmbedInternal(eb, EmbedColor.Error).Build(); + return this; + } + + public ResponseBuilder Confirm(string text) + => InternalColoredText(text, EmbedColor.Ok); + + public ResponseBuilder Confirm(LocStr str) + => Confirm(GetText(str)); + + public ResponseBuilder Pending(string text) + => InternalColoredText(text, EmbedColor.Ok); + + public ResponseBuilder Pending(LocStr str) + => Pending(GetText(str)); + + public ResponseBuilder Error(string text) + => InternalColoredText(text, EmbedColor.Error); + + public ResponseBuilder Error(LocStr str) + => Error(GetText(str)); + + + public ResponseBuilder UserBasedMentions() + { + sanitizeMentions = !((InternalResolveUser() as IGuildUser)?.GuildPermissions.MentionEveryone ?? false); + return this; + } + + private IUser? InternalResolveUser() + => ctx?.User ?? user ?? msg?.Author; + + public ResponseBuilder Embed(EmbedBuilder eb) + { + embedBuilder = eb; + return this; + } + + public ResponseBuilder Embed(Func embedFactory) + { + // todo colors + this.embed = embedFactory(_ebs).Build(); + + return this; + } + + public ResponseBuilder Channel(IMessageChannel channel) + { + this.channel = channel; + return this; + } + + public ResponseBuilder Sanitize(bool shouldSantize = true) + { + sanitizeMentions = shouldSantize; + return this; + } + + public ResponseBuilder Context(ICommandContext ctx) + { + this.ctx = ctx; + return this; + } + + public ResponseBuilder Message(IUserMessage msg) + { + this.msg = msg; + return this; + } + + public ResponseBuilder User(IUser user) + { + this.user = user; + return this; + } + + public ResponseBuilder NoReply() + { + shouldReply = false; + return this; + } + + public ResponseBuilder Interaction(NadekoInteraction inter) + { + // todo implement + return this; + } + + public ResponseBuilder Embeds(IReadOnlyCollection inputEmbeds) + { + embeds = inputEmbeds; + return this; + } +} \ No newline at end of file diff --git a/src/NadekoBot/_common/Sender/ResponseBuilderExtensions.cs b/src/NadekoBot/_common/Sender/ResponseBuilderExtensions.cs new file mode 100644 index 000000000..f49a863c3 --- /dev/null +++ b/src/NadekoBot/_common/Sender/ResponseBuilderExtensions.cs @@ -0,0 +1,18 @@ +namespace NadekoBot.Extensions; + +public static class ResponseBuilderExtensions +{ + // todo delete this + + public static EmbedBuilder WithColor(this EmbedBuilder eb, EmbedColor color) + => eb; + + public static EmbedBuilder WithPendingColor(this EmbedBuilder eb) + => eb.WithColor(EmbedColor.Error); + + public static EmbedBuilder WithOkColor(this EmbedBuilder eb) + => eb.WithColor(EmbedColor.Ok); + + public static EmbedBuilder WithErrorColor(this EmbedBuilder eb) + => eb.WithColor(EmbedColor.Error); +} \ No newline at end of file diff --git a/src/NadekoBot/_common/Services/IEmbedBuilderService.cs b/src/NadekoBot/_common/Services/IEmbedBuilderService.cs index 1474a08f7..80533b465 100644 --- a/src/NadekoBot/_common/Services/IEmbedBuilderService.cs +++ b/src/NadekoBot/_common/Services/IEmbedBuilderService.cs @@ -1,12 +1,12 @@ #nullable disable using NadekoBot.Common.Configs; +// todo remove namespace NadekoBot.Services; public interface IEmbedBuilderService { - IEmbedBuilder Create(ICommandContext ctx = null); - IEmbedBuilder Create(EmbedBuilder eb); + EmbedBuilder Create(ICommandContext ctx = null); } public class EmbedBuilderService : IEmbedBuilderService, INService @@ -16,11 +16,9 @@ public class EmbedBuilderService : IEmbedBuilderService, INService public EmbedBuilderService(BotConfigService botConfigService) => _botConfigService = botConfigService; - public IEmbedBuilder Create(ICommandContext ctx = null) - => new DiscordEmbedBuilderWrapper(_botConfigService.Data); + public EmbedBuilder Create(ICommandContext ctx = null) + => new EmbedBuilder(); - public IEmbedBuilder Create(EmbedBuilder embed) - => new DiscordEmbedBuilderWrapper(_botConfigService.Data, embed); } public sealed class DiscordEmbedBuilderWrapper : IEmbedBuilder @@ -34,31 +32,31 @@ public sealed class DiscordEmbedBuilderWrapper : IEmbedBuilder this.embed = embed ?? new EmbedBuilder(); } - public IEmbedBuilder WithDescription(string desc) + public EmbedBuilder WithDescription(string desc) => Wrap(embed.WithDescription(desc)); - public IEmbedBuilder WithTitle(string title) + public EmbedBuilder WithTitle(string title) => Wrap(embed.WithTitle(title)); - public IEmbedBuilder AddField(string title, object value, bool isInline = false) + public EmbedBuilder AddField(string title, object value, bool isInline = false) => Wrap(embed.AddField(title, value, isInline)); - public IEmbedBuilder WithFooter(string text, string iconUrl = null) + public EmbedBuilder WithFooter(string text, string iconUrl = null) => Wrap(embed.WithFooter(text, iconUrl)); - public IEmbedBuilder WithAuthor(string name, string iconUrl = null, string url = null) + public EmbedBuilder WithAuthor(string name, string iconUrl = null, string url = null) => Wrap(embed.WithAuthor(name, iconUrl, url)); - public IEmbedBuilder WithUrl(string url) + public EmbedBuilder WithUrl(string url) => Wrap(embed.WithUrl(url)); - public IEmbedBuilder WithImageUrl(string url) + public EmbedBuilder WithImageUrl(string url) => Wrap(embed.WithImageUrl(url)); - public IEmbedBuilder WithThumbnailUrl(string url) + public EmbedBuilder WithThumbnailUrl(string url) => Wrap(embed.WithThumbnailUrl(url)); - public IEmbedBuilder WithColor(EmbedColor color) + public EmbedBuilder WithColor(EmbedColor color) => color switch { EmbedColor.Ok => Wrap(embed.WithColor(_botConfig.Color.Ok.ToDiscordColor())), @@ -67,15 +65,15 @@ public sealed class DiscordEmbedBuilderWrapper : IEmbedBuilder _ => throw new ArgumentOutOfRangeException(nameof(color), "Unsupported EmbedColor type") }; - public IEmbedBuilder WithDiscordColor(Color color) + public EmbedBuilder WithDiscordColor(Color color) => Wrap(embed.WithColor(color)); public Embed Build() => embed.Build(); - private IEmbedBuilder Wrap(EmbedBuilder eb) + private EmbedBuilder Wrap(EmbedBuilder eb) { embed = eb; - return this; + return eb; } } \ No newline at end of file diff --git a/src/NadekoBot/_common/Services/Impl/CommandsUtilityService.cs b/src/NadekoBot/_common/Services/Impl/CommandsUtilityService.cs index 48f77aef4..31f2002b6 100644 --- a/src/NadekoBot/_common/Services/Impl/CommandsUtilityService.cs +++ b/src/NadekoBot/_common/Services/Impl/CommandsUtilityService.cs @@ -28,7 +28,7 @@ public sealed class CommandsUtilityService : ICommandsUtilityService, INService _medusae = medusae; } - public IEmbedBuilder GetCommandHelp(CommandInfo com, IGuild guild) + public EmbedBuilder GetCommandHelp(CommandInfo com, IGuild guild) { var prefix = _ch.GetPrefix(guild); @@ -39,17 +39,19 @@ public sealed class CommandsUtilityService : ICommandsUtilityService, INService var culture = _loc.GetCultureInfo(guild); - var em = _eb.Create() - .AddField(str, $"{com.RealSummary(_strings, _medusae, culture, prefix)}", true); + var em = new EmbedBuilder() + .AddField(str, $"{com.RealSummary(_strings, _medusae, culture, prefix)}", true); _dpos.TryGetOverrides(guild?.Id ?? 0, com.Name, out var overrides); var reqs = GetCommandRequirements(com, (GuildPermission?)overrides); if (reqs.Any()) em.AddField(GetText(strs.requires, guild), string.Join("\n", reqs)); - Extensions.Extensions.WithOkColor(em.AddField(_strings.GetText(strs.usage), - string.Join("\n", com.RealRemarksArr(_strings, _medusae, culture, prefix).Map(arg => Format.Code(arg)))) - .WithFooter(GetText(strs.module(com.Module.GetTopLevelModule().Name), guild))); + em + .WithOkColor() + .AddField(_strings.GetText(strs.usage), + string.Join("\n", com.RealRemarksArr(_strings, _medusae, culture, prefix).Map(arg => Format.Code(arg)))) + .WithFooter(GetText(strs.module(com.Module.GetTopLevelModule().Name), guild)); var opt = GetNadekoOptionType(com.Attributes); if (opt is not null) @@ -72,31 +74,31 @@ public sealed class CommandsUtilityService : ICommandsUtilityService, INService public static List GetCommandOptionHelpList(Type opt) { var strs = opt.GetProperties() - .Select(x => x.GetCustomAttributes(true).FirstOrDefault(a => a is OptionAttribute)) - .Where(x => x is not null) - .Cast() - .Select(x => - { - var toReturn = $"`--{x.LongName}`"; + .Select(x => x.GetCustomAttributes(true).FirstOrDefault(a => a is OptionAttribute)) + .Where(x => x is not null) + .Cast() + .Select(x => + { + var toReturn = $"`--{x.LongName}`"; - if (!string.IsNullOrWhiteSpace(x.ShortName)) - toReturn += $" (`-{x.ShortName}`)"; + if (!string.IsNullOrWhiteSpace(x.ShortName)) + toReturn += $" (`-{x.ShortName}`)"; - toReturn += $" {x.HelpText} "; - return toReturn; - }) - .ToList(); + toReturn += $" {x.HelpText} "; + return toReturn; + }) + .ToList(); return strs; } public static Type? GetNadekoOptionType(IEnumerable attributes) => attributes - .Select(a => a.GetType()) - .Where(a => a.IsGenericType - && a.GetGenericTypeDefinition() == typeof(NadekoOptionsAttribute<>)) - .Select(a => a.GenericTypeArguments[0]) - .FirstOrDefault(); + .Select(a => a.GetType()) + .Where(a => a.IsGenericType + && a.GetGenericTypeDefinition() == typeof(NadekoOptionsAttribute<>)) + .Select(a => a.GenericTypeArguments[0]) + .FirstOrDefault(); public static string[] GetCommandRequirements(CommandInfo cmd, GuildPerm? overrides = null) { @@ -107,38 +109,38 @@ public sealed class CommandsUtilityService : ICommandsUtilityService, INService if (cmd.Preconditions.Any(x => x is NoPublicBotAttribute) || cmd.Module - .Preconditions - .Any(x => x is NoPublicBotAttribute) + .Preconditions + .Any(x => x is NoPublicBotAttribute) || cmd.Module.GetTopLevelModule() - .Preconditions - .Any(x => x is NoPublicBotAttribute)) + .Preconditions + .Any(x => x is NoPublicBotAttribute)) toReturn.Add("No Public Bot"); if (cmd.Preconditions - .Any(x => x is OnlyPublicBotAttribute) + .Any(x => x is OnlyPublicBotAttribute) || cmd.Module - .Preconditions - .Any(x => x is OnlyPublicBotAttribute) + .Preconditions + .Any(x => x is OnlyPublicBotAttribute) || cmd.Module.GetTopLevelModule() - .Preconditions - .Any(x => x is OnlyPublicBotAttribute)) + .Preconditions + .Any(x => x is OnlyPublicBotAttribute)) toReturn.Add("Only Public Bot"); var userPermString = cmd.Preconditions - .Where(ca => ca is UserPermAttribute) - .Cast() - .Select(userPerm => - { - if (userPerm.ChannelPermission is { } cPerm) - return GetPreconditionString(cPerm); + .Where(ca => ca is UserPermAttribute) + .Cast() + .Select(userPerm => + { + if (userPerm.ChannelPermission is { } cPerm) + return GetPreconditionString(cPerm); - if (userPerm.GuildPermission is { } gPerm) - return GetPreconditionString(gPerm); + if (userPerm.GuildPermission is { } gPerm) + return GetPreconditionString(gPerm); - return string.Empty; - }) - .Where(x => !string.IsNullOrWhiteSpace(x)) - .Join('\n'); + return string.Empty; + }) + .Where(x => !string.IsNullOrWhiteSpace(x)) + .Join('\n'); if (overrides is null) { @@ -166,7 +168,7 @@ public sealed class CommandsUtilityService : ICommandsUtilityService, INService => _strings.GetText(str, guild?.Id); } -public interface ICommandsUtilityService +public interface ICommandsUtilityService { - IEmbedBuilder GetCommandHelp(CommandInfo com, IGuild guild); + EmbedBuilder GetCommandHelp(CommandInfo com, IGuild guild); } \ No newline at end of file diff --git a/src/NadekoBot/_common/SmartText/SmartText.cs b/src/NadekoBot/_common/SmartText/SmartText.cs index daf05b476..a3449cb33 100644 --- a/src/NadekoBot/_common/SmartText/SmartText.cs +++ b/src/NadekoBot/_common/SmartText/SmartText.cs @@ -17,6 +17,9 @@ public abstract record SmartText [JsonIgnore] public bool IsEmbedArray => this is SmartEmbedTextArray; + + public static implicit operator SmartText(string input) + => new SmartPlainText(input); public static SmartText operator +(SmartText text, string input) => text switch diff --git a/src/NadekoBot/_common/_Extensions/Extensions.cs b/src/NadekoBot/_common/_Extensions/Extensions.cs index 1592b6f33..a0f7fd2cd 100644 --- a/src/NadekoBot/_common/_Extensions/Extensions.cs +++ b/src/NadekoBot/_common/_Extensions/Extensions.cs @@ -18,8 +18,8 @@ public static class Extensions private static readonly Regex _urlRegex = new(@"^(https?|ftp)://(?[^\s/$.?#].[^\s]*)$", RegexOptions.Compiled); - public static IEmbedBuilder WithAuthor(this IEmbedBuilder eb, IUser author) - => eb.WithAuthor(author.ToString()!, author.RealAvatarUrl().ToString()); + // public static EmbedBuilder WithAuthor(this EmbedBuilder eb, IUser author) + // => eb.WithAuthor(author.ToString()!, author.RealAvatarUrl().ToString()); public static Task EditAsync(this IUserMessage msg, SmartText text) => text switch @@ -134,22 +134,22 @@ public static class Extensions private static string GetFullUsage(string commandName, string args, string prefix) => $"{prefix}{commandName} {string.Format(args, prefix)}".TrimEnd(); - public static IEmbedBuilder AddPaginatedFooter(this IEmbedBuilder embed, int curPage, int? lastPage) + public static EmbedBuilder AddPaginatedFooter(this EmbedBuilder embed, int curPage, int? lastPage) { if (lastPage is not null) return embed.WithFooter($"{curPage + 1} / {lastPage + 1}"); return embed.WithFooter(curPage.ToString()); } - public static IEmbedBuilder WithOkColor(this IEmbedBuilder eb) - => eb.WithColor(EmbedColor.Ok); - - public static IEmbedBuilder WithPendingColor(this IEmbedBuilder eb) - => eb.WithColor(EmbedColor.Pending); - - public static IEmbedBuilder WithErrorColor(this IEmbedBuilder eb) - => eb.WithColor(EmbedColor.Error); - + // public static EmbedBuilder WithOkColor(this EmbedBuilder eb) + // => eb.WithColor(EmbedColor.Ok); + // + // public static EmbedBuilder WithPendingColor(this EmbedBuilder eb) + // => eb.WithColor(EmbedColor.Pending); + // + // public static EmbedBuilder WithErrorColor(this EmbedBuilder eb) + // => eb.WithColor(EmbedColor.Error); + // public static IMessage DeleteAfter(this IUserMessage msg, float seconds, ILogCommandService? logService = null) { Task.Run(async () => diff --git a/src/NadekoBot/_common/_Extensions/SocketMessageComponentExtensions.cs b/src/NadekoBot/_common/_Extensions/SocketMessageComponentExtensions.cs index 0f4444132..a6ea2d103 100644 --- a/src/NadekoBot/_common/_Extensions/SocketMessageComponentExtensions.cs +++ b/src/NadekoBot/_common/_Extensions/SocketMessageComponentExtensions.cs @@ -48,9 +48,9 @@ public static class SocketMessageComponentExtensions public static Task EmbedAsync( this SocketMessageComponent smc, - IEmbedBuilder? embed, + EmbedBuilder? embed, string plainText = "", - IReadOnlyCollection? embeds = null, + IReadOnlyCollection? embeds = null, NadekoInteraction? inter = null, bool ephemeral = false) => smc.RespondAsync(plainText, @@ -66,7 +66,7 @@ public static class SocketMessageComponentExtensions bool ephemeral = false, NadekoInteraction? inter = null) { - var builder = eb.Create().WithDescription(text); + var builder = new EmbedBuilder().WithDescription(text); builder = (type switch { @@ -81,13 +81,6 @@ public static class SocketMessageComponentExtensions // embed title and optional footer overloads - public static Task RespondErrorAsync( - this SocketMessageComponent smc, - IEmbedBuilderService eb, - string text, - bool ephemeral = false) - => smc.RespondAsync(eb, text, MsgType.Error, ephemeral); - public static Task RespondConfirmAsync( this SocketMessageComponent smc, IEmbedBuilderService eb, diff --git a/src/NadekoBot/_common/_Extensions/UserExtensions.cs b/src/NadekoBot/_common/_Extensions/UserExtensions.cs index 79da0c824..37525e2d5 100644 --- a/src/NadekoBot/_common/_Extensions/UserExtensions.cs +++ b/src/NadekoBot/_common/_Extensions/UserExtensions.cs @@ -4,7 +4,7 @@ namespace NadekoBot.Extensions; public static class UserExtensions { - public static async Task EmbedAsync(this IUser user, IEmbedBuilder embed, string msg = "") + public static async Task EmbedAsync(this IUser user, EmbedBuilder embed, string msg = "") { var ch = await user.CreateDMChannelAsync(); return await ch.EmbedAsync(embed, msg); @@ -17,13 +17,7 @@ public static class UserExtensions } public static async Task SendConfirmAsync(this IUser user, IEmbedBuilderService eb, string text) - => await user.SendMessageAsync("", embed: eb.Create().WithOkColor().WithDescription(text).Build()); - - public static async Task SendErrorAsync(this IUser user, IEmbedBuilderService eb, string error) - => await user.SendMessageAsync("", embed: eb.Create().WithErrorColor().WithDescription(error).Build()); - - public static async Task SendPendingAsync(this IUser user, IEmbedBuilderService eb, string message) - => await user.SendMessageAsync("", embed: eb.Create().WithPendingColor().WithDescription(message).Build()); + => await user.SendMessageAsync("", embed: new EmbedBuilder().WithOkColor().WithDescription(text).Build()); // This method is used by everything that fetches the avatar from a user public static Uri RealAvatarUrl(this IUser usr, ushort size = 256) diff --git a/src/NadekoBot/data/strings/commands/commands.en-US.yml b/src/NadekoBot/data/strings/commands/commands.en-US.yml index f2f0be14d..3e7d8d9e0 100644 --- a/src/NadekoBot/data/strings/commands/commands.en-US.yml +++ b/src/NadekoBot/data/strings/commands/commands.en-US.yml @@ -2264,7 +2264,7 @@ eval: args: - "123 / 4.5f" - "await ctx.OkAsync();" - - 'await ctx.SendConfirmAsync("uwu");' + - 'await ctx.Response().Confirm("uwu").SendAsync();' betdraw: desc: |- Bet on the card value and/or color. Specify the amount followed by your guess.