2eme partie last push
This commit is contained in:
@@ -15,13 +15,14 @@ import (
|
||||
|
||||
// BotServiceImpl implements panel.BotService and handlers.DiscordInfo.
|
||||
type BotServiceImpl struct {
|
||||
session *discordgo.Session
|
||||
panelRepo *db.PanelConfigRepo
|
||||
ticketRepo *db.TicketRepo
|
||||
convocRepo *db.ConvocationConfigRepo
|
||||
guildID string
|
||||
allowedGuilds []string
|
||||
startedAt time.Time
|
||||
session *discordgo.Session
|
||||
panelRepo *db.PanelConfigRepo
|
||||
ticketRepo *db.TicketRepo
|
||||
convocRepo *db.ConvocationConfigRepo
|
||||
convocPanelRepo *db.ConvocationPanelRepo
|
||||
guildID string
|
||||
allowedGuilds []string
|
||||
startedAt time.Time
|
||||
}
|
||||
|
||||
func NewBotService(
|
||||
@@ -29,17 +30,19 @@ func NewBotService(
|
||||
panelRepo *db.PanelConfigRepo,
|
||||
ticketRepo *db.TicketRepo,
|
||||
convocRepo *db.ConvocationConfigRepo,
|
||||
convocPanelRepo *db.ConvocationPanelRepo,
|
||||
guildID string,
|
||||
allowedGuilds []string,
|
||||
) *BotServiceImpl {
|
||||
return &BotServiceImpl{
|
||||
session: s,
|
||||
panelRepo: panelRepo,
|
||||
ticketRepo: ticketRepo,
|
||||
convocRepo: convocRepo,
|
||||
guildID: guildID,
|
||||
allowedGuilds: allowedGuilds,
|
||||
startedAt: time.Now(),
|
||||
session: s,
|
||||
panelRepo: panelRepo,
|
||||
ticketRepo: ticketRepo,
|
||||
convocRepo: convocRepo,
|
||||
convocPanelRepo: convocPanelRepo,
|
||||
guildID: guildID,
|
||||
allowedGuilds: allowedGuilds,
|
||||
startedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,6 +368,68 @@ func (b *BotServiceImpl) SendConvocPanel(guildID string) error {
|
||||
return b.convocRepo.SetConvocPanelMessage(ctx, guildID, cfg.PanelChannelID, msg.ID)
|
||||
}
|
||||
|
||||
// SendConvocPanelByID sends (or updates) the Discord embed+button for a specific convocation panel.
|
||||
func (b *BotServiceImpl) SendConvocPanelByID(panelID int64) error {
|
||||
ctx := context.Background()
|
||||
p, err := b.convocPanelRepo.GetByID(ctx, panelID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get convoc panel: %w", err)
|
||||
}
|
||||
if p == nil {
|
||||
return fmt.Errorf("convoc panel %d not found", panelID)
|
||||
}
|
||||
if p.ChannelID == "" {
|
||||
return fmt.Errorf("convoc panel %d has no channel configured", panelID)
|
||||
}
|
||||
|
||||
title := p.EmbedTitle
|
||||
if title == "" {
|
||||
title = "Créer une convocation"
|
||||
}
|
||||
color := parseHexColor(p.EmbedColor)
|
||||
if color == 0 {
|
||||
color = 0x5865f2
|
||||
}
|
||||
|
||||
embed := &discordgo.MessageEmbed{
|
||||
Title: title,
|
||||
Description: p.EmbedDesc,
|
||||
Color: color,
|
||||
}
|
||||
components := []discordgo.MessageComponent{
|
||||
discordgo.ActionsRow{Components: []discordgo.MessageComponent{
|
||||
discordgo.Button{
|
||||
Label: "Créer une convocation",
|
||||
Style: discordgo.PrimaryButton,
|
||||
CustomID: fmt.Sprintf("convoc:panel:%s", p.GuildID),
|
||||
},
|
||||
}},
|
||||
}
|
||||
|
||||
if p.MessageID != "" {
|
||||
_, editErr := b.session.ChannelMessageEditComplex(&discordgo.MessageEdit{
|
||||
Channel: p.ChannelID,
|
||||
ID: p.MessageID,
|
||||
Embeds: &[]*discordgo.MessageEmbed{embed},
|
||||
Components: &components,
|
||||
})
|
||||
if editErr == nil {
|
||||
return nil
|
||||
}
|
||||
// Message deleted — fall through to send new
|
||||
_ = b.convocPanelRepo.SetMessage(ctx, panelID, "")
|
||||
}
|
||||
|
||||
msg, err := b.session.ChannelMessageSendComplex(p.ChannelID, &discordgo.MessageSend{
|
||||
Embeds: []*discordgo.MessageEmbed{embed},
|
||||
Components: components,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("send convoc panel: %w", err)
|
||||
}
|
||||
return b.convocPanelRepo.SetMessage(ctx, panelID, msg.ID)
|
||||
}
|
||||
|
||||
func sanitizeConvocUsername(username string) string {
|
||||
var out []byte
|
||||
for _, b := range []byte(username) {
|
||||
|
||||
Reference in New Issue
Block a user