Documentation
¶
Index ¶
- Constants
- Variables
- func ArgsSplitter(in string) []string
- type CCConfig
- type Command
- type CommandGroupContainer
- type CommandHandler
- type Commander
- func (c *Commander) Close()
- func (c *Commander) GetCommandGroups() map[string]*CommandGroupContainer
- func (c *Commander) GetCommands() map[string]*Command
- func (c *Commander) HandleError(f func(error))
- func (c *Commander) Help(m *MessageContext, args []string) error
- func (c *Commander) JoinChannel(platform PlatformType, channel interface{}) error
- func (c *Commander) LeaveChannel(platform PlatformType, channel interface{}) error
- func (c *Commander) Open() error
- func (c *Commander) RegisterCommand(groupName string) func(info *PJCommand, handler CommandHandler) errordeprecated
- func (c *Commander) SendMessage(platform PlatformType, channelID interface{}, message interface{}) (interface{}, error)
- func (c *Commander) SetupPlugin(setup func(RegisterCommand, context.Context), info *PluginJSON)deprecated
- func (c *Commander) SetupPluginFromConfig(setup func(ctx context.Context) (map[string]CommandHandler, error), ...) error
- type GetCommandHandler
- type GetPlugin
- type Loader
- type LoaderFactory
- type Message
- type MessageContext
- type MessageUser
- type NativeLoader
- type NewNativeLoader
- type PJCommand
- type Platform
- type PlatformType
- type PluginJSON
- type PluginType
- type RegisterCommand
Constants ¶
View Source
const ( EventCommanderClose = "commander:close" MaxDepth = 8 )
Variables ¶
View Source
var DefaultLoaderChain = []LoaderFactory{}
Functions ¶
func ArgsSplitter ¶
Types ¶
type CCConfig ¶
type CCConfig struct {
Platforms []Platform
Prefix string
AutoloadPlugins bool
PluginLoaders []LoaderFactory
Tokens map[PlatformType]string
OtherConfig map[string]interface{}
// Where supported, join these channels when commander starts
AutoJoinChannels map[PlatformType][]interface{}
}
type Command ¶
type Command struct {
Handler CommandHandler
Info *PJCommand
Subcommands map[string]*Command
}
type CommandGroupContainer ¶
type CommandGroupContainer struct {
Commands map[string]*Command
Info *PluginJSON
}
type CommandHandler ¶
type CommandHandler func(*MessageContext, []string) error
type Commander ¶
type Commander struct {
OnError func(error)
// returning false *will stop execution*
GuardBeforeCommandCheck func(*MessageContext, string, []string) bool
// returning false *will stop execution*
GuardBeforeCommandExec func(*MessageContext, string, []string) bool
GuardPostCommandCheck func(*MessageContext, string, []string)
// contains filtered or unexported fields
}
func NewCommander ¶
Make a new instance of a commander.
func (*Commander) GetCommandGroups ¶
func (c *Commander) GetCommandGroups() map[string]*CommandGroupContainer
func (*Commander) GetCommands ¶
func (*Commander) HandleError ¶
func (*Commander) JoinChannel ¶
func (c *Commander) JoinChannel(platform PlatformType, channel interface{}) error
func (*Commander) LeaveChannel ¶
func (c *Commander) LeaveChannel(platform PlatformType, channel interface{}) error
func (*Commander) RegisterCommand
deprecated
func (c *Commander) RegisterCommand(groupName string) func(info *PJCommand, handler CommandHandler) error
Deprecated: RegisterCommand does not support subcommands. Do not use it directly.
func (*Commander) SendMessage ¶
func (c *Commander) SendMessage(platform PlatformType, channelID interface{}, message interface{}) (interface{}, error)
func (*Commander) SetupPlugin
deprecated
func (c *Commander) SetupPlugin(setup func(RegisterCommand, context.Context), info *PluginJSON)
Deprecated: With the move to loaders, this no longer works properly and you may have to faff for it to work. Use the new loader system. Register the plugin into the list of 'groups' (read: plugins)
func (*Commander) SetupPluginFromConfig ¶
func (c *Commander) SetupPluginFromConfig(setup func(ctx context.Context) (map[string]CommandHandler, error), info *PluginJSON) error
type GetCommandHandler ¶
type GetCommandHandler func(string) (CommandHandler, error)
type Loader ¶
type Loader interface {
LoadPlugin(string) error
GetCommandHandler(string) (CommandHandler, error)
}
type LoaderFactory ¶
type LoaderFactory interface {
GetTypeName() PluginType
// We pass context in here just in case you need to build some stuff up (the native loader does)
New(context.Context) Loader
}
type Message ¶
type Message struct {
RealmID string
Author MessageUser
}
type MessageContext ¶
func (*MessageContext) Send ¶
func (m *MessageContext) Send(message interface{}) (interface{}, error)
func (*MessageContext) SendTo ¶
func (m *MessageContext) SendTo(channelID interface{}, message interface{}) (interface{}, error)
type MessageUser ¶
type NativeLoader ¶
func (*NativeLoader) GetCommandHandler ¶
func (n *NativeLoader) GetCommandHandler(name string) (CommandHandler, error)
func (*NativeLoader) LoadPlugin ¶
func (n *NativeLoader) LoadPlugin(name string) error
type NewNativeLoader ¶
type NewNativeLoader struct{}
func (*NewNativeLoader) GetTypeName ¶
func (n *NewNativeLoader) GetTypeName() PluginType
type Platform ¶
type Platform interface {
// The string here will be a token (since that's what most platforms use)
Setup(string) error
GetPlatformType() PlatformType
// sometimes we have a need to access the underlying funcs for a platform (i.e. DiscordGo's Session.State)
GetClient() interface{}
// Register events with your library like OnServerJoin or OnMemberJoin or the like.
// The events from your library should be passed through EventBus using BusPublisher.Publish
RegisterEvents(EventBus.BusPublisher) error
RegisterMessageHandler(func(string, *MessageContext)) error
// Begin the connection.
// Context is passed so that you can store it and pass it down to events
Open(context.Context) error
// Close the connection.
// Fire off *your* close event, but not a EventCommanderClose.
Close() error
// Allow each platform to generate its own help messages (i.e. discord can use embeds, twitch can send a link &c.)
// The interface will be a map[string]*Command or a map[string]*CommandGroupContainer depending on the passed param
GenHelp(interface{}, *MessageContext) error
// Join another channel by the given name/id/whatever.
JoinChannel(interface{}) error
// Leave a channel with given name/id
LeaveChannel(interface{}) error
}
type PlatformType ¶
type PlatformType uint
const ( PlatformDiscord PlatformType = 1 << iota PlatformGlimesh PlatformTwitch )
func (PlatformType) ToString ¶
func (pt PlatformType) ToString() string
type PluginJSON ¶
type PluginJSON struct {
Name string
Creator string
License string
URL string `json:"url"`
Description string
PluginType PluginType `json:"plugin_type"`
SupportedPlatforms PlatformType `json:"supported_platforms"`
Commands []*PJCommand
HideInHelp bool `json:"hide_in_help"`
}
type PluginType ¶
type PluginType string
const NativePluginLoader PluginType = "uk.co.rpgpn.crius.commander.loader:native"
type RegisterCommand ¶
type RegisterCommand func(*PJCommand, CommandHandler) error
Source Files
¶
Click to show internal directories.
Click to hide internal directories.