diff --git a/cmd_ask.go b/cmd_ask.go index fefadbd..402cf6f 100644 --- a/cmd_ask.go +++ b/cmd_ask.go @@ -1,5 +1,6 @@ package main +/* import ( "github.com/bwmarrin/discordgo" "github.com/sirupsen/logrus" @@ -31,3 +32,4 @@ var cmd_ask Command = Command{ }, AllowDM: true, } +*/ diff --git a/cmd_autojoinroles.go b/cmd_autojoinroles.go index 9b47539..118074c 100644 --- a/cmd_autojoinroles.go +++ b/cmd_autojoinroles.go @@ -1,10 +1,6 @@ package main -import ( - "github.com/bwmarrin/discordgo" - "github.com/sirupsen/logrus" -) - +/* var cmd_autojoinroles Command = Command{ Definition: discordgo.ApplicationCommand{ Name: "autojoinroles", @@ -66,3 +62,4 @@ var cmd_autojoinroles Command = Command{ purgeUnusedAutoJoinRoles(i.GuildID) }, } +*/ diff --git a/cmd_autopublish.go b/cmd_autopublish.go index bd643ea..a69b0b6 100644 --- a/cmd_autopublish.go +++ b/cmd_autopublish.go @@ -1,5 +1,6 @@ package main +/* import ( "github.com/bwmarrin/discordgo" "github.com/sirupsen/logrus" @@ -32,3 +33,4 @@ var cmd_autopublish Command = Command{ } }, } +*/ diff --git a/cmd_cat.go b/cmd_cat.go index 54c2674..7e14008 100644 --- a/cmd_cat.go +++ b/cmd_cat.go @@ -1,14 +1,6 @@ package main -import ( - "encoding/json" - "io" - "net/http" - - "github.com/bwmarrin/discordgo" - "github.com/sirupsen/logrus" -) - +/* var cmd_cat Command = Command{ Definition: discordgo.ApplicationCommand{ Name: "cat", @@ -52,3 +44,4 @@ func GetCatImageURL() (string, error) { return "https://cataas.com/cat/" + images.ID, err } +*/ diff --git a/cmd_dadjoke.go b/cmd_dadjoke.go index 9cee282..1a976b0 100644 --- a/cmd_dadjoke.go +++ b/cmd_dadjoke.go @@ -1,5 +1,6 @@ package main +/* import ( "github.com/bwmarrin/discordgo" "github.com/sirupsen/logrus" @@ -18,3 +19,4 @@ var cmd_dadjoke Command = Command{ }, AllowDM: true, } +*/ diff --git a/cmd_form.go b/cmd_form.go index 62ebdcd..13a1d98 100644 --- a/cmd_form.go +++ b/cmd_form.go @@ -1,15 +1,6 @@ package main -import ( - "bytes" - "fmt" - "strings" - - "github.com/bwmarrin/discordgo" - "github.com/google/uuid" - "github.com/sirupsen/logrus" -) - +/* var cmd_form Command = Command{ Definition: discordgo.ApplicationCommand{ Name: "form", @@ -572,3 +563,4 @@ func getFormButtonIDs() []string { } return IDs } +*/ diff --git a/cmd_info.go b/cmd_info.go index d84f2cf..4ebdeac 100644 --- a/cmd_info.go +++ b/cmd_info.go @@ -1,5 +1,6 @@ package main +/* import ( "encoding/json" "fmt" @@ -232,3 +233,4 @@ func parseRetryAfterHeader(headers http.Header) time.Duration { return time.Duration(retryAfter) * time.Millisecond } +*/ diff --git a/cmd_ping.go b/cmd_ping.go index 9341bb9..9068e90 100644 --- a/cmd_ping.go +++ b/cmd_ping.go @@ -1,5 +1,6 @@ package main +/* import ( "fmt" "net/http" @@ -48,3 +49,4 @@ var cmd_ping Command = Command{ }, AllowDM: true, } +*/ diff --git a/cmd_sticky.go b/cmd_sticky.go index cdbedfb..8d9901f 100644 --- a/cmd_sticky.go +++ b/cmd_sticky.go @@ -1,5 +1,6 @@ package main +/* import ( "github.com/bwmarrin/discordgo" "github.com/sirupsen/logrus" @@ -99,3 +100,4 @@ func inputStickyMessage(i *discordgo.InteractionCreate) { } } } +*/ diff --git a/cmd_tag.go b/cmd_tag.go index 6daafc8..ef6dc0e 100644 --- a/cmd_tag.go +++ b/cmd_tag.go @@ -1,7 +1,6 @@ package main import ( - "github.com/bwmarrin/discordgo" "github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/events" "github.com/disgoorg/json" @@ -49,10 +48,12 @@ var cmd_tag Command = Command{ case "get": GetTagCommand(e) case "add": - AddTagCommand(i, "") + AddTagCommand(e, "") case "remove": - removeTag(i.GuildID, i.ApplicationCommandData().Options[0].Options[0].StringValue()) - err := respond(i.Interaction, "Tag removed!", true) + removeTag(e.GuildID().String(), e.SlashCommandInteractionData().String("tag")) + err := e.CreateMessage(discord.NewMessageCreateBuilder(). + SetContent("Tag removed!").SetEphemeral(true). + Build()) if err != nil { logrus.Error(err) } @@ -76,12 +77,11 @@ var cmd_tag Command = Command{ } var cmd_tag_short Command = Command{ - Definition: discordgo.ApplicationCommand{ + Definition: discord.SlashCommandCreate{ Name: "g", Description: "A short command to get presaved messages.", - Options: []*discordgo.ApplicationCommandOption{ - { - Type: discordgo.ApplicationCommandOptionString, + Options: []discord.ApplicationCommandOption{ + discord.ApplicationCommandOptionString{ Name: "tag", Description: "Your predefined tag for the saved message", Required: true, @@ -89,86 +89,95 @@ var cmd_tag_short Command = Command{ }, }, }, - Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) { - GetTagCommand(i, i.ApplicationCommandData().Options[0]) + Interact: func(e *events.ApplicationCommandInteractionCreate) { + GetTagCommand(e) }, - Autocomplete: func(s *discordgo.Session, i *discordgo.InteractionCreate) { - AutocompleteTag(i) + Autocomplete: func(e *events.AutocompleteInteractionCreate) { + AutocompleteTag(e) }, } var context_tag Command = Command{ - Definition: discordgo.ApplicationCommand{ - Type: discordgo.MessageApplicationCommand, + Definition: discord.SlashCommandCreate{ Name: "Save as tag", - DefaultMemberPermissions: int64Ptr(discordgo.PermissionManageServer), + DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionManageGuild), }, - Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) { - AddTagCommand(i, i.ApplicationCommandData().Resolved.Messages[i.ApplicationCommandData().TargetID].Content) + Interact: func(e *events.ApplicationCommandInteractionCreate) { + AddTagCommand(e, e.SlashCommandInteractionData().String("")) }, } func GetTagCommand(e *events.ApplicationCommandInteractionCreate) { - err := e.CreateMessage(discord.NewMessageCreateBuilder().SetContent(getTagContent(guildID, option)).SetEphemeral(true).Build()) + err := e.CreateMessage(discord.NewMessageCreateBuilder(). + SetContent(getTagContent(e.GuildID().String(), e.SlashCommandInteractionData().String("tag"))). + Build()) if err != nil { logrus.Error(err) } } -func AddTagCommand(i *discordgo.InteractionCreate, prevalue string) { - err := bot.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseModal, - Data: &discordgo.InteractionResponseData{ - CustomID: "tag_add_modal" + i.Interaction.Member.User.ID, - Title: "Add a custom tag command", - Components: []discordgo.MessageComponent{ - discordgo.ActionsRow{ - Components: []discordgo.MessageComponent{ - discordgo.TextInput{ - CustomID: "tag_add_modal_name", - Label: "Name", - Style: discordgo.TextInputShort, - Required: true, - MaxLength: 20, - Value: "", - }, - }, - }, - discordgo.ActionsRow{ - Components: []discordgo.MessageComponent{ - discordgo.TextInput{ - CustomID: "tag_add_modal_content", - Label: "Content", - Placeholder: "Content that gets returned when the tag will be run", - Style: discordgo.TextInputParagraph, - Required: true, - MaxLength: 2000, - Value: prevalue, - }, - }, +func AddTagCommand(e *events.ApplicationCommandInteractionCreate, prevalue string) { + err := e.Modal(discord.ModalCreate{ + CustomID: "tag_add_modal" + e.User().ID.String(), + Title: "Add a custom tag command", + Components: []discord.ContainerComponent{ + discord.ActionRowComponent{ + discord.TextInputComponent{ + CustomID: "tag_add_modal_name", + Label: "Name", + Style: discord.TextInputStyleShort, + Required: true, + MaxLength: 20, + Value: "", }, }, }, }) - if err != nil { - logrus.Error(err) - } -} - -func AutocompleteTag(i *discordgo.InteractionCreate) { - err := bot.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionApplicationCommandAutocompleteResult, - Data: &discordgo.InteractionResponseData{ - Choices: generateTagChoices(i.GuildID), + /*Data: &discordgo.InteractionResponseData{ + CustomID: "tag_add_modal" + i.Interaction.Member.User.ID, + Title: "Add a custom tag command", + Components: []discordgo.MessageComponent{ + discordgo.ActionsRow{ + Components: []discordgo.MessageComponent{ + discordgo.TextInput{ + CustomID: "tag_add_modal_name", + Label: "Name", + Style: discordgo.TextInputShort, + Required: true, + MaxLength: 20, + Value: "", + }, + }, + }, + discordgo.ActionsRow{ + Components: []discordgo.MessageComponent{ + discordgo.TextInput{ + CustomID: "tag_add_modal_content", + Label: "Content", + Placeholder: "Content that gets returned when the tag will be run", + Style: discordgo.TextInputParagraph, + Required: true, + MaxLength: 2000, + Value: prevalue, + }, + }, + }, }, - }) + },*/ if err != nil { logrus.Error(err) } } -func generateTagChoices(guildID string) []*discordgo.ApplicationCommandOptionChoice { - choices := []*discordgo.ApplicationCommandOptionChoice{} +func AutocompleteTag(e *events.AutocompleteInteractionCreate) { + err := e.AutocompleteResult(generateTagChoices(e.GuildID().String())) + if err != nil { + logrus.Error(err) + } +} + +func generateTagChoices(guildID string) []discord.AutocompleteChoice { + choices := []discord.AutocompleteChoice{} IDs, err := getTagIDs(guildID) if err != nil { logrus.Error(err) @@ -176,7 +185,7 @@ func generateTagChoices(guildID string) []*discordgo.ApplicationCommandOptionCho } for _, id := range IDs { id_name := getTagName(guildID, id) - choices = append(choices, &discordgo.ApplicationCommandOptionChoice{ + choices = append(choices, &discord.AutocompleteChoiceString{ Name: id_name, Value: id, }) diff --git a/handlers.go b/handlers.go index 6f917c3..5723d1f 100644 --- a/handlers.go +++ b/handlers.go @@ -24,7 +24,7 @@ type Command struct { AllowDM bool } -var commands []Command = []Command{cmd_form, cmd_ticket_form, cmd_tag, cmd_tag_short, cmd_dadjoke, cmd_ping, cmd_ask, cmd_sticky, cmd_cat, cmd_autojoinroles, cmd_autopublish, context_sticky, context_tag, cmd_userinfo} +var commands []Command = []Command{cmd_tag, cmd_tag_short, context_tag /*, cmd_form, cmd_ticket_form, cmd_dadjoke, cmd_ping, cmd_ask, cmd_sticky, cmd_cat, cmd_autojoinroles, cmd_autopublish, context_sticky, cmd_userinfo*/} func ready(e *events.Ready) { logrus.Info("Starting up...") @@ -43,9 +43,9 @@ func ready(e *events.Ready) { if !slices.Contains(existingCommandNames, command.Definition.Name) || slices.Contains(os.Args, "--update="+command.Definition.Name) || slices.Contains(os.Args, "--update=all") || slices.Contains(os.Args, "--clean") { cmd, err := client.Rest().CreateGlobalCommand(app.Bot.ID, command.Definition) if err != nil { - logrus.Errorf("error creating global command '%s': %v", cmd.Name, err) + logrus.Errorf("error creating global command '%s': %v", cmd.Name(), err) } else { - logrus.Infof("Added global command '%s'", cmd.Name) + logrus.Infof("Added global command '%s'", cmd.Name()) } } } @@ -139,7 +139,7 @@ func modalSubmitInteractionCreate(e *events.ModalSubmitInteractionCreate) { func removeOldCommandFromAllGuilds() { globalCommands, err := client.Rest().GetGlobalCommands(app.Bot.ID, false) if err != nil { - logrus.Error("error fetching existing global commands: %v", err) + logrus.Errorf("error fetching existing global commands: %v", err) return } var commandNames []string @@ -149,10 +149,10 @@ func removeOldCommandFromAllGuilds() { for _, existingCommand := range globalCommands { if slices.Contains(commandNames, existingCommand.Name()) { - logrus.Info("Deleting command '%s'", existingCommand.Name) + logrus.Infof("Deleting command '%s'", existingCommand.Name()) err := client.Rest().DeleteGlobalCommand(app.Bot.ID, existingCommand.ID()) if err != nil { - logrus.Error("error deleting command %s: %v", existingCommand.Name, err) + logrus.Errorf("error deleting command %s: %v", existingCommand.Name(), err) } } } diff --git a/main.go b/main.go index 08e45e5..b33c067 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,8 @@ import ( "syscall" "time" + _ "github.com/lib/pq" + "github.com/disgoorg/disgo" "github.com/disgoorg/disgo/bot" "github.com/disgoorg/disgo/discord" @@ -36,7 +38,7 @@ func main() { logrus.Fatal(err) } initTables() - client, err := disgo.New("Bot "+os.Getenv("BOT_TOKEN"), + client, err := disgo.New(os.Getenv("BOT_TOKEN"), bot.WithGatewayConfigOpts( gateway.WithIntents( gateway.IntentGuilds, @@ -47,6 +49,8 @@ func main() { bot.WithEventListenerFunc(ready), bot.WithEventListenerFunc(applicationCommandInteractionCreate), bot.WithEventListenerFunc(autocompleteInteractionCreate), + bot.WithEventListenerFunc(componentInteractionCreate), + bot.WithEventListenerFunc(modalSubmitInteractionCreate), bot.WithEventListenerFunc(messageCreate), bot.WithEventListenerFunc(messageDelete), bot.WithEventListenerFunc(guildMemberJoin),