From b1f18c322e1407a8fce9ce7320c5bb70be986ff3 Mon Sep 17 00:00:00 2001 From: DownloadableFox Date: Sun, 9 Jun 2024 21:58:31 -0500 Subject: [PATCH] Added forum create command just to see if I can create a forum in a non public guild --- modules/debug/services.go | 2 ++ modules/extra/commands.go | 54 +++++++++++++++++++++++++++++++++++++++ modules/extra/events.go | 1 + modules/extra/register.go | 9 +++++++ 4 files changed, 66 insertions(+) diff --git a/modules/debug/services.go b/modules/debug/services.go index 9b5a092..f51fa99 100644 --- a/modules/debug/services.go +++ b/modules/debug/services.go @@ -2,6 +2,8 @@ package debug import "github.com/downloadablefox/twotto/core" +// ModuleProvider is an interface for managing modules and features. + type ModuleProvider interface { // Modules EnableModule(module string, guildId string) error diff --git a/modules/extra/commands.go b/modules/extra/commands.go index 18db649..d90e121 100644 --- a/modules/extra/commands.go +++ b/modules/extra/commands.go @@ -2,6 +2,7 @@ package extra import ( "context" + "fmt" "github.com/bwmarrin/discordgo" "github.com/downloadablefox/twotto/core" @@ -59,3 +60,56 @@ func HandleSayCommand(_ context.Context, s *discordgo.Session, e *discordgo.Inte return nil } + +var CreateForumCommandDMPermission = false +var CreateForumCommandPermissions int64 = discordgo.PermissionAdministrator + +var CreateForumCommand = &discordgo.ApplicationCommand{ + Name: "create-forum", + Description: "Creates a forum channel.", + DMPermission: &CreateForumCommandDMPermission, + DefaultMemberPermissions: &CreateForumCommandPermissions, + Options: []*discordgo.ApplicationCommandOption{ + { + Name: "name", + Description: "The name of the forum.", + Type: discordgo.ApplicationCommandOptionString, + Required: true, + }, + }, +} + +func HandleCreateForumCommand(_ context.Context, s *discordgo.Session, e *discordgo.InteractionCreate) error { + // Defers the response + if err := s.InteractionRespond(e.Interaction, &discordgo.InteractionResponse{ + Type: discordgo.InteractionResponseDeferredChannelMessageWithSource, + Data: &discordgo.InteractionResponseData{ + Flags: discordgo.MessageFlagsEphemeral, + }, + }); err != nil { + return err + } + + data := e.ApplicationCommandData() + + // Creates the channel + channel, err := s.GuildChannelCreate(e.GuildID, data.Options[0].StringValue(), discordgo.ChannelTypeGuildForum) + if err != nil { + return err + } + + // Responds to the interaction + embed := &discordgo.MessageEmbed{ + Title: "Forum Created", + Description: fmt.Sprintf("Forum created at <#%s>.", channel.ID), + Color: core.ColorSuccess, + } + + if _, err := s.InteractionResponseEdit(e.Interaction, &discordgo.WebhookEdit{ + Embeds: &[]*discordgo.MessageEmbed{embed}, + }); err != nil { + return err + } + + return nil +} diff --git a/modules/extra/events.go b/modules/extra/events.go index 4566b17..553c34d 100644 --- a/modules/extra/events.go +++ b/modules/extra/events.go @@ -14,6 +14,7 @@ func HandleOnReadyEvent(ctx context.Context, s *discordgo.Session, e *discordgo. // Register commands err := core.ApplyCommands( SayCommand, + CreateForumCommand, ).For(s, "") if err != nil { log.Warn().Err(err).Msg("[DebugModule] Failed to register commands") diff --git a/modules/extra/register.go b/modules/extra/register.go index 4565dac..d1055b3 100644 --- a/modules/extra/register.go +++ b/modules/extra/register.go @@ -24,6 +24,15 @@ func RegisterModule(client *discordgo.Session) { ) client.AddHandler(core.HandleEvent(sayCommand)) + // Add forum create command + forumCreateCommandIdent := core.NewIdentifier("extra", "commands/create-forum") + forumCreateCommand := core.ApplyMiddlewares( + HandleCreateForumCommand, + debug.MidwareForCommand(CreateForumCommand), + debug.MidwareErrorWrap(forumCreateCommandIdent), + ) + client.AddHandler(core.HandleEvent(forumCreateCommand)) + // Add twitter link command client.AddHandler(core.HandleEvent(HandleTwitterLinkEvent)) }