-
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(Secret Santa): added secret santa admin commands
- Loading branch information
Showing
9 changed files
with
219 additions
and
23 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,72 @@ | ||
package secretsanta | ||
|
||
import ( | ||
"cake4everybot/data/lang" | ||
"cake4everybot/util" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
// The Chat (slash) command of the secret santa package. | ||
type Chat struct { | ||
secretSantaBase | ||
ID string | ||
} | ||
|
||
// AppCmd (ApplicationCommand) returns the definition of the chat command | ||
func (Chat) AppCmd() *discordgo.ApplicationCommand { | ||
return &discordgo.ApplicationCommand{ | ||
Name: lang.GetDefault(tp + "cmd.base"), | ||
NameLocalizations: util.TranslateLocalization(tp + "cmd.base"), | ||
Description: lang.GetDefault(tp + "cmd.base.description"), | ||
DescriptionLocalizations: util.TranslateLocalization(tp + "cmd.base.description"), | ||
Options: []*discordgo.ApplicationCommandOption{ | ||
{ | ||
Type: discordgo.ApplicationCommandOptionSubCommand, | ||
Name: lang.GetDefault(tp + "cmd.option.show"), | ||
NameLocalizations: *util.TranslateLocalization(tp + "cmd.option.show"), | ||
Description: lang.GetDefault(tp + "cmd.option.show.description"), | ||
DescriptionLocalizations: *util.TranslateLocalization(tp + "cmd.option.show.description"), | ||
}, | ||
{ | ||
Type: discordgo.ApplicationCommandOptionSubCommand, | ||
Name: lang.GetDefault(tp + "cmd.option.update"), | ||
NameLocalizations: *util.TranslateLocalization(tp + "cmd.option.update"), | ||
Description: lang.GetDefault(tp + "cmd.option.update.description"), | ||
DescriptionLocalizations: *util.TranslateLocalization(tp + "cmd.option.update.description"), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// Handle handles the functionality of a command | ||
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} | ||
} | ||
|
||
switch i.ApplicationCommandData().Options[0].Name { | ||
case lang.GetDefault(tp + "cmd.option.show"): | ||
cmd.handleSubcommandShow() | ||
return | ||
case lang.GetDefault(tp + "cmd.option.update"): | ||
cmd.handleSubcommandUpdate() | ||
return | ||
} | ||
|
||
} | ||
|
||
// 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,19 @@ | ||
package secretsanta | ||
|
||
// handleSubcommandShow handles the functionality of the show subcommand | ||
func (cmd Chat) handleSubcommandShow() { | ||
players, err := cmd.getPlayers() | ||
if err != nil { | ||
cmd.ReplyError() | ||
return | ||
} | ||
|
||
var list string | ||
for _, p := range players { | ||
list += "- " + | ||
p.Mention() + | ||
" - (`" + p.User.Username + "`)" + | ||
"\n" | ||
} | ||
cmd.ReplyHiddenSimpleEmbed(0x690042, list) | ||
} |
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,53 @@ | ||
package secretsanta | ||
|
||
import ( | ||
"cake4everybot/data/lang" | ||
"cake4everybot/util" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
// handleSubcommandUpdate handles the functionality of the update subcommand | ||
func (cmd Chat) handleSubcommandUpdate() { | ||
cmd.ReplyDeferedHidden() | ||
players, err := cmd.getPlayers() | ||
if err != nil { | ||
cmd.ReplyError() | ||
return | ||
} | ||
|
||
var failedToSend string | ||
for _, p := range players { | ||
var DMChannel *discordgo.Channel | ||
DMChannel, err = cmd.Session.UserChannelCreate(p.User.ID) | ||
if err != nil { | ||
log.Printf("ERROR: could not create DM channel for user %s: %+v", p.User.ID, err) | ||
failedToSend += "\n- " + p.Mention() | ||
continue | ||
} | ||
|
||
if p.MessageID == "" { | ||
var msg *discordgo.Message | ||
msg, err = cmd.Session.ChannelMessageSendComplex(DMChannel.ID, cmd.inviteMessage(p)) | ||
if err != nil { | ||
log.Printf("ERROR: could not send invite message for %s: %+v", p.DisplayName(), err) | ||
failedToSend += "\n- " + p.Mention() | ||
continue | ||
} | ||
p.MessageID = msg.ID | ||
} else { | ||
_, err = cmd.Session.ChannelMessageEditComplex(util.MessageComplexEdit(cmd.inviteMessage(p), DMChannel.ID, p.MessageID)) | ||
if err != nil { | ||
log.Printf("ERROR: could not update bot message for %s '%s/%s': %+v", p.DisplayName(), cmd.Interaction.ChannelID, p.MessageID, err) | ||
failedToSend += "\n- " + p.Mention() | ||
return | ||
} | ||
} | ||
} | ||
|
||
if failedToSend != "" { | ||
cmd.ReplyHiddenf(lang.GetDefault(tp+"msg.cmd.update.error"), failedToSend) | ||
return | ||
} | ||
cmd.ReplyHiddenf(lang.GetDefault(tp+"msg.cmd.update.success"), len(players)) | ||
} |
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