Skip to content

Commit 0f6d90b

Browse files
committed
fix invite create event
1 parent f24ca9a commit 0f6d90b

File tree

3 files changed

+46
-32
lines changed

3 files changed

+46
-32
lines changed

events/guild_invite_events.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,45 @@ import (
44
"github.com/disgoorg/snowflake/v2"
55

66
"github.com/disgoorg/disgo/discord"
7+
"github.com/disgoorg/disgo/gateway"
78
)
89

9-
// GenericInvite is called upon receiving InviteCreate or InviteDelete (requires gateway.IntentGuildInvites)
10-
type GenericInvite struct {
10+
// InviteCreate is called upon creation of a new discord.Invite (requires gateway.IntentGuildInvites)
11+
type InviteCreate struct {
1112
*GenericEvent
12-
GuildID *snowflake.ID
13-
ChannelID snowflake.ID
14-
Code string
13+
14+
gateway.EventInviteCreate
1515
}
1616

1717
// Channel returns the discord.GuildChannel the GenericInvite happened in.
18-
func (e *GenericInvite) Channel() (discord.GuildChannel, bool) {
18+
func (e *InviteCreate) Channel() (discord.GuildChannel, bool) {
1919
return e.Client().Caches().Channel(e.ChannelID)
2020
}
2121

22-
// InviteCreate is called upon creation of a new discord.Invite (requires gateway.IntentGuildInvites)
23-
type InviteCreate struct {
24-
*GenericInvite
25-
Invite discord.Invite
22+
func (e *InviteCreate) Guild() (discord.Guild, bool) {
23+
if e.GuildID == nil {
24+
return discord.Guild{}, false
25+
}
26+
return e.Client().Caches().Guild(*e.GuildID)
2627
}
2728

2829
// InviteDelete is called upon deletion of a discord.Invite (requires gateway.IntentGuildInvites)
2930
type InviteDelete struct {
30-
*GenericInvite
31+
*GenericEvent
32+
33+
GuildID *snowflake.ID
34+
ChannelID snowflake.ID
35+
Code string
36+
}
37+
38+
// Channel returns the discord.GuildChannel the GenericInvite happened in.
39+
func (e *InviteDelete) Channel() (discord.GuildChannel, bool) {
40+
return e.Client().Caches().Channel(e.ChannelID)
41+
}
42+
43+
func (e *InviteDelete) Guild() (discord.Guild, bool) {
44+
if e.GuildID == nil {
45+
return discord.Guild{}, false
46+
}
47+
return e.Client().Caches().Guild(*e.GuildID)
3148
}

gateway/gateway_events.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,18 @@ func (EventInteractionCreate) messageData() {}
462462
func (EventInteractionCreate) eventData() {}
463463

464464
type EventInviteCreate struct {
465-
discord.Invite
465+
ChannelID snowflake.ID `json:"channel_id"`
466+
Code string `json:"code"`
467+
CreatedAt time.Time `json:"created_at"`
468+
GuildID *snowflake.ID `json:"guild_id"`
469+
Inviter *discord.User `json:"inviter"`
470+
MaxAge int `json:"max_age"`
471+
MaxUses int `json:"max_uses"`
472+
TargetType discord.InviteTargetType `json:"target_type"`
473+
TargetUser *discord.User `json:"target_user"`
474+
TargetApplication *discord.PartialApplication `json:"target_application"`
475+
Temporary bool `json:"temporary"`
476+
Uses int `json:"uses"`
466477
}
467478

468479
func (EventInviteCreate) messageData() {}

handlers/invite_handlers.go

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,23 @@
11
package handlers
22

33
import (
4-
"github.com/disgoorg/snowflake/v2"
5-
64
"github.com/disgoorg/disgo/bot"
75
"github.com/disgoorg/disgo/events"
86
"github.com/disgoorg/disgo/gateway"
97
)
108

119
func gatewayHandlerInviteCreate(client bot.Client, sequenceNumber int, shardID int, event gateway.EventInviteCreate) {
12-
var guildID *snowflake.ID
13-
if event.Guild != nil {
14-
guildID = &event.Guild.ID
15-
}
16-
1710
client.EventManager().DispatchEvent(&events.InviteCreate{
18-
GenericInvite: &events.GenericInvite{
19-
GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID),
20-
GuildID: guildID,
21-
Code: event.Code,
22-
ChannelID: event.ChannelID,
23-
},
24-
Invite: event.Invite,
11+
GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID),
12+
EventInviteCreate: event,
2513
})
2614
}
2715

2816
func gatewayHandlerInviteDelete(client bot.Client, sequenceNumber int, shardID int, event gateway.EventInviteDelete) {
2917
client.EventManager().DispatchEvent(&events.InviteDelete{
30-
GenericInvite: &events.GenericInvite{
31-
GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID),
32-
GuildID: event.GuildID,
33-
ChannelID: event.ChannelID,
34-
Code: event.Code,
35-
},
18+
GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID),
19+
GuildID: event.GuildID,
20+
ChannelID: event.ChannelID,
21+
Code: event.Code,
3622
})
3723
}

0 commit comments

Comments
 (0)