Skip to content

Commit

Permalink
Merge pull request #48 from federinik/feature/44-invite-command
Browse files Browse the repository at this point in the history
#44 - invite command implementation
  • Loading branch information
BrammyS authored Oct 16, 2022
2 parents eb2bf58 + 0aa4359 commit 77cfada
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Bot.Discord/Commands/HelpCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public Task<Result<IDiscordInteractionResponse>> 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();

Expand Down
51 changes: 51 additions & 0 deletions src/Bot.Discord/Commands/InviteCommands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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.API.DataModels;
using Color_Chan.Discord.Core.Common.Models;
using Color_Chan.Discord.Core.Common.Models.Interaction;
using Color_Chan.Discord.Core.Results;

namespace Bot.Discord.Commands;

/// <summary>
/// The command module for inviting the bot to other Discord's servers.
/// </summary>
[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!";

/// <summary>
/// An invitation command where the bot will reply back with a link to be added to other servers.
/// </summary>
/// <returns>
/// An embedded response with the provided message.
/// </returns>
[SlashCommand(InviteCommandName, InviteCommandDesc)]
public Task<Result<IDiscordInteractionResponse>> 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(InviteMe)
.Build();

// Return the response to Discord.
return Task.FromResult(FromSuccess(inviteResponse));
}

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

0 comments on commit 77cfada

Please sign in to comment.