From 6958472163f7b8884dc3202d7cf03202ec733ab9 Mon Sep 17 00:00:00 2001 From: Fedor Lapshin Date: Fri, 7 Apr 2023 16:19:12 +0300 Subject: [PATCH] Implement Audit Log Entry Create event (#1314) * Implement GUILD_AUDIT_LOG_ENTRY_CREATE event. * Rename IntentGuildBans constant to IntentGuildModeration to match API documentation. --- eventhandlers.go | 24 ++++++++++++++++++++++++ events.go | 5 +++++ structs.go | 4 +++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/eventhandlers.go b/eventhandlers.go index 9f69a607c..fc0071736 100644 --- a/eventhandlers.go +++ b/eventhandlers.go @@ -19,6 +19,7 @@ const ( connectEventType = "__CONNECT__" disconnectEventType = "__DISCONNECT__" eventEventType = "__EVENT__" + guildAuditLogEntryCreateEventType = "GUILD_AUDIT_LOG_ENTRY_CREATE" guildBanAddEventType = "GUILD_BAN_ADD" guildBanRemoveEventType = "GUILD_BAN_REMOVE" guildCreateEventType = "GUILD_CREATE" @@ -294,6 +295,26 @@ func (eh eventEventHandler) Handle(s *Session, i interface{}) { } } +// guildAuditLogEntryCreateEventHandler is an event handler for GuildAuditLogEntryCreate events. +type guildAuditLogEntryCreateEventHandler func(*Session, *GuildAuditLogEntryCreate) + +// Type returns the event type for GuildAuditLogEntryCreate events. +func (eh guildAuditLogEntryCreateEventHandler) Type() string { + return guildAuditLogEntryCreateEventType +} + +// New returns a new instance of GuildAuditLogEntryCreate. +func (eh guildAuditLogEntryCreateEventHandler) New() interface{} { + return &GuildAuditLogEntryCreate{} +} + +// Handle is the handler for GuildAuditLogEntryCreate events. +func (eh guildAuditLogEntryCreateEventHandler) Handle(s *Session, i interface{}) { + if t, ok := i.(*GuildAuditLogEntryCreate); ok { + eh(s, t) + } +} + // guildBanAddEventHandler is an event handler for GuildBanAdd events. type guildBanAddEventHandler func(*Session, *GuildBanAdd) @@ -1277,6 +1298,8 @@ func handlerForInterface(handler interface{}) EventHandler { return disconnectEventHandler(v) case func(*Session, *Event): return eventEventHandler(v) + case func(*Session, *GuildAuditLogEntryCreate): + return guildAuditLogEntryCreateEventHandler(v) case func(*Session, *GuildBanAdd): return guildBanAddEventHandler(v) case func(*Session, *GuildBanRemove): @@ -1388,6 +1411,7 @@ func init() { registerInterfaceProvider(channelDeleteEventHandler(nil)) registerInterfaceProvider(channelPinsUpdateEventHandler(nil)) registerInterfaceProvider(channelUpdateEventHandler(nil)) + registerInterfaceProvider(guildAuditLogEntryCreateEventHandler(nil)) registerInterfaceProvider(guildBanAddEventHandler(nil)) registerInterfaceProvider(guildBanRemoveEventHandler(nil)) registerInterfaceProvider(guildCreateEventHandler(nil)) diff --git a/events.go b/events.go index 6608ab6ee..8438ff833 100644 --- a/events.go +++ b/events.go @@ -401,3 +401,8 @@ type AutoModerationActionExecution struct { MatchedKeyword string `json:"matched_keyword"` MatchedContent string `json:"matched_content"` } + +// GuildAuditLogEntryCreate is the data for a GuildAuditLogEntryCreate event. +type GuildAuditLogEntryCreate struct { + *AuditLogEntry +} diff --git a/structs.go b/structs.go index 2dad321cd..f23f257a6 100644 --- a/structs.go +++ b/structs.go @@ -2351,7 +2351,7 @@ type Intent int const ( IntentGuilds Intent = 1 << 0 IntentGuildMembers Intent = 1 << 1 - IntentGuildBans Intent = 1 << 2 + IntentGuildModeration Intent = 1 << 2 IntentGuildEmojis Intent = 1 << 3 IntentGuildIntegrations Intent = 1 << 4 IntentGuildWebhooks Intent = 1 << 5 @@ -2371,6 +2371,8 @@ const ( // TODO: remove when compatibility is not needed + IntentGuildBans Intent = IntentGuildModeration + IntentsGuilds Intent = 1 << 0 IntentsGuildMembers Intent = 1 << 1 IntentsGuildBans Intent = 1 << 2