From 594a3b1f979efe4e28eca8bce43ded768694fda3 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 23 Dec 2021 20:58:39 +0100 Subject: [PATCH] Removed some obsolete commands and strings --- src/NadekoBot/Bot.cs | 13 ++++-- src/NadekoBot/Db/Models/FollowedStream.cs | 13 +----- .../CustomReactions/CustomReactions.cs | 15 ------- .../Modules/Gambling/TestGamblingService.cs | 12 +++-- src/NadekoBot/Modules/Music/Music.cs | 8 ---- .../Modules/Utility/PatreonCommands.cs | 45 ------------------- src/NadekoBot/Services/CommandHandler.cs | 19 ++++++-- src/NadekoBot/data/aliases.yml | 11 ----- .../data/strings/commands/commands.en-US.yml | 8 ---- .../strings/responses/responses.en-US.json | 11 ----- 10 files changed, 36 insertions(+), 119 deletions(-) delete mode 100644 src/NadekoBot/Modules/Utility/PatreonCommands.cs diff --git a/src/NadekoBot/Bot.cs b/src/NadekoBot/Bot.cs index cd0363b4d..438af1002 100644 --- a/src/NadekoBot/Bot.cs +++ b/src/NadekoBot/Bot.cs @@ -7,6 +7,8 @@ using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Common.Configs; using NadekoBot.Db; using NadekoBot.Modules.Administration.Services; +using Discord.Interactions; +using RunMode = Discord.Interactions.RunMode; namespace NadekoBot; @@ -16,7 +18,8 @@ public sealed class Bot private readonly CommandService _commandService; private readonly DbService _db; private readonly IBotCredsProvider _credsProvider; - + private readonly InteractionService _interactionService; + public event Func JoinedGuild = delegate { return Task.CompletedTask; }; public DiscordSocketClient Client { get; } @@ -57,9 +60,11 @@ public sealed class Bot _commandService = new(new() { CaseSensitiveCommands = false, - DefaultRunMode = RunMode.Sync, + DefaultRunMode = Discord.Commands.RunMode.Sync, }); + _interactionService = new(Client.Rest); + #if GLOBAL_NADEKO || DEBUG Client.Log += Client_Log; #endif @@ -89,6 +94,7 @@ public sealed class Bot .AddRedis(_creds.RedisOptions) // redis .AddSingleton(Client) // discord socket client .AddSingleton(_commandService) + .AddSingleton(_interactionService) .AddSingleton(this) .AddSingleton() .AddSingleton() @@ -308,7 +314,8 @@ public sealed class Bot await commandHandler.StartHandling().ConfigureAwait(false); await _commandService.AddModulesAsync(typeof(Bot).Assembly, Services); - + await _interactionService.AddModulesAsync(typeof(Bot).Assembly, Services); + await _interactionService.RegisterCommandsToGuildAsync(117523346618318850); IsReady = true; _ = Task.Run(ExecuteReadySubscriptions); Log.Information("Shard {ShardId} ready", Client.ShardId); diff --git a/src/NadekoBot/Db/Models/FollowedStream.cs b/src/NadekoBot/Db/Models/FollowedStream.cs index 960c67100..f48e75f9f 100644 --- a/src/NadekoBot/Db/Models/FollowedStream.cs +++ b/src/NadekoBot/Db/Models/FollowedStream.cs @@ -14,10 +14,6 @@ public class FollowedStream : DbEntity public enum FType { Twitch = 0, - [Obsolete("No longer supported.")] - Smashcast = 1, - [Obsolete("No longer supported.")] - Mixer = 2, Picarto = 3, Youtube = 4, Facebook = 5, @@ -35,13 +31,8 @@ public class FollowedStream : DbEntity return HashCode.Combine(ChannelId, Username, (int) Type); } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != this.GetType()) return false; - return Equals((FollowedStream) obj); - } + public override bool Equals(object obj) + => obj is FollowedStream fs && Equals(fs); public StreamDataKey CreateKey() => new StreamDataKey(Type, Username.ToLower()); diff --git a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs index 776589b50..33ca8ceb7 100644 --- a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -109,21 +109,6 @@ public class CustomReactions : NadekoModule All } - [NadekoCommand, Aliases] - [Priority(0)] - public async Task ListCustReact(All _) - { - await ReplyPendingLocalizedAsync(strs.obsolete_use(Format.Code($"{Prefix}crsexport"))); - await CrsExport(); - } - - [NadekoCommand, Aliases] - public async Task ListCustReactG(int page = 1) - { - await ReplyPendingLocalizedAsync(strs.obsolete_use(Format.Code($"{Prefix}crsexport"))); - await CrsExport(); - } - [NadekoCommand, Aliases] public async Task ShowCustReact(kwum id) { diff --git a/src/NadekoBot/Modules/Gambling/TestGamblingService.cs b/src/NadekoBot/Modules/Gambling/TestGamblingService.cs index 3ad229694..7e76aeb4f 100644 --- a/src/NadekoBot/Modules/Gambling/TestGamblingService.cs +++ b/src/NadekoBot/Modules/Gambling/TestGamblingService.cs @@ -1,6 +1,12 @@ -namespace NadekoBot.Modules.Gambling; +using Discord.Interactions; -public class TestGamblingService +namespace NadekoBot.Modules.Gambling; + +public class TestGamblingService : InteractionModuleBase { - + [SlashCommand("test", "uwu")] + public async Task Test(string input1, int input2) + { + await RespondAsync("Bravo " + input1 + input2); + } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 80a8b1915..c0b41b2c4 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -499,14 +499,6 @@ public sealed partial class Music : NadekoModule await ReplyConfirmLocalizedAsync(strs.repeating_track); } - [NadekoCommand, Aliases] - [RequireContext(ContextType.Guild)] - public async Task ReptCurSong() - { - await ReplyPendingLocalizedAsync(strs.obsolete_use($"`{Prefix}qrp song`")); - await QueueRepeat(InputRepeatType.Song); - } - [NadekoCommand, Aliases] [RequireContext(ContextType.Guild)] public async Task Pause() diff --git a/src/NadekoBot/Modules/Utility/PatreonCommands.cs b/src/NadekoBot/Modules/Utility/PatreonCommands.cs deleted file mode 100644 index 1a4621586..000000000 --- a/src/NadekoBot/Modules/Utility/PatreonCommands.cs +++ /dev/null @@ -1,45 +0,0 @@ -using NadekoBot.Modules.Utility.Services; - -namespace NadekoBot.Modules.Utility; - -public partial class Utility -{ - [Group] - public class PatreonCommands : NadekoSubmodule - { - private readonly IBotCredentials _creds; - - public PatreonCommands(IBotCredentials creds) - { - _creds = creds; - } - - [NadekoCommand, Aliases] - [RequireContext(ContextType.DM)] - public async Task ClaimPatreonRewards() - { - if (string.IsNullOrWhiteSpace(_creds.Patreon.AccessToken)) - { - Log.Warning("In order to use patreon reward commands, " + - "you need to specify CampaignId and AccessToken in creds.yml"); - return; - } - - if (DateTime.UtcNow.Day < 5) - { - await ReplyErrorLocalizedAsync(strs.clpa_too_early).ConfigureAwait(false); - return; - } - - var rem = _service.Interval - (DateTime.UtcNow - _service.LastUpdate); - var helpcmd = Format.Code(Prefix + "donate"); - await ctx.Channel.EmbedAsync(_eb.Create().WithOkColor() - .WithDescription(GetText(strs.clpa_obsolete)) - .AddField(GetText(strs.clpa_fail_already_title), GetText(strs.clpa_fail_already)) - .AddField(GetText(strs.clpa_fail_wait_title), GetText(strs.clpa_fail_wait)) - .AddField(GetText(strs.clpa_fail_conn_title), GetText(strs.clpa_fail_conn)) - .AddField(GetText(strs.clpa_fail_sup_title), GetText(strs.clpa_fail_sup(helpcmd))) - .WithFooter(GetText(strs.clpa_next_update(rem)))); - } - } -} \ No newline at end of file diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index b6c35a51a..c784a47d9 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -2,6 +2,7 @@ using System.Collections.Immutable; using NadekoBot.Common.Configs; using NadekoBot.Db; +using Discord.Interactions; namespace NadekoBot.Services; @@ -35,7 +36,8 @@ public class CommandHandler : INService BotConfigService bss, Bot bot, IBehaviourExecutor behaviourExecutor, - IServiceProvider services) + IServiceProvider services, + InteractionService interactions) { _client = client; _commandService = commandService; @@ -44,6 +46,7 @@ public class CommandHandler : INService _behaviourExecutor = behaviourExecutor; _db = db; _services = services; + _interactions = interactions; _clearUsersOnShortCooldown = new(_ => { @@ -121,12 +124,20 @@ public class CommandHandler : INService public Task StartHandling() { - _client.MessageReceived += msg => { var _ = Task.Run(() => MessageReceivedHandler(msg)); return Task.CompletedTask; }; + _client.MessageReceived += MessageReceivedHandler; + _client.SlashCommandExecuted += SlashCommandExecuted; return Task.CompletedTask; } + private async Task SlashCommandExecuted(SocketSlashCommand arg) + { + var ctx = new SocketInteractionContext(_client, arg); + await _interactions.ExecuteCommandAsync(ctx, _services); + } + private const float _oneThousandth = 1.0f / 1000; private readonly DbService _db; + private readonly InteractionService _interactions; private Task LogSuccessfulExecution(IUserMessage usrMsg, ITextChannel channel, params int[] execPoints) { @@ -264,7 +275,7 @@ public class CommandHandler : INService return (false, null, null); var commands = searchResult.Commands; - var preconditionResults = new Dictionary(); + var preconditionResults = new Dictionary(); foreach (var match in commands) { @@ -352,7 +363,7 @@ public class CommandHandler : INService //If we get this far, at least one parse was successful. Execute the most likely overload. var chosenOverload = successfulParses[0]; - var execResult = (ExecuteResult)await chosenOverload.Key.ExecuteAsync(context, chosenOverload.Value, services).ConfigureAwait(false); + var execResult = (Discord.Commands.ExecuteResult)await chosenOverload.Key.ExecuteAsync(context, chosenOverload.Value, services).ConfigureAwait(false); if (execResult.Exception != null && (!(execResult.Exception is HttpException he) || he.DiscordCode != DiscordErrorCode.InsufficientPermissions)) { diff --git a/src/NadekoBot/data/aliases.yml b/src/NadekoBot/data/aliases.yml index 647e2b8b0..ea44fce89 100644 --- a/src/NadekoBot/data/aliases.yml +++ b/src/NadekoBot/data/aliases.yml @@ -103,11 +103,6 @@ listcustreact: - lcr - exprli - exl -listcustreactg: -- listcustreactg -- lcrg -- exprlg -- exlg showcustreact: - showcustreact - scr @@ -503,9 +498,6 @@ trackremove: movesong: - movesong - ms -reptcursong: -- reptcursong -- rcs queuerepeat: - queuerepeat - qrp @@ -989,9 +981,6 @@ warnpunishlist: warnpunish: - warnpunish - warnp -claimpatreonrewards: -- clparew -- claparew ping: - ping time: diff --git a/src/NadekoBot/data/strings/commands/commands.en-US.yml b/src/NadekoBot/data/strings/commands/commands.en-US.yml index 231ab2b57..8bc00185c 100644 --- a/src/NadekoBot/data/strings/commands/commands.en-US.yml +++ b/src/NadekoBot/data/strings/commands/commands.en-US.yml @@ -862,10 +862,6 @@ setmaxqueue: args: - "50" - "" -reptcursong: - desc: "Obsolete. Use `{0}queuerepeat`" - args: - - "" queuerepeat: desc: "Sets music player repeat strategy for this server.\n- `n` / `no` - player will stop once it reaches the end of the queue\n- `s` / `song` - player will repeat current song\n- `q` / `queue` or empty - player will repeat entire music queue" args: @@ -1685,10 +1681,6 @@ warnpunish: - "5 Ban" - "5 Mute 2d12h" - "4 AddRole toxic 1h" -clparew: - desc: "Claim patreon rewards. If you're subscribed to bot owner's patreon you can use this command to claim your rewards - assuming bot owner did setup has their patreon key." - args: - - "" ping: desc: "Ping the bot to see if there are latency issues." args: diff --git a/src/NadekoBot/data/strings/responses/responses.en-US.json b/src/NadekoBot/data/strings/responses/responses.en-US.json index ba46f056a..b090c14f9 100644 --- a/src/NadekoBot/data/strings/responses/responses.en-US.json +++ b/src/NadekoBot/data/strings/responses/responses.en-US.json @@ -681,16 +681,6 @@ "warn_punish_rem": "Having {0} warnings will no longer trigger a punishment.", "warn_punish_set": "I will apply {0} punishment to users with {1} warnings.", "warn_punish_set_timed": "I will apply {0} punishment for {2} to users with {1} warnings.", - "clpa_obsolete": ":tada: **Patreon currency rewards are now automatic!** :tada:\nThis command is now obsolete.\nIf you did not receive your reward for this month's pledge, below are some of the reasons as to why that might be.", - "clpa_fail_already": "Maybe you've already received your reward for this month. You can receive rewards only once a month unless you increase your pledge.\nYou can check it by using `.curtrs` command.", - "clpa_fail_already_title": "Already rewarded", - "clpa_fail_conn": "Your discord account might not be connected to Patreon. If you are unsure what that means, or don't know how to connect it - you have to go to [Patreon account settings page](https://www.patreon.com/settings/apps) and click 'Connect to discord' button.", - "clpa_fail_conn_title": "Discord account not connected", - "clpa_fail_sup": "In order to be eligible for the reward, you must support the project on patreon. You can use {0} command to get the link.", - "clpa_fail_sup_title": "Not supporting", - "clpa_fail_wait": "You have to wait 5-10 minutes after making your pledge (and coonnecting your discord account to your patreon) for your currency to show up.", - "clpa_fail_wait_title": "Wait some time", - "clpa_too_early": "Rewards can be claimed on or after 5th of each month.", "time_new": "Time", "timezone": "Timezone", "timezone_db_api_key": "You need to activate your TimezoneDB API key. You can do so by clicking on the link you've received in the email with your API key.", @@ -701,7 +691,6 @@ "shop_none": "No shop items found on this page.", "shop_role": "You will get {0} role.", "type": "Type", - "clpa_next_update": "Next update in {0}", "gvc_disabled": "Game Voice Channel feature has been disabled on this server.", "gvc_enabled": "{0} is a Game Voice Channel now.", "not_in_voice": "You are not in a voice channel on this server.",