Implement Audit Log Entry Create event (#1314)

* Implement GUILD_AUDIT_LOG_ENTRY_CREATE event.
* Rename IntentGuildBans constant to IntentGuildModeration to match API documentation.
This commit is contained in:
Fedor Lapshin 2023-04-07 16:19:12 +03:00 committed by GitHub
parent b7c431c368
commit 6958472163
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 1 deletions

View file

@ -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))

View file

@ -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
}

View file

@ -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