Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secret Santa #13

Merged
merged 17 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ cake4everybot

# configuration files for tokens, access keys and other connection data
*env.yaml

# runtime config files (as described in config.yml)
modules/secretsanta/backlist.json
modules/secretsanta/players.json
twitch/prizes.json
twitch/times.json
55 changes: 47 additions & 8 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,65 @@ event:

adventcalendar:
images: data/images/adventcalendar
# Name: The name of this emoji, e.g. '🎅', '❤️' when a default emoji
# ID: The snowflake ID if when a custom emoji
# Animated: Whether this emoji is animated. Defaults to false
emoji.name: ✅
#emoji.id:
#emoji.animated: true

secretsanta:
# the filepath for the players
players: modules/secretsanta/players.json
# the filepath for the blacklist
# the blacklist maps a user ID to a list of user IDs that should not be matched
blacklist: modules/secretsanta/backlist.json

twitch_giveaway:
# The amount of points a single giveaway ticket costs.
ticket_cost: 1000
# Cooldown in minutes before beeing able to by another ticket
# Cooldown in minutes before beeing able to buy another ticket
cooldown: 15
# the filepath for of the json giveaway prizes
prizes: twitch/prizes.json
# the filepath for storing the giveaway cooldown times
times: twitch/times.json

emoji:
# Configuration for emojis used by the bot
# Name: The name of this emoji, e.g. '🎅', '❤️' when a default emoji
# ID: The snowflake ID when a custom emoji
# Animated: Whether this emoji is animated. Defaults to false if not set

# Voting for yes
vote.yes:
name: 👍
#id:
#animated: true
# Voting for no
vote.no:
name: 👎
#id:
#animated: true
# Emoji for entering the advent calendar giveaway
adventcalendar:
name: ✅
#id:
#animated: true
secretsanta: vote.yes
secretsanta.invite.show_match:
name: 🎁
#id:
#animated: true
secretsanta.invite.set_address:
name: 🏠
#id:
#animated: true
secretsanta.invite.delete:
name: 🗑️
#id:
#animated: true
secretsanta.invite.nudge_match:
name: 👉
#id:
#animated: true

webserver:
favicon: webserver/favicon.png
birthday_hour: 8 # Time to trigger daily birthday check (24h format)

twitch:
name: c4e_bot
Expand Down
44 changes: 44 additions & 0 deletions data/lang/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,50 @@ 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.
msg.setup.users: Teilnehmer
msg.setup.match_error: Fehler beim Auslosen
msg.setup.invite: Einladen
msg.setup.invite.error: "Einladung(en) konnte(n) nicht verschickt werden an:%s"
msg.setup.error: "%d Einladungen konnten nicht verschickt werden."
msg.setup.success: Einladungen wurden verschickt!

msg.invite.title: Einladung zum Wichteln.
msg.invite.description: Du nimmst am Cake4Everyone Wichteln teil. Klicke die Knöpfe unten, um deinen Partner zu sehen und deine Adresse einzutragen.
msg.invite.set_address.match: Dein Partner hat eine Adresse eingetragen
msg.invite.button.show_match: Partner anzeigen
msg.invite.show_match.title: Dein Partner ist %s
msg.invite.show_match.description: Bitte breite ein Wichtelgeschenk vor und schicke es ihm/ihr. Halte dich dabei an unsere vereinbarten Regeln.
msg.invite.show_match.address: Adresse
msg.invite.show_match.address_not_set: Dein Partner hat noch keine Adresse eingetragen.

Falls schon einige Tage vergangen sind, kannst du den "Anstupsen" Knopf drücken. Dein Partner bekommt daraufhin einen Hinweis die Adresse einzutragen.
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.
msg.invite.set_address: Deine Adresse wurde eingetragen
msg.invite.button.set_address: Deine Adresse eintragen
msg.invite.set_address.changed: Deine Adresse wurde aktualisiert auf
msg.invite.set_address.not_changed: Deine Adresse wurde nicht aktualisiert, weil es die gleiche ist wie vorher.
msg.invite.set_address.match_updated: Dein Partner hat gerade seine/ihre Adresse aktualisiert. Das ist nur um dich zu informieren - Boop Boop 🤖
msg.invite.button.delete: Schließen
msg.invite.button.nudge_match: Anstupsen
msg.invite.nudge_match.confirm: Bist du sicher, dass du deinen Partner anstupsen möchtest?

Bestätige, dass du deinen Partner anstupsen möchtest. Er/Sie bekommt dann einen Hinweis die Adresse zu aktualisieren.
msg.invite.nudge_match.success: Dein Partner wurde erfolgreich angestupst
msg.invite.nudge_match.pending: Du hast deinen Partner angestupst. Ich melde mich, sobald er/sie die Adresse aktualisiert hat.
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.

msg.invite.modal.set_address.title: Deine Adresse eintragen
msg.invite.modal.set_address.label: Deine Adresse wird deinem Wichtel angezeigt
msg.invite.modal.set_address.placeholder: "Max Mustermann\nMusterstraße 1\n12345 Musterstadt"

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

secretsanta:
base: 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.
msg.setup.users: Members
msg.setup.match_error: Failed to match
msg.setup.invite: Invite
msg.setup.invite.error: "Failed to send invite(s) to:%s"
msg.setup.error: Failed to send %d invites.
msg.setup.success: Invites sent!

msg.invite.title: Invite for secret santa.
msg.invite.description: You are participating in Cake4Everyone Secret Santa. Click the buttons below to see your partner and set your address.
msg.invite.set_address.match: Your partner has set an address
msg.invite.button.show_match: Show partner
msg.invite.show_match.title: Your partner is %s
msg.invite.show_match.description: Please prepare and send them a secret gift according to our agreed rules.
msg.invite.show_match.address: Address
msg.invite.show_match.address_not_set: Your partner has not set an address yet.

If some days passed, you can click the "Nudge" button below. Your partner will receive a notification saying that they enter their address.
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.
msg.invite.set_address: Your address is set
msg.invite.button.set_address: Set your address
msg.invite.set_address.changed: Your address was updated to
msg.invite.set_address.not_changed: Your address was not updated, because it is the same as before.
msg.invite.set_address.match_updated: Your partner just updated their address. This is just to inform you - Beep Boop 🤖
msg.invite.button.delete: Close
msg.invite.button.nudge_match: Nudge
msg.invite.nudge_match.confirm: Are you sure you want to nudge your partner?

Please confirm that you want to nudge your partner. They will receive a notification that they should update their address.
msg.invite.nudge_match.success: Your partner was nudged!
msg.invite.nudge_match.pending: You nudged your partner. I will notify you, when they updated their address.
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.

msg.invite.modal.set_address.title: Set your address
msg.invite.modal.set_address.label: Your address will be shown your secret santa
msg.invite.modal.set_address.placeholder: "Mr. John Doe\n123 Main Street\nAnytown, USA 12345"

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
7 changes: 7 additions & 0 deletions event/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package event
import (
"cake4everybot/event/command"
"cake4everybot/event/component"
"cake4everybot/event/modal"
"strings"

"github.com/bwmarrin/discordgo"
Expand All @@ -42,5 +43,11 @@ func handleInteractionCreate(s *discordgo.Session, i *discordgo.InteractionCreat
} else {
log.Printf("got component interaction from unknown module '%s' (full id '%s')", strings.Split(data.CustomID, ".")[0], data.CustomID)
}

case discordgo.InteractionModalSubmit:
data := i.ModalSubmitData()
if m, ok := modal.ModalMap[strings.Split(data.CustomID, ".")[0]]; ok {
m.HandleModal(s, i)
}
}
}
2 changes: 2 additions & 0 deletions event/component/componentBase.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package component

import (
"cake4everybot/modules/adventcalendar"
"cake4everybot/modules/secretsanta"
"log"

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

componentList = append(componentList, adventcalendar.Component{})
componentList = append(componentList, secretsanta.Component{})

if len(componentList) == 0 {
return
Expand Down
2 changes: 2 additions & 0 deletions event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package event
import (
"cake4everybot/event/command"
"cake4everybot/event/component"
"cake4everybot/event/modal"
"cake4everybot/event/twitch"
logger "log"

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

twitch.Register(t)

Expand Down
42 changes: 42 additions & 0 deletions event/modal/componentBase.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package modal

import (
"cake4everybot/modules/secretsanta"
"log"

"github.com/bwmarrin/discordgo"
)

// Modal is an interface wrapper for all message components.
type Modal interface {
// Function of a component.
// All things that should happen after submitting a modal.
HandleModal(*discordgo.Session, *discordgo.InteractionCreate)

// Custom ID of the modal to identify the module
ID() string
}

// ModalMap holds all active modals. It maps them from a unique string identifier to the
// corresponding [Modal].
var ModalMap = make(map[string]Modal)

// Register registers modals
func Register() {
// This is the list of modals to use. Add a modal via
// simply appending the struct (which must implement the
// [Modal] interface) to the list, e.g.:
//
// ModalList = append(ModalList, mymodule.MyComponent{})
var ModalList []Modal

ModalList = append(ModalList, secretsanta.Component{})

if len(ModalList) == 0 {
return
}
for _, c := range ModalList {
ModalMap[c.ID()] = c
}
log.Printf("Added %d modal handler(s)!", len(ModalMap))
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/gorilla/mux v1.8.1
github.com/kesuaheli/twitchgo v0.2.7
github.com/spf13/viper v1.19.0
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f
)

require (
Expand All @@ -27,7 +28,6 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
6 changes: 1 addition & 5 deletions modules/adventcalendar/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ func postData(t time.Time) *discordgo.MessageSend {
fmt.Sprintf("%s.post.%s", Component.ID(Component{}), t.Format("2006.01.02")),
lang.GetDefault("module.adventcalendar.post.button"),
discordgo.PrimaryButton,
&discordgo.ComponentEmoji{
Name: viper.GetString("event.adventcalendar.emoji.name"),
ID: viper.GetString("event.adventcalendar.emoji.id"),
Animated: viper.GetBool("event.adventcalendar.emoji.animated"),
},
util.GetConfigComponentEmoji("adventcalendar"),
),
}},
}
Expand Down
Loading
Loading