Skip to content

Commit

Permalink
feat: added secret santa message command
Browse files Browse the repository at this point in the history
  • Loading branch information
Kesuaheli committed Nov 16, 2024
1 parent 2699af1 commit dc7fae2
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 0 deletions.
9 changes: 9 additions & 0 deletions data/lang/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ discord.command:
msg.winner.details: "__Gewinner: %s__\nTickets: %d/24\nGewinnchance: %.2f%%"
msg.winner.congratulation: "Herzlichen Glückwunsch, %s! :heart:\nFrohe Weihnachten an alle!"

secretsanta:
base: wichteln
display: Wichteln

title: Wichteln

msg.setup.no_reactions: Diese Nachricht hat keine Reaktionen. Nur Leute, die mit %s reagiert haben, werden eingeschlossen.
msg.setup.not_enough_reactions: Nicht genug Reaktionen um zu starten. Es werden mindestens %d Reaktionen benötigt.

module:
adventcalendar:
post.message: Noch %d Mal schlafen bis Heilig Abend! Heute öffnet sich das **Türchen %d**.
Expand Down
9 changes: 9 additions & 0 deletions data/lang/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ discord.command:
msg.winner.details: "__Winner: %s__\nTickets: %d/24\nProbability of winning: %.2f%%"
msg.winner.congratulation: "Congratulations, %s! :heart:\nMerry XMas everyone!"

secretsanta:
setup: Secret Santa
display: Secret Santa

title: Secret Santa

msg.setup.no_reactions: This message doesn't have any vote reactions. Only members who reated with %s are included.
msg.setup.not_enough_reactions: Not enough votes to start a game. At least %d votes are required.

module:
adventcalendar:
post.message: Just sleep %d more times! Its time for **door %d**.
Expand Down
2 changes: 2 additions & 0 deletions event/command/commandBase.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"cake4everybot/modules/adventcalendar"
"cake4everybot/modules/birthday"
"cake4everybot/modules/info"
"cake4everybot/modules/secretsanta"
"cake4everybot/util"
"fmt"
"log"
Expand Down Expand Up @@ -69,6 +70,7 @@ func Register(s *discordgo.Session, guildID string) error {
commandsList = append(commandsList, &birthday.Chat{})
commandsList = append(commandsList, &info.Chat{})
commandsList = append(commandsList, &adventcalendar.Chat{})
commandsList = append(commandsList, &secretsanta.MsgCmd{})
// messsage commands
// user commands
commandsList = append(commandsList, &birthday.UserShow{})
Expand Down
46 changes: 46 additions & 0 deletions modules/secretsanta/handlerMessageSetup.go
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
}
}
49 changes: 49 additions & 0 deletions modules/secretsanta/messageCommandSetup.go
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"
)

type MsgCmd struct {
secretSantaBase

data discordgo.ApplicationCommandInteractionData
ID string
}

// Definition of a command.
// E.g., name, description, options, subcommands.
func (cmd *MsgCmd) AppCmd() *discordgo.ApplicationCommand {
return &discordgo.ApplicationCommand{
Type: discordgo.MessageApplicationCommand,
Name: lang.GetDefault(tp + "setup"),
NameLocalizations: util.TranslateLocalization(tp + "setup"),
}
}

// Function of a command.
// All things that should happen at execution.
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()
}

// Sets the registered command ID for internal uses after uploading to discord
func (cmd *MsgCmd) SetID(id string) {
cmd.ID = id
}

// Gets the registered command ID
func (cmd *MsgCmd) GetID() string {
return cmd.ID
}
22 changes: 22 additions & 0 deletions modules/secretsanta/secretsantabase.go
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
}

0 comments on commit dc7fae2

Please sign in to comment.