|
| 1 | +package secretsanta |
| 2 | + |
| 3 | +import ( |
| 4 | + "cake4everybot/data/lang" |
| 5 | + "cake4everybot/util" |
| 6 | + |
| 7 | + "github.com/bwmarrin/discordgo" |
| 8 | +) |
| 9 | + |
| 10 | +// The Chat (slash) command of the secret santa package. |
| 11 | +type Chat struct { |
| 12 | + secretSantaBase |
| 13 | + ID string |
| 14 | +} |
| 15 | + |
| 16 | +// AppCmd (ApplicationCommand) returns the definition of the chat command |
| 17 | +func (Chat) AppCmd() *discordgo.ApplicationCommand { |
| 18 | + return &discordgo.ApplicationCommand{ |
| 19 | + Name: lang.GetDefault(tp + "cmd.base"), |
| 20 | + NameLocalizations: util.TranslateLocalization(tp + "cmd.base"), |
| 21 | + Description: lang.GetDefault(tp + "cmd.base.description"), |
| 22 | + DescriptionLocalizations: util.TranslateLocalization(tp + "cmd.base.description"), |
| 23 | + Options: []*discordgo.ApplicationCommandOption{ |
| 24 | + { |
| 25 | + Type: discordgo.ApplicationCommandOptionSubCommand, |
| 26 | + Name: lang.GetDefault(tp + "cmd.option.show"), |
| 27 | + NameLocalizations: *util.TranslateLocalization(tp + "cmd.option.show"), |
| 28 | + Description: lang.GetDefault(tp + "cmd.option.show.description"), |
| 29 | + DescriptionLocalizations: *util.TranslateLocalization(tp + "cmd.option.show.description"), |
| 30 | + }, |
| 31 | + { |
| 32 | + Type: discordgo.ApplicationCommandOptionSubCommand, |
| 33 | + Name: lang.GetDefault(tp + "cmd.option.update"), |
| 34 | + NameLocalizations: *util.TranslateLocalization(tp + "cmd.option.update"), |
| 35 | + Description: lang.GetDefault(tp + "cmd.option.update.description"), |
| 36 | + DescriptionLocalizations: *util.TranslateLocalization(tp + "cmd.option.update.description"), |
| 37 | + }, |
| 38 | + }, |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +// Handle handles the functionality of a command |
| 43 | +func (cmd Chat) Handle(s *discordgo.Session, i *discordgo.InteractionCreate) { |
| 44 | + cmd.InteractionUtil = util.InteractionUtil{Session: s, Interaction: i} |
| 45 | + cmd.member = i.Member |
| 46 | + cmd.user = i.User |
| 47 | + if i.Member != nil { |
| 48 | + cmd.user = i.Member.User |
| 49 | + } else if i.User != nil { |
| 50 | + cmd.member = &discordgo.Member{User: i.User} |
| 51 | + } |
| 52 | + |
| 53 | + switch i.ApplicationCommandData().Options[0].Name { |
| 54 | + case lang.GetDefault(tp + "cmd.option.show"): |
| 55 | + cmd.handleSubcommandShow() |
| 56 | + return |
| 57 | + case lang.GetDefault(tp + "cmd.option.update"): |
| 58 | + cmd.handleSubcommandUpdate() |
| 59 | + return |
| 60 | + } |
| 61 | + |
| 62 | +} |
| 63 | + |
| 64 | +// SetID sets the registered command ID for internal uses after uploading to discord |
| 65 | +func (cmd *Chat) SetID(id string) { |
| 66 | + cmd.ID = id |
| 67 | +} |
| 68 | + |
| 69 | +// GetID gets the registered command ID |
| 70 | +func (cmd Chat) GetID() string { |
| 71 | + return cmd.ID |
| 72 | +} |
0 commit comments