-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Random): added random command setup
- Loading branch information
Showing
8 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package random | ||
|
||
import ( | ||
"cake4everybot/data/lang" | ||
"cake4everybot/util" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
const ( | ||
// Prefix for translation key, i.e.: | ||
// key := tp+"base" // => random | ||
tp = "discord.command.random." | ||
) | ||
|
||
type Chat struct { | ||
randomBase | ||
ID string | ||
} | ||
|
||
type subcommand interface { | ||
appCmd() *discordgo.ApplicationCommandOption | ||
handle() | ||
} | ||
|
||
func (cmd Chat) AppCmd() *discordgo.ApplicationCommand { | ||
options := []*discordgo.ApplicationCommandOption{ | ||
cmd.subcommandCoin().appCmd(), | ||
cmd.subcommandDice().appCmd(), | ||
cmd.subcommandTeams().appCmd(), | ||
} | ||
|
||
return &discordgo.ApplicationCommand{ | ||
Name: lang.GetDefault(tp + "base"), | ||
NameLocalizations: util.TranslateLocalization(tp + "base"), | ||
Description: lang.GetDefault(tp + "base.description"), | ||
DescriptionLocalizations: util.TranslateLocalization(tp + "base.description"), | ||
Options: options, | ||
} | ||
} | ||
|
||
func (cmd Chat) Handle(s *discordgo.Session, i *discordgo.InteractionCreate) { | ||
cmd.InteractionUtil = util.InteractionUtil{Session: s, Interaction: i} | ||
cmd.member = i.Member | ||
cmd.user = i.User | ||
if i.Member != nil { | ||
cmd.user = i.Member.User | ||
} else if i.User != nil { | ||
cmd.member = &discordgo.Member{User: i.User} | ||
} | ||
|
||
subcommandName := i.ApplicationCommandData().Options[0].Name | ||
var sub subcommand | ||
switch subcommandName { | ||
case lang.GetDefault(tp + "option.dice"): | ||
sub = cmd.subcommandDice() | ||
case lang.GetDefault(tp + "option.coin"): | ||
sub = cmd.subcommandCoin() | ||
case lang.GetDefault(tp + "option.teams"): | ||
sub = cmd.subcommandTeams() | ||
default: | ||
return | ||
} | ||
|
||
sub.handle() | ||
} | ||
|
||
// SetID sets the registered command ID for internal uses after uploading to discord | ||
func (cmd *Chat) SetID(id string) { | ||
cmd.ID = id | ||
} | ||
|
||
// GetID gets the registered command ID | ||
func (cmd Chat) GetID() string { | ||
return cmd.ID | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package random | ||
|
||
import ( | ||
"cake4everybot/data/lang" | ||
"cake4everybot/util" | ||
"math/rand/v2" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
// The set subcommand. Used when executing the slash-command "/random coin". | ||
type subcommandCoin struct { | ||
Chat | ||
*discordgo.ApplicationCommandInteractionDataOption | ||
} | ||
|
||
// Constructor for subcommandCoin, the struct for the slash-command "/random coin". | ||
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, | ||
} | ||
} | ||
|
||
func (cmd subcommandCoin) appCmd() *discordgo.ApplicationCommandOption { | ||
return &discordgo.ApplicationCommandOption{ | ||
Type: discordgo.ApplicationCommandOptionSubCommand, | ||
Name: lang.GetDefault(tp + "option.coin"), | ||
NameLocalizations: *util.TranslateLocalization(tp + "option.coin"), | ||
Description: lang.GetDefault(tp + "option.coin.description"), | ||
DescriptionLocalizations: *util.TranslateLocalization(tp + "option.coin.description"), | ||
} | ||
} | ||
|
||
func (cmd subcommandCoin) handle() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package random | ||
|
||
import ( | ||
"cake4everybot/data/lang" | ||
"cake4everybot/util" | ||
"math/rand/v2" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
// The set subcommand. Used when executing the slash-command "/random dice". | ||
type subcommandDice struct { | ||
Chat | ||
*discordgo.ApplicationCommandInteractionDataOption | ||
} | ||
|
||
// Constructor for subcommandDice, the struct for the slash-command "/random dice". | ||
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, | ||
} | ||
} | ||
|
||
func (cmd subcommandDice) appCmd() *discordgo.ApplicationCommandOption { | ||
options := []*discordgo.ApplicationCommandOption{ | ||
cmd.optionRange(), | ||
} | ||
|
||
return &discordgo.ApplicationCommandOption{ | ||
Type: discordgo.ApplicationCommandOptionSubCommand, | ||
Name: lang.GetDefault(tp + "option.dice"), | ||
NameLocalizations: *util.TranslateLocalization(tp + "option.dice"), | ||
Description: lang.GetDefault(tp + "option.dice.description"), | ||
DescriptionLocalizations: *util.TranslateLocalization(tp + "option.dice.description"), | ||
Options: options, | ||
} | ||
} | ||
|
||
func (cmd subcommandDice) optionRange() *discordgo.ApplicationCommandOption { | ||
minValueTwo := float64(2) | ||
return &discordgo.ApplicationCommandOption{ | ||
Type: discordgo.ApplicationCommandOptionInteger, | ||
Name: lang.GetDefault(tp + "option.dice.option.range"), | ||
NameLocalizations: *util.TranslateLocalization(tp + "option.dice.option.range"), | ||
Description: lang.GetDefault(tp + "option.dice.option.range.description"), | ||
DescriptionLocalizations: *util.TranslateLocalization(tp + "option.dice.option.range.description"), | ||
Required: false, | ||
MinValue: &minValueTwo, | ||
} | ||
} | ||
|
||
func (cmd subcommandDice) handle() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package random | ||
|
||
import ( | ||
"cake4everybot/data/lang" | ||
"cake4everybot/util" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
// The set subcommand. Used when executing the slash-command "/random teams". | ||
type subcommandTeams struct { | ||
Chat | ||
*discordgo.ApplicationCommandInteractionDataOption | ||
} | ||
|
||
// Constructor for subcommandTeams, the struct for the slash-command "/random teams". | ||
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, | ||
} | ||
} | ||
|
||
func (cmd subcommandTeams) appCmd() *discordgo.ApplicationCommandOption { | ||
return &discordgo.ApplicationCommandOption{ | ||
Type: discordgo.ApplicationCommandOptionSubCommand, | ||
Name: lang.GetDefault(tp + "option.teams"), | ||
NameLocalizations: *util.TranslateLocalization(tp + "option.teams"), | ||
Description: lang.GetDefault(tp + "option.teams.description"), | ||
DescriptionLocalizations: *util.TranslateLocalization(tp + "option.teams.description"), | ||
} | ||
} | ||
|
||
func (cmd subcommandTeams) handle() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package random | ||
|
||
import ( | ||
"cake4everybot/logger" | ||
"cake4everybot/util" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
var log = logger.New("Random") | ||
|
||
type randomBase struct { | ||
util.InteractionUtil | ||
member *discordgo.Member | ||
user *discordgo.User | ||
} |