-
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.
added secret santa invitation message
- Loading branch information
Showing
9 changed files
with
233 additions
and
2 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
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,47 @@ | ||
package secretsanta | ||
|
||
import ( | ||
"cake4everybot/util" | ||
"strings" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
// The Component of the secret santa package. | ||
type Component struct { | ||
secretSantaBase | ||
data discordgo.MessageComponentInteractionData | ||
} | ||
|
||
// ID returns the custom ID of the modal to identify the module | ||
func (c Component) Handle(s *discordgo.Session, i *discordgo.InteractionCreate) { | ||
c.InteractionUtil = util.InteractionUtil{Session: s, Interaction: i} | ||
c.member = i.Member | ||
c.user = i.User | ||
if i.Member != nil { | ||
c.user = i.Member.User | ||
} else if i.User != nil { | ||
c.member = &discordgo.Member{User: i.User} | ||
} | ||
c.data = i.MessageComponentData() | ||
|
||
ids := strings.Split(c.data.CustomID, ".") | ||
// pop the first level identifier | ||
util.ShiftL(ids) | ||
|
||
switch util.ShiftL(ids) { | ||
case "setup": | ||
c.handleSetup(s, ids) | ||
return | ||
case "invite": | ||
c.handleInvite(s, ids) | ||
default: | ||
log.Printf("Unknown component interaction ID: %s", c.data.CustomID) | ||
} | ||
|
||
} | ||
|
||
// Custom ID of the modal to identify the module | ||
func (c Component) ID() string { | ||
return "secretsanta" | ||
} |
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,64 @@ | ||
package secretsanta | ||
|
||
import ( | ||
"cake4everybot/util" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
func (c Component) handleInvite(s *discordgo.Session, ids []string) { | ||
switch util.ShiftL(ids) { | ||
case "show_match": | ||
c.handleInviteShowMatch(s, ids) | ||
return | ||
case "set_address": | ||
c.handleInviteSetAddress(s, ids) | ||
return | ||
case "show_address": | ||
c.handleInviteShowAddress(s, ids) | ||
return | ||
default: | ||
log.Printf("Unknown component interaction ID: %s", c.data.CustomID) | ||
} | ||
} | ||
|
||
func (c Component) handleInviteShowMatch(s *discordgo.Session, ids []string) { | ||
guildID := util.ShiftL(ids) | ||
_, err := c.getPlayers() | ||
if err != nil { | ||
log.Printf("ERROR: could not get players: %+v", err) | ||
c.ReplyError() | ||
return | ||
} | ||
players := allPlayers[guildID] | ||
if len(players) == 0 { | ||
log.Printf("ERROR: no players in guild %s", guildID) | ||
c.ReplyError() | ||
return | ||
} | ||
var player *player | ||
for _, p := range players { | ||
if p.User.ID == c.Interaction.User.ID { | ||
player = p | ||
} | ||
} | ||
|
||
if player == nil { | ||
log.Printf("ERROR: could not find player %s in guild %s: %+v", c.Interaction.User.ID, guildID, c.Interaction.User.ID) | ||
c.ReplyError() | ||
return | ||
} | ||
|
||
e := util.AuthoredEmbed(s, player.Match.Member, tp+"display") | ||
|
||
util.SetEmbedFooter(s, tp+"display", e) | ||
c.ReplyHiddenEmbed(e) | ||
} | ||
|
||
func (c Component) handleInviteSetAddress(s *discordgo.Session, ids []string) { | ||
|
||
} | ||
|
||
func (c Component) handleInviteShowAddress(s *discordgo.Session, ids []string) { | ||
|
||
} |
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,84 @@ | ||
package secretsanta | ||
|
||
import ( | ||
"cake4everybot/data/lang" | ||
"cake4everybot/util" | ||
"fmt" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
func (c Component) handleSetup(s *discordgo.Session, ids []string) { | ||
switch util.ShiftL(ids) { | ||
case "invite": | ||
c.handleSetupInvite(s) | ||
return | ||
default: | ||
log.Printf("Unknown component interaction ID: %s", c.data.CustomID) | ||
} | ||
} | ||
|
||
func (c Component) handleSetupInvite(s *discordgo.Session) { | ||
players, err := c.getPlayers() | ||
if err != nil { | ||
log.Printf("ERROR: could not get players: %+v", err) | ||
c.ReplyError() | ||
return | ||
} | ||
c.ReplyDeferedHidden() | ||
|
||
inviteMessage := &discordgo.MessageSend{ | ||
Embeds: []*discordgo.MessageEmbed{{ | ||
Title: lang.GetDefault(tp + "msg.invite.title"), | ||
Fields: []*discordgo.MessageEmbedField{}, | ||
}}, | ||
Components: []discordgo.MessageComponent{ | ||
discordgo.ActionsRow{Components: []discordgo.MessageComponent{ | ||
util.CreateButtonComponent( | ||
fmt.Sprintf("secretsanta.invite.show_match.%s", c.Interaction.GuildID), | ||
lang.GetDefault(tp+"msg.invite.button.show_match"), | ||
discordgo.PrimaryButton, | ||
util.GetConfigComponentEmoji("secretsanta.invite.show_match"), | ||
), | ||
util.CreateButtonComponent( | ||
fmt.Sprintf("secretsanta.invite.set_address.%s", c.Interaction.GuildID), | ||
lang.GetDefault(tp+"msg.invite.button.set_address"), | ||
discordgo.SecondaryButton, | ||
util.GetConfigComponentEmoji("secretsanta.invite.set_address"), | ||
), | ||
util.CreateButtonComponent( | ||
fmt.Sprintf("secretsanta.invite.show_address.%s", c.Interaction.GuildID), | ||
lang.GetDefault(tp+"msg.invite.button.show_address"), | ||
discordgo.SecondaryButton, | ||
util.GetConfigComponentEmoji("secretsanta.invite.show_address"), | ||
), | ||
}}, | ||
}, | ||
} | ||
|
||
var errCount int | ||
for _, player := range players { | ||
var DMChannel *discordgo.Channel | ||
DMChannel, err = s.UserChannelCreate(player.User.ID) | ||
if err != nil { | ||
log.Printf("ERROR: could not create DM channel for user %s: %+v", player.User.ID, err) | ||
errCount++ | ||
continue | ||
} | ||
|
||
_, err = s.ChannelMessageSendComplex(DMChannel.ID, inviteMessage) | ||
if err != nil { | ||
log.Printf("ERROR: could not send invite: %+v", err) | ||
errCount++ | ||
continue | ||
} | ||
log.Printf("Sent invite to user %s in channel %s", player.User.ID, DMChannel.ID) | ||
} | ||
|
||
if errCount > 0 { | ||
c.ReplyHiddenf("Failed to send %d invites!", errCount) | ||
return | ||
} | ||
|
||
c.ReplyHidden(lang.GetDefault(tp + "msg.setup.success")) | ||
} |
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