Skip to content

Commit 97da3f6

Browse files
committed
Add MarshalJSON for WebhookParams to make editing consistent across all edit types
1 parent cd03d4f commit 97da3f6

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

automod_legacy/bot.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ func (p *Plugin) BotInit() {
3030

3131
pubsub.AddHandler("update_automod_legacy_rules", HandleUpdateAutomodRules, nil)
3232
confCache = ccache.New(ccache.Configure().MaxSize(1000))
33-
// invitesCacheDuration is the period between ticks for the invitesCache gc in minutes
34-
const invitesCacheDuration = 60
33+
3534
invitesCache = cachedGuildInvites{guilds: make(map[int64]GuildInvites)}
36-
go invitesCache.gc(invitesCacheDuration * time.Minute)
35+
go invitesCache.gc(60 * time.Minute)
3736
}
3837

3938
// Invalidate the cache when the rules have changed

automod_legacy/rules.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ type cachedGuildInvites struct {
206206
}
207207

208208
func (c *cachedGuildInvites) gc(d time.Duration) {
209+
logger.Info("Init worker for invite cache GC")
209210
ticker := time.NewTicker(d)
210211
for range ticker.C {
211212
c.tick(d)

lib/discordgo/structs.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,33 @@ type WebhookParams struct {
14771477
AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"`
14781478
}
14791479

1480+
func (m *WebhookParams) MarshalJSON() ([]byte, error) {
1481+
type WebhookParamsAlias WebhookParams
1482+
temp := struct {
1483+
*WebhookParamsAlias
1484+
Content string `json:"content,omitempty"`
1485+
Components *[]TopLevelComponent `json:"components,omitempty"`
1486+
Embeds *[]*MessageEmbed `json:"embeds,omitempty"`
1487+
AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"`
1488+
Flags *MessageFlags `json:"flags,omitempty"`
1489+
}{
1490+
WebhookParamsAlias: (*WebhookParamsAlias)(m),
1491+
Content: m.Content,
1492+
AllowedMentions: m.AllowedMentions,
1493+
Flags: &m.Flags,
1494+
}
1495+
1496+
if m.Components != nil {
1497+
temp.Components = &m.Components
1498+
}
1499+
1500+
if m.Embeds != nil {
1501+
temp.Embeds = &m.Embeds
1502+
}
1503+
1504+
return json.Marshal(temp)
1505+
}
1506+
14801507
// MessageReaction stores the data for a message reaction.
14811508
type MessageReaction struct {
14821509
UserID int64 `json:"user_id,string"`

0 commit comments

Comments
 (0)