Skip to content

Commit

Permalink
Added forum create command just to see if I can create a forum in a n…
Browse files Browse the repository at this point in the history
…on public guild
  • Loading branch information
DownloadableFox committed Jun 10, 2024
1 parent 6b37e61 commit b1f18c3
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modules/debug/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions modules/extra/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package extra

import (
"context"
"fmt"

"github.com/bwmarrin/discordgo"
"github.com/downloadablefox/twotto/core"
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions modules/extra/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions modules/extra/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit b1f18c3

Please sign in to comment.