Add Discord guild ID configuration and enhance event announcement options
This commit introduces the `DISCORD_GUILD_ID` environment variable to the configuration files, allowing for better integration with Discord for role synchronization. The event announcement functionality has been updated to include an option for the `@everyone` mention, which can be toggled during event creation. The backend logic has been modified to handle this new option, and corresponding updates have been made to the frontend to allow users to control the mention behavior. Additionally, tests have been added to ensure the correct functionality of these features.
This commit is contained in:
@@ -116,16 +116,16 @@ func New(config Config) (*Announcer, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *Announcer) AnnounceEventCreated(ctx context.Context, event domain.Event) error {
|
||||
err := a.announceEventCreated(ctx, event)
|
||||
func (a *Announcer) AnnounceEventCreated(ctx context.Context, event domain.Event, pingEveryone bool) error {
|
||||
err := a.announceEventCreated(ctx, event, pingEveryone)
|
||||
if err != nil {
|
||||
slog.Error("Discord event announcement failed", "event_id", event.ID, "error", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *Announcer) announceEventCreated(ctx context.Context, event domain.Event) error {
|
||||
payload, err := json.Marshal(a.createdMessage(event))
|
||||
func (a *Announcer) announceEventCreated(ctx context.Context, event domain.Event, pingEveryone bool) error {
|
||||
payload, err := json.Marshal(a.createdMessage(event, pingEveryone))
|
||||
if err != nil {
|
||||
return fmt.Errorf("encode Discord message: %w", err)
|
||||
}
|
||||
@@ -149,11 +149,10 @@ func (a *Announcer) announceEventCreated(ctx context.Context, event domain.Event
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Announcer) createdMessage(event domain.Event) messagePayload {
|
||||
func (a *Announcer) createdMessage(event domain.Event, pingEveryone bool) messagePayload {
|
||||
text := announcementTranslations(a.locale)
|
||||
eventURL := a.publicURL + "/events/" + url.PathEscape(event.ID)
|
||||
return messagePayload{
|
||||
Content: "@everyone",
|
||||
message := messagePayload{
|
||||
Embeds: []embed{{
|
||||
Title: truncate(text.titlePrefix+event.Name, 256),
|
||||
Description: truncate(event.Description, 4096),
|
||||
@@ -173,8 +172,13 @@ func (a *Announcer) createdMessage(event domain.Event) messagePayload {
|
||||
URL: eventURL,
|
||||
}},
|
||||
}},
|
||||
AllowedMentions: allowedMentions{Parse: []string{"everyone"}},
|
||||
AllowedMentions: allowedMentions{Parse: []string{}},
|
||||
}
|
||||
if pingEveryone {
|
||||
message.Content = "@everyone"
|
||||
message.AllowedMentions.Parse = []string{"everyone"}
|
||||
}
|
||||
return message
|
||||
}
|
||||
|
||||
func announcementTranslations(locale string) translations {
|
||||
|
||||
Reference in New Issue
Block a user