diff --git a/api/audio_controller.go b/api/audio_controller.go index 4819ca7a..ae9e8388 100644 --- a/api/audio_controller.go +++ b/api/audio_controller.go @@ -4,7 +4,7 @@ import "errors" // errors returned when no gateway or ws conn exists var ( - ErrNoGateway = errors.New("no gateway initialized") + ErrNoGateway = errors.New("no gateway initialized") ErrNoGatewayConn = errors.New("no active gateway connection found") ) diff --git a/api/disgo.go b/api/disgo.go index 7730a960..c491ebea 100644 --- a/api/disgo.go +++ b/api/disgo.go @@ -20,7 +20,7 @@ type Disgo interface { RestClient() RestClient WebhookServer() WebhookServer Cache() Cache - Intents() Intents + GatewayIntents() GatewayIntents RawGatewayEventsEnabled() bool ApplicationID() Snowflake SelfUser() *User @@ -56,7 +56,7 @@ type GatewayEventHandler interface { // WebhookEventHandler is used to handle raw webhook events type WebhookEventHandler interface { EventHandler - HandleWebhookEvent(disgo Disgo, eventManager EventManager, replyChannel chan interface{}, payload interface{}) + HandleWebhookEvent(disgo Disgo, eventManager EventManager, replyChannel chan *InteractionResponse, payload interface{}) } // EventListener is used to create new EventListener to listen to events @@ -75,7 +75,7 @@ type EventManager interface { Disgo() Disgo Close() AddEventListeners(eventListeners ...EventListener) - Handle(eventType GatewayEventType, replyChannel chan interface{}, sequenceNumber int, payload json.RawMessage) + Handle(eventType GatewayEventType, replyChannel chan *InteractionResponse, sequenceNumber int, payload json.RawMessage) Dispatch(event Event) } diff --git a/api/disgo_builder.go b/api/disgo_builder.go index 5469f2e7..a9b0620b 100644 --- a/api/disgo_builder.go +++ b/api/disgo_builder.go @@ -11,7 +11,7 @@ type DisgoBuilder interface { SetLogger(level log.Logger) DisgoBuilder SetToken(token string) DisgoBuilder SetHTTPClient(httpClient *http.Client) DisgoBuilder - SetIntents(intents Intents) DisgoBuilder + SetGatewayIntents(GatewayIntents GatewayIntents) DisgoBuilder SetRawGatewayEventsEnabled(enabled bool) DisgoBuilder SetVoiceDispatchInterceptor(voiceDispatchInterceptor VoiceDispatchInterceptor) DisgoBuilder SetEntityBuilder(entityBuilder EntityBuilder) DisgoBuilder diff --git a/api/entity_builder.go b/api/entity_builder.go index 073b7711..c97a6379 100644 --- a/api/entity_builder.go +++ b/api/entity_builder.go @@ -1,7 +1,7 @@ package api // CacheStrategy is used to determine whether something should be cached when making an api request. When using the -// gateway, you'll receive the event shortly afterwards if you have the correct intents. +// gateway, you'll receive the event shortly afterwards if you have the correct GatewayIntents. type CacheStrategy func(disgo Disgo) bool // Default cache strategy choices diff --git a/api/events/dm_events.go b/api/events/dm_events.go index 6f271d81..88d06db3 100644 --- a/api/events/dm_events.go +++ b/api/events/dm_events.go @@ -26,7 +26,7 @@ type DMChannelDeleteEvent struct { GenericDMChannelEvent } -// DMUserTypingEvent indicates that a api.User started typing in a api.DMChannel(requires api.IntentsDirectMessageTyping) +// DMUserTypingEvent indicates that a api.User started typing in a api.DMChannel(requires api.GatewayIntentsDirectMessageTyping) type DMUserTypingEvent struct { GenericDMChannelEvent } diff --git a/api/events/dm_message_event.go b/api/events/dm_message_event.go index 39b012be..8c891132 100644 --- a/api/events/dm_message_event.go +++ b/api/events/dm_message_event.go @@ -4,7 +4,7 @@ import ( "github.com/DisgoOrg/disgo/api" ) -// GenericDMMessageEvent is called upon receiving DMMessageCreateEvent, DMMessageUpdateEvent, DMMessageDeleteEvent, GenericDMMessageReactionEvent, DMMessageReactionAddEvent, DMMessageReactionRemoveEvent, DMMessageReactionRemoveEmoteEvent or DMMessageReactionRemoveAllEvent(requires api.IntentsDirectMessages) +// GenericDMMessageEvent is called upon receiving DMMessageCreateEvent, DMMessageUpdateEvent, DMMessageDeleteEvent, GenericDMMessageReactionEvent, DMMessageReactionAddEvent, DMMessageReactionRemoveEvent, DMMessageReactionRemoveEmoteEvent or DMMessageReactionRemoveAllEvent(requires api.GatewayIntentsDirectMessages) type GenericDMMessageEvent struct { GenericMessageEvent } @@ -14,18 +14,18 @@ func (e GenericDMMessageEvent) DMChannel() *api.DMChannel { return e.Disgo().Cache().DMChannel(e.ChannelID) } -// DMMessageCreateEvent is called upon receiving a api.Message in a api.DMChannel(requires api.IntentsDirectMessages) +// DMMessageCreateEvent is called upon receiving a api.Message in a api.DMChannel(requires api.GatewayIntentsDirectMessages) type DMMessageCreateEvent struct { GenericDMMessageEvent } -// DMMessageUpdateEvent is called upon editing a api.Message in a api.DMChannel(requires api.IntentsDirectMessages) +// DMMessageUpdateEvent is called upon editing a api.Message in a api.DMChannel(requires api.GatewayIntentsDirectMessages) type DMMessageUpdateEvent struct { GenericDMMessageEvent OldMessage *api.Message } -// DMMessageDeleteEvent is called upon deleting a api.Message in a api.DMChannel(requires api.IntentsDirectMessages) +// DMMessageDeleteEvent is called upon deleting a api.Message in a api.DMChannel(requires api.GatewayIntentsDirectMessages) type DMMessageDeleteEvent struct { GenericDMMessageEvent } diff --git a/api/events/dm_message_reaction_events.go b/api/events/dm_message_reaction_events.go index 40027fe9..470084c6 100644 --- a/api/events/dm_message_reaction_events.go +++ b/api/events/dm_message_reaction_events.go @@ -2,7 +2,7 @@ package events import "github.com/DisgoOrg/disgo/api" -// GenericDMMessageReactionEvent is called upon receiving DMMessageReactionAddEvent or DMMessageReactionRemoveEvent(requires the api.IntentsDirectMessageReactions) +// GenericDMMessageReactionEvent is called upon receiving DMMessageReactionAddEvent or DMMessageReactionRemoveEvent(requires the api.GatewayIntentsDirectMessageReactions) type GenericDMMessageReactionEvent struct { GenericGuildMessageEvent UserID api.Snowflake @@ -10,23 +10,23 @@ type GenericDMMessageReactionEvent struct { MessageReaction api.MessageReaction } -// DMMessageReactionAddEvent indicates that a api.User added a api.MessageReaction to a api.Message in a api.DMChannel(requires the api.IntentsDirectMessageReactions) +// DMMessageReactionAddEvent indicates that a api.User added a api.MessageReaction to a api.Message in a api.DMChannel(requires the api.GatewayIntentsDirectMessageReactions) type DMMessageReactionAddEvent struct { GenericDMMessageReactionEvent } -// DMMessageReactionRemoveEvent indicates that a api.User removed a api.MessageReaction from a api.Message in a api.DMChannel(requires the api.IntentsDirectMessageReactions) +// DMMessageReactionRemoveEvent indicates that a api.User removed a api.MessageReaction from a api.Message in a api.DMChannel(requires the api.GatewayIntentsDirectMessageReactions) type DMMessageReactionRemoveEvent struct { GenericDMMessageReactionEvent } -// DMMessageReactionRemoveEmoteEvent indicates someone removed all api.MessageReaction of a specific api.Emote from a api.Message in a api.DMChannel(requires the api.IntentsDirectMessageReactions) +// DMMessageReactionRemoveEmoteEvent indicates someone removed all api.MessageReaction of a specific api.Emote from a api.Message in a api.DMChannel(requires the api.GatewayIntentsDirectMessageReactions) type DMMessageReactionRemoveEmoteEvent struct { GenericDMMessageEvent MessageReaction api.MessageReaction } -// DMMessageReactionRemoveAllEvent indicates someone removed all api.MessageReaction(s) from a api.Message in a api.DMChannel(requires the api.IntentsDirectMessageReactions) +// DMMessageReactionRemoveAllEvent indicates someone removed all api.MessageReaction(s) from a api.Message in a api.DMChannel(requires the api.GatewayIntentsDirectMessageReactions) type DMMessageReactionRemoveAllEvent struct { GenericDMMessageEvent } diff --git a/api/events/emote_events.go b/api/events/emote_events.go index 7e6f6876..bcafda7a 100644 --- a/api/events/emote_events.go +++ b/api/events/emote_events.go @@ -4,24 +4,24 @@ import ( "github.com/DisgoOrg/disgo/api" ) -// GenericEmoteEvent is called upon receiving EmoteCreateEvent, EmoteUpdateEvent or EmoteDeleteEvent(requires api.IntentsGuildEmojis) +// GenericEmoteEvent is called upon receiving EmoteCreateEvent, EmoteUpdateEvent or EmoteDeleteEvent(requires api.GatewayIntentsGuildEmojis) type GenericEmoteEvent struct { GenericGuildEvent Emote *api.Emote } -// EmoteCreateEvent indicates that a new api.Emote got created in a api.Guild(requires api.IntentsGuildEmojis) +// EmoteCreateEvent indicates that a new api.Emote got created in a api.Guild(requires api.GatewayIntentsGuildEmojis) type EmoteCreateEvent struct { GenericEmoteEvent } -// EmoteUpdateEvent indicates that a api.Emote got updated in a api.Guild(requires api.IntentsGuildEmojis) +// EmoteUpdateEvent indicates that a api.Emote got updated in a api.Guild(requires api.GatewayIntentsGuildEmojis) type EmoteUpdateEvent struct { GenericEmoteEvent OldEmote *api.Emote } -// EmoteDeleteEvent indicates that a api.Emote got deleted in a api.Guild(requires api.IntentsGuildEmojis) +// EmoteDeleteEvent indicates that a api.Emote got deleted in a api.Guild(requires api.GatewayIntentsGuildEmojis) type EmoteDeleteEvent struct { GenericEmoteEvent } diff --git a/api/events/guild_invite_events.go b/api/events/guild_invite_events.go index 0fa4c812..fc66ca8d 100644 --- a/api/events/guild_invite_events.go +++ b/api/events/guild_invite_events.go @@ -4,7 +4,7 @@ import ( "github.com/DisgoOrg/disgo/api" ) -// GenericGuildInviteEvent is called upon receiving GuildInviteCreateEvent or GuildInviteDeleteEvent(requires api.IntentsGuildInvites) +// GenericGuildInviteEvent is called upon receiving GuildInviteCreateEvent or GuildInviteDeleteEvent(requires api.GatewayIntentsGuildInvites) type GenericGuildInviteEvent struct { GenericGuildEvent Code string @@ -35,22 +35,24 @@ func (e GenericGuildInviteEvent) TextChannel() *api.TextChannel { func (e GenericGuildInviteEvent) VoiceChannel() *api.VoiceChannel { return e.Disgo().Cache().VoiceChannel(e.ChannelID) } + // StoreChannel returns the api.StoreChannel the GenericGuildInviteEvent happened in(returns nil if the api.StoreChannel is uncached or api.CacheFlagStoreChannels is disabled) func (e GenericGuildInviteEvent) StoreChannel() *api.StoreChannel { return e.Disgo().Cache().StoreChannel(e.ChannelID) } + // Category returns the api.Category the GenericGuildInviteEvent happened in(returns nil if the api.Category is uncached or api.CacheFlagCategories is disabled) func (e GenericGuildInviteEvent) Category() *api.Category { return e.Disgo().Cache().Category(e.ChannelID) } -// GuildInviteCreateEvent is called upon creation of a new api.Invite in a api.Guild(requires api.IntentsGuildInvites) +// GuildInviteCreateEvent is called upon creation of a new api.Invite in a api.Guild(requires api.GatewayIntentsGuildInvites) type GuildInviteCreateEvent struct { GenericGuildInviteEvent Invite *api.Invite } -// GuildInviteDeleteEvent is called upon deletion of a new api.Invite in a api.Guild(requires api.IntentsGuildInvites) +// GuildInviteDeleteEvent is called upon deletion of a new api.Invite in a api.Guild(requires api.GatewayIntentsGuildInvites) type GuildInviteDeleteEvent struct { GenericGuildInviteEvent } diff --git a/api/events/guild_member_events.go b/api/events/guild_member_events.go index 32ce9a55..7d8c16b4 100644 --- a/api/events/guild_member_events.go +++ b/api/events/guild_member_events.go @@ -35,7 +35,7 @@ type GuildMemberLeaveEvent struct { User *api.User } -// GuildMemberTypingEvent indicates that a api.Member started typing in a api.TextChannel(requires api.IntentsGuildMessageTyping) +// GuildMemberTypingEvent indicates that a api.Member started typing in a api.TextChannel(requires api.GatewayIntentsGuildMessageTyping) type GuildMemberTypingEvent struct { GenericGuildMemberEvent ChannelID api.Snowflake diff --git a/api/events/guild_message_reaction_events.go b/api/events/guild_message_reaction_events.go index 77f0f7ed..d9f70104 100644 --- a/api/events/guild_message_reaction_events.go +++ b/api/events/guild_message_reaction_events.go @@ -1,6 +1,7 @@ package events import "github.com/DisgoOrg/disgo/api" + // GenericGuildMessageReactionEvent is called upon receiving DMMessageReactionAddEvent or DMMessageReactionRemoveEvent type GenericGuildMessageReactionEvent struct { GenericGuildMessageEvent @@ -8,23 +9,24 @@ type GenericGuildMessageReactionEvent struct { Member *api.Member MessageReaction api.MessageReaction } -// GuildMessageReactionAddEvent indicates that a api.Member added a api.MessageReaction to a api.Message in a api.TextChannel(requires the api.IntentsGuildMessageReactions) + +// GuildMessageReactionAddEvent indicates that a api.Member added a api.MessageReaction to a api.Message in a api.TextChannel(requires the api.GatewayIntentsGuildMessageReactions) type GuildMessageReactionAddEvent struct { GenericGuildMessageReactionEvent } -// GuildMessageReactionRemoveEvent indicates that a api.Member removed a api.MessageReaction from a api.Message in a api.TextChannel(requires the api.IntentsGuildMessageReactions) +// GuildMessageReactionRemoveEvent indicates that a api.Member removed a api.MessageReaction from a api.Message in a api.TextChannel(requires the api.GatewayIntentsGuildMessageReactions) type GuildMessageReactionRemoveEvent struct { GenericGuildMessageReactionEvent } -// GuildMessageReactionRemoveEmoteEvent indicates someone removed all api.MessageReaction of a specific api.Emote from a api.Message in a api.TextChannel(requires the api.IntentsGuildMessageReactions) +// GuildMessageReactionRemoveEmoteEvent indicates someone removed all api.MessageReaction of a specific api.Emote from a api.Message in a api.TextChannel(requires the api.GatewayIntentsGuildMessageReactions) type GuildMessageReactionRemoveEmoteEvent struct { GenericGuildMessageEvent MessageReaction api.MessageReaction } -// GuildMessageReactionRemoveAllEvent indicates someone removed all api.MessageReaction(s) from a api.Message in a api.TextChannel(requires the api.IntentsGuildMessageReactions) +// GuildMessageReactionRemoveAllEvent indicates someone removed all api.MessageReaction(s) from a api.Message in a api.TextChannel(requires the api.GatewayIntentsGuildMessageReactions) type GuildMessageReactionRemoveAllEvent struct { GenericGuildMessageEvent } diff --git a/api/events/guild_voice_events.go b/api/events/guild_voice_events.go index 60d14088..cd6ca213 100644 --- a/api/events/guild_voice_events.go +++ b/api/events/guild_voice_events.go @@ -10,18 +10,18 @@ type GenericGuildVoiceEvent struct { VoiceState *api.VoiceState } -// GuildVoiceJoinEvent indicates that a api.Member joined a api.VoiceChannel(requires api.IntentsGuildVoiceStates) +// GuildVoiceJoinEvent indicates that a api.Member joined a api.VoiceChannel(requires api.GatewayIntentsGuildVoiceStates) type GuildVoiceJoinEvent struct { GenericGuildVoiceEvent } -// GuildVoiceUpdateEvent indicates that a api.Member moved a api.VoiceChannel(requires api.IntentsGuildVoiceStates) +// GuildVoiceUpdateEvent indicates that a api.Member moved a api.VoiceChannel(requires api.GatewayIntentsGuildVoiceStates) type GuildVoiceUpdateEvent struct { GenericGuildVoiceEvent OldVoiceState *api.VoiceState } -// GuildVoiceLeaveEvent indicates that a api.Member left a api.VoiceChannel(requires api.IntentsGuildVoiceStates) +// GuildVoiceLeaveEvent indicates that a api.Member left a api.VoiceChannel(requires api.GatewayIntentsGuildVoiceStates) type GuildVoiceLeaveEvent struct { GenericGuildVoiceEvent } diff --git a/api/events/interaction_events.go b/api/events/interaction_events.go index bc9611d3..28da43fb 100644 --- a/api/events/interaction_events.go +++ b/api/events/interaction_events.go @@ -9,47 +9,7 @@ import ( // GenericInteractionEvent generic api.Interaction event type GenericInteractionEvent struct { GenericEvent - *api.Interaction -} - -// Guild returns the api.Guild from the api.Cache -func (e GenericInteractionEvent) Guild() *api.Guild { - if e.Interaction.GuildID == nil { - return nil - } - return e.Disgo().Cache().Guild(*e.Interaction.GuildID) -} - -// DMChannel returns the api.DMChannel from the api.Cache -func (e GenericInteractionEvent) DMChannel() *api.DMChannel { - if e.Interaction.ChannelID == nil { - return nil - } - return e.Disgo().Cache().DMChannel(*e.Interaction.ChannelID) -} - -// MessageChannel returns the api.MessageChannel from the api.Cache -func (e GenericInteractionEvent) MessageChannel() *api.MessageChannel { - if e.Interaction.ChannelID == nil { - return nil - } - return e.Disgo().Cache().MessageChannel(*e.Interaction.ChannelID) -} - -// TextChannel returns the api.TextChannel from the api.Cache -func (e GenericInteractionEvent) TextChannel() *api.TextChannel { - if e.Interaction.ChannelID == nil { - return nil - } - return e.Disgo().Cache().TextChannel(*e.Interaction.ChannelID) -} - -// GuildChannel returns the api.GuildChannel from the api.Cache -func (e GenericInteractionEvent) GuildChannel() *api.GuildChannel { - if e.Interaction.ChannelID == nil { - return nil - } - return e.Disgo().Cache().GuildChannel(*e.Interaction.ChannelID) + Interaction *api.Interaction } // SlashCommandEvent indicates that a slash api.Command was ran in a api.Guild @@ -109,8 +69,17 @@ func (e SlashCommandEvent) OptionsT(optionType api.CommandOptionType) []*api.Opt } // Acknowledge replies to the api.Interaction with api.InteractionResponseTypeDeferredChannelMessageWithSource -func (e *SlashCommandEvent) Acknowledge() error { - return e.Reply(api.NewInteractionResponseBuilder().SetType(api.InteractionResponseTypeDeferredChannelMessageWithSource).Build()) +func (e *SlashCommandEvent) Acknowledge(ephemeral bool) error { + var data *api.InteractionResponseData + if ephemeral { + data = &api.InteractionResponseData{ + Flags: api.MessageFlagEphemeral, + } + } + return e.Reply(&api.InteractionResponse{ + Type: api.InteractionResponseTypeDeferredChannelMessageWithSource, + Data: data, + }) } // Reply replies to the api.Interaction with the provided api.InteractionResponse @@ -125,30 +94,5 @@ func (e *SlashCommandEvent) Reply(response *api.InteractionResponse) error { return nil } - return e.Disgo().RestClient().SendInteractionResponse(e.Interaction.ID, e.Interaction.Token, response) -} - -// EditOriginal edits the original api.InteractionResponse -func (e *SlashCommandEvent) EditOriginal(followupMessage *api.FollowupMessage) (*api.Message, error) { - return e.Disgo().RestClient().EditInteractionResponse(e.Disgo().ApplicationID(), e.Interaction.Token, followupMessage) -} - -// DeleteOriginal deletes the original api.InteractionResponse -func (e *SlashCommandEvent) DeleteOriginal() error { - return e.Disgo().RestClient().DeleteInteractionResponse(e.Disgo().ApplicationID(), e.Interaction.Token) -} - -// SendFollowup used to send a api.FollowupMessage to an api.Interaction -func (e *SlashCommandEvent) SendFollowup(followupMessage *api.FollowupMessage) (*api.Message, error) { - return e.Disgo().RestClient().SendFollowupMessage(e.Disgo().ApplicationID(), e.Interaction.Token, followupMessage) -} - -// EditFollowup used to edit a api.FollowupMessage from an api.Interaction -func (e *SlashCommandEvent) EditFollowup(messageID api.Snowflake, followupMessage *api.FollowupMessage) (*api.Message, error) { - return e.Disgo().RestClient().EditFollowupMessage(e.Disgo().ApplicationID(), e.Interaction.Token, messageID, followupMessage) -} - -// DeleteFollowup used to delete a api.FollowupMessage from an api.Interaction -func (e *SlashCommandEvent) DeleteFollowup(messageID api.Snowflake) error { - return e.Disgo().RestClient().DeleteFollowupMessage(e.Disgo().ApplicationID(), e.Interaction.Token, messageID) + return e.Interaction.Disgo.RestClient().SendInteractionResponse(e.Interaction.ID, e.Interaction.Token, response) } diff --git a/api/events/message_reaction_events.go b/api/events/message_reaction_events.go index fc4cf972..b8e7da36 100644 --- a/api/events/message_reaction_events.go +++ b/api/events/message_reaction_events.go @@ -10,23 +10,23 @@ type GenericReactionEvents struct { MessageReaction api.MessageReaction } -// MessageReactionAddEvent indicates that a api.User added a api.MessageReaction to a api.Message in a api.Channel(this+++ requires the api.IntentsGuildMessageReactions and/or api.IntentsDirectMessageReactions) +// MessageReactionAddEvent indicates that a api.User added a api.MessageReaction to a api.Message in a api.Channel(this+++ requires the api.GatewayIntentsGuildMessageReactions and/or api.GatewayIntentsDirectMessageReactions) type MessageReactionAddEvent struct { GenericReactionEvents } -// MessageReactionRemoveEvent indicates that a api.User removed a api.MessageReaction from a api.Message in a api.Channel(requires the api.IntentsGuildMessageReactions and/or api.IntentsDirectMessageReactions) +// MessageReactionRemoveEvent indicates that a api.User removed a api.MessageReaction from a api.Message in a api.Channel(requires the api.GatewayIntentsGuildMessageReactions and/or api.GatewayIntentsDirectMessageReactions) type MessageReactionRemoveEvent struct { GenericReactionEvents } -// MessageReactionRemoveEmoteEvent indicates someone removed all api.MessageReaction of a specific api.Emote from a api.Message in a api.Channel(requires the api.IntentsGuildMessageReactions and/or api.IntentsDirectMessageReactions) +// MessageReactionRemoveEmoteEvent indicates someone removed all api.MessageReaction of a specific api.Emote from a api.Message in a api.Channel(requires the api.GatewayIntentsGuildMessageReactions and/or api.GatewayIntentsDirectMessageReactions) type MessageReactionRemoveEmoteEvent struct { GenericMessageEvent MessageReaction api.MessageReaction } -// MessageReactionRemoveAllEvent indicates someone removed all api.MessageReaction(s) from a api.Message in a api.Channel(requires the api.IntentsGuildMessageReactions and/or api.IntentsDirectMessageReactionss) +// MessageReactionRemoveAllEvent indicates someone removed all api.MessageReaction(s) from a api.Message in a api.Channel(requires the api.GatewayIntentsGuildMessageReactions and/or api.GatewayIntentsDirectMessageReactionss) type MessageReactionRemoveAllEvent struct { GenericMessageEvent } diff --git a/api/events/self_update_events.go b/api/events/self_update_events.go index 4a12a6c4..61221f1c 100644 --- a/api/events/self_update_events.go +++ b/api/events/self_update_events.go @@ -7,6 +7,6 @@ import ( // SelfUpdateEvent is called when something about this api.User updates type SelfUpdateEvent struct { GenericEvent - Self *api.User + Self *api.User OldSelf *api.User } diff --git a/api/events/user_activity_events.go b/api/events/user_activity_events.go index 3aa5a942..cd98991b 100644 --- a/api/events/user_activity_events.go +++ b/api/events/user_activity_events.go @@ -4,26 +4,26 @@ import ( "github.com/DisgoOrg/disgo/api" ) -// GenericUserActivityEvent is called upon receiving UserActivityStartEvent, UserActivityUpdateEvent or UserActivityEndEvent(requires the api.IntentsGuildPresences) +// GenericUserActivityEvent is called upon receiving UserActivityStartEvent, UserActivityUpdateEvent or UserActivityEndEvent(requires the api.GatewayIntentsGuildPresences) type GenericUserActivityEvent struct { GenericGuildMemberEvent Member *api.Member } -// UserActivityStartEvent indicates that a api.User started a new api.Activity(requires the api.IntentsGuildPresences) +// UserActivityStartEvent indicates that a api.User started a new api.Activity(requires the api.GatewayIntentsGuildPresences) type UserActivityStartEvent struct { GenericUserActivityEvent Activity *api.Activity } -// UserActivityUpdateEvent indicates that a api.User's api.Activity(s) updated(requires the api.IntentsGuildPresences) +// UserActivityUpdateEvent indicates that a api.User's api.Activity(s) updated(requires the api.GatewayIntentsGuildPresences) type UserActivityUpdateEvent struct { GenericUserActivityEvent NewActivities *api.Activity OldActivities *api.Activity } -// UserActivityEndEvent indicates that a api.User ended a api.Activity(requires the api.IntentsGuildPresences) +// UserActivityEndEvent indicates that a api.User ended a api.Activity(requires the api.GatewayIntentsGuildPresences) type UserActivityEndEvent struct { GenericUserActivityEvent Activity *api.Activity diff --git a/api/events/user_events.go b/api/events/user_events.go index c961ccbf..0ae3381a 100644 --- a/api/events/user_events.go +++ b/api/events/user_events.go @@ -16,7 +16,8 @@ type UserUpdateEvent struct { GenericUserEvent OldUser *api.User } -// UserTypingEvent indicates that a api.User started typing in a api.DMChannel or api.TextChannel(requires the api.IntentsDirectMessageTyping and/or api.IntentsGuildMessageTyping) + +// UserTypingEvent indicates that a api.User started typing in a api.DMChannel or api.TextChannel(requires the api.GatewayIntentsDirectMessageTyping and/or api.GatewayIntentsGuildMessageTyping) type UserTypingEvent struct { GenericUserEvent ChannelID api.Snowflake diff --git a/api/gateway.go b/api/gateway.go index 6b47acaa..cc11abd9 100644 --- a/api/gateway.go +++ b/api/gateway.go @@ -57,49 +57,53 @@ type GatewayEventType string // Constants for the gateway events const ( - GatewayEventApplicationCommandCreate GatewayEventType = "APPLICATION_COMMAND_CREATE" - GatewayEventApplicationCommandUpdate GatewayEventType = "APPLICATION_COMMAND_UPDATE" - GatewayEventApplicationCommandDelete GatewayEventType = "APPLICATION_COMMAND_DELETE" - GatewayEventChannelCreate GatewayEventType = "CHANNEL_CREATE" - GatewayEventChannelDelete GatewayEventType = "CHANNEL_DELETE" - GatewayEventChannelPinsUpdate GatewayEventType = "CHANNEL_PINS_UPDATE" - GatewayEventChannelUpdate GatewayEventType = "CHANNEL_UPDATE" - GatewayEventGuildBanAdd GatewayEventType = "GUILD_BAN_ADD" - GatewayEventGuildBanRemove GatewayEventType = "GUILD_BAN_REMOVE" - GatewayEventGuildCreate GatewayEventType = "GUILD_CREATE" - GatewayEventGuildDelete GatewayEventType = "GUILD_DELETE" - GatewayEventGuildEmojisUpdate GatewayEventType = "GUILD_EMOJIS_UPDATE" - GatewayEventGuildIntegrationsUpdate GatewayEventType = "GUILD_INTEGRATIONS_UPDATE" - GatewayEventGuildMemberAdd GatewayEventType = "GUILD_MEMBER_ADD" - GatewayEventGuildMemberRemove GatewayEventType = "GUILD_MEMBER_REMOVE" - GatewayEventGuildMemberUpdate GatewayEventType = "GUILD_MEMBER_UPDATE" - GatewayEventGuildMembersChunk GatewayEventType = "GUILD_MEMBERS_CHUNK" - GatewayEventGuildRoleCreate GatewayEventType = "GUILD_ROLE_CREATE" - GatewayEventGuildRoleDelete GatewayEventType = "GUILD_ROLE_DELETE" - GatewayEventGuildRoleUpdate GatewayEventType = "GUILD_ROLE_UPDATE" - GatewayEventGuildUpdate GatewayEventType = "GUILD_UPDATE" - GatewayEventInteractionCreate GatewayEventType = "INTERACTION_CREATE" - WebhookEventInteractionCreate GatewayEventType = "INTERACTION_WEBHOOK_CREATE" - GatewayEventMessageAck GatewayEventType = "MESSAGE_ACK" - GatewayEventMessageCreate GatewayEventType = "MESSAGE_CREATE" - GatewayEventMessageDelete GatewayEventType = "MESSAGE_DELETE" - GatewayEventMessageDeleteBulk GatewayEventType = "MESSAGE_DELETE_BULK" - GatewayEventMessageReactionAdd GatewayEventType = "MESSAGE_REACTION_ADD" - GatewayEventMessageReactionRemove GatewayEventType = "MESSAGE_REACTION_REMOVE" - GatewayEventMessageReactionRemoveAll GatewayEventType = "MESSAGE_REACTION_REMOVE_ALL" - GatewayEventMessageUpdate GatewayEventType = "MESSAGE_UPDATE" - GatewayEventPresenceUpdate GatewayEventType = "PRESENCE_UPDATE" - GatewayEventPresencesReplace GatewayEventType = "PRESENCES_REPLACE" - GatewayEventReady GatewayEventType = "READY" - GatewayEventResumed GatewayEventType = "RESUMED" - GatewayEventTypingStart GatewayEventType = "TYPING_START" - GatewayEventUserGuildSettingsUpdate GatewayEventType = "USER_GUILD_SETTINGS_UPDATE" - GatewayEventUserNoteUpdate GatewayEventType = "USER_NOTE_UPDATE" - GatewayEventUserSettingsUpdate GatewayEventType = "USER_SETTINGS_UPDATE" - GatewayEventUserUpdate GatewayEventType = "USER_UPDATE" - GatewayEventVoiceServerUpdate GatewayEventType = "VOICE_SERVER_UPDATE" - GatewayEventVoiceStateUpdate GatewayEventType = "VOICE_STATE_UPDATE" - GatewayEventWebhooksUpdate GatewayEventType = "WEBHOOKS_UPDATE" + GatewayEventHello GatewayEventType = "HELLO" + GatewayEventReady GatewayEventType = "READY" + GatewayEventResumed GatewayEventType = "RESUMED" + GatewayEventReconnect GatewayEventType = "RECONNECT" + GatewayEventInvalidSession GatewayEventType = "INVALID_SESSION" + GatewayEventApplicationCommandCreate GatewayEventType = "APPLICATION_COMMAND_CREATE" + GatewayEventApplicationCommandUpdate GatewayEventType = "APPLICATION_COMMAND_UPDATE" + GatewayEventApplicationCommandDelete GatewayEventType = "APPLICATION_COMMAND_DELETE" + GatewayEventChannelCreate GatewayEventType = "CHANNEL_CREATE" + GatewayEventChannelUpdate GatewayEventType = "CHANNEL_UPDATE" + GatewayEventChannelDelete GatewayEventType = "CHANNEL_DELETE" + GatewayEventChannelPinsUpdate GatewayEventType = "CHANNEL_PINS_UPDATE" + GatewayEventGuildCreate GatewayEventType = "GUILD_CREATE" + GatewayEventGuildUpdate GatewayEventType = "GUILD_UPDATE" + GatewayEventGuildDelete GatewayEventType = "GUILD_DELETE" + GatewayEventGuildBanAdd GatewayEventType = "GUILD_BAN_ADD" + GatewayEventGuildBanRemove GatewayEventType = "GUILD_BAN_REMOVE" + GatewayEventGuildEmojisUpdate GatewayEventType = "GUILD_EMOJIS_UPDATE" + GatewayEventGuildIntegrationsUpdate GatewayEventType = "GUILD_INTEGRATIONS_UPDATE" + GatewayEventGuildMemberAdd GatewayEventType = "GUILD_MEMBER_ADD" + GatewayEventGuildMemberRemove GatewayEventType = "GUILD_MEMBER_REMOVE" + GatewayEventGuildMemberUpdate GatewayEventType = "GUILD_MEMBER_UPDATE" + GatewayEventGuildMembersChunk GatewayEventType = "GUILD_MEMBERS_CHUNK" + GatewayEventGuildRoleCreate GatewayEventType = "GUILD_ROLE_CREATE" + GatewayEventGuildRoleUpdate GatewayEventType = "GUILD_ROLE_UPDATE" + GatewayEventGuildRoleDelete GatewayEventType = "GUILD_ROLE_DELETE" + GatewayEventIntegrationCreate GatewayEventType = "INTEGRATION_CREATE" + GatewayEventIntegrationUpdate GatewayEventType = "INTEGRATION_UPDATE" + GatewayEventIntegrationDelete GatewayEventType = "INTEGRATION_DELETE" + GatewayEventInteractionCreate GatewayEventType = "INTERACTION_CREATE" + WebhookEventInteractionCreate GatewayEventType = "WEBHOOK_INTERACTION_CREATE" + GatewayEventInviteCreate GatewayEventType = "INVITE_CREATE" + GatewayEventInviteDelete GatewayEventType = "INVITE_DELETE" + GatewayEventMessageCreate GatewayEventType = "MESSAGE_CREATE" + GatewayEventMessageUpdate GatewayEventType = "MESSAGE_UPDATE" + GatewayEventMessageDelete GatewayEventType = "MESSAGE_DELETE" + GatewayEventMessageDeleteBulk GatewayEventType = "MESSAGE_DELETE_BULK" + GatewayEventMessageReactionAdd GatewayEventType = "MESSAGE_REACTION_ADD" + GatewayEventMessageReactionRemove GatewayEventType = "MESSAGE_REACTION_REMOVE" + GatewayEventMessageReactionRemoveAll GatewayEventType = "MESSAGE_REACTION_REMOVE_ALL" + GatewayEventMessageReactionRemoveAllEmoji GatewayEventType = "MESSAGE_REACTION_REMOVE_ALL_EMOJI" + GatewayEventPresenceUpdate GatewayEventType = "PRESENCE_UPDATE" + GatewayEventTypingStart GatewayEventType = "TYPING_START" + GatewayEventUserUpdate GatewayEventType = "USER_UPDATE" + GatewayEventVoiceStateUpdate GatewayEventType = "VOICE_STATE_UPDATE" + GatewayEventVoiceServerUpdate GatewayEventType = "VOICE_SERVER_UPDATE" + GatewayEventWebhooksUpdate GatewayEventType = "WEBHOOKS_UPDATE" ) // GatewayRs contains the response for GET /gateway diff --git a/api/gateway_commands.go b/api/gateway_commands.go index 239a6963..fc6c5434 100644 --- a/api/gateway_commands.go +++ b/api/gateway_commands.go @@ -1,8 +1,8 @@ package api // NewGatewayCommand returns a new GatewayCommand struct with the given payload -func NewGatewayCommand(op GatewayOp, d interface{}) GatewayCommand { - return GatewayCommand{ +func NewGatewayCommand(op GatewayOp, d interface{}) *GatewayCommand { + return &GatewayCommand{ GatewayPacket: GatewayPacket{ Op: op, S: nil, @@ -24,7 +24,7 @@ type IdentifyCommand struct { Properties IdentifyCommandDataProperties `json:"properties"` Compress bool `json:"compress,omitempty"` LargeThreshold int `json:"large_threshold,omitempty"` - Intents Intents `json:"intents"` + GatewayIntents GatewayIntents `json:"intents"` // Todo: Add presence property here, need presence methods/struct // Todo: Add shard property here, need to discuss } diff --git a/api/gateway_intents.go b/api/gateway_intents.go new file mode 100644 index 00000000..526bb4a0 --- /dev/null +++ b/api/gateway_intents.go @@ -0,0 +1,92 @@ +package api + +// GatewayIntents is an extension of the Bit structure used when identifying with discord +type GatewayIntents int64 + +// Add allows you to add multiple bits together, producing a new bit +func (p GatewayIntents) Add(bits ...Bit) Bit { + total := GatewayIntents(0) + for _, bit := range bits { + total |= bit.(GatewayIntents) + } + p |= total + return p +} + +// Remove allows you to subtract multiple bits from the first, producing a new bit +func (p GatewayIntents) Remove(bits ...Bit) Bit { + total := GatewayIntents(0) + for _, bit := range bits { + total |= bit.(GatewayIntents) + } + p &^= total + return p +} + +// HasAll will ensure that the bit includes all of the bits entered +func (p GatewayIntents) HasAll(bits ...Bit) bool { + for _, bit := range bits { + if !p.Has(bit) { + return false + } + } + return true +} + +// Has will check whether the Bit contains another bit +func (p GatewayIntents) Has(bit Bit) bool { + return (p & bit.(GatewayIntents)) == bit +} + +// MissingAny will check whether the bit is missing any one of the bits +func (p GatewayIntents) MissingAny(bits ...Bit) bool { + for _, bit := range bits { + if !p.Has(bit) { + return true + } + } + return false +} + +// Missing will do the inverse of Bit.Has +func (p GatewayIntents) Missing(bit Bit) bool { + return !p.Has(bit) +} + +// Constants for the different bit offsets of GatewayIntents +const ( + GatewayIntentsGuilds GatewayIntents = 1 << iota + GatewayIntentsGuildMembers + GatewayIntentsGuildBans + GatewayIntentsGuildEmojis + GatewayIntentsGuildIntegrations + GatewayIntentsGuildWebhooks + GatewayIntentsGuildInvites + GatewayIntentsGuildVoiceStates + GatewayIntentsGuildPresences + GatewayIntentsGuildMessages + GatewayIntentsGuildMessageReactions + GatewayIntentsGuildMessageTyping + GatewayIntentsDirectMessages + GatewayIntentsDirectMessageReactions + GatewayIntentsDirectMessageTyping + + GatewayIntentsNonPrivileged = GatewayIntentsGuilds | + GatewayIntentsGuildBans | + GatewayIntentsGuildEmojis | + GatewayIntentsGuildIntegrations | + GatewayIntentsGuildWebhooks | + GatewayIntentsGuildInvites | + GatewayIntentsGuildVoiceStates | + GatewayIntentsGuildMessages | + GatewayIntentsGuildMessageReactions | + GatewayIntentsGuildMessageTyping | + GatewayIntentsDirectMessages | + GatewayIntentsDirectMessageReactions | + GatewayIntentsDirectMessageTyping + GatewayIntentsPrivileged = GatewayIntentsGuildMembers | + GatewayIntentsGuildPresences + GatewayIntentsAll = GatewayIntentsNonPrivileged | + GatewayIntentsPrivileged + GatewayIntentsNone GatewayIntents = 0 +) diff --git a/api/intents.go b/api/intents.go deleted file mode 100644 index bc907f75..00000000 --- a/api/intents.go +++ /dev/null @@ -1,91 +0,0 @@ -package api - -// Intents is an extension of the Bit structure used when identifying with discord -type Intents int64 - -// Add allows you to add multiple bits together, producing a new bit -func (p Intents) Add(bits ...Bit) Bit { - total := Intents(0) - for _, bit := range bits { - total |= bit.(Intents) - } - p |= total - return p -} - -// Remove allows you to subtract multiple bits from the first, producing a new bit -func (p Intents) Remove(bits ...Bit) Bit { - total := Intents(0) - for _, bit := range bits { - total |= bit.(Intents) - } - p &^= total - return p -} - -// HasAll will ensure that the bit includes all of the bits entered -func (p Intents) HasAll(bits ...Bit) bool { - for _, bit := range bits { - if !p.Has(bit) { - return false - } - } - return true -} - -// Has will check whether the Bit contains another bit -func (p Intents) Has(bit Bit) bool { - return (p & bit.(Intents)) == bit -} - -// MissingAny will check whether the bit is missing any one of the bits -func (p Intents) MissingAny(bits ...Bit) bool { - for _, bit := range bits { - if !p.Has(bit) { - return true - } - } - return false -} - -// Missing will do the inverse of Bit.Has -func (p Intents) Missing(bit Bit) bool { - return !p.Has(bit) -} - -// Constants for the different bit offsets of intents -const ( - IntentsGuilds Intents = 1 << iota - IntentsGuildMembers - IntentsGuildBans - IntentsGuildEmojis - IntentsGuildIntegrations - IntentsGuildWebhooks - IntentsGuildInvites - IntentsGuildVoiceStates - IntentsGuildPresences - IntentsGuildMessages - IntentsGuildMessageReactions - IntentsGuildMessageTyping - IntentsDirectMessages - IntentsDirectMessageReactions - IntentsDirectMessageTyping - - IntentsAllWithoutPrivileged = IntentsGuilds | - IntentsGuildBans | - IntentsGuildEmojis | - IntentsGuildIntegrations | - IntentsGuildWebhooks | - IntentsGuildInvites | - IntentsGuildVoiceStates | - IntentsGuildMessages | - IntentsGuildMessageReactions | - IntentsGuildMessageTyping | - IntentsDirectMessages | - IntentsDirectMessageReactions | - IntentsDirectMessageTyping - IntentsAll = IntentsAllWithoutPrivileged | - IntentsGuildMembers | - IntentsGuildPresences - IntentsNone Intents = 0 -) diff --git a/api/interaction.go b/api/interaction.go index 20cdbba4..af0a5a60 100644 --- a/api/interaction.go +++ b/api/interaction.go @@ -11,6 +11,7 @@ const ( // An Interaction is the slash command object you receive when a user uses one of your commands type Interaction struct { + Disgo Disgo ID Snowflake `json:"id"` Type InteractionType `json:"type"` Data *InteractionData `json:"data,omitempty"` @@ -22,6 +23,71 @@ type Interaction struct { Version int `json:"version"` } +// Guild returns the api.Guild from the api.Cache +func (i *Interaction) Guild() *Guild { + if i.GuildID == nil { + return nil + } + return i.Disgo.Cache().Guild(*i.GuildID) +} + +// DMChannel returns the api.DMChannel from the api.Cache +func (i *Interaction) DMChannel() *DMChannel { + if i.ChannelID == nil { + return nil + } + return i.Disgo.Cache().DMChannel(*i.ChannelID) +} + +// MessageChannel returns the api.MessageChannel from the api.Cache +func (i *Interaction) MessageChannel() *MessageChannel { + if i.ChannelID == nil { + return nil + } + return i.Disgo.Cache().MessageChannel(*i.ChannelID) +} + +// TextChannel returns the api.TextChannel from the api.Cache +func (i *Interaction) TextChannel() *TextChannel { + if i.ChannelID == nil { + return nil + } + return i.Disgo.Cache().TextChannel(*i.ChannelID) +} + +// GuildChannel returns the api.GuildChannel from the api.Cache +func (i *Interaction) GuildChannel() *GuildChannel { + if i.ChannelID == nil { + return nil + } + return i.Disgo.Cache().GuildChannel(*i.ChannelID) +} + +// EditOriginal edits the original api.InteractionResponse +func (i *Interaction) EditOriginal(followupMessage *FollowupMessage) (*Message, error) { + return i.Disgo.RestClient().EditInteractionResponse(i.Disgo.ApplicationID(), i.Token, followupMessage) +} + +// DeleteOriginal deletes the original api.InteractionResponse +func (i *Interaction) DeleteOriginal() error { + return i.Disgo.RestClient().DeleteInteractionResponse(i.Disgo.ApplicationID(), i.Token) +} + +// SendFollowup used to send a api.FollowupMessage to an api.Interaction +func (i *Interaction) SendFollowup(followupMessage *FollowupMessage) (*Message, error) { + return i.Disgo.RestClient().SendFollowupMessage(i.Disgo.ApplicationID(), i.Token, followupMessage) +} + +// EditFollowup used to edit a api.FollowupMessage from an api.Interaction +func (i *Interaction) EditFollowup(messageID Snowflake, followupMessage *FollowupMessage) (*Message, error) { + return i.Disgo.RestClient().EditFollowupMessage(i.Disgo.ApplicationID(), i.Token, messageID, followupMessage) +} + +// DeleteFollowup used to delete a api.FollowupMessage from an api.Interaction +func (i *Interaction) DeleteFollowup(messageID Snowflake) error { + return i.Disgo.RestClient().DeleteFollowupMessage(i.Disgo.ApplicationID(), i.Token, messageID) +} + // InteractionData is the command data payload type InteractionData struct { ID Snowflake `json:"id"` diff --git a/api/interaction_followup.go b/api/interaction_followup.go index 529d9f12..570c44ef 100644 --- a/api/interaction_followup.go +++ b/api/interaction_followup.go @@ -8,7 +8,7 @@ type FollowupMessage struct { TTS *bool `json:"tts,omitempty"` Embeds []*Embed `json:"embeds,omitempty"` AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"` - Flags *MessageFlags `json:"flags,omitempty"` + Flags MessageFlags `json:"flags,omitempty"` } // FollowupMessageBuilder allows you to create an FollowupMessage with ease @@ -83,7 +83,7 @@ func (b *FollowupMessageBuilder) SetAllowedMentionsEmpty() *FollowupMessageBuild // SetFlags sets the message flags of the FollowupMessage func (b *FollowupMessageBuilder) SetFlags(flags MessageFlags) *FollowupMessageBuilder { - b.Flags = &flags + b.Flags = flags return b } diff --git a/api/interaction_response.go b/api/interaction_response.go index 4df2f0dd..990efe29 100644 --- a/api/interaction_response.go +++ b/api/interaction_response.go @@ -26,7 +26,7 @@ type InteractionResponseData struct { Content *string `json:"content,omitempty"` Embeds []*Embed `json:"embeds,omitempty"` AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"` - Flags *MessageFlags `json:"flags,omitempty"` + Flags MessageFlags `json:"flags,omitempty"` } // InteractionResponseBuilder allows you to create an InteractionResponse with ease @@ -139,7 +139,7 @@ func (b *InteractionResponseBuilder) SetFlags(flags MessageFlags) *InteractionRe if b.Data == nil { b.Data = &InteractionResponseData{} } - b.Data.Flags = &flags + b.Data.Flags = flags return b } @@ -150,11 +150,11 @@ func (b *InteractionResponseBuilder) SetEphemeral(ephemeral bool) *InteractionRe } if ephemeral { if !b.Data.Flags.Has(MessageFlagEphemeral) { - b.Data.Flags.Add(MessageFlagEphemeral) + b.Data.Flags = b.Data.Flags.Add(MessageFlagEphemeral) } } else { if b.Data.Flags.Has(MessageFlagEphemeral) { - b.Data.Flags.Remove(MessageFlagEphemeral) + b.Data.Flags = b.Data.Flags.Remove(MessageFlagEphemeral) } } return b diff --git a/api/member.go b/api/member.go index a5ef98e1..dec914a7 100644 --- a/api/member.go +++ b/api/member.go @@ -17,7 +17,7 @@ type Member struct { Permissions *Permissions `json:"permissions,omitempty"` } -// VoiceState returns the VoiceState for this Member from the Cache(requires CacheFlagVoiceState and IntentsGuildVoiceStates) +// VoiceState returns the VoiceState for this Member from the Cache(requires CacheFlagVoiceState and GatewayIntentsGuildVoiceStates) func (m Member) VoiceState() *VoiceState { return m.Disgo.Cache().VoiceState(m.GuildID, m.User.ID) } diff --git a/api/message.go b/api/message.go index ad5906f9..5a1d4916 100644 --- a/api/message.go +++ b/api/message.go @@ -37,23 +37,23 @@ const ( type MessageFlags int64 // Add allows you to add multiple bits together, producing a new bit -func (f MessageFlags) Add(bits ...MessageFlags) *MessageFlags { +func (f MessageFlags) Add(bits ...MessageFlags) MessageFlags { total := MessageFlags(0) for _, bit := range bits { total |= bit } f |= total - return &f + return f } // Remove allows you to subtract multiple bits from the first, producing a new bit -func (f MessageFlags) Remove(bits ...MessageFlags) *MessageFlags { +func (f MessageFlags) Remove(bits ...MessageFlags) MessageFlags { total := MessageFlags(0) for _, bit := range bits { total |= bit } f &^= total - return &f + return f } // HasAll will ensure that the bit includes all of the bits entered diff --git a/api/options.go b/api/options.go index 22b01cdb..433d0979 100644 --- a/api/options.go +++ b/api/options.go @@ -9,7 +9,7 @@ import ( // Options is the configuration used when creating the client type Options struct { Logger log.Logger - Intents Intents + GatewayIntents GatewayIntents RestTimeout int EnableWebhookInteractions bool ListenPort int diff --git a/example/examplebot.go b/example/examplebot.go index 0c86325e..051922b4 100644 --- a/example/examplebot.go +++ b/example/examplebot.go @@ -35,7 +35,7 @@ func main() { dgo, err := disgo.NewBuilder(os.Getenv("token")). SetLogger(logger). SetHTTPClient(client). - SetIntents(api.IntentsGuilds | api.IntentsGuildMessages | api.IntentsGuildMembers). + SetGatewayIntents(api.GatewayIntentsGuilds | api.GatewayIntentsGuildMessages | api.GatewayIntentsGuildMembers). SetMemberCachePolicy(api.MemberCachePolicyAll). AddEventListeners(&events.ListenerAdapter{ OnGuildAvailable: guildAvailListener, @@ -194,7 +194,7 @@ func slashCommandListener(event *events.SlashCommandEvent) { embed.SetField(1, "Time", strconv.Itoa(int(elapsed.Milliseconds()))+"ms", true) if err != nil { - _, _ = event.EditOriginal(api.NewFollowupMessageBuilder(). + _, _ = event.Interaction.EditOriginal(api.NewFollowupMessageBuilder(). SetEmbeds(embed. SetColor(red). SetField(0, "Status", "Failed", true). @@ -205,7 +205,7 @@ func slashCommandListener(event *events.SlashCommandEvent) { ) return } - _, _ = event.EditOriginal(api.NewFollowupMessageBuilder(). + _, _ = event.Interaction.EditOriginal(api.NewFollowupMessageBuilder(). SetEmbeds(embed. SetColor(green). SetField(0, "Status", "Success", true). @@ -225,10 +225,10 @@ func slashCommandListener(event *events.SlashCommandEvent) { case "test": go func() { - _ = event.Acknowledge() + _ = event.Acknowledge(true) time.Sleep(2 * time.Second) - _, _ = event.EditOriginal(api.NewFollowupMessageBuilder(). + _, _ = event.Interaction.EditOriginal(api.NewFollowupMessageBuilder(). SetEmbeds(api.NewEmbedBuilder(). SetDescription("finished with thinking"). Build(), @@ -236,7 +236,7 @@ func slashCommandListener(event *events.SlashCommandEvent) { ) time.Sleep(1 * time.Second) - _, _ = event.SendFollowup(api.NewFollowupMessageBuilder(). + _, _ = event.Interaction.SendFollowup(api.NewFollowupMessageBuilder(). SetEmbeds(api.NewEmbedBuilder(). SetDescription("followup 1"). Build(), @@ -244,7 +244,7 @@ func slashCommandListener(event *events.SlashCommandEvent) { ) time.Sleep(1 * time.Second) - _, _ = event.SendFollowup(api.NewFollowupMessageBuilder(). + _, _ = event.Interaction.SendFollowup(api.NewFollowupMessageBuilder(). SetEphemeral(true). SetContent("followup 2 only you can see"). Build(), diff --git a/internal/disgo_builder_impl.go b/internal/disgo_builder_impl.go index ded4528e..760cb3d7 100644 --- a/internal/disgo_builder_impl.go +++ b/internal/disgo_builder_impl.go @@ -29,7 +29,7 @@ type DisgoBuilderImpl struct { memberCachePolicy api.MemberCachePolicy messageCachePolicy api.MessageCachePolicy cacheFlags api.CacheFlags - intents api.Intents + gatewayIntents api.GatewayIntents rawGatewayEventsEnabled bool entityBuilder api.EntityBuilder eventManager api.EventManager @@ -59,9 +59,9 @@ func (b *DisgoBuilderImpl) SetHTTPClient(httpClient *http.Client) api.DisgoBuild return b } -// SetIntents sets the api.Intents to connect to discord -func (b *DisgoBuilderImpl) SetIntents(intents api.Intents) api.DisgoBuilder { - b.intents = intents +// SetGatewayIntents sets the api.GatewayIntents to connect to discord +func (b *DisgoBuilderImpl) SetGatewayIntents(GatewayIntents api.GatewayIntents) api.DisgoBuilder { + b.gatewayIntents = GatewayIntents return b } @@ -204,7 +204,7 @@ func (b *DisgoBuilderImpl) Build() (api.Disgo, error) { } disgo.audioController = b.audioController - disgo.intents = b.intents + disgo.gatewayIntents = b.gatewayIntents if b.entityBuilder == nil { b.entityBuilder = newEntityBuilderImpl(disgo) diff --git a/internal/disgo_impl.go b/internal/disgo_impl.go index dc8d1fce..901256dd 100644 --- a/internal/disgo_impl.go +++ b/internal/disgo_impl.go @@ -18,7 +18,7 @@ func New(token string, options api.Options) (api.Disgo, error) { disgo := &DisgoImpl{ botToken: token, - intents: options.Intents, + gatewayIntents: options.GatewayIntents, largeThreshold: options.LargeThreshold, logger: options.Logger, rawGatewayEventsEnabled: options.RawGatewayEventsEnabled, @@ -55,7 +55,7 @@ type DisgoImpl struct { logger log.Logger gateway api.Gateway restClient api.RestClient - intents api.Intents + gatewayIntents api.GatewayIntents rawGatewayEventsEnabled bool entityBuilder api.EntityBuilder eventManager api.EventManager @@ -156,10 +156,10 @@ func (d *DisgoImpl) Cache() api.Cache { return d.cache } -// Intents returns the Intents originally specified when creating the client -func (d *DisgoImpl) Intents() api.Intents { - // clones the intents so they can't be modified - c := d.intents +// GatewayIntents returns the GatewayIntents originally specified when creating the client +func (d *DisgoImpl) GatewayIntents() api.GatewayIntents { + // clones the GatewayIntents so they can't be modified + c := d.gatewayIntents return c } diff --git a/internal/entity_builder_impl.go b/internal/entity_builder_impl.go index f4e9744a..7bfa746e 100644 --- a/internal/entity_builder_impl.go +++ b/internal/entity_builder_impl.go @@ -20,6 +20,7 @@ func (b EntityBuilderImpl) Disgo() api.Disgo { // CreateInteraction returns a new api.Interaction entity func (b EntityBuilderImpl) CreateInteraction(interaction *api.Interaction, updateCache api.CacheStrategy) *api.Interaction { + interaction.Disgo = b.disgo if interaction.Member != nil { interaction.Member = b.CreateMember(*interaction.GuildID, interaction.Member, api.CacheStrategyYes) } diff --git a/internal/event_manager_impl.go b/internal/event_manager_impl.go index a6b112bc..2265e638 100644 --- a/internal/event_manager_impl.go +++ b/internal/event_manager_impl.go @@ -42,17 +42,20 @@ func (e *EventManagerImpl) Close() { } // Handle calls the correct api.EventHandler -func (e *EventManagerImpl) Handle(name api.GatewayEventType, c chan interface{}, sequenceNumber int, payload json.RawMessage) { +func (e *EventManagerImpl) Handle(name api.GatewayEventType, c chan *api.InteractionResponse, sequenceNumber int, payload json.RawMessage) { if handler, ok := e.handlers[name]; ok { eventPayload := handler.New() if err := json.Unmarshal(payload, &eventPayload); err != nil { - e.disgo.Logger().Errorf("error while unmarshaling event. error: %s", err) + e.disgo.Logger().Errorf("error while unmarshalling event. error: %s", err) } + switch h := handler.(type) { case api.GatewayEventHandler: h.HandleGatewayEvent(e.disgo, e, sequenceNumber, eventPayload) case api.WebhookEventHandler: h.HandleWebhookEvent(e.disgo, e, c, eventPayload) + default: + e.Disgo().Logger().Errorf("no event handler found for: %s", name) } } } diff --git a/internal/gateway_impl.go b/internal/gateway_impl.go index 4490b356..1f5478db 100644 --- a/internal/gateway_impl.go +++ b/internal/gateway_impl.go @@ -145,7 +145,7 @@ func (g *GatewayImpl) Open() error { }, Compress: false, LargeThreshold: g.Disgo().LargeThreshold(), - Intents: g.Disgo().Intents(), + GatewayIntents: g.Disgo().GatewayIntents(), }), ); err != nil { return err diff --git a/internal/handlers/interaction_create_handler.go b/internal/handlers/interaction_create_handler.go index b50c6d96..b513e696 100644 --- a/internal/handlers/interaction_create_handler.go +++ b/internal/handlers/interaction_create_handler.go @@ -63,9 +63,9 @@ func handleInteraction(disgo api.Disgo, eventManager api.EventManager, sequenceN } eventManager.Dispatch(events.SlashCommandEvent{ + GenericInteractionEvent: genericInteractionEvent, ResponseChannel: c, FromWebhook: c != nil, - GenericInteractionEvent: genericInteractionEvent, CommandID: interaction.Data.ID, CommandName: interaction.Data.Name, SubCommandName: subCommandName, diff --git a/internal/handlers/interaction_create_webhook_handler.go b/internal/handlers/interaction_create_webhook_handler.go index 1751759f..495b56f8 100644 --- a/internal/handlers/interaction_create_webhook_handler.go +++ b/internal/handlers/interaction_create_webhook_handler.go @@ -25,6 +25,7 @@ func (h InteractionCreateWebhookHandler) HandleWebhookEvent(disgo api.Disgo, eve } if interaction.Type == api.InteractionTypePing { + disgo.Logger().Debugf("received interaction ping") c <- &api.InteractionResponse{ Type: api.InteractionResponseTypePong, } diff --git a/internal/restclient_impl.go b/internal/restclient_impl.go index 86d8f6fb..74759d8c 100644 --- a/internal/restclient_impl.go +++ b/internal/restclient_impl.go @@ -7,6 +7,7 @@ import ( "io" "io/ioutil" "net/http" + "net/url" "strings" "github.com/DisgoOrg/disgo/api/events" @@ -56,12 +57,21 @@ func (r RestClientImpl) UserAgent() string { func (r RestClientImpl) Request(route *endpoints.CompiledAPIRoute, rqBody interface{}, rsBody interface{}) error { var reader io.Reader var rqJSON []byte + var contentType string if rqBody != nil { - rqJSON, err := json.Marshal(rqBody) - if err != nil { - return err + switch v := rqBody.(type) { + case url.Values: + contentType = "application/x-www-form-urlencoded" + rqJSON = []byte(v.Encode()) + default: + contentType = "application/json" + var err error + rqJSON, err = json.Marshal(rqBody) + if err != nil { + return err + } } - r.Disgo().Logger().Debugf("request json: \"%s\"", string(rqJSON)) + r.Disgo().Logger().Debugf("request body: \"%s\"", string(rqJSON)) reader = bytes.NewBuffer(rqJSON) } else { reader = nil @@ -71,10 +81,9 @@ func (r RestClientImpl) Request(route *endpoints.CompiledAPIRoute, rqBody interf if err != nil { return err } - rq.Header.Set("User-Agent", r.UserAgent()) rq.Header.Set("Authorization", "Bot "+r.disgo.Token()) - rq.Header.Set("Content-Type", "application/json") + rq.Header.Set("Content-Type", contentType) rs, err := r.client.Do(rq) if err != nil { diff --git a/internal/webhook_server_impl.go b/internal/webhook_server_impl.go index 6b4403aa..a522d1fb 100644 --- a/internal/webhook_server_impl.go +++ b/internal/webhook_server_impl.go @@ -93,14 +93,15 @@ func (h *webhookInteractionHandler) ServeHTTP(w http.ResponseWriter, r *http.Req }() rawBody, err := ioutil.ReadAll(r.Body) if err != nil { + h.disgo.Logger().Errorf("error reading body: %s", err) w.WriteHeader(http.StatusBadRequest) return } - c := make(chan interface{}) + c := make(chan *api.InteractionResponse) go h.webhookServer.Disgo().EventManager().Handle(api.WebhookEventInteractionCreate, c, -1, rawBody) - w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) err = json.NewEncoder(w).Encode(<-c) if err != nil {