-
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: added secret santa message command
- Loading branch information
Showing
6 changed files
with
137 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,46 @@ | ||
package secretsanta | ||
|
||
import ( | ||
"cake4everybot/data/lang" | ||
"cake4everybot/util" | ||
|
||
) | ||
|
||
func (cmd MsgCmd) handler() { | ||
const emojiName = "👍" | ||
|
||
msg := cmd.data.Resolved.Messages[cmd.data.TargetID] | ||
if len(msg.Reactions) == 0 { | ||
cmd.ReplyHiddenf(lang.GetDefault(tp+"msg.setup.no_reactions"), emojiName) | ||
return | ||
} | ||
var reaction *discordgo.MessageReactions | ||
for _, r := range msg.Reactions { | ||
if r.Emoji.Name != emojiName { | ||
continue | ||
} | ||
reaction = r | ||
break | ||
} | ||
|
||
if reaction == nil { | ||
cmd.ReplyHiddenf(lang.GetDefault(tp+"msg.setup.no_reactions"), emojiName) | ||
return | ||
} | ||
|
||
emojiID := reaction.Emoji.ID | ||
if emojiID == "" { | ||
emojiID = reaction.Emoji.Name | ||
} | ||
users, err := cmd.Session.MessageReactions(msg.ChannelID, msg.ID, emojiID, 100, "", "") | ||
if err != nil { | ||
log.Printf("Error on get users: %v\n", err) | ||
cmd.ReplyError() | ||
return | ||
} | ||
|
||
if len(users) < 2 { | ||
cmd.ReplyHiddenf(lang.GetDefault(tp+"msg.setup.not_enough_reactions"), 2) | ||
return | ||
} | ||
} |
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,49 @@ | ||
package secretsanta | ||
|
||
import ( | ||
"cake4everybot/data/lang" | ||
"cake4everybot/util" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
// MsgCmd represents the mesaage command of the secretsanta package. It adds the ability to start a | ||
// new secret santa game. | ||
type MsgCmd struct { | ||
secretSantaBase | ||
|
||
data discordgo.ApplicationCommandInteractionData | ||
ID string | ||
} | ||
|
||
// AppCmd (ApplicationCommand) returns the definition of the chat command | ||
func (cmd *MsgCmd) AppCmd() *discordgo.ApplicationCommand { | ||
return &discordgo.ApplicationCommand{ | ||
Type: discordgo.MessageApplicationCommand, | ||
Name: lang.GetDefault(tp + "setup"), | ||
NameLocalizations: util.TranslateLocalization(tp + "setup"), | ||
} | ||
} | ||
|
||
// Handle handles the functionality of a command | ||
func (cmd *MsgCmd) 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 | ||
} | ||
|
||
cmd.data = cmd.Interaction.ApplicationCommandData() | ||
cmd.handler() | ||
} | ||
|
||
// SetID sets the registered command ID for internal uses after uploading to discord | ||
func (cmd *MsgCmd) SetID(id string) { | ||
cmd.ID = id | ||
} | ||
|
||
// GetID gets the registered command ID | ||
func (cmd *MsgCmd) 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,22 @@ | ||
package secretsanta | ||
|
||
import ( | ||
"cake4everybot/util" | ||
logger "log" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
const ( | ||
// Prefix for translation key, i.e.: | ||
// key := tp+"base" // => adventcalendar | ||
tp = "discord.command.secretsanta." | ||
) | ||
|
||
var log = logger.New(logger.Writer(), "[SecretSanta] ", logger.LstdFlags|logger.Lmsgprefix) | ||
|
||
type secretSantaBase struct { | ||
util.InteractionUtil | ||
member *discordgo.Member | ||
user *discordgo.User | ||
} |