Skip to content

Commit

Permalink
feat(Secret Santa): added send-receive package buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Kesuaheli committed Dec 15, 2024
1 parent 8307905 commit d5ba457
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 66 deletions.
10 changes: 8 additions & 2 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ event:
name: 👎
#id:
#animated: true
# Emoji for entering the advent calendar giveaway
adventcalendar:
vote.check:
name:
#id:
#animated: true
# Emoji for entering the advent calendar giveaway
adventcalendar: vote.check
secretsanta: vote.yes
secretsanta.invite.show_match:
name: 🎁
Expand All @@ -89,6 +90,11 @@ event:
name: 👉
#id:
#animated: true
secretsanta.invite.send_package:
name: 📦
#id:
#animated: true
secretsanta.invite.received_package: vote.check

webserver:
favicon: webserver/favicon.png
Expand Down
17 changes: 17 additions & 0 deletions data/lang/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,23 @@ discord.command:
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.button.send_package: Paket verschicken
msg.invite.send_package.status: Dein Paket Status
msg.invite.send_package.status.not_sent: Du hast dein Geschenk noch nicht verschickt.
msg.invite.send_package.status.sent: Dein Paket ist auf dem Weg zu deinem Partner.
msg.invite.send_package.status.received: Dein Geschenk wurde von deinem Partner erhalten.
msg.invite.send_package: Dein Wichtel hat gerade das Geschenk als verschickt markiert. Du kannst ab jetzt nicht mehr deine Adresse eintragen. Stattdessen kannst du das Geschenk als erhalten markieren um deinen Wichtel zu informieren, dass das Geschenk bei dir angekommen ist.
msg.invite.send_package.confirm: Bis du sicher, dass du dein Geschenk als verschickt markieren möchtest?

Bestätige, dass du dein Geschenk als verschickt markieren möchtest. Dein Partner bekommt daraufhin einen Hinweis, dass das Paket unterwegs ist.
msg.invite.send_package.success: Dein Geschenk wurde als verschickt markiert!
msg.invite.button.received_package: Geschenk erhalten
msg.invite.received_package: Dein Partner hat das Geschenk gerade als erhalten markiert!
msg.invite.received_package.confirm: Bist du sicher, dass du das Geschenk als erhalten markieren möchtest?

Bestätige, dass du das Geschenk als erhalten markieren möchtest. Dein Wichtel bekommt daraufhin einen Hinweis, dass das Geschenk bei dir angekommen ist.
msg.invite.received_package.success: Du hast das Geschenk als erhalten markiert!

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"
Expand Down
17 changes: 17 additions & 0 deletions data/lang/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,23 @@ discord.command:
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.button.send_package: Send package
msg.invite.send_package.status: Your package status
msg.invite.send_package.status.not_sent: You have not sent your package yet.
msg.invite.send_package.status.sent: Your package is on the way to your partner.
msg.invite.send_package.status.received: Your gift was received by your partner.
msg.invite.send_package: Your santa just marked their gift as sent. You no longer have the option to change your address. Instead you can mark your package as received to notify your santa that the package was received successfully.
msg.invite.send_package.confirm: Are you sure you want to mark your package as sent?

Please confirm that you want to mark your package as sent. Your partner will receive a notification that the package is on the way.
msg.invite.send_package.success: Your package was marked as sent!
msg.invite.button.received_package: Received package
msg.invite.received_package: Your partner just marked your gift as received!
msg.invite.received_package.confirm: Are you sure you want to mark your package as received?

Please confirm that you want to mark your package as received. Your santa will receive a notification that the package was received.
msg.invite.received_package.success: You marked the gift as received!

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"
Expand Down
27 changes: 1 addition & 26 deletions modules/secretsanta/handleChatCommandUpdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package secretsanta

import (
"cake4everybot/data/lang"
"cake4everybot/util"

"github.com/bwmarrin/discordgo"
)

// handleSubcommandUpdate handles the functionality of the update subcommand
Expand All @@ -18,30 +15,8 @@ func (cmd Chat) handleSubcommandUpdate() {

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)
if _, _, ok := cmd.updateInviteMessage(p); !ok {
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
}
}
}

Expand Down
200 changes: 190 additions & 10 deletions modules/secretsanta/handleComponentInvite.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,22 @@ func (c Component) handleInvite(ids []string) {
return
case "nudge_match":
c.handleInviteNudgeMatch(ids)
return
case "confirm_nudge":
c.handleInviteConfirmNudge(ids)
return
case "send_package":
c.handleInviteSendPackage(ids)
return
case "confirm_send_package":
c.handleInviteConfirmSendPackage(ids)
return
case "received_package":
c.handleInviteReceivedPackage(ids)
return
case "confirm_received_package":
c.handleInviteConfirmReceivedPackage(ids)
return
case "delete":
err := c.Session.ChannelMessageDelete(c.Interaction.ChannelID, c.Interaction.Message.ID)
if err != nil {
Expand Down Expand Up @@ -67,16 +80,29 @@ func (c Component) handleInviteShowMatch(ids []string) {
}

util.SetEmbedFooter(c.Session, tp+"display", e)
c.ReplyComponentsHiddenEmbed(
[]discordgo.MessageComponent{discordgo.ActionsRow{Components: []discordgo.MessageComponent{
util.CreateButtonComponent(
fmt.Sprintf("secretsanta.invite.nudge_match.%s", c.Interaction.GuildID),
lang.GetDefault(tp+"msg.invite.button.nudge_match"),
discordgo.SecondaryButton,
util.GetConfigComponentEmoji("secretsanta.invite.nudge_match"),
),
}}},
e)

var components []discordgo.MessageComponent
if player.SendPackage == 0 {
components = append(components, util.CreateButtonComponent(
fmt.Sprintf("secretsanta.invite.nudge_match.%s", c.Interaction.GuildID),
lang.GetDefault(tp+"msg.invite.button.nudge_match"),
discordgo.SecondaryButton,
util.GetConfigComponentEmoji("secretsanta.invite.nudge_match"),
))
if player.Match.Address != "" {
components = append(components, util.CreateButtonComponent(
fmt.Sprintf("secretsanta.invite.send_package.%s", c.Interaction.GuildID),
lang.GetDefault(tp+"msg.invite.button.send_package"),
discordgo.SuccessButton,
util.GetConfigComponentEmoji("secretsanta.invite.send_package"),
))
}
}
if len(components) == 0 {
c.ReplyHiddenEmbed(e)
} else {
c.ReplyComponentsHiddenEmbed([]discordgo.MessageComponent{discordgo.ActionsRow{Components: components}}, e)
}
}

func (c Component) handleInviteSetAddress(ids []string) {
Expand Down Expand Up @@ -147,6 +173,12 @@ func (c Component) handleInviteConfirmNudge(ids []string) {
return
}
player.Match.PendingNudge = true
err = c.setPlayers(players)
if err != nil {
log.Printf("ERROR: could not set players: %+v", err)
c.ReplyError()
return
}

matchChannel, err := c.Session.UserChannelCreate(player.Match.User.ID)
if err != nil {
Expand Down Expand Up @@ -188,3 +220,151 @@ func (c Component) handleInviteConfirmNudge(ids []string) {
}
c.ReplyHiddenSimpleEmbedUpdate(0x690042, lang.GetDefault(tp+"msg.invite.nudge_match.success"))
}

func (c Component) handleInviteSendPackage(ids []string) {
c.ReplyComponentsHiddenSimpleEmbedUpdate(
[]discordgo.MessageComponent{discordgo.ActionsRow{Components: []discordgo.MessageComponent{
util.CreateButtonComponent(
"secretsanta.invite.confirm_send_package."+strings.Join(ids, "."),
lang.GetDefault(tp+"msg.invite.button.send_package"),
discordgo.SuccessButton,
util.GetConfigComponentEmoji("secretsanta.invite.send_package"),
),
}}},
0x690042,
lang.GetDefault(tp+"msg.invite.send_package.confirm"))
}

func (c Component) handleInviteConfirmSendPackage(ids []string) {
c.Interaction.GuildID = util.ShiftL(ids)
players, err := c.getPlayers()
if err != nil {
log.Printf("ERROR: could not get players: %+v", err)
c.ReplyError()
return
}
if len(players) == 0 {
log.Printf("ERROR: no players in guild %s", c.Interaction.GuildID)
c.ReplyError()
return
}

player, ok := players[c.Interaction.User.ID]
if !ok {
log.Printf("ERROR: could not find player %s in guild %s: %+v", c.Interaction.User.ID, c.Interaction.GuildID, c.Interaction.User.ID)
c.ReplyError()
return
}
player.SendPackage = 1
player.Match.PendingNudge = false
err = c.setPlayers(players)
if err != nil {
log.Printf("ERROR: could not set players: %+v", err)
c.ReplyError()
return
}

if _, _, ok = c.updateInviteMessage(player); !ok {
c.ReplyError()
return
}
var matchChannel *discordgo.Channel
if matchChannel, _, ok = c.updateInviteMessage(player.Match); !ok {
c.ReplyError()
return
}

data := &discordgo.MessageSend{
Content: lang.GetDefault(tp + "msg.invite.send_package"),
Reference: &discordgo.MessageReference{MessageID: player.Match.MessageID},
Components: []discordgo.MessageComponent{discordgo.ActionsRow{Components: []discordgo.MessageComponent{
util.CreateButtonComponent(
"secretsanta.invite.delete",
lang.GetDefault(tp+"msg.invite.button.delete"),
discordgo.DangerButton,
util.GetConfigComponentEmoji("secretsanta.invite.delete"),
),
}}},
}
_, err = c.Session.ChannelMessageSendComplex(matchChannel.ID, data)
if err != nil {
log.Printf("ERROR: could not send nudge message: %+v", err)
c.ReplyError()
return
}
c.ReplyHiddenSimpleEmbedUpdate(0x690042, lang.GetDefault(tp+"msg.invite.send_package.success"))
}

func (c Component) handleInviteReceivedPackage(ids []string) {
c.ReplyComponentsHiddenSimpleEmbed(
[]discordgo.MessageComponent{discordgo.ActionsRow{Components: []discordgo.MessageComponent{
util.CreateButtonComponent(
"secretsanta.invite.confirm_received_package."+strings.Join(ids, "."),
lang.GetDefault(tp+"msg.invite.button.received_package"),
discordgo.SuccessButton,
util.GetConfigComponentEmoji("secretsanta.invite.received_package"),
),
}}},
0x690042,
lang.GetDefault(tp+"msg.invite.received_package.confirm"))
}

func (c Component) handleInviteConfirmReceivedPackage(ids []string) {
c.Interaction.GuildID = util.ShiftL(ids)
players, err := c.getPlayers()
if err != nil {
log.Printf("ERROR: could not get players: %+v", err)
c.ReplyError()
return
}
if len(players) == 0 {
log.Printf("ERROR: no players in guild %s", c.Interaction.GuildID)
c.ReplyError()
return
}

player, ok := players[c.Interaction.User.ID]
if !ok {
log.Printf("ERROR: could not find player %s in guild %s: %+v", c.Interaction.User.ID, c.Interaction.GuildID, c.Interaction.User.ID)
c.ReplyError()
return
}
santaPlayer := c.getSantaForPlayer(player.User.ID)
santaPlayer.SendPackage = 2
err = c.setPlayers(players)
if err != nil {
log.Printf("ERROR: could not set players: %+v", err)
c.ReplyError()
return
}

if _, _, ok = c.updateInviteMessage(player); !ok {
c.ReplyError()
return
}
var santaChannel *discordgo.Channel
if santaChannel, _, ok = c.updateInviteMessage(santaPlayer); !ok {
c.ReplyError()
return
}

data := &discordgo.MessageSend{
Content: lang.GetDefault(tp + "msg.invite.received_package"),
Reference: &discordgo.MessageReference{MessageID: santaPlayer.MessageID},
Components: []discordgo.MessageComponent{discordgo.ActionsRow{Components: []discordgo.MessageComponent{
util.CreateButtonComponent(
"secretsanta.invite.delete",
lang.GetDefault(tp+"msg.invite.button.delete"),
discordgo.DangerButton,
util.GetConfigComponentEmoji("secretsanta.invite.delete"),
),
}}},
}
_, err = c.Session.ChannelMessageSendComplex(santaChannel.ID, data)
if err != nil {
log.Printf("ERROR: could not send nudge message: %+v", err)
c.ReplyError()
return
}
c.ReplyHiddenSimpleEmbedUpdate(0x690042, lang.GetDefault(tp+"msg.invite.received_package.success"))
}
Loading

0 comments on commit d5ba457

Please sign in to comment.