From 3a7e8ae72179c3bbc34791169873f8c60ffb0582 Mon Sep 17 00:00:00 2001 From: Joren Date: Sat, 6 Jul 2024 22:02:03 +0200 Subject: [PATCH] Make sure people in the admin_role can do the setupo --- main.go | 61 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/main.go b/main.go index 3f4ef56..71d16f3 100644 --- a/main.go +++ b/main.go @@ -147,6 +147,39 @@ var ( } commandsHandlers = map[string]func(client *discordgo.Session, i *discordgo.InteractionCreate){ "setup": func(client *discordgo.Session, i *discordgo.InteractionCreate) { + hasAdminPermission := false + for _, roleID := range config.Discord.AdminRoles { + member, err := client.GuildMember(i.GuildID, i.Member.User.ID) + if err != nil { + log.Println("Error fetching member info:", err) + return + } + + for _, role := range member.Roles { + if role == roleID { + hasAdminPermission = true + break + } + } + if hasAdminPermission { + break + } + } + + if !hasAdminPermission { + err := client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ + Type: discordgo.InteractionResponseChannelMessageWithSource, + Data: &discordgo.InteractionResponseData{ + Content: "You do not have permission to run this command.", + Flags: discordgo.MessageFlagsEphemeral, + }, + }) + if err != nil { + log.Println("Error sending interaction response:", err) + } + return + } + channelOption := i.ApplicationCommandData().Options[0].ChannelValue(client) _, err := client.ChannelMessageSendComplex(channelOption.ID, &discordgo.MessageSend{ Content: "Click the button below to request a HWID reset:", @@ -177,6 +210,7 @@ var ( } }, } + componentsHandlers = map[string]func(client *discordgo.Session, i *discordgo.InteractionCreate){ "create_ticket": func(client *discordgo.Session, i *discordgo.InteractionCreate) { err := client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ @@ -494,33 +528,6 @@ func resetHWID(tableName string, uids []int) { } } -func getIdentifiers(tableName string, uid int) { - query := fmt.Sprintf(`SELECT "StorageIdentifier", "BootIdentifier" - FROM public.%q - WHERE "UID" = $1`, tableName) - - var storageIdentifier, bootIdentifier sql.NullString - err := db.QueryRow(query, uid).Scan(&storageIdentifier, &bootIdentifier) - if err != nil { - if err == sql.ErrNoRows { - fmt.Println("HWID not set") - return - } - fmt.Println("Error querying the database:", err) - return - } - - if !storageIdentifier.Valid { - storageIdentifier = sql.NullString{String: "NULL", Valid: false} - } - - if !bootIdentifier.Valid { - bootIdentifier = sql.NullString{String: "NULL", Valid: false} - } - - fmt.Printf("UID: %d, S: %s, B: %s\n", uid, storageIdentifier.String, bootIdentifier.String) -} - func resetAndVerify(tableName string, uid int) (bool, error) { var beforeHash string err := db.QueryRow(