From f75926c604d6ac4d4efaf3d92a99d98bda4b87ae Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Tue, 18 Jul 2023 19:18:35 +0500 Subject: [PATCH] Do not allow certain commands to be used in DMs (#49) This PR prevents usage of `/about`, `/ping` and `/remind` inside DMs. While it may look like these commands do not require a guild attached to them, the language system depends on having a guild to fetch settings from, so it is not possible to use these commands in DMs. Signed-off-by: Octol1ttle --- src/Commands/AboutCommandGroup.cs | 4 ++++ src/Commands/PingCommandGroup.cs | 4 ++++ src/Commands/RemindCommandGroup.cs | 4 +++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Commands/AboutCommandGroup.cs b/src/Commands/AboutCommandGroup.cs index edb34d2..70f4bcf 100644 --- a/src/Commands/AboutCommandGroup.cs +++ b/src/Commands/AboutCommandGroup.cs @@ -6,6 +6,8 @@ using JetBrains.Annotations; using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Discord.API.Abstractions.Rest; +using Remora.Discord.Commands.Attributes; +using Remora.Discord.Commands.Conditions; using Remora.Discord.Commands.Contexts; using Remora.Discord.Commands.Feedback.Services; using Remora.Discord.Extensions.Embeds; @@ -41,6 +43,8 @@ public class AboutCommandGroup : CommandGroup { /// A feedback sending result which may or may not have succeeded. /// [Command("about")] + [DiscordDefaultDMPermission(false)] + [RequireContext(ChannelContext.Guild)] [Description("Shows Boyfriend's developers")] [UsedImplicitly] public async Task SendAboutBotAsync() { diff --git a/src/Commands/PingCommandGroup.cs b/src/Commands/PingCommandGroup.cs index 52d924f..ad05451 100644 --- a/src/Commands/PingCommandGroup.cs +++ b/src/Commands/PingCommandGroup.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Discord.API.Abstractions.Rest; +using Remora.Discord.Commands.Attributes; +using Remora.Discord.Commands.Conditions; using Remora.Discord.Commands.Contexts; using Remora.Discord.Commands.Feedback.Services; using Remora.Discord.Extensions.Embeds; @@ -44,6 +46,8 @@ public class PingCommandGroup : CommandGroup { /// [Command("ping", "пинг")] [Description("Get bot latency")] + [DiscordDefaultDMPermission(false)] + [RequireContext(ChannelContext.Guild)] [UsedImplicitly] public async Task SendPingAsync() { if (!_context.TryGetContextIDs(out var guildId, out var channelId, out _)) diff --git a/src/Commands/RemindCommandGroup.cs b/src/Commands/RemindCommandGroup.cs index 7203fbd..28fc0ed 100644 --- a/src/Commands/RemindCommandGroup.cs +++ b/src/Commands/RemindCommandGroup.cs @@ -6,6 +6,7 @@ using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.Commands.Attributes; +using Remora.Discord.Commands.Conditions; using Remora.Discord.Commands.Contexts; using Remora.Discord.Commands.Feedback.Services; using Remora.Discord.Extensions.Embeds; @@ -40,8 +41,9 @@ public class RemindCommandGroup : CommandGroup { /// The text of the reminder. /// A feedback sending result which may or may not have succeeded. [Command("remind")] - [DiscordDefaultDMPermission(false)] [Description("Create a reminder")] + [DiscordDefaultDMPermission(false)] + [RequireContext(ChannelContext.Guild)] [UsedImplicitly] public async Task AddReminderAsync( [Description("After what period of time mention the reminder")]