Merge pull request 'Make sure people in the admin_role can do the setupo' (#3) from Perms into main

Reviewed-on: #3
This commit is contained in:
Joren 2024-07-06 22:02:36 +02:00
commit 2e4a30ea01

61
main.go
View File

@ -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(