From 0c2b5faa1afd56816facba4795b6a5ccc837cf48 Mon Sep 17 00:00:00 2001 From: suhaibinator Date: Sat, 13 Jul 2024 07:37:12 -0400 Subject: [PATCH 1/5] Add support for integration events --- eventhandlers.go | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ events.go | 15 +++++++++++ 2 files changed, 81 insertions(+) diff --git a/eventhandlers.go b/eventhandlers.go index 1d0a61638..ade03d58a 100644 --- a/eventhandlers.go +++ b/eventhandlers.go @@ -39,6 +39,9 @@ const ( guildScheduledEventUserAddEventType = "GUILD_SCHEDULED_EVENT_USER_ADD" guildScheduledEventUserRemoveEventType = "GUILD_SCHEDULED_EVENT_USER_REMOVE" guildUpdateEventType = "GUILD_UPDATE" + integrationCreateEventType = "INTEGRATION_CREATE" + integrationUpdateEventType = "INTEGRATION_UPDATE" + integrationDeleteEventType = "INTEGRATION_DELETE" interactionCreateEventType = "INTERACTION_CREATE" inviteCreateEventType = "INVITE_CREATE" inviteDeleteEventType = "INVITE_DELETE" @@ -717,6 +720,66 @@ func (eh interactionCreateEventHandler) Handle(s *Session, i interface{}) { } } +// IntegrationCreateEventHandler is an event handler for IntegrationCreate events. +type IntegrationCreateEventHandler func(*Session, *IntegrationCreate) + +// Type returns the event type for IntegrationCreate events. +func (eh IntegrationCreateEventHandler) Type() string { + return integrationCreateEventType +} + +// New returns a new instance of IntegrationCreate. +func (eh IntegrationCreateEventHandler) New() interface{} { + return &IntegrationCreate{} +} + +// Handle is the handler for IntegrationCreate events. +func (eh IntegrationCreateEventHandler) Handle(s *Session, i interface{}) { + if t, ok := i.(*IntegrationCreate); ok { + eh(s, t) + } +} + +// IntegrationUpdateEventHandler is an event handler for IntegrationUpdate events. +type IntegrationUpdateEventHandler func(*Session, *IntegrationUpdate) + +// Type returns the event type for IntegrationUpdate events. +func (eh IntegrationUpdateEventHandler) Type() string { + return integrationUpdateEventType +} + +// New returns a new instance of IntegrationUpdate. +func (eh IntegrationUpdateEventHandler) New() interface{} { + return &IntegrationUpdate{} +} + +// Handle is the handler for IntegrationUpdate events. +func (eh IntegrationUpdateEventHandler) Handle(s *Session, i interface{}) { + if t, ok := i.(*IntegrationUpdate); ok { + eh(s, t) + } +} + +// IntegrationDeleteEventHandler is an event handler for IntegrationDelete events. +type IntegrationDeleteEventHandler func(*Session, *IntegrationDelete) + +// Type returns the event type for IntegrationDelete events. +func (eh IntegrationDeleteEventHandler) Type() string { + return integrationDeleteEventType +} + +// New returns a new instance of IntegrationDelete. +func (eh IntegrationDeleteEventHandler) New() interface{} { + return &IntegrationDelete{} +} + +// Handle is the handler for IntegrationDelete events. +func (eh IntegrationDeleteEventHandler) Handle(s *Session, i interface{}) { + if t, ok := i.(*IntegrationDelete); ok { + eh(s, t) + } +} + // inviteCreateEventHandler is an event handler for InviteCreate events. type inviteCreateEventHandler func(*Session, *InviteCreate) @@ -1478,6 +1541,9 @@ func init() { registerInterfaceProvider(guildScheduledEventUserRemoveEventHandler(nil)) registerInterfaceProvider(guildUpdateEventHandler(nil)) registerInterfaceProvider(interactionCreateEventHandler(nil)) + registerInterfaceProvider(IntegrationCreateEventHandler(nil)) + registerInterfaceProvider(IntegrationUpdateEventHandler(nil)) + registerInterfaceProvider(IntegrationDeleteEventHandler(nil)) registerInterfaceProvider(inviteCreateEventHandler(nil)) registerInterfaceProvider(inviteDeleteEventHandler(nil)) registerInterfaceProvider(messageCreateEventHandler(nil)) diff --git a/events.go b/events.go index e19290ec0..27678407f 100644 --- a/events.go +++ b/events.go @@ -241,6 +241,21 @@ type GuildScheduledEventUserRemove struct { GuildID string `json:"guild_id"` } +// IntegrationCreate is the data for a IntegrationCreate event. +type IntegrationCreate struct { + *Integration +} + +// IntegrationUpdate is the data for a IntegrationUpdate event. +type IntegrationUpdate struct { + *Integration +} + +// IntegrationDelete is the data for a IntegrationDelete event. +type IntegrationDelete struct { + *Integration +} + // MessageCreate is the data for a MessageCreate event. type MessageCreate struct { *Message From 5f5e2201dad9efb19219d4308a4568523c56ecc4 Mon Sep 17 00:00:00 2001 From: Suhaibinator <42899065+Suhaibinator@users.noreply.github.com> Date: Sun, 28 Jul 2024 10:09:26 -0400 Subject: [PATCH 2/5] Update events.go Co-authored-by: Fedor Lapshin --- events.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/events.go b/events.go index 27678407f..fb86d012c 100644 --- a/events.go +++ b/events.go @@ -253,7 +253,9 @@ type IntegrationUpdate struct { // IntegrationDelete is the data for a IntegrationDelete event. type IntegrationDelete struct { - *Integration + ID string `json:"id"` + GuildID string `json:"guild_id"` + ApplicationID string `json:"application_id,omitempty"` } // MessageCreate is the data for a MessageCreate event. From 84ab8086fa9163b53a54fb64792f26bcd7d8d401 Mon Sep 17 00:00:00 2001 From: suhaibinator Date: Sun, 28 Jul 2024 10:13:42 -0400 Subject: [PATCH 3/5] Added GuildID to IntegrationCreate and IntegrationUpdate as requested --- events.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/events.go b/events.go index fb86d012c..6a23a9e23 100644 --- a/events.go +++ b/events.go @@ -244,18 +244,20 @@ type GuildScheduledEventUserRemove struct { // IntegrationCreate is the data for a IntegrationCreate event. type IntegrationCreate struct { *Integration + GuildID string `json:"guild_id"` } // IntegrationUpdate is the data for a IntegrationUpdate event. type IntegrationUpdate struct { *Integration + GuildID string `json:"guild_id"` } // IntegrationDelete is the data for a IntegrationDelete event. type IntegrationDelete struct { - ID string `json:"id"` - GuildID string `json:"guild_id"` - ApplicationID string `json:"application_id,omitempty"` + ID string `json:"id"` + GuildID string `json:"guild_id"` + ApplicationID string `json:"application_id,omitempty"` } // MessageCreate is the data for a MessageCreate event. From e291124ad35046dacba5712b5b4116a07e6f4c3b Mon Sep 17 00:00:00 2001 From: Fedor Lapshin Date: Mon, 29 Jul 2024 13:05:33 +0300 Subject: [PATCH 4/5] chore: regenerate event handlers --- eventhandlers.go | 92 ++++++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/eventhandlers.go b/eventhandlers.go index ade03d58a..659b6748e 100644 --- a/eventhandlers.go +++ b/eventhandlers.go @@ -40,8 +40,8 @@ const ( guildScheduledEventUserRemoveEventType = "GUILD_SCHEDULED_EVENT_USER_REMOVE" guildUpdateEventType = "GUILD_UPDATE" integrationCreateEventType = "INTEGRATION_CREATE" - integrationUpdateEventType = "INTEGRATION_UPDATE" - integrationDeleteEventType = "INTEGRATION_DELETE" + integrationDeleteEventType = "INTEGRATION_DELETE" + integrationUpdateEventType = "INTEGRATION_UPDATE" interactionCreateEventType = "INTERACTION_CREATE" inviteCreateEventType = "INVITE_CREATE" inviteDeleteEventType = "INVITE_DELETE" @@ -700,82 +700,82 @@ func (eh guildUpdateEventHandler) Handle(s *Session, i interface{}) { } } -// interactionCreateEventHandler is an event handler for InteractionCreate events. -type interactionCreateEventHandler func(*Session, *InteractionCreate) +// integrationCreateEventHandler is an event handler for IntegrationCreate events. +type integrationCreateEventHandler func(*Session, *IntegrationCreate) -// Type returns the event type for InteractionCreate events. -func (eh interactionCreateEventHandler) Type() string { - return interactionCreateEventType +// Type returns the event type for IntegrationCreate events. +func (eh integrationCreateEventHandler) Type() string { + return integrationCreateEventType } -// New returns a new instance of InteractionCreate. -func (eh interactionCreateEventHandler) New() interface{} { - return &InteractionCreate{} +// New returns a new instance of IntegrationCreate. +func (eh integrationCreateEventHandler) New() interface{} { + return &IntegrationCreate{} } -// Handle is the handler for InteractionCreate events. -func (eh interactionCreateEventHandler) Handle(s *Session, i interface{}) { - if t, ok := i.(*InteractionCreate); ok { +// Handle is the handler for IntegrationCreate events. +func (eh integrationCreateEventHandler) Handle(s *Session, i interface{}) { + if t, ok := i.(*IntegrationCreate); ok { eh(s, t) } } -// IntegrationCreateEventHandler is an event handler for IntegrationCreate events. -type IntegrationCreateEventHandler func(*Session, *IntegrationCreate) +// integrationDeleteEventHandler is an event handler for IntegrationDelete events. +type integrationDeleteEventHandler func(*Session, *IntegrationDelete) -// Type returns the event type for IntegrationCreate events. -func (eh IntegrationCreateEventHandler) Type() string { - return integrationCreateEventType +// Type returns the event type for IntegrationDelete events. +func (eh integrationDeleteEventHandler) Type() string { + return integrationDeleteEventType } -// New returns a new instance of IntegrationCreate. -func (eh IntegrationCreateEventHandler) New() interface{} { - return &IntegrationCreate{} +// New returns a new instance of IntegrationDelete. +func (eh integrationDeleteEventHandler) New() interface{} { + return &IntegrationDelete{} } -// Handle is the handler for IntegrationCreate events. -func (eh IntegrationCreateEventHandler) Handle(s *Session, i interface{}) { - if t, ok := i.(*IntegrationCreate); ok { +// Handle is the handler for IntegrationDelete events. +func (eh integrationDeleteEventHandler) Handle(s *Session, i interface{}) { + if t, ok := i.(*IntegrationDelete); ok { eh(s, t) } } -// IntegrationUpdateEventHandler is an event handler for IntegrationUpdate events. -type IntegrationUpdateEventHandler func(*Session, *IntegrationUpdate) +// integrationUpdateEventHandler is an event handler for IntegrationUpdate events. +type integrationUpdateEventHandler func(*Session, *IntegrationUpdate) // Type returns the event type for IntegrationUpdate events. -func (eh IntegrationUpdateEventHandler) Type() string { +func (eh integrationUpdateEventHandler) Type() string { return integrationUpdateEventType } // New returns a new instance of IntegrationUpdate. -func (eh IntegrationUpdateEventHandler) New() interface{} { +func (eh integrationUpdateEventHandler) New() interface{} { return &IntegrationUpdate{} } // Handle is the handler for IntegrationUpdate events. -func (eh IntegrationUpdateEventHandler) Handle(s *Session, i interface{}) { +func (eh integrationUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*IntegrationUpdate); ok { eh(s, t) } } -// IntegrationDeleteEventHandler is an event handler for IntegrationDelete events. -type IntegrationDeleteEventHandler func(*Session, *IntegrationDelete) +// interactionCreateEventHandler is an event handler for InteractionCreate events. +type interactionCreateEventHandler func(*Session, *InteractionCreate) -// Type returns the event type for IntegrationDelete events. -func (eh IntegrationDeleteEventHandler) Type() string { - return integrationDeleteEventType +// Type returns the event type for InteractionCreate events. +func (eh interactionCreateEventHandler) Type() string { + return interactionCreateEventType } -// New returns a new instance of IntegrationDelete. -func (eh IntegrationDeleteEventHandler) New() interface{} { - return &IntegrationDelete{} +// New returns a new instance of InteractionCreate. +func (eh interactionCreateEventHandler) New() interface{} { + return &InteractionCreate{} } -// Handle is the handler for IntegrationDelete events. -func (eh IntegrationDeleteEventHandler) Handle(s *Session, i interface{}) { - if t, ok := i.(*IntegrationDelete); ok { +// Handle is the handler for InteractionCreate events. +func (eh interactionCreateEventHandler) Handle(s *Session, i interface{}) { + if t, ok := i.(*InteractionCreate); ok { eh(s, t) } } @@ -1443,6 +1443,12 @@ func handlerForInterface(handler interface{}) EventHandler { return guildScheduledEventUserRemoveEventHandler(v) case func(*Session, *GuildUpdate): return guildUpdateEventHandler(v) + case func(*Session, *IntegrationCreate): + return integrationCreateEventHandler(v) + case func(*Session, *IntegrationDelete): + return integrationDeleteEventHandler(v) + case func(*Session, *IntegrationUpdate): + return integrationUpdateEventHandler(v) case func(*Session, *InteractionCreate): return interactionCreateEventHandler(v) case func(*Session, *InviteCreate): @@ -1540,10 +1546,10 @@ func init() { registerInterfaceProvider(guildScheduledEventUserAddEventHandler(nil)) registerInterfaceProvider(guildScheduledEventUserRemoveEventHandler(nil)) registerInterfaceProvider(guildUpdateEventHandler(nil)) + registerInterfaceProvider(integrationCreateEventHandler(nil)) + registerInterfaceProvider(integrationDeleteEventHandler(nil)) + registerInterfaceProvider(integrationUpdateEventHandler(nil)) registerInterfaceProvider(interactionCreateEventHandler(nil)) - registerInterfaceProvider(IntegrationCreateEventHandler(nil)) - registerInterfaceProvider(IntegrationUpdateEventHandler(nil)) - registerInterfaceProvider(IntegrationDeleteEventHandler(nil)) registerInterfaceProvider(inviteCreateEventHandler(nil)) registerInterfaceProvider(inviteDeleteEventHandler(nil)) registerInterfaceProvider(messageCreateEventHandler(nil)) From d0dba19acc4818225b162a00deaf312aee5e377b Mon Sep 17 00:00:00 2001 From: suhaibinator Date: Mon, 29 Jul 2024 06:09:46 -0400 Subject: [PATCH 5/5] fix formatting issue --- eventhandlers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eventhandlers.go b/eventhandlers.go index ade03d58a..23eb466b8 100644 --- a/eventhandlers.go +++ b/eventhandlers.go @@ -40,8 +40,8 @@ const ( guildScheduledEventUserRemoveEventType = "GUILD_SCHEDULED_EVENT_USER_REMOVE" guildUpdateEventType = "GUILD_UPDATE" integrationCreateEventType = "INTEGRATION_CREATE" - integrationUpdateEventType = "INTEGRATION_UPDATE" - integrationDeleteEventType = "INTEGRATION_DELETE" + integrationUpdateEventType = "INTEGRATION_UPDATE" + integrationDeleteEventType = "INTEGRATION_DELETE" interactionCreateEventType = "INTERACTION_CREATE" inviteCreateEventType = "INVITE_CREATE" inviteDeleteEventType = "INVITE_DELETE"