From 0a735aaf8a2f23502c49ccd8f62073c17c1b63f4 Mon Sep 17 00:00:00 2001 From: Eccentric Date: Sun, 31 Dec 2023 15:00:52 +0000 Subject: [PATCH] refactor: everthing discord command made it private and made it deffer the message instead of executing after --- discord/admin.go | 61 ++++++++++++++++++++++++------------------- discord/handlers.go | 46 ++++++++++++++++---------------- person/permissions.go | 1 + 3 files changed, 58 insertions(+), 50 deletions(-) diff --git a/discord/admin.go b/discord/admin.go index ea29203..2d99601 100644 --- a/discord/admin.go +++ b/discord/admin.go @@ -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) { looker := person.FindByDiscord(i.Member.User.ID) 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.", + }) +} \ No newline at end of file diff --git a/discord/handlers.go b/discord/handlers.go index 5c94749..de8beac 100644 --- a/discord/handlers.go +++ b/discord/handlers.go @@ -109,29 +109,6 @@ func addCommands() { Handler: banHandler, 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{ Command: &discordgo.ApplicationCommand{ @@ -237,6 +214,29 @@ func addCommands() { Handler: takeItemHandler, 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 { diff --git a/person/permissions.go b/person/permissions.go index ea500eb..69988b6 100644 --- a/person/permissions.go +++ b/person/permissions.go @@ -10,6 +10,7 @@ const ( PermissionGiveItem Permission = "give_item" PermissionTakeItem Permission = "take_item" PermissionReset Permission = "reset" + PermissionFullLocker Permission = "full_locker" PermissionAll Permission = "all" ) \ No newline at end of file