Skip to content

Commit

Permalink
Merge pull request #18 from DisgoOrg/development
Browse files Browse the repository at this point in the history
small fixes and rename
  • Loading branch information
topi314 committed May 25, 2021
2 parents 01dd5d6 + f6e8b5c commit d4c3991
Show file tree
Hide file tree
Showing 37 changed files with 324 additions and 289 deletions.
2 changes: 1 addition & 1 deletion api/audio_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

Expand Down
6 changes: 3 additions & 3 deletions api/disgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Disgo interface {
RestClient() RestClient
WebhookServer() WebhookServer
Cache() Cache
Intents() Intents
GatewayIntents() GatewayIntents
RawGatewayEventsEnabled() bool
ApplicationID() Snowflake
SelfUser() *User
Expand Down Expand Up @@ -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
Expand All @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion api/disgo_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion api/entity_builder.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion api/events/dm_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions api/events/dm_message_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
10 changes: 5 additions & 5 deletions api/events/dm_message_reaction_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ 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
User *api.User
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
}
8 changes: 4 additions & 4 deletions api/events/emote_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 5 additions & 3 deletions api/events/guild_invite_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion api/events/guild_member_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions api/events/guild_message_reaction_events.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
package events

import "github.com/DisgoOrg/disgo/api"

// GenericGuildMessageReactionEvent is called upon receiving DMMessageReactionAddEvent or DMMessageReactionRemoveEvent
type GenericGuildMessageReactionEvent struct {
GenericGuildMessageEvent
UserID api.Snowflake
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
}
6 changes: 3 additions & 3 deletions api/events/guild_voice_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
82 changes: 13 additions & 69 deletions api/events/interaction_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
8 changes: 4 additions & 4 deletions api/events/message_reaction_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading

0 comments on commit d4c3991

Please sign in to comment.