eventsystem

package
v1.24.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2020 License: MIT Imports: 10 Imported by: 0

README

YAGPDB's Event System

Instead of just using discordgo's standard simple event system, I like to experiment a little as I work on stuff to see what happens.

It all boils down to a simple 3D slice of handlers (handlers [][][]Handler)

The first index is the event index, that length is generated by events_gen.go

Next index is order, there is 3 orders:

0 - first ran 1 - state handler is here 2 - last, ran concurrently from here on

Orders 1 and 0 are run synchronously, but 2 is run concurrently, this is in order to have the state be as proper as possible.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DiscordState *dstate.State
View Source
var EventNames = []string{
	"NewGuild",
	"All",
	"AllPre",
	"AllPost",
	"MemberFetched",
	"YagShardReady",
	"YagShardsAdded",
	"YagShardRemoved",
	"ChannelCreate",
	"ChannelDelete",
	"ChannelPinsUpdate",
	"ChannelUpdate",
	"Connect",
	"Disconnect",
	"GuildBanAdd",
	"GuildBanRemove",
	"GuildCreate",
	"GuildDelete",
	"GuildEmojisUpdate",
	"GuildIntegrationsUpdate",
	"GuildMemberAdd",
	"GuildMemberRemove",
	"GuildMemberUpdate",
	"GuildMembersChunk",
	"GuildRoleCreate",
	"GuildRoleDelete",
	"GuildRoleUpdate",
	"GuildUpdate",
	"InviteCreate",
	"InviteDelete",
	"MessageAck",
	"MessageCreate",
	"MessageDelete",
	"MessageDeleteBulk",
	"MessageReactionAdd",
	"MessageReactionRemove",
	"MessageReactionRemoveAll",
	"MessageUpdate",
	"PresenceUpdate",
	"PresencesReplace",
	"RateLimit",
	"Ready",
	"RelationshipAdd",
	"RelationshipRemove",
	"Resumed",
	"TypingStart",
	"UserGuildSettingsUpdate",
	"UserNoteUpdate",
	"UserSettingsUpdate",
	"UserUpdate",
	"VoiceServerUpdate",
	"VoiceStateUpdate",
	"WebhooksUpdate",
}

Functions

func AddHandler

func AddHandler(p common.Plugin, handler HandlerFunc, order Order, evts ...Event)

AddHandler adds a event handler

func AddHandlerAsyncLast added in v1.19.0

func AddHandlerAsyncLast(p common.Plugin, handler HandlerFunc, evts ...Event)

AddHandlerAsyncLast adds handlers using the OrderAsyncPostState order

func AddHandlerAsyncLastLegacy added in v1.20.0

func AddHandlerAsyncLastLegacy(p common.Plugin, handler HandlerFuncLegacy, evts ...Event)

AddHandlerAsyncLast adds handlers using the OrderAsyncPostState order

func AddHandlerFirst

func AddHandlerFirst(p common.Plugin, handler HandlerFunc, evts ...Event)

AddHandlerFirst adds handlers using the OrderSyncPreState order

func AddHandlerFirstLegacy added in v1.20.0

func AddHandlerFirstLegacy(p common.Plugin, handler HandlerFuncLegacy, evts ...Event)

AddHandlerFirst adds handlers using the OrderSyncPreState order

func AddHandlerLegacy added in v1.20.0

func AddHandlerLegacy(p common.Plugin, handler HandlerFuncLegacy, order Order, evts ...Event)

AddHandler adds a event handler

func AddHandlerSecond added in v1.19.0

func AddHandlerSecond(p common.Plugin, handler HandlerFunc, evts ...Event)

AddHandlerSecond adds handlers using the OrderSyncPostState order

func AddHandlerSecondLegacy added in v1.20.0

func AddHandlerSecondLegacy(p common.Plugin, handler HandlerFuncLegacy, evts ...Event)

AddHandlerSecond adds handlers using the OrderSyncPostState order

func EmitEvent

func EmitEvent(data *EventData, evt Event)

EmitEvent emits an event

func HandleEvent

func HandleEvent(s *discordgo.Session, evt interface{})

func InitWorkers added in v1.20.0

func InitWorkers(totalShards int)

func QueueEventNonDiscord added in v1.24.6

func QueueEventNonDiscord(evtData *EventData)

Types

type Event

type Event int
const (
	EventNewGuild                 Event = 0
	EventAll                      Event = 1
	EventAllPre                   Event = 2
	EventAllPost                  Event = 3
	EventMemberFetched            Event = 4
	EventYagShardReady            Event = 5
	EventYagShardsAdded           Event = 6
	EventYagShardRemoved          Event = 7
	EventChannelCreate            Event = 8
	EventChannelDelete            Event = 9
	EventChannelPinsUpdate        Event = 10
	EventChannelUpdate            Event = 11
	EventConnect                  Event = 12
	EventDisconnect               Event = 13
	EventGuildBanAdd              Event = 14
	EventGuildBanRemove           Event = 15
	EventGuildCreate              Event = 16
	EventGuildDelete              Event = 17
	EventGuildEmojisUpdate        Event = 18
	EventGuildIntegrationsUpdate  Event = 19
	EventGuildMemberAdd           Event = 20
	EventGuildMemberRemove        Event = 21
	EventGuildMemberUpdate        Event = 22
	EventGuildMembersChunk        Event = 23
	EventGuildRoleCreate          Event = 24
	EventGuildRoleDelete          Event = 25
	EventGuildRoleUpdate          Event = 26
	EventGuildUpdate              Event = 27
	EventInviteCreate             Event = 28
	EventInviteDelete             Event = 29
	EventMessageAck               Event = 30
	EventMessageCreate            Event = 31
	EventMessageDelete            Event = 32
	EventMessageDeleteBulk        Event = 33
	EventMessageReactionAdd       Event = 34
	EventMessageReactionRemove    Event = 35
	EventMessageReactionRemoveAll Event = 36
	EventMessageUpdate            Event = 37
	EventPresenceUpdate           Event = 38
	EventPresencesReplace         Event = 39
	EventRateLimit                Event = 40
	EventReady                    Event = 41
	EventRelationshipAdd          Event = 42
	EventRelationshipRemove       Event = 43
	EventResumed                  Event = 44
	EventTypingStart              Event = 45
	EventUserGuildSettingsUpdate  Event = 46
	EventUserNoteUpdate           Event = 47
	EventUserSettingsUpdate       Event = 48
	EventUserUpdate               Event = 49
	EventVoiceServerUpdate        Event = 50
	EventVoiceStateUpdate         Event = 51
	EventWebhooksUpdate           Event = 52
)

func (Event) String

func (e Event) String() string

type EventData

type EventData struct {
	EvtInterface interface{}
	Type         Event

	Session           *discordgo.Session
	GuildFeatureFlags []string

	GS *dstate.GuildState // Guaranteed to be available for guild events, except creates and deletes
	// contains filtered or unexported fields
}

func NewEventData added in v1.19.0

func NewEventData(session *discordgo.Session, t Event, evtInterface interface{}) *EventData

func (*EventData) CS added in v1.20.0

func (d *EventData) CS() *dstate.ChannelState

CS will attempt to fetch the channel state from either cached, or state, or return nil if nonexistent (e.g a channel create before the state has been populated by it)

func (*EventData) Cancel added in v1.19.0

func (e *EventData) Cancel()

func (*EventData) ChannelCreate added in v1.4.1

func (data *EventData) ChannelCreate() *discordgo.ChannelCreate

func (*EventData) ChannelDelete added in v1.4.1

func (data *EventData) ChannelDelete() *discordgo.ChannelDelete

func (*EventData) ChannelPinsUpdate added in v1.4.1

func (data *EventData) ChannelPinsUpdate() *discordgo.ChannelPinsUpdate

func (*EventData) ChannelUpdate added in v1.4.1

func (data *EventData) ChannelUpdate() *discordgo.ChannelUpdate

func (*EventData) Connect added in v1.4.1

func (data *EventData) Connect() *discordgo.Connect

func (*EventData) Context

func (e *EventData) Context() context.Context

func (*EventData) Disconnect added in v1.4.1

func (data *EventData) Disconnect() *discordgo.Disconnect

func (*EventData) GuildBanAdd added in v1.4.1

func (data *EventData) GuildBanAdd() *discordgo.GuildBanAdd

func (*EventData) GuildBanRemove added in v1.4.1

func (data *EventData) GuildBanRemove() *discordgo.GuildBanRemove

func (*EventData) GuildCreate added in v1.4.1

func (data *EventData) GuildCreate() *discordgo.GuildCreate

func (*EventData) GuildDelete added in v1.4.1

func (data *EventData) GuildDelete() *discordgo.GuildDelete

func (*EventData) GuildEmojisUpdate added in v1.4.1

func (data *EventData) GuildEmojisUpdate() *discordgo.GuildEmojisUpdate

func (*EventData) GuildIntegrationsUpdate added in v1.4.1

func (data *EventData) GuildIntegrationsUpdate() *discordgo.GuildIntegrationsUpdate

func (*EventData) GuildMemberAdd added in v1.4.1

func (data *EventData) GuildMemberAdd() *discordgo.GuildMemberAdd

func (*EventData) GuildMemberRemove added in v1.4.1

func (data *EventData) GuildMemberRemove() *discordgo.GuildMemberRemove

func (*EventData) GuildMemberUpdate added in v1.4.1

func (data *EventData) GuildMemberUpdate() *discordgo.GuildMemberUpdate

func (*EventData) GuildMembersChunk added in v1.4.1

func (data *EventData) GuildMembersChunk() *discordgo.GuildMembersChunk

func (*EventData) GuildRoleCreate added in v1.4.1

func (data *EventData) GuildRoleCreate() *discordgo.GuildRoleCreate

func (*EventData) GuildRoleDelete added in v1.4.1

func (data *EventData) GuildRoleDelete() *discordgo.GuildRoleDelete

func (*EventData) GuildRoleUpdate added in v1.4.1

func (data *EventData) GuildRoleUpdate() *discordgo.GuildRoleUpdate

func (*EventData) GuildUpdate added in v1.4.1

func (data *EventData) GuildUpdate() *discordgo.GuildUpdate

func (*EventData) HasFeatureFlag added in v1.24.11

func (e *EventData) HasFeatureFlag(flag string) bool

HasFeatureFlag returns true if the guild the event came from has the provided feature flag

func (*EventData) InviteCreate added in v1.24.6

func (data *EventData) InviteCreate() *discordgo.InviteCreate

func (*EventData) InviteDelete added in v1.24.6

func (data *EventData) InviteDelete() *discordgo.InviteDelete

func (*EventData) MessageAck added in v1.4.1

func (data *EventData) MessageAck() *discordgo.MessageAck

func (*EventData) MessageCreate added in v1.4.1

func (data *EventData) MessageCreate() *discordgo.MessageCreate

func (*EventData) MessageDelete added in v1.4.1

func (data *EventData) MessageDelete() *discordgo.MessageDelete

func (*EventData) MessageDeleteBulk added in v1.4.1

func (data *EventData) MessageDeleteBulk() *discordgo.MessageDeleteBulk

func (*EventData) MessageReactionAdd added in v1.4.1

func (data *EventData) MessageReactionAdd() *discordgo.MessageReactionAdd

func (*EventData) MessageReactionRemove added in v1.4.1

func (data *EventData) MessageReactionRemove() *discordgo.MessageReactionRemove

func (*EventData) MessageReactionRemoveAll added in v1.4.1

func (data *EventData) MessageReactionRemoveAll() *discordgo.MessageReactionRemoveAll

func (*EventData) MessageUpdate added in v1.4.1

func (data *EventData) MessageUpdate() *discordgo.MessageUpdate

func (*EventData) PresenceUpdate added in v1.4.1

func (data *EventData) PresenceUpdate() *discordgo.PresenceUpdate

func (*EventData) PresencesReplace added in v1.4.1

func (data *EventData) PresencesReplace() *discordgo.PresencesReplace

func (*EventData) RateLimit added in v1.4.1

func (data *EventData) RateLimit() *discordgo.RateLimit

func (*EventData) Ready added in v1.4.1

func (data *EventData) Ready() *discordgo.Ready

func (*EventData) RelationshipAdd added in v1.4.1

func (data *EventData) RelationshipAdd() *discordgo.RelationshipAdd

func (*EventData) RelationshipRemove added in v1.4.1

func (data *EventData) RelationshipRemove() *discordgo.RelationshipRemove

func (*EventData) Resumed added in v1.4.1

func (data *EventData) Resumed() *discordgo.Resumed

func (*EventData) TypingStart added in v1.4.1

func (data *EventData) TypingStart() *discordgo.TypingStart

func (*EventData) UserGuildSettingsUpdate added in v1.4.1

func (data *EventData) UserGuildSettingsUpdate() *discordgo.UserGuildSettingsUpdate

func (*EventData) UserNoteUpdate added in v1.4.1

func (data *EventData) UserNoteUpdate() *discordgo.UserNoteUpdate

func (*EventData) UserSettingsUpdate added in v1.4.1

func (data *EventData) UserSettingsUpdate() *discordgo.UserSettingsUpdate

func (*EventData) UserUpdate added in v1.4.1

func (data *EventData) UserUpdate() *discordgo.UserUpdate

func (*EventData) VoiceServerUpdate added in v1.4.1

func (data *EventData) VoiceServerUpdate() *discordgo.VoiceServerUpdate

func (*EventData) VoiceStateUpdate added in v1.4.1

func (data *EventData) VoiceStateUpdate() *discordgo.VoiceStateUpdate

func (*EventData) WebhooksUpdate added in v1.19.0

func (data *EventData) WebhooksUpdate() *discordgo.WebhooksUpdate

func (*EventData) WithContext

func (e *EventData) WithContext(ctx context.Context) *EventData

type Handler

type Handler struct {
	Plugin  common.Plugin
	F       HandlerFunc
	FLegacy HandlerFuncLegacy
}

type HandlerFunc added in v1.20.0

type HandlerFunc func(evtData *EventData) (retry bool, err error)

func RequireCSMW added in v1.20.0

func RequireCSMW(inner HandlerFunc) HandlerFunc

RequireCSMW will only call the inner handler if a channel state is available

type HandlerFuncLegacy added in v1.20.0

type HandlerFuncLegacy func(evtData *EventData)

type Order added in v1.19.0

type Order int
const (
	// Ran first, syncrounously, before changes from the event is applied to state
	OrderSyncPreState Order = 0
	// Ran second, syncrounsly, after state changes have been applied
	OrderSyncPostState Order = 1
	// Ran last, asyncrounously, most handlers should use this unless you need something else in special circumstances
	OrderAsyncPostState Order = 2
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL