From 10e57fe2a02950243a001f94b7d423fc8192f8f9 Mon Sep 17 00:00:00 2001 From: vaporvee Date: Tue, 20 Feb 2024 14:06:35 +0100 Subject: [PATCH] tried adding notify command --- command_notify.go | 63 ++++++++++++++++++++++++++++++++++++++++++++ main.go | 1 - register_commands.go | 35 +----------------------- 3 files changed, 64 insertions(+), 35 deletions(-) create mode 100644 command_notify.go diff --git a/command_notify.go b/command_notify.go new file mode 100644 index 0000000..e4e0379 --- /dev/null +++ b/command_notify.go @@ -0,0 +1,63 @@ +package main + +import ( + "fmt" + + "github.com/bwmarrin/discordgo" +) + +// disabled +var notify_command Command = Command{ + Definition: discordgo.ApplicationCommand{ + Name: "notify", + Description: "Manage social media notifications.", + Options: []*discordgo.ApplicationCommandOption{ + { + Type: discordgo.ApplicationCommandOptionSubCommand, + Name: "add", + Description: "Set channels where your social media notifications should appear.", + Options: []*discordgo.ApplicationCommandOption{ + { + Name: "platform", + Type: discordgo.ApplicationCommandOptionString, + Description: "The social media platform to receive notifications from.", + Required: true, + Choices: []*discordgo.ApplicationCommandOptionChoice{ + { + Name: "Twitch", + Value: "twitch", + }, + }, + }, + { + Name: "username", + Type: discordgo.ApplicationCommandOptionString, + Required: true, + Description: "The social media platform to receive notifications from.", + }, + { + Name: "channel", + Type: discordgo.ApplicationCommandOptionChannel, + Required: true, + Description: "The social media platform to receive notifications from.", + }, + }, + }, + { + Type: discordgo.ApplicationCommandOptionSubCommand, + Name: "remove", + Description: "Remove a social media notification.", + }, + }, + }, + Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) { + options := i.ApplicationCommandData().Options[0] + switch options.Name { + case "add": + switch options.Options[0].Value { + case "twitch": + fmt.Print("twitch") + } + } + }, +} diff --git a/main.go b/main.go index 86da019..c7f3faa 100644 --- a/main.go +++ b/main.go @@ -29,7 +29,6 @@ func main() { log.Fatal(err) } initTables() - discord, err := discordgo.New("Bot " + os.Getenv("BOT_TOKEN")) if err != nil { fmt.Println("error creating Discord session,", err) diff --git a/register_commands.go b/register_commands.go index 485b305..74e98bf 100644 --- a/register_commands.go +++ b/register_commands.go @@ -23,7 +23,7 @@ func ready(s *discordgo.Session, event *discordgo.Ready) { _, err := s.ApplicationCommandCreate(s.State.User.ID, guild.ID, &command.Definition) if err != nil { fmt.Println("error creating command,", err) - continue // Continue to the next guild + continue } } } @@ -64,36 +64,3 @@ func removeCommandFromAllGuilds(s *discordgo.Session) { } } } - -/* -func hasManageServerPermissions(s *discordgo.Session, userID string, guildID string) bool { - member, err := s.GuildMember(guildID, userID) - if err != nil { - fmt.Printf("Error fetching guild member: %v\n", err) - return false - } - - guild, err := s.Guild(guildID) - if err != nil { - fmt.Printf("Error fetching guild: %v\n", err) - return false - } - - if guild.OwnerID == userID { - return true - } - - for _, roleID := range member.Roles { - role, err := s.State.Role(guildID, roleID) - if err != nil { - fmt.Printf("Error fetching role: %v\n", err) - continue - } - if role.Permissions&discordgo.PermissionManageServer != 0 || role.Permissions&discordgo.PermissionAdministrator != 0 { - return true - } - } - - return false -} -*/