From d7c884bf1d5d696d3461161f6d64860bef1958a7 Mon Sep 17 00:00:00 2001 From: Joren Date: Sat, 6 Jul 2024 20:07:07 +0200 Subject: [PATCH] Delete channel once request is accepted/declined --- main.go | 105 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 59 insertions(+), 46 deletions(-) diff --git a/main.go b/main.go index 958b7ec..6751be1 100644 --- a/main.go +++ b/main.go @@ -183,7 +183,7 @@ var ( }, }, }, - Flags: discordgo.MessageFlagsEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) if err != nil { @@ -259,55 +259,62 @@ var ( log.Println("Error sending message to the ticket channel:", err) } }, -"accept": func(client *discordgo.Session, i *discordgo.InteractionCreate) { - data := i.MessageComponentData().CustomID - parts := strings.Split(data, "_") - if len(parts) != 3 { - log.Println("Invalid accept button custom ID") - return - } - userID := parts[1] - softwareType := parts[2] - - member, err := client.GuildMember(i.GuildID, userID) - if err != nil { - log.Println("Error fetching member info:", err) - return - } - var userName string - if member.Nick != "" { - userName = member.Nick - } else if member.User.GlobalName != "" { - userName = member.User.GlobalName - } else { - userName = member.User.Username - } + "accept": func(client *discordgo.Session, i *discordgo.InteractionCreate) { + data := i.MessageComponentData().CustomID + parts := strings.Split(data, "_") + if len(parts) != 3 { + log.Println("Invalid accept button custom ID") + return + } + userID := parts[1] + softwareType := parts[2] - reset(userName, softwareType) + member, err := client.GuildMember(i.GuildID, userID) + if err != nil { + log.Println("Error fetching member info:", err) + return + } + var userName string + if member.Nick != "" { + userName = member.Nick + } else if member.User.GlobalName != "" { + userName = member.User.GlobalName + } else { + userName = member.User.Username + } - err = client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: "Request accepted and processed.", - Flags: discordgo.MessageFlagsEphemeral, - }, - }) - if err != nil { - log.Println("Error sending interaction response:", err) - } + reset(userName, softwareType) - dmChannel, err := client.UserChannelCreate(userID) - if err != nil { - log.Println("Error creating DM channel:", err) - return - } + err = client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ + Type: discordgo.InteractionResponseChannelMessageWithSource, + Data: &discordgo.InteractionResponseData{ + Content: "Request accepted and processed.", + Flags: discordgo.MessageFlagsEphemeral, + }, + }) + if err != nil { + log.Println("Error sending interaction response:", err) + } - _, err = client.ChannelMessageSend(dmChannel.ID, fmt.Sprintf("Your reset request for %s has been accepted and processed.", softwareType)) - if err != nil { - log.Println("Error sending DM:", err) - } -}, + + _,err = client.ChannelDelete(i.ChannelID) + if err != nil { + log.Println("Error deleting channel:", err) + } + + + dmChannel, err := client.UserChannelCreate(userID) + if err != nil { + log.Println("Error creating DM channel:", err) + return + } + + _, err = client.ChannelMessageSend(dmChannel.ID, fmt.Sprintf("Your reset request for %s has been accepted and processed.", softwareType)) + if err != nil { + log.Println("Error sending DM:", err) + } + }, "decline": func(client *discordgo.Session, i *discordgo.InteractionCreate) { data := i.MessageComponentData().CustomID @@ -317,7 +324,6 @@ var ( return } userID := parts[1] - err := client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, @@ -330,6 +336,13 @@ var ( log.Println("Error sending interaction response:", err) } + + _,err = client.ChannelDelete(i.ChannelID) + if err != nil { + log.Println("Error deleting channel:", err) + } + + dmChannel, err := client.UserChannelCreate(userID) if err != nil { log.Println("Error creating DM channel:", err)