Skip to content

Commit 78699f3

Browse files
authored
feat(Secret Santa): merged pull request #13
2 parents c7535af + 9358940 commit 78699f3

20 files changed

+1187
-18
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ cake4everybot
1717

1818
# configuration files for tokens, access keys and other connection data
1919
*env.yaml
20+
21+
# runtime config files (as described in config.yml)
22+
modules/secretsanta/backlist.json
23+
modules/secretsanta/players.json
24+
twitch/prizes.json
25+
twitch/times.json

config.yaml

+47-8
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,65 @@ event:
3333

3434
adventcalendar:
3535
images: data/images/adventcalendar
36-
# Name: The name of this emoji, e.g. '🎅', '❤️' when a default emoji
37-
# ID: The snowflake ID if when a custom emoji
38-
# Animated: Whether this emoji is animated. Defaults to false
39-
emoji.name:
40-
#emoji.id:
41-
#emoji.animated: true
36+
37+
secretsanta:
38+
# the filepath for the players
39+
players: modules/secretsanta/players.json
40+
# the filepath for the blacklist
41+
# the blacklist maps a user ID to a list of user IDs that should not be matched
42+
blacklist: modules/secretsanta/backlist.json
4243

4344
twitch_giveaway:
4445
# The amount of points a single giveaway ticket costs.
4546
ticket_cost: 1000
46-
# Cooldown in minutes before beeing able to by another ticket
47+
# Cooldown in minutes before beeing able to buy another ticket
4748
cooldown: 15
4849
# the filepath for of the json giveaway prizes
4950
prizes: twitch/prizes.json
5051
# the filepath for storing the giveaway cooldown times
5152
times: twitch/times.json
5253

54+
emoji:
55+
# Configuration for emojis used by the bot
56+
# Name: The name of this emoji, e.g. '🎅', '❤️' when a default emoji
57+
# ID: The snowflake ID when a custom emoji
58+
# Animated: Whether this emoji is animated. Defaults to false if not set
59+
60+
# Voting for yes
61+
vote.yes:
62+
name: 👍
63+
#id:
64+
#animated: true
65+
# Voting for no
66+
vote.no:
67+
name: 👎
68+
#id:
69+
#animated: true
70+
# Emoji for entering the advent calendar giveaway
71+
adventcalendar:
72+
name:
73+
#id:
74+
#animated: true
75+
secretsanta: vote.yes
76+
secretsanta.invite.show_match:
77+
name: 🎁
78+
#id:
79+
#animated: true
80+
secretsanta.invite.set_address:
81+
name: 🏠
82+
#id:
83+
#animated: true
84+
secretsanta.invite.delete:
85+
name: 🗑️
86+
#id:
87+
#animated: true
88+
secretsanta.invite.nudge_match:
89+
name: 👉
90+
#id:
91+
#animated: true
92+
5393
webserver:
5494
favicon: webserver/favicon.png
55-
birthday_hour: 8 # Time to trigger daily birthday check (24h format)
5695

5796
twitch:
5897
name: c4e_bot

data/lang/de.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,50 @@ discord.command:
123123
msg.winner.details: "__Gewinner: %s__\nTickets: %d/24\nGewinnchance: %.2f%%"
124124
msg.winner.congratulation: "Herzlichen Glückwunsch, %s! :heart:\nFrohe Weihnachten an alle!"
125125

126+
secretsanta:
127+
base: Wichteln
128+
display: Wichteln
129+
130+
title: Wichteln
131+
132+
msg.setup.no_reactions: Diese Nachricht hat keine Reaktionen. Nur Leute, die mit %s reagiert haben, werden eingeschlossen.
133+
msg.setup.not_enough_reactions: Nicht genug Reaktionen um zu starten. Es werden mindestens %d Reaktionen benötigt.
134+
msg.setup.users: Teilnehmer
135+
msg.setup.match_error: Fehler beim Auslosen
136+
msg.setup.invite: Einladen
137+
msg.setup.invite.error: "Einladung(en) konnte(n) nicht verschickt werden an:%s"
138+
msg.setup.error: "%d Einladungen konnten nicht verschickt werden."
139+
msg.setup.success: Einladungen wurden verschickt!
140+
141+
msg.invite.title: Einladung zum Wichteln.
142+
msg.invite.description: Du nimmst am Cake4Everyone Wichteln teil. Klicke die Knöpfe unten, um deinen Partner zu sehen und deine Adresse einzutragen.
143+
msg.invite.set_address.match: Dein Partner hat eine Adresse eingetragen
144+
msg.invite.button.show_match: Partner anzeigen
145+
msg.invite.show_match.title: Dein Partner ist %s
146+
msg.invite.show_match.description: Bitte breite ein Wichtelgeschenk vor und schicke es ihm/ihr. Halte dich dabei an unsere vereinbarten Regeln.
147+
msg.invite.show_match.address: Adresse
148+
msg.invite.show_match.address_not_set: Dein Partner hat noch keine Adresse eingetragen.
149+
150+
Falls schon einige Tage vergangen sind, kannst du den "Anstupsen" Knopf drücken. Dein Partner bekommt daraufhin einen Hinweis die Adresse einzutragen.
151+
msg.invite.show_match.nudge_description: Wenn du vermutest, dass die eingetragene Adresse einen Fehler enthält, kannst du unten den den "Anstupsen" Knopf drücken. Dein Partner bekommt daraufhin einen Hinweis die Adresse zu aktualisieren.
152+
msg.invite.set_address: Deine Adresse wurde eingetragen
153+
msg.invite.button.set_address: Deine Adresse eintragen
154+
msg.invite.set_address.changed: Deine Adresse wurde aktualisiert auf
155+
msg.invite.set_address.not_changed: Deine Adresse wurde nicht aktualisiert, weil es die gleiche ist wie vorher.
156+
msg.invite.set_address.match_updated: Dein Partner hat gerade seine/ihre Adresse aktualisiert. Das ist nur um dich zu informieren - Boop Boop 🤖
157+
msg.invite.button.delete: Schließen
158+
msg.invite.button.nudge_match: Anstupsen
159+
msg.invite.nudge_match.confirm: Bist du sicher, dass du deinen Partner anstupsen möchtest?
160+
161+
Bestätige, dass du deinen Partner anstupsen möchtest. Er/Sie bekommt dann einen Hinweis die Adresse zu aktualisieren.
162+
msg.invite.nudge_match.success: Dein Partner wurde erfolgreich angestupst
163+
msg.invite.nudge_match.pending: Du hast deinen Partner angestupst. Ich melde mich, sobald er/sie die Adresse aktualisiert hat.
164+
msg.invite.nudge_received: Dein Wichtel hat dich anstupst. Bitte trage eine Adresse ein falls du es noch nicht gemacht hast oder überprüfe deine bereits eingetragene Adresse ob sie eventuell einen Tippfehler oder ähnliches enthält.
165+
166+
msg.invite.modal.set_address.title: Deine Adresse eintragen
167+
msg.invite.modal.set_address.label: Deine Adresse wird deinem Wichtel angezeigt
168+
msg.invite.modal.set_address.placeholder: "Max Mustermann\nMusterstraße 1\n12345 Musterstadt"
169+
126170
module:
127171
adventcalendar:
128172
post.message: Noch %d Mal schlafen bis Heilig Abend! Heute öffnet sich das **Türchen %d**.

data/lang/en.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,50 @@ discord.command:
123123
msg.winner.details: "__Winner: %s__\nTickets: %d/24\nProbability of winning: %.2f%%"
124124
msg.winner.congratulation: "Congratulations, %s! :heart:\nMerry XMas everyone!"
125125

126+
secretsanta:
127+
base: Secret Santa
128+
display: Secret Santa
129+
130+
title: Secret Santa
131+
132+
msg.setup.no_reactions: This message doesn't have any vote reactions. Only members who reated with %s are included.
133+
msg.setup.not_enough_reactions: Not enough votes to start a game. At least %d votes are required.
134+
msg.setup.users: Members
135+
msg.setup.match_error: Failed to match
136+
msg.setup.invite: Invite
137+
msg.setup.invite.error: "Failed to send invite(s) to:%s"
138+
msg.setup.error: Failed to send %d invites.
139+
msg.setup.success: Invites sent!
140+
141+
msg.invite.title: Invite for secret santa.
142+
msg.invite.description: You are participating in Cake4Everyone Secret Santa. Click the buttons below to see your partner and set your address.
143+
msg.invite.set_address.match: Your partner has set an address
144+
msg.invite.button.show_match: Show partner
145+
msg.invite.show_match.title: Your partner is %s
146+
msg.invite.show_match.description: Please prepare and send them a secret gift according to our agreed rules.
147+
msg.invite.show_match.address: Address
148+
msg.invite.show_match.address_not_set: Your partner has not set an address yet.
149+
150+
If some days passed, you can click the "Nudge" button below. Your partner will receive a notification saying that they enter their address.
151+
msg.invite.show_match.nudge_description: If you think the entered address is wrong, you can click the "Nudge" button below. Your partner will receive a notification saying that they should update their address.
152+
msg.invite.set_address: Your address is set
153+
msg.invite.button.set_address: Set your address
154+
msg.invite.set_address.changed: Your address was updated to
155+
msg.invite.set_address.not_changed: Your address was not updated, because it is the same as before.
156+
msg.invite.set_address.match_updated: Your partner just updated their address. This is just to inform you - Beep Boop 🤖
157+
msg.invite.button.delete: Close
158+
msg.invite.button.nudge_match: Nudge
159+
msg.invite.nudge_match.confirm: Are you sure you want to nudge your partner?
160+
161+
Please confirm that you want to nudge your partner. They will receive a notification that they should update their address.
162+
msg.invite.nudge_match.success: Your partner was nudged!
163+
msg.invite.nudge_match.pending: You nudged your partner. I will notify you, when they updated their address.
164+
msg.invite.nudge_received: Your santa nudged you. Please enter an address if you haven't done it yet or check your already entered address for any typos.
165+
166+
msg.invite.modal.set_address.title: Set your address
167+
msg.invite.modal.set_address.label: Your address will be shown your secret santa
168+
msg.invite.modal.set_address.placeholder: "Mr. John Doe\n123 Main Street\nAnytown, USA 12345"
169+
126170
module:
127171
adventcalendar:
128172
post.message: Just sleep %d more times! Its time for **door %d**.

event/command/commandBase.go

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"cake4everybot/modules/adventcalendar"
1919
"cake4everybot/modules/birthday"
2020
"cake4everybot/modules/info"
21+
"cake4everybot/modules/secretsanta"
2122
"cake4everybot/util"
2223
"fmt"
2324
"log"
@@ -69,6 +70,7 @@ func Register(s *discordgo.Session, guildID string) error {
6970
commandsList = append(commandsList, &birthday.Chat{})
7071
commandsList = append(commandsList, &info.Chat{})
7172
commandsList = append(commandsList, &adventcalendar.Chat{})
73+
commandsList = append(commandsList, &secretsanta.MsgCmd{})
7274
// messsage commands
7375
// user commands
7476
commandsList = append(commandsList, &birthday.UserShow{})

event/commands.go

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package event
1717
import (
1818
"cake4everybot/event/command"
1919
"cake4everybot/event/component"
20+
"cake4everybot/event/modal"
2021
"strings"
2122

2223
"github.com/bwmarrin/discordgo"
@@ -42,5 +43,11 @@ func handleInteractionCreate(s *discordgo.Session, i *discordgo.InteractionCreat
4243
} else {
4344
log.Printf("got component interaction from unknown module '%s' (full id '%s')", strings.Split(data.CustomID, ".")[0], data.CustomID)
4445
}
46+
47+
case discordgo.InteractionModalSubmit:
48+
data := i.ModalSubmitData()
49+
if m, ok := modal.ModalMap[strings.Split(data.CustomID, ".")[0]]; ok {
50+
m.HandleModal(s, i)
51+
}
4552
}
4653
}

event/component/componentBase.go

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package component
22

33
import (
44
"cake4everybot/modules/adventcalendar"
5+
"cake4everybot/modules/secretsanta"
56
"log"
67

78
"github.com/bwmarrin/discordgo"
@@ -31,6 +32,7 @@ func Register() {
3132
var componentList []Component
3233

3334
componentList = append(componentList, adventcalendar.Component{})
35+
componentList = append(componentList, secretsanta.Component{})
3436

3537
if len(componentList) == 0 {
3638
return

event/event.go

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package event
1717
import (
1818
"cake4everybot/event/command"
1919
"cake4everybot/event/component"
20+
"cake4everybot/event/modal"
2021
"cake4everybot/event/twitch"
2122
logger "log"
2223

@@ -33,6 +34,7 @@ func PostRegister(dc *discordgo.Session, t *twitchgo.Twitch, guildID string) err
3334
return err
3435
}
3536
component.Register()
37+
modal.Register()
3638

3739
twitch.Register(t)
3840

event/modal/componentBase.go

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package modal
2+
3+
import (
4+
"cake4everybot/modules/secretsanta"
5+
"log"
6+
7+
"github.com/bwmarrin/discordgo"
8+
)
9+
10+
// Modal is an interface wrapper for all message components.
11+
type Modal interface {
12+
// Function of a component.
13+
// All things that should happen after submitting a modal.
14+
HandleModal(*discordgo.Session, *discordgo.InteractionCreate)
15+
16+
// Custom ID of the modal to identify the module
17+
ID() string
18+
}
19+
20+
// ModalMap holds all active modals. It maps them from a unique string identifier to the
21+
// corresponding [Modal].
22+
var ModalMap = make(map[string]Modal)
23+
24+
// Register registers modals
25+
func Register() {
26+
// This is the list of modals to use. Add a modal via
27+
// simply appending the struct (which must implement the
28+
// [Modal] interface) to the list, e.g.:
29+
//
30+
// ModalList = append(ModalList, mymodule.MyComponent{})
31+
var ModalList []Modal
32+
33+
ModalList = append(ModalList, secretsanta.Component{})
34+
35+
if len(ModalList) == 0 {
36+
return
37+
}
38+
for _, c := range ModalList {
39+
ModalMap[c.ID()] = c
40+
}
41+
log.Printf("Added %d modal handler(s)!", len(ModalMap))
42+
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/gorilla/mux v1.8.1
99
github.com/kesuaheli/twitchgo v0.2.7
1010
github.com/spf13/viper v1.19.0
11+
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f
1112
)
1213

1314
require (
@@ -27,7 +28,6 @@ require (
2728
github.com/subosito/gotenv v1.6.0 // indirect
2829
go.uber.org/multierr v1.11.0 // indirect
2930
golang.org/x/crypto v0.29.0 // indirect
30-
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
3131
golang.org/x/sys v0.27.0 // indirect
3232
golang.org/x/text v0.20.0 // indirect
3333
gopkg.in/ini.v1 v1.67.0 // indirect

modules/adventcalendar/post.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ func postData(t time.Time) *discordgo.MessageSend {
6868
fmt.Sprintf("%s.post.%s", Component.ID(Component{}), t.Format("2006.01.02")),
6969
lang.GetDefault("module.adventcalendar.post.button"),
7070
discordgo.PrimaryButton,
71-
&discordgo.ComponentEmoji{
72-
Name: viper.GetString("event.adventcalendar.emoji.name"),
73-
ID: viper.GetString("event.adventcalendar.emoji.id"),
74-
Animated: viper.GetBool("event.adventcalendar.emoji.animated"),
75-
},
71+
util.GetConfigComponentEmoji("adventcalendar"),
7672
),
7773
}},
7874
}

0 commit comments

Comments
 (0)