Skip to content

Commit

Permalink
added RawGatewayEvent toggle & event docs/cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Apr 13, 2021
1 parent 68147d5 commit 272f226
Show file tree
Hide file tree
Showing 48 changed files with 185 additions and 91 deletions.
1 change: 1 addition & 0 deletions api/audio_controller.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package api

// AudioController lets you Connect / Disconnect from a VoiceChannel
type AudioController interface {
Disgo() Disgo
Connect(guildID Snowflake, channelID Snowflake) error
Expand Down
1 change: 1 addition & 0 deletions api/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type VoiceChannel struct {
GuildChannel
}

// Connect sends a api.GatewayCommand to connect to this VoiceChannel
func (c *VoiceChannel) Connect() error {
return c.Disgo.AudioController().Connect(*c.GuildID, c.ID)
}
Expand Down
1 change: 1 addition & 0 deletions api/disgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Disgo interface {
WebhookServer() WebhookServer
Cache() Cache
Intents() Intents
RawGatewayEventsEnabled() bool
ApplicationID() Snowflake
SelfUser() *User
EntityBuilder() EntityBuilder
Expand Down
1 change: 1 addition & 0 deletions api/disgo_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type DisgoBuilder interface {
SetLogger(level log.Logger) DisgoBuilder
SetToken(token endpoints.Token) DisgoBuilder
SetIntents(intents Intents) DisgoBuilder
SetRawGatewayEventsEnabled(enabled bool) DisgoBuilder
SetVoiceDispatchInterceptor(voiceDispatchInterceptor VoiceDispatchInterceptor) DisgoBuilder
SetEntityBuilder(entityBuilder EntityBuilder) DisgoBuilder
SetEventManager(eventManager EventManager) DisgoBuilder
Expand Down
2 changes: 1 addition & 1 deletion api/endpoints/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,5 @@ var (

// Other
var (
InviteURL = NewRoute("https://discord.gg/{code}")
InviteURL = NewRoute("https://discord.gg/{code}")
)
2 changes: 1 addition & 1 deletion api/endpoints/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Token string

// MarshalJSON makes sure we don#t send ********* to discords as tokens
func (t Token) MarshalJSON() ([]byte, error) {
return []byte("\""+t+"\""), nil
return []byte("\"" + t + "\""), nil
}

// UnmarshalJSON makes sure we parse tokens from discord correctly
Expand Down
5 changes: 5 additions & 0 deletions api/events/application_command_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,34 @@ import (
"github.com/DisgoOrg/disgo/api"
)

// GenericApplicationCommandEvent is called upon receiving either ApplicationCommandCreateEvent, ApplicationCommandUpdateEvent or ApplicationCommandDeleteEvent
type GenericApplicationCommandEvent struct {
GenericEvent
CommandID api.Snowflake
Command *api.Command
GuildID *api.Snowflake
}

// Guild returns the api.Guild the api.Event got called or nil for global api.Command(s)
func (e GenericApplicationCommandEvent) Guild() *api.Guild {
if e.GuildID == nil {
return nil
}
return e.Disgo().Cache().Guild(*e.GuildID)
}

// ApplicationCommandCreateEvent indicates that a new api.Command got created(this can come from any bot!)
type ApplicationCommandCreateEvent struct {
GenericApplicationCommandEvent
}

// ApplicationCommandUpdateEvent indicates that a api.Command got updated(this can come from any bot!)
type ApplicationCommandUpdateEvent struct {
GenericApplicationCommandEvent
OldCommand *api.Command
}

// ApplicationCommandDeleteEvent indicates that a api.Command got deleted(this can come from any bot!)
type ApplicationCommandDeleteEvent struct {
GenericApplicationCommandEvent
}
4 changes: 4 additions & 0 deletions api/events/category_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ import (
"github.com/DisgoOrg/disgo/api"
)

// GenericCategoryEvent is called upon receiving CategoryCreateEvent, CategoryUpdateEvent or CategoryDeleteEvent
type GenericCategoryEvent struct {
GenericChannelEvent
Category *api.Category
}

// CategoryCreateEvent indicates that a new api.Category got created in a api.Guild
type CategoryCreateEvent struct {
GenericCategoryEvent
}

// CategoryUpdateEvent indicates that a api.Category got updated in a api.Guild
type CategoryUpdateEvent struct {
GenericCategoryEvent
OldCategory *api.Category
}

// CategoryDeleteEvent indicates that a api.Category got deleted in a api.Guild
type CategoryDeleteEvent struct {
GenericCategoryEvent
}
3 changes: 2 additions & 1 deletion api/events/channel_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"github.com/DisgoOrg/disgo/api"
)

// GenericChannelEvent is called upon receiving an event in a api.Channel
// GenericChannelEvent is called upon receiving any api.Channel api.Event
type GenericChannelEvent struct {
GenericEvent
ChannelID api.Snowflake
}

// Channel returns the api.Channel from the api.Cache if cached
func (e GenericChannelEvent) Channel() *api.Channel {
return e.Disgo().Cache().Channel(e.ChannelID)
}
9 changes: 5 additions & 4 deletions api/events/dm_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@ import (
"github.com/DisgoOrg/disgo/api"
)

// GenericDMChannelEvent is called upon receiving DMChannelCreateEvent, DMChannelUpdateEvent, DMChannelDeleteEvent or DMUserTypingEvent
type GenericDMChannelEvent struct {
GenericChannelEvent
DMChannel *api.DMChannel
}

// DMChannelCreateEvent indicates that a new api.DMChannel got created
type DMChannelCreateEvent struct {
GenericDMChannelEvent
}

// DMChannelUpdateEvent indicates that a api.DMChannel got updated
type DMChannelUpdateEvent struct {
GenericDMChannelEvent
OldDMChannel *api.DMChannel
}

// DMChannelDeleteEvent indicates that a api.DMChannel got deleted
type DMChannelDeleteEvent struct {
GenericDMChannelEvent
}

// DMUserTypingEvent indicates that a api.User started typing in a api.DMChannel(requires api.IntentsDirectMessageTyping)
type DMUserTypingEvent struct {
GenericDMChannelEvent
}

func (e DMUserTypingEvent) DMChannel() *api.DMChannel {
return e.Disgo().Cache().DMChannel(e.ChannelID)
}
9 changes: 5 additions & 4 deletions api/events/dm_message_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@ import (
"github.com/DisgoOrg/disgo/api"
)

// GenericDMMessageEvent generic api.DMChannel api.Message api.GenericEvent
// GenericDMMessageEvent is called upon receiving DMMessageCreateEvent, DMMessageUpdateEvent, DMMessageDeleteEvent, GenericDMMessageReactionEvent, DMMessageReactionAddEvent, DMMessageReactionRemoveEvent, DMMessageReactionRemoveEmoteEvent or DMMessageReactionRemoveAllEvent(requires api.IntentsDirectMessages)
type GenericDMMessageEvent struct {
GenericMessageEvent
Message *api.Message
}

// DMChannel returns the api.DMChannel where the GenericDMMessageEvent happened
func (e GenericDMMessageEvent) DMChannel() *api.DMChannel {
return e.Disgo().Cache().DMChannel(e.ChannelID)
}

// DMMessageCreateEvent called upon receiving a api.Message in a api.DMChannel
// DMMessageCreateEvent is called upon receiving a api.Message in a api.DMChannel(requires api.IntentsDirectMessages)
type DMMessageCreateEvent struct {
GenericDMMessageEvent
}

// DMMessageUpdateEvent called upon editing a api.Message in a api.DMChannel
// DMMessageUpdateEvent is called upon editing a api.Message in a api.DMChannel(requires api.IntentsDirectMessages)
type DMMessageUpdateEvent struct {
GenericDMMessageEvent
OldMessage *api.Message
}

// DMMessageDeleteEvent called upon deleting a api.Message in a api.DMChannel
// DMMessageDeleteEvent is called upon deleting a api.Message in a api.DMChannel(requires api.IntentsDirectMessages)
type DMMessageDeleteEvent struct {
GenericDMMessageEvent
}
5 changes: 5 additions & 0 deletions api/events/dm_message_reaction_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@ package events

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

// GenericDMMessageReactionEvent is called upon receiving DMMessageReactionAddEvent or DMMessageReactionRemoveEvent(requires the api.IntentsDirectMessageReactions)
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)
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)
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)
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)
type DMMessageReactionRemoveAllEvent struct {
GenericDMMessageEvent
}
4 changes: 4 additions & 0 deletions api/events/emote_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ import (
"github.com/DisgoOrg/disgo/api"
)

// GenericEmoteEvent is called upon receiving EmoteCreateEvent, EmoteUpdateEvent or EmoteDeleteEvent(requires api.IntentsGuildEmojis)
type GenericEmoteEvent struct {
GenericGuildEvent
Emote *api.Emote
}

// EmoteCreateEvent indicates that a new api.Emote got created in a api.Guild(requires api.IntentsGuildEmojis)
type EmoteCreateEvent struct {
GenericEmoteEvent
}

// EmoteUpdateEvent indicates that a api.Emote got updated in a api.Guild(requires api.IntentsGuildEmojis)
type EmoteUpdateEvent struct {
GenericEmoteEvent
OldEmote *api.Emote
}

// EmoteDeleteEvent indicates that a api.Emote got deleted in a api.Guild(requires api.IntentsGuildEmojis)
type EmoteDeleteEvent struct {
GenericEmoteEvent
}
5 changes: 0 additions & 5 deletions api/events/exception_event.go

This file was deleted.

11 changes: 5 additions & 6 deletions api/events/gateway_status_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@ import (
"github.com/DisgoOrg/disgo/api"
)

// GenericGatewayStatusEvent is called upon receiving ConnectedEvent, ReconnectedEvent, ResumedEvent, DisconnectedEvent or ShutdownEvent
type GenericGatewayStatusEvent struct {
GenericEvent
Status api.GatewayStatus
}

// ConnectedEvent indicates disgo connected to the api.Gateway
type ConnectedEvent struct {
GenericGatewayStatusEvent
}

// ReconnectedEvent indicates disgo reconnected to the api.Gateway
type ReconnectedEvent struct {
GenericGatewayStatusEvent
}

// ResumedEvent indicates disgo resumed to the api.Gateway
type ResumedEvent struct {
GenericGatewayStatusEvent
}

// DisconnectedEvent indicates disgo disconnected to the api.Gateway
type DisconnectedEvent struct {
GenericGatewayStatusEvent
}

type ShutdownEvent struct {
GenericGatewayStatusEvent
}


16 changes: 9 additions & 7 deletions api/events/guild_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,50 @@ import (
"github.com/DisgoOrg/disgo/api"
)

// GenericGuildEvent generic api.Guild api.GenericEvent
// GenericGuildEvent is called upon receiving GuildUpdateEvent, GuildAvailableEvent, GuildUnavailableEvent, GuildJoinEvent, GuildLeaveEvent, GuildReadyEvent, GuildBanEvent, GuildUnbanEvent
type GenericGuildEvent struct {
GenericEvent
Guild *api.Guild
}

// GuildUpdateEvent called upon receiving api.Guild updates
// GuildUpdateEvent is called upon receiving api.Guild updates
type GuildUpdateEvent struct {
GenericGuildEvent
OldGuild *api.Guild
}

// GuildAvailableEvent called when an unavailable api.Guild becomes available
// GuildAvailableEvent is called when an unavailable api.Guild becomes available
type GuildAvailableEvent struct {
GenericGuildEvent
}

// GuildUnavailableEvent called when an available api.Guild becomes unavailable
// GuildUnavailableEvent is called when an available api.Guild becomes unavailable
type GuildUnavailableEvent struct {
GenericGuildEvent
}

// GuildJoinEvent called when the bot joins a api.Guild
// GuildJoinEvent is called when the bot joins a api.Guild
type GuildJoinEvent struct {
GenericGuildEvent
}

// GuildLeaveEvent called when the bot leaves a api.Guild
// GuildLeaveEvent is called when the bot leaves a api.Guild
type GuildLeaveEvent struct {
GenericGuildEvent
}

// GuildReadyEvent called when the loaded the api.Guild in login phase
// GuildReadyEvent is called when the loaded the api.Guild in login phase
type GuildReadyEvent struct {
GenericGuildEvent
}

// GuildBanEvent is called when a api.Member/api.User is banned from the api.Guild
type GuildBanEvent struct {
GenericGuildEvent
User *api.User
}

// GuildUnbanEvent is called when a api.Member/api.User is unbanned from the api.Guild
type GuildUnbanEvent struct {
GenericGuildEvent
User *api.User
Expand Down
Loading

0 comments on commit 272f226

Please sign in to comment.