From 980a2f6c76a5f261d7c7a5538109e798b6f3f4b3 Mon Sep 17 00:00:00 2001 From: Kesuaheli Date: Sat, 28 Dec 2024 00:28:40 +0100 Subject: [PATCH] chore(Random): slight restructure of subcommands --- modules/random/handleSubcommandCoin.go | 15 ++++++++++----- modules/random/handleSubcommandDice.go | 17 +++++++++++------ modules/random/handleSubcommandTeams.go | 15 ++++++++++----- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/modules/random/handleSubcommandCoin.go b/modules/random/handleSubcommandCoin.go index c6c20f2..c5c44cb 100644 --- a/modules/random/handleSubcommandCoin.go +++ b/modules/random/handleSubcommandCoin.go @@ -10,19 +10,24 @@ import ( // The set subcommand. Used when executing the slash-command "/random coin". type subcommandCoin struct { - Chat - *discordgo.ApplicationCommandInteractionDataOption + randomBase + *Chat + data *discordgo.ApplicationCommandInteractionDataOption +} + +func (rb randomBase) subcommandCoin() subcommandCoin { + return subcommandCoin{randomBase: rb} } // Constructor for subcommandCoin, the struct for the slash-command "/random coin". -func (cmd Chat) subcommandCoin() subcommandCoin { +func (cmd *Chat) subcommandCoin() subcommandCoin { var subcommand *discordgo.ApplicationCommandInteractionDataOption if cmd.Interaction != nil { subcommand = cmd.Interaction.ApplicationCommandData().Options[0] } return subcommandCoin{ - Chat: cmd, - ApplicationCommandInteractionDataOption: subcommand, + Chat: cmd, + data: subcommand, } } diff --git a/modules/random/handleSubcommandDice.go b/modules/random/handleSubcommandDice.go index 6f121a2..efc7643 100644 --- a/modules/random/handleSubcommandDice.go +++ b/modules/random/handleSubcommandDice.go @@ -11,21 +11,26 @@ import ( // The set subcommand. Used when executing the slash-command "/random dice". type subcommandDice struct { - Chat - *discordgo.ApplicationCommandInteractionDataOption + randomBase + *Chat + data *discordgo.ApplicationCommandInteractionDataOption diceRange *discordgo.ApplicationCommandInteractionDataOption // optional } +func (rb randomBase) subcommandDice() subcommandDice { + return subcommandDice{randomBase: rb} +} + // Constructor for subcommandDice, the struct for the slash-command "/random dice". -func (cmd Chat) subcommandDice() subcommandDice { +func (cmd *Chat) subcommandDice() subcommandDice { var subcommand *discordgo.ApplicationCommandInteractionDataOption if cmd.Interaction != nil { subcommand = cmd.Interaction.ApplicationCommandData().Options[0] } return subcommandDice{ - Chat: cmd, - ApplicationCommandInteractionDataOption: subcommand, + Chat: cmd, + data: subcommand, } } @@ -58,7 +63,7 @@ func (cmd subcommandDice) optionRange() *discordgo.ApplicationCommandOption { } func (cmd subcommandDice) handle() { - for _, opt := range cmd.Options { + for _, opt := range cmd.data.Options { switch opt.Name { case lang.GetDefault(tp + "option.dice.option.range"): cmd.diceRange = opt diff --git a/modules/random/handleSubcommandTeams.go b/modules/random/handleSubcommandTeams.go index 48c0127..e506c3e 100644 --- a/modules/random/handleSubcommandTeams.go +++ b/modules/random/handleSubcommandTeams.go @@ -9,19 +9,24 @@ import ( // The set subcommand. Used when executing the slash-command "/random teams". type subcommandTeams struct { - Chat - *discordgo.ApplicationCommandInteractionDataOption + randomBase + *Chat + data *discordgo.ApplicationCommandInteractionDataOption +} + +func (rb randomBase) subcommandTeams() subcommandTeams { + return subcommandTeams{randomBase: rb} } // Constructor for subcommandTeams, the struct for the slash-command "/random teams". -func (cmd Chat) subcommandTeams() subcommandTeams { +func (cmd *Chat) subcommandTeams() subcommandTeams { var subcommand *discordgo.ApplicationCommandInteractionDataOption if cmd.Interaction != nil { subcommand = cmd.Interaction.ApplicationCommandData().Options[0] } return subcommandTeams{ - Chat: cmd, - ApplicationCommandInteractionDataOption: subcommand, + Chat: cmd, + data: subcommand, } }