handler

package
v0.0.0-...-93194af Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2018 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Connect                 = "Connect"
	Disconnect              = "Disconnect"
	RateLimit               = "RateLimit"
	Event                   = "Event"
	Ready                   = "Ready"
	ChannelCreate           = "ChannelCreate"
	ChannelUpdate           = "ChannelUpdate"
	ChannelDelete           = "ChannelDelete"
	ChannelPinsUpdate       = "ChannelPinsUpdate"
	GuildCreate             = "GuildCreate"
	GuildUpdate             = "GuildUpdate"
	GuildDelete             = "GuildDelete"
	GuildBanAdd             = "GuildBanAdd"
	GuildBanRemove          = "GuildBanRemove"
	GuildMemberAdd          = "GuildMemberAdd"
	GuildMemberUpdate       = "GuildMemberUpdate"
	GuildMemberRemove       = "GuildMemberRemove"
	GuildRoleCreate         = "GuildRoleCreate"
	GuildRoleUpdate         = "GuildRoleUpdate"
	GuildRoleDelete         = "GuildRoleDelete"
	GuildEmojisUpdate       = "GuildEmojisUpdate"
	GuildMembersChunk       = "GuildMembersChunk"
	GuildIntegrationsUpdate = "GuildIntegrationsUpdate"
	MessageAck              = "MessageAck"
	MessageCreate           = "MessageCreate"
	MessageUpdate           = "MessageUpdate"
	MessageDelete           = "MessageDelete"
	MessageReactionAdd      = "MessageReactionAdd"
	MessageReactionRemove   = "MessageReactionRemove"
	PresencesReplace        = "PresencesReplace"
	PresenceUpdate          = "PresenceUpdate"
	Resumed                 = "Resumed"
	RelationshipAdd         = "RelationshipAdd"
	RelationshipRemove      = "RelationshipRemove"
	TypingStart             = "TypingStart"
	UserUpdate              = "UserUpdate"
	UserSettingsUpdate      = "UserSettingsUpdate"
	UserGuildSettingsUpdate = "UserGuildSettingsUpdate"
	VoiceServerUpdate       = "VoiceServerUpdate"
	VoiceStateUpdate        = "VoiceStateUpdate"
)
View Source
const (
	// NoDroplet is the string used to check whether a droplet listener has an
	// owner assigned or not.
	NoDroplet = "__NO_DROPLET__"

	// Internal is the string constant identifier for bot listeners.
	Internal = "__INTERNAL__"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action interface {
	Do(v interface{})
}

An Action is an interface wrapper for listener commands. It is primarily used to execute the function by passing it a discord event struct. The function will handle the type conversion.

type ChannelCreateHandler

type ChannelCreateHandler func(*discordgo.ChannelCreate)

ChannelCreateHandler is the handler for ChannelCreate Listeners.

func (ChannelCreateHandler) Do

func (eh ChannelCreateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type ChannelDeleteHandler

type ChannelDeleteHandler func(*discordgo.ChannelDelete)

ChannelDeleteHandler is the handler for ChannelDelete Listeners.

func (ChannelDeleteHandler) Do

func (eh ChannelDeleteHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type ChannelPinsUpdateHandler

type ChannelPinsUpdateHandler func(*discordgo.ChannelPinsUpdate)

ChannelPinsUpdateHandler is the handler for ChannelPinsUpdate Listeners.

func (ChannelPinsUpdateHandler) Do

func (eh ChannelPinsUpdateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type ChannelUpdateHandler

type ChannelUpdateHandler func(*discordgo.ChannelUpdate)

ChannelUpdateHandler is the handler for ChannelUpdate Listeners.

func (ChannelUpdateHandler) Do

func (eh ChannelUpdateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type Command

type Command interface {
	Invoke() error
	SetArguments(string)
	SetEvent(*discordgo.MessageCreate)
	SetName(string)
	GetName() string
	Owner() string
}

Command is an interface for both internal and droplets.

type CommandData

type CommandData struct {
	Owner   string
	Command string
}

CommandData holds information pertaining to a command. The command will always be specified but the owner is not guaranteed to be filled.

type ConnectHandler

type ConnectHandler func(*discordgo.Connect)

ConnectHandler is the handler for Connect Listeners.

func (ConnectHandler) Do

func (eh ConnectHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type DisconnectHandler

type DisconnectHandler func(*discordgo.Disconnect)

DisconnectHandler is the handler for Disconnect Listeners.

func (DisconnectHandler) Do

func (eh DisconnectHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type DropletListener

type DropletListener struct {
	Event interface{}
	// contains filtered or unexported fields
}

The DropletListener struct is similar to InternalListener, but is used for droplet listeners. The most notable difference is how action is handled.

func (*DropletListener) Owner

func (l *DropletListener) Owner() string

Owner will return the name of the droplet to which this listener belongs to.

func (*DropletListener) Run

func (l *DropletListener) Run() error

Run will run the listener's action that being an RPC call.

func (*DropletListener) SetActionHandler

func (l *DropletListener) SetActionHandler(a Action)

SetActionHandler will set the listener's action.

func (*DropletListener) SetEvent

func (l *DropletListener) SetEvent(v interface{})

SetEvent will set a listener's event for future use when calling action.Do().

type EventHandler

type EventHandler func(*discordgo.Event)

EventHandler is the handler for Event Listeners.

func (EventHandler) Do

func (eh EventHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type GuildBanAddHandler

type GuildBanAddHandler func(*discordgo.GuildBanAdd)

GuildBanAddHandler is the handler for GuildBanAdd Listeners.

func (GuildBanAddHandler) Do

func (eh GuildBanAddHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type GuildBanRemoveHandler

type GuildBanRemoveHandler func(*discordgo.GuildBanRemove)

GuildBanRemoveHandler is the handler for GuildBanRemove Listeners.

func (GuildBanRemoveHandler) Do

func (eh GuildBanRemoveHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type GuildCreateHandler

type GuildCreateHandler func(*discordgo.GuildCreate)

GuildCreateHandler is the handler for GuildCreate Listeners.

func (GuildCreateHandler) Do

func (eh GuildCreateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type GuildDeleteHandler

type GuildDeleteHandler func(*discordgo.GuildDelete)

GuildDeleteHandler is the handler for GuildDelete Listeners.

func (GuildDeleteHandler) Do

func (eh GuildDeleteHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type GuildEmojisUpdateHandler

type GuildEmojisUpdateHandler func(*discordgo.GuildEmojisUpdate)

GuildEmojisUpdateHandler is the handler for GuildEmojisUpdate Listeners.

func (GuildEmojisUpdateHandler) Do

func (eh GuildEmojisUpdateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type GuildIntegrationsUpdateHandler

type GuildIntegrationsUpdateHandler func(*discordgo.GuildIntegrationsUpdate)

GuildIntegrationsUpdateHandler is the handler for GuildIntegrationsUpdate Listeners.

func (GuildIntegrationsUpdateHandler) Do

func (eh GuildIntegrationsUpdateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type GuildMemberAddHandler

type GuildMemberAddHandler func(*discordgo.GuildMemberAdd)

GuildMemberAddHandler is the handler for GuildMemberAdd Listeners.

func (GuildMemberAddHandler) Do

func (eh GuildMemberAddHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type GuildMemberRemoveHandler

type GuildMemberRemoveHandler func(*discordgo.GuildMemberRemove)

GuildMemberRemoveHandler is the handler for GuildMemberRemove Listeners.

func (GuildMemberRemoveHandler) Do

func (eh GuildMemberRemoveHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type GuildMemberUpdateHandler

type GuildMemberUpdateHandler func(*discordgo.GuildMemberUpdate)

GuildMemberUpdateHandler is the handler for GuildMemberUpdate Listeners.

func (GuildMemberUpdateHandler) Do

func (eh GuildMemberUpdateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type GuildMembersChunkHandler

type GuildMembersChunkHandler func(*discordgo.GuildMembersChunk)

GuildMembersChunkHandler is the handler for GuildMembersChunk Listeners.

func (GuildMembersChunkHandler) Do

func (eh GuildMembersChunkHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type GuildRoleCreateHandler

type GuildRoleCreateHandler func(*discordgo.GuildRoleCreate)

GuildRoleCreateHandler is the handler for GuildRoleCreate Listeners.

func (GuildRoleCreateHandler) Do

func (eh GuildRoleCreateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type GuildRoleDeleteHandler

type GuildRoleDeleteHandler func(*discordgo.GuildRoleDelete)

GuildRoleDeleteHandler is the handler for GuildRoleDelete Listeners.

func (GuildRoleDeleteHandler) Do

func (eh GuildRoleDeleteHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type GuildRoleUpdateHandler

type GuildRoleUpdateHandler func(*discordgo.GuildRoleUpdate)

GuildRoleUpdateHandler is the handler for GuildRoleUpdate Listeners.

func (GuildRoleUpdateHandler) Do

func (eh GuildRoleUpdateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type GuildUpdateHandler

type GuildUpdateHandler func(*discordgo.GuildUpdate)

GuildUpdateHandler is the handler for GuildUpdate Listeners.

func (GuildUpdateHandler) Do

func (eh GuildUpdateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type Handler

type Handler struct {
	Status bool

	Commands map[string]map[string]*InternalCommand
	// contains filtered or unexported fields
}

Handler contains all information necessary for handling listeners.

func NewHandler

func NewHandler() *Handler

NewHandler will create a new handler.

func (*Handler) AddInternalCommand

func (h *Handler) AddInternalCommand(name string,
	f func(string, *discordgo.MessageCreate) error)

AddInternalCommand takes a function and wraps it into a command.

func (*Handler) AddInternalListener

func (h *Handler) AddInternalListener(v interface{}) Listener

AddInternalListener takes a function and wraps it into a listener. This listener is then added to registry and returned to the caller. If the value passed to this function is not valid, listener will be nil.

func (*Handler) Attach

func (h *Handler) Attach(s *discordgo.Session)

Attach will add all dispatch functions to the discord session for each supported discord event. Supported events are those from the discordgo library.

func (*Handler) InvokeCommand

func (h *Handler) InvokeCommand(cd *CommandData,
	e *discordgo.MessageCreate) error

InvokeCommand takes a CommandData struct and uses it to run a specified command.

func (*Handler) StartPluginServer

func (h *Handler) StartPluginServer()

StartPluginServer starts a websocket server for plugins to connect to. Currently just echos information sent to it.

type InternalCommand

type InternalCommand struct {
	Event       *discordgo.MessageCreate
	CommandFunc func(string, *discordgo.MessageCreate) error
	Arguments   string
	// contains filtered or unexported fields
}

The InternalCommand struct is a wrapper for internal commands.

func (*InternalCommand) GetName

func (ic *InternalCommand) GetName() string

GetName will return the name for this command.

func (*InternalCommand) Invoke

func (ic *InternalCommand) Invoke() error

Invoke runs the commandFunc for the internal command.

func (*InternalCommand) Owner

func (ic *InternalCommand) Owner() string

Owner returns the internal command's owner. Always handler.Internal.

func (*InternalCommand) SetArguments

func (ic *InternalCommand) SetArguments(arguments string)

SetArguments sets the internal command's argument string.

func (*InternalCommand) SetEvent

func (ic *InternalCommand) SetEvent(e *discordgo.MessageCreate)

SetEvent sets the internal command's MessageCreate event. It will always be the one corresponding to the message that specified the command.

func (*InternalCommand) SetName

func (ic *InternalCommand) SetName(name string)

SetName will set the name for the command. This name is used to call the command from Discord.

type InternalListener

type InternalListener struct {
	Event interface{}
	// contains filtered or unexported fields
}

InternalListener is the struct for internal listeners. It does not have a droplet field like DropletListener.

func (*InternalListener) Owner

func (il *InternalListener) Owner() string

Owner for InternalListener returns the string constant "__INTERNAL__".

func (*InternalListener) Run

func (il *InternalListener) Run() error

Run will execute the listener's Action.

func (*InternalListener) SetActionHandler

func (il *InternalListener) SetActionHandler(a Action)

SetActionHandler will set the listener's action. It is set during a call to AddInternalListener().

func (*InternalListener) SetEvent

func (il *InternalListener) SetEvent(v interface{})

SetEvent will set the listener's event for future use when Do() is called on the listener's action.

type Listener

type Listener interface {
	Run() error
	SetActionHandler(a Action)
	SetEvent(v interface{})
	Owner() string
}

Listener is the interface for both internal listeners and droplet listeners. Use the Owner() function to discern if a listener is internal. If it is, it will return the string constant "__INTERNAL__".

type MessageAckHandler

type MessageAckHandler func(*discordgo.MessageAck)

MessageAckHandler is the handler for MessageAck Listeners.

func (MessageAckHandler) Do

func (eh MessageAckHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type MessageCreateHandler

type MessageCreateHandler func(*discordgo.MessageCreate)

MessageCreateHandler is the handler for MessageCreate Listeners.

func (MessageCreateHandler) Do

func (eh MessageCreateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type MessageDeleteHandler

type MessageDeleteHandler func(*discordgo.MessageDelete)

MessageDeleteHandler is the handler for MessageDelete Listeners.

func (MessageDeleteHandler) Do

func (eh MessageDeleteHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type MessageReactionAddHandler

type MessageReactionAddHandler func(*discordgo.MessageReactionAdd)

MessageReactionAddHandler is the handler for MessageReactionAdd Listeners.

func (MessageReactionAddHandler) Do

func (eh MessageReactionAddHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type MessageReactionRemoveHandler

type MessageReactionRemoveHandler func(*discordgo.MessageReactionRemove)

MessageReactionRemoveHandler is the handler for MessageReactionRemove Listeners.

func (MessageReactionRemoveHandler) Do

func (eh MessageReactionRemoveHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type MessageUpdateHandler

type MessageUpdateHandler func(*discordgo.MessageUpdate)

MessageUpdateHandler is the handler for MessageUpdate Listeners.

func (MessageUpdateHandler) Do

func (eh MessageUpdateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type PresenceUpdateHandler

type PresenceUpdateHandler func(*discordgo.PresenceUpdate)

PresenceUpdateHandler is the handler for PresenceUpdate Listeners.

func (PresenceUpdateHandler) Do

func (eh PresenceUpdateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type PresencesReplaceHandler

type PresencesReplaceHandler func(*discordgo.PresencesReplace)

PresencesReplaceHandler is the handler for PresencesReplace Listeners.

func (PresencesReplaceHandler) Do

func (eh PresencesReplaceHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type RateLimitHandler

type RateLimitHandler func(*discordgo.RateLimit)

RateLimitHandler is the handler for RateLimit Listeners.

func (RateLimitHandler) Do

func (eh RateLimitHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type ReadyHandler

type ReadyHandler func(*discordgo.Ready)

ReadyHandler is the handler for Ready Listeners.

func (ReadyHandler) Do

func (eh ReadyHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type Registry

type Registry struct {
	Listeners map[string]map[string][]Listener
	Commands  map[string]map[string]Command
}

The Registry holds all listeners registered with the bot. They are grouped by droplet, however each contains an entry of listeners belonging to the bot. This entry is identified with the "__INTERNAL__" string constant.

func (*Registry) AddCommand

func (r *Registry) AddCommand(c Command)

AddCommand will add a command to the registry.

func (*Registry) CreateListener

func (r *Registry) CreateListener(v interface{}, isInternal bool) Listener

CreateListener creates a new listener from a given function.

func (*Registry) Initialize

func (r *Registry) Initialize()

Initialize will initialize all maps in the registry.

type RelationshipAddHandler

type RelationshipAddHandler func(*discordgo.RelationshipAdd)

RelationshipAddHandler is the handler for RelationshipAdd Listeners.

func (RelationshipAddHandler) Do

func (eh RelationshipAddHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type RelationshipRemoveHandler

type RelationshipRemoveHandler func(*discordgo.RelationshipRemove)

RelationshipRemoveHandler is the handler for RelationshipRemove Listeners.

func (RelationshipRemoveHandler) Do

func (eh RelationshipRemoveHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type ResumedHandler

type ResumedHandler func(*discordgo.Resumed)

ResumedHandler is the handler for Resumed Listeners.

func (ResumedHandler) Do

func (eh ResumedHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type TypingStartHandler

type TypingStartHandler func(*discordgo.TypingStart)

TypingStartHandler is the handler for TypingStart Listeners.

func (TypingStartHandler) Do

func (eh TypingStartHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type UserGuildSettingsUpdateHandler

type UserGuildSettingsUpdateHandler func(*discordgo.UserGuildSettingsUpdate)

UserGuildSettingsUpdateHandler is the handler for UserGuildSettingsUpdate Listeners.

func (UserGuildSettingsUpdateHandler) Do

func (eh UserGuildSettingsUpdateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type UserSettingsUpdateHandler

type UserSettingsUpdateHandler func(*discordgo.UserSettingsUpdate)

UserSettingsUpdateHandler is the handler for UserSettingsUpdate Listeners.

func (UserSettingsUpdateHandler) Do

func (eh UserSettingsUpdateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type UserUpdateHandler

type UserUpdateHandler func(*discordgo.UserUpdate)

UserUpdateHandler is the handler for UserUpdate Listeners.

func (UserUpdateHandler) Do

func (eh UserUpdateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type VoiceServerUpdateHandler

type VoiceServerUpdateHandler func(*discordgo.VoiceServerUpdate)

VoiceServerUpdateHandler is the handler for VoiceServerUpdate Listeners.

func (VoiceServerUpdateHandler) Do

func (eh VoiceServerUpdateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

type VoiceStateUpdateHandler

type VoiceStateUpdateHandler func(*discordgo.VoiceStateUpdate)

VoiceStateUpdateHandler is the handler for VoiceStateUpdate Listeners.

func (VoiceStateUpdateHandler) Do

func (eh VoiceStateUpdateHandler) Do(v interface{})

Do runs the underlying function for the handled Listener.

Jump to

Keyboard shortcuts

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