refactor: everthing discord command

made it private and made it deffer the message instead of executing after
This commit is contained in:
Eccentric 2023-12-31 15:00:52 +00:00 committed by GitHub
parent 0c2ab10297
commit 0a735aaf8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 50 deletions

View File

@ -134,33 +134,6 @@ func banHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
}) })
} }
func GiveFLHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
looker := person.FindByDiscord(i.Member.User.ID)
if looker == nil {
s.InteractionRespond(i.Interaction, &ErrorNoPermission)
return
}
if !looker.HasPermission(person.PermissionBan) {
s.InteractionRespond(i.Interaction, &ErrorNoPermission)
return
}
player := getPersonFromOptions(i.ApplicationCommandData(), s)
if player == nil {
s.InteractionRespond(i.Interaction, &ErrorInvalidDisplayOrDiscord)
return
}
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: player.DisplayName + " has been granted everything.",
},
})
fortnite.GiveEverything(player)
}
func unbanHandler(s *discordgo.Session, i *discordgo.InteractionCreate) { func unbanHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
looker := person.FindByDiscord(i.Member.User.ID) looker := person.FindByDiscord(i.Member.User.ID)
if looker == nil { if looker == nil {
@ -320,3 +293,37 @@ func takeItemHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
}, },
}) })
} }
func giveEverythingHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
looker := person.FindByDiscord(i.Member.User.ID)
if looker == nil {
s.InteractionRespond(i.Interaction, &ErrorNoPermission)
return
}
if !looker.HasPermission(person.PermissionGiveItem) {
s.InteractionRespond(i.Interaction, &ErrorNoPermission)
return
}
player := getPersonFromOptions(i.ApplicationCommandData(), s)
if player == nil {
s.InteractionRespond(i.Interaction, &ErrorInvalidDisplayOrDiscord)
return
}
if !player.HasPermission(person.PermissionFullLocker) {
s.InteractionRespond(i.Interaction, &ErrorNoPermission)
return
}
s.InteractionResponseEdit(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseDefferedChannelMessageWithSource,
})
fortnite.GiveEverything(player)
s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: player.DisplayName + " has been granted everything.",
})
}

View File

@ -109,29 +109,6 @@ func addCommands() {
Handler: banHandler, Handler: banHandler,
AdminOnly: true, AdminOnly: true,
}) })
addCommand(&DiscordCommand{
Command: &discordgo.ApplicationCommand{
Name: "give-everything",
Description: "Give a player full locker",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionUser,
Name: "discord",
Description: "The discord account of the player.",
Required: false,
},
{
Type: discordgo.ApplicationCommandOptionString,
Name: "display",
Description: "The display name of the player.",
Required: false,
},
},
},
Handler: GiveFLHandler,
AdminOnly: true,
})
addCommand(&DiscordCommand{ addCommand(&DiscordCommand{
Command: &discordgo.ApplicationCommand{ Command: &discordgo.ApplicationCommand{
@ -237,6 +214,29 @@ func addCommands() {
Handler: takeItemHandler, Handler: takeItemHandler,
AdminOnly: true, AdminOnly: true,
}) })
addCommand(&DiscordCommand{
Command: &discordgo.ApplicationCommand{
Name: "everything",
Description: "Give a player full locker",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionUser,
Name: "discord",
Description: "The discord account of the player.",
Required: false,
},
{
Type: discordgo.ApplicationCommandOptionString,
Name: "display",
Description: "The display name of the player.",
Required: false,
},
},
},
Handler: giveEverythingHandler,
AdminOnly: true,
})
} }
func getPersonFromOptions(data discordgo.ApplicationCommandInteractionData, s *discordgo.Session) *person.Person { func getPersonFromOptions(data discordgo.ApplicationCommandInteractionData, s *discordgo.Session) *person.Person {

View File

@ -10,6 +10,7 @@ const (
PermissionGiveItem Permission = "give_item" PermissionGiveItem Permission = "give_item"
PermissionTakeItem Permission = "take_item" PermissionTakeItem Permission = "take_item"
PermissionReset Permission = "reset" PermissionReset Permission = "reset"
PermissionFullLocker Permission = "full_locker"
PermissionAll Permission = "all" PermissionAll Permission = "all"
) )