Documentation
¶
Overview ¶
Copyright (c) 2020, The OneBot Contributors. All rights reserved.
Copyright (c) 2020, The OneBot Contributors. All rights reserved.
Copyright (c) 2020, The OneBot Contributors. All rights reserved.
Copyright (c) 2020, The OneBot Contributors. All rights reserved.
Copyright (c) 2020, The OneBot Contributors. All rights reserved.
Index ¶
- Constants
- Variables
- func InitLoggers()
- func LoadConfig()
- func LoadPlugin(name string) error
- func LoadPlugins()
- func LoadProtocol(name string) error
- func LoadProtocols()
- func ProcessMessage(prefix string, msg Message, sender Sender)
- func UnloadPlugin(name string) error
- func UnloadPlugins()
- func UnloadProtocols()
- type Command
- type CommandMap
- type Database
- type Location
- type Message
- type Monitor
- type MonitorSlice
- type Plugin
- type PluginMap
- type Protocol
- type ProtocolMap
- type Sender
- type UUID
Constants ¶
const (
DEBUG = 1
)
Variables ¶
var ( LogFile string Error *logger Info *logger Debug *logger )
var ( DefaultPrefix string DefaultNickname string // Key is protocol name (ex: "discord") Protocols *ProtocolMap // Key is plugin name (ex: "admin_tools") Plugins *PluginMap // Key is command trigger (ex: "help") Commands *CommandMap Monitors *MonitorSlice // Db is configured via config file only Db Database DbEngine string PluginDir string // Only used for loading the default plugins PluginLoadList []string ProtocolDir string // Only used for loading the default protocols ProtocolLoadList []string // The main thread will watch this to terminate the process Quit chan os.Signal )
Functions ¶
func InitLoggers ¶
func InitLoggers()
func LoadConfig ¶
func LoadConfig()
TODO set default config path TODO implement DB override Should set all variables unless DB overrides. This also inits DB.
func LoadPlugin ¶
LoadPlugin loads a plugin by filename (minus extension)
func LoadProtocol ¶
LoadProtocol loads a protocol by filename (minus extension)
func LoadProtocols ¶
func LoadProtocols()
LoadProtocols loads all protocols in the protocol directory
func ProcessMessage ¶
ProcessMessage processes command and monitor triggers, spawning a new goroutine for every trigger.
func UnloadPlugin ¶
func UnloadProtocols ¶
func UnloadProtocols()
Unloads every protocol, calling their unload routines.
Types ¶
type CommandMap ¶
type CommandMap struct {
// contains filtered or unexported fields
}
A concurrent-safe map of commands
func (*CommandMap) Delete ¶
func (cm *CommandMap) Delete(commandName string)
Delete removes the command from the active command list, calling the command's unload method via goroutine
func (*CommandMap) DeleteAll ¶
func (cm *CommandMap) DeleteAll()
DeleteAll removes all commands from the active command list
func (*CommandMap) DeleteSet ¶
func (cm *CommandMap) DeleteSet(set map[string]Command)
Delete removes the command from the active command list, calling the command's unload method via goroutine
func (*CommandMap) Get ¶
func (cm *CommandMap) Get(commandName string) Command
Get a command from the CommandMap
func (*CommandMap) Put ¶
func (cm *CommandMap) Put(commandName string, command Command)
Put a command into the CommandMap
type Database ¶
type Database interface {
Get(table, key string) (map[string]interface{}, error) // Retrieves value by key directly
GetString(table, key string) (string, error) // Retrieve a string stored with PutString.
Search(table, field, key string) (map[string]interface{}, error) // Searches for key in field, containing key (IE: field:'username', key:'admin'), using an index if exists.
Put(table string, data map[string]interface{}) ([]byte, error) // Inserts data into database, using "_id" field as key, generating one if none exists. Returns key.
PutString(table, key, text string) error // Inserts text at location "key" for retrieval via GetString
SetIndex(table, field string) error // Sets an index on field.
Close() error // Terminate a database session (only run if nothing is using the database).
}
Database represents a database connection. It's meant to be simple, to work for most general usage. TODO LevelDB is ordered and MongoDB supports comparators. Maybe support simple range returns (IE: select users /w money > 50).
type Location ¶
type Location interface {
DisplayName() string // Display name of the location
Nickname() string // The nickname of the bot in the location
Topic() string // The topic of the location
// Picture // TODO The avatar of the location
UUID() UUID // Unique identifier for the location
Send(msg Message) // Sends a message to the location
SendText(text string) // Sends text to the location
Protocol() string // Returns the name of the protocol the location is in
}
type Message ¶
type Message interface {
Text() string // The unformatted text being received (minus the trigger word for commands)
// Reactions() []Reaction // TODO The reactions on the message
StripPrefix() Message // Returns a copy of the message with `prefix + commandName + " "` stripped (Ex: "!say Hello" becomes "Hello")
Raw() []byte // The raw data received
}
Message contains information either being sent or received
type MonitorSlice ¶
type MonitorSlice struct {
// contains filtered or unexported fields
}
A concurrent-safe slice of monitors
func NewMonitorSlice ¶
func NewMonitorSlice() *MonitorSlice
Returns a new concurrent-safe MonitorSlice
func (*MonitorSlice) Delete ¶
func (ms *MonitorSlice) Delete(monitor *Monitor)
Delete removes the monitor from the active monitor list
func (MonitorSlice) DeleteAll ¶
func (ms MonitorSlice) DeleteAll()
DeleteAll removes all monitors from the active monitor list
func (*MonitorSlice) Get ¶
func (ms *MonitorSlice) Get() []*Monitor
Get copy of monitor slice for reading
func (*MonitorSlice) Put ¶
func (ms *MonitorSlice) Put(monitor *Monitor)
Put a monitor into the MonitorSlice
type Plugin ¶
type Plugin interface {
Name() string // The name of the plugin, used in the plugin map (should be same as filename, minus extension)
LongName() string // The display name of the plugin
Version() int // The version of the plugin
Implements() (map[string]Command, *Monitor) // Returns lists of commands and monitor the plugin implements
Remove() // Called when the plugin is about to be terminated
}
type PluginMap ¶
type PluginMap struct {
// contains filtered or unexported fields
}
A concurrent-safe map of plugins
func (*PluginMap) Delete ¶
Delete removes the plugin from the active plugin list, calling the plugin's unload method via goroutine
func (*PluginMap) DeleteAll ¶
func (pm *PluginMap) DeleteAll()
DeleteAll removes all plugins from the active plugin list, calling the plugin's unload method via goroutine
type Protocol ¶
type Protocol interface {
Name() string // The name of the protocol, used in the protocol map (should be same as filename, minus extension)
LongName() string // The display name of the protocol
Version() int // The version of the protocol
NewMessage(raw []byte) Message // Returns a new Message object built from []byte (TODO: I hate this)
Send(to UUID, msg Message) // Sends a Message to a location
SendText(to UUID, text string) // Sends text to a location
Remove() // Called when the protocol is about to be terminated
}
Protocol contains information about a protocol plugin
type ProtocolMap ¶
type ProtocolMap struct {
// contains filtered or unexported fields
}
A concurrent-safe map of protocols
func (*ProtocolMap) Delete ¶
func (pm *ProtocolMap) Delete(protocolName string)
Delete removes the protocol from the active protocol list, calling the protocol's unload method via goroutine
func (*ProtocolMap) DeleteAll ¶
func (pm *ProtocolMap) DeleteAll()
DeleteAll removes all protocols from the active protocol list, calling the protocol's unload method via goroutine
func (*ProtocolMap) Get ¶
func (pm *ProtocolMap) Get(protocolName string) Protocol
Get a protocol from the ProtocolMap
func (*ProtocolMap) Put ¶
func (pm *ProtocolMap) Put(protocolName string, protocol Protocol)
Put an already loaded protocol into the ProtocolMap
type Sender ¶
type Sender interface {
DisplayName() string // Display name of the sender
Username() string // Username of the sender (often unknown, should return an empty string if so)
UUID() UUID // Unique identifier for the sender
// Picture // TODO The avatar of the location
Location() Location // The location where this sender sent the message from
Protocol() string // Returns the protocol name responsible for the sender
Send(msg Message) // Sends a Message to the sender
SendText(text string) // Sends text to the sender
}
Sender contains information about who and where a message came from