From ea2c5e8e61415e982bc923e6d84458fd3f181ed1 Mon Sep 17 00:00:00 2001 From: Federico Tomasi Date: Sun, 16 Oct 2022 18:53:30 +0200 Subject: [PATCH 1/2] #44 invite command implementation --- src/Bot.Discord/Commands/InviteCommands.cs | 48 +++++++++++++++++++++ src/Bot.Discord/Components/InviteButtons.cs | 13 ++++++ 2 files changed, 61 insertions(+) create mode 100644 src/Bot.Discord/Commands/InviteCommands.cs create mode 100644 src/Bot.Discord/Components/InviteButtons.cs diff --git a/src/Bot.Discord/Commands/InviteCommands.cs b/src/Bot.Discord/Commands/InviteCommands.cs new file mode 100644 index 0000000..8c0ad76 --- /dev/null +++ b/src/Bot.Discord/Commands/InviteCommands.cs @@ -0,0 +1,48 @@ +using Bot.Discord.Components; +using Color_Chan.Discord.Commands.Attributes; +using Color_Chan.Discord.Commands.Attributes.ProvidedRequirements; +using Color_Chan.Discord.Commands.MessageBuilders; +using Color_Chan.Discord.Commands.Modules; +using Color_Chan.Discord.Core.Common.Models.Embed; +using Color_Chan.Discord.Core.Common.Models.Interaction; +using Color_Chan.Discord.Core.Results; + +namespace Bot.Discord.Commands; + +/// +/// The command module for inviting the bot to other Discord's servers. +/// +[UserRateLimit(5, 10)] // Sets the rate lcimit for this command module to 5 requests per 10 seconds per user. +public class InviteCommands : SlashCommandModule +{ + public const string InviteCommandName = "invite"; + public const string InviteCommandDesc = "Invite the bot somewhere else!"; + + + /// + /// An invitation command where the bot will reply back with a link to be added to other servers. + /// + /// + /// An embedded response with the provided message. + /// + [SlashCommand(InviteCommandName, InviteCommandDesc)] + public Task> InviteAsync() + { + // Build the embedded response. + var inviteResponse = new InteractionResponseBuilder() + .WithEmbed(InviteMeEmbed) + .WithComponent(InviteButtons.InviteMe) + .Build(); + + // Return the response to Discord. + return Task.FromResult(FromSuccess(inviteResponse)); + } + + public static readonly IDiscordEmbed InviteMeEmbed = + new DiscordEmbedBuilder() + .WithTitle("Invite me") + .WithDescription("I need more friends, add me to other Discord servers!") + .WithColor(Constants.Colors.Successful) + .WithTimeStamp() + .Build(); +} \ No newline at end of file diff --git a/src/Bot.Discord/Components/InviteButtons.cs b/src/Bot.Discord/Components/InviteButtons.cs new file mode 100644 index 0000000..a941a6b --- /dev/null +++ b/src/Bot.Discord/Components/InviteButtons.cs @@ -0,0 +1,13 @@ +using Color_Chan.Discord.Commands.MessageBuilders; +using Color_Chan.Discord.Core.Common.API.DataModels; +using Color_Chan.Discord.Core.Common.Models; + +namespace Bot.Discord.Components; + +public static class InviteButtons +{ + public static readonly IDiscordComponent InviteMe = + new ActionRowComponentBuilder() + .WithButton("Invite me!", DiscordButtonStyle.Link, null, $"https://discord.com/api/oauth2/authorize?client_id={Constants.BotId}&permissions=0&scope=bot%20applications.commands") + .Build(); +} From 0aa4359d8714d23bd68df829d70fba2f088ba272 Mon Sep 17 00:00:00 2001 From: Federico Tomasi Date: Sun, 16 Oct 2022 21:05:51 +0200 Subject: [PATCH 2/2] #44 - code refactor, add help snippet for invite comman --- src/Bot.Discord/Commands/HelpCommands.cs | 1 + src/Bot.Discord/Commands/InviteCommands.cs | 27 ++++++++++++--------- src/Bot.Discord/Components/InviteButtons.cs | 13 ---------- 3 files changed, 16 insertions(+), 25 deletions(-) delete mode 100644 src/Bot.Discord/Components/InviteButtons.cs diff --git a/src/Bot.Discord/Commands/HelpCommands.cs b/src/Bot.Discord/Commands/HelpCommands.cs index b2fae08..28946e4 100644 --- a/src/Bot.Discord/Commands/HelpCommands.cs +++ b/src/Bot.Discord/Commands/HelpCommands.cs @@ -59,6 +59,7 @@ public Task> ShowHelpAsync() new DiscordEmbedBuilder() .WithTitle("Help | Misc commands | Page 3") .WithField($"{Constants.SlashPrefix}{AboutCommands.AboutCommandName}", AboutCommands.AboutCommandDesc) + .WithField($"{Constants.SlashPrefix}{InviteCommands.InviteCommandName}", InviteCommands.InviteCommandDesc) .WithColor(Constants.Colors.Neutral) .Build(); diff --git a/src/Bot.Discord/Commands/InviteCommands.cs b/src/Bot.Discord/Commands/InviteCommands.cs index 8c0ad76..3171582 100644 --- a/src/Bot.Discord/Commands/InviteCommands.cs +++ b/src/Bot.Discord/Commands/InviteCommands.cs @@ -1,9 +1,9 @@ -using Bot.Discord.Components; -using Color_Chan.Discord.Commands.Attributes; +using Color_Chan.Discord.Commands.Attributes; using Color_Chan.Discord.Commands.Attributes.ProvidedRequirements; using Color_Chan.Discord.Commands.MessageBuilders; using Color_Chan.Discord.Commands.Modules; -using Color_Chan.Discord.Core.Common.Models.Embed; +using Color_Chan.Discord.Core.Common.API.DataModels; +using Color_Chan.Discord.Core.Common.Models; using Color_Chan.Discord.Core.Common.Models.Interaction; using Color_Chan.Discord.Core.Results; @@ -18,7 +18,6 @@ public class InviteCommands : SlashCommandModule public const string InviteCommandName = "invite"; public const string InviteCommandDesc = "Invite the bot somewhere else!"; - /// /// An invitation command where the bot will reply back with a link to be added to other servers. /// @@ -28,21 +27,25 @@ public class InviteCommands : SlashCommandModule [SlashCommand(InviteCommandName, InviteCommandDesc)] public Task> InviteAsync() { + var inviteMeEmbed = new DiscordEmbedBuilder() + .WithTitle("Invite me") + .WithDescription("I need more friends, add me to other Discord servers!") + .WithColor(Constants.Colors.Successful) + .WithTimeStamp() + .Build(); + // Build the embedded response. var inviteResponse = new InteractionResponseBuilder() - .WithEmbed(InviteMeEmbed) - .WithComponent(InviteButtons.InviteMe) + .WithEmbed(inviteMeEmbed) + .WithComponent(InviteMe) .Build(); // Return the response to Discord. return Task.FromResult(FromSuccess(inviteResponse)); } - public static readonly IDiscordEmbed InviteMeEmbed = - new DiscordEmbedBuilder() - .WithTitle("Invite me") - .WithDescription("I need more friends, add me to other Discord servers!") - .WithColor(Constants.Colors.Successful) - .WithTimeStamp() + public static readonly IDiscordComponent InviteMe = + new ActionRowComponentBuilder() + .WithButton("Invite me!", DiscordButtonStyle.Link, null, $"https://discord.com/api/oauth2/authorize?client_id={Constants.BotId}&permissions=0&scope=bot%20applications.commands") .Build(); } \ No newline at end of file diff --git a/src/Bot.Discord/Components/InviteButtons.cs b/src/Bot.Discord/Components/InviteButtons.cs deleted file mode 100644 index a941a6b..0000000 --- a/src/Bot.Discord/Components/InviteButtons.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Color_Chan.Discord.Commands.MessageBuilders; -using Color_Chan.Discord.Core.Common.API.DataModels; -using Color_Chan.Discord.Core.Common.Models; - -namespace Bot.Discord.Components; - -public static class InviteButtons -{ - public static readonly IDiscordComponent InviteMe = - new ActionRowComponentBuilder() - .WithButton("Invite me!", DiscordButtonStyle.Link, null, $"https://discord.com/api/oauth2/authorize?client_id={Constants.BotId}&permissions=0&scope=bot%20applications.commands") - .Build(); -}