Delete channel once request is accepted/declined

This commit is contained in:
Joren 2024-07-06 20:07:07 +02:00
parent 71bec93b58
commit d7c884bf1d
Signed by: Joren
GPG Key ID: 280E33DFBC0F1B55

103
main.go
View File

@ -259,55 +259,62 @@ var (
log.Println("Error sending message to the ticket channel:", err) log.Println("Error sending message to the ticket channel:", err)
} }
}, },
"accept": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
data := i.MessageComponentData().CustomID "accept": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
parts := strings.Split(data, "_") data := i.MessageComponentData().CustomID
if len(parts) != 3 { parts := strings.Split(data, "_")
log.Println("Invalid accept button custom ID") if len(parts) != 3 {
return log.Println("Invalid accept button custom ID")
} return
userID := parts[1] }
softwareType := parts[2] 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
}
reset(userName, softwareType)
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)
}
member, err := client.GuildMember(i.GuildID, userID) _,err = client.ChannelDelete(i.ChannelID)
if err != nil { if err != nil {
log.Println("Error fetching member info:", err) log.Println("Error deleting channel:", 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
}
reset(userName, softwareType)
err = client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ dmChannel, err := client.UserChannelCreate(userID)
Type: discordgo.InteractionResponseChannelMessageWithSource, if err != nil {
Data: &discordgo.InteractionResponseData{ log.Println("Error creating DM channel:", err)
Content: "Request accepted and processed.", return
Flags: discordgo.MessageFlagsEphemeral, }
},
})
if err != nil {
log.Println("Error sending interaction response:", err)
}
dmChannel, err := client.UserChannelCreate(userID) _, err = client.ChannelMessageSend(dmChannel.ID, fmt.Sprintf("Your reset request for %s has been accepted and processed.", softwareType))
if err != nil { if err != nil {
log.Println("Error creating DM channel:", err) log.Println("Error sending DM:", 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) { "decline": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
data := i.MessageComponentData().CustomID data := i.MessageComponentData().CustomID
@ -318,7 +325,6 @@ var (
} }
userID := parts[1] userID := parts[1]
err := client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ err := client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource, Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{ Data: &discordgo.InteractionResponseData{
@ -330,6 +336,13 @@ var (
log.Println("Error sending interaction response:", err) 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) dmChannel, err := client.UserChannelCreate(userID)
if err != nil { if err != nil {
log.Println("Error creating DM channel:", err) log.Println("Error creating DM channel:", err)