Skip to content

Commit

Permalink
chore(Random): slight restructure of subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
Kesuaheli committed Dec 27, 2024
1 parent 9576a27 commit 980a2f6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
15 changes: 10 additions & 5 deletions modules/random/handleSubcommandCoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
17 changes: 11 additions & 6 deletions modules/random/handleSubcommandDice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions modules/random/handleSubcommandTeams.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down

0 comments on commit 980a2f6

Please sign in to comment.