catbase/bot/interfaces.go

87 lines
2.2 KiB
Go
Raw Normal View History

2016-03-19 19:32:51 +00:00
// © 2016 the CatBase Authors under the WTFPL license. See AUTHORS for the list of authors.
2016-03-10 18:37:07 +00:00
package bot
import (
"github.com/jmoiron/sqlx"
"github.com/velour/catbase/bot/msg"
"github.com/velour/catbase/bot/user"
"github.com/velour/catbase/config"
)
const (
_ = iota
// Message any standard chat
Message
// Reply something containing a message reference
Reply
// Action any /me action
Action
// Reaction Icon reaction if service supports it
Reaction
// Edit message ref'd new message to replace
Edit
// Not sure what event is
Event
// Help is used when the bot help system is triggered
Help
// SelfMessage triggers when the bot is sending a message
SelfMessage
)
type ImageAttachment struct {
URL string
AltTxt string
}
2019-02-05 17:25:31 +00:00
type Kind int
2019-05-27 23:21:53 +00:00
type Callback func(Connector, Kind, msg.Message, ...interface{}) bool
type CallbackMap map[string]map[Kind][]Callback
// Bot interface serves to allow mocking of the actual bot
type Bot interface {
// Config allows access to the bot's configuration system
Config() *config.Config
// DB gives access to the current database
DB() *sqlx.DB
// Who lists users in a particular channel
Who(string) []user.User
2019-05-27 23:21:53 +00:00
// WhoAmI gives a nick for the bot
WhoAmI() string
// AddPlugin registers a new plugin handler
AddPlugin(Plugin)
// First arg should be one of bot.Message/Reply/Action/etc
2019-05-27 23:21:53 +00:00
Send(Connector, Kind, ...interface{}) (string, error)
// First arg should be one of bot.Message/Reply/Action/etc
2019-05-27 23:21:53 +00:00
Receive(Connector, Kind, msg.Message, ...interface{}) bool
// Register a callback
Register(Plugin, Kind, Callback)
Filter(msg.Message, string) string
LastMessage(string) (msg.Message, error)
CheckAdmin(string) bool
GetEmojiList() map[string]string
2017-09-29 04:58:21 +00:00
RegisterFilter(string, func(string) string)
2019-02-07 16:30:42 +00:00
RegisterWeb(string, string)
2019-05-27 23:21:53 +00:00
DefaultConnector() Connector
}
// Connector represents a server connection to a chat service
2016-03-10 18:37:07 +00:00
type Connector interface {
RegisterEvent(Callback)
2016-03-10 18:37:07 +00:00
Send(Kind, ...interface{}) (string, error)
GetEmojiList() map[string]string
Serve() error
2016-04-21 15:19:38 +00:00
Who(string) []string
2016-03-10 18:37:07 +00:00
}
// Plugin interface used for compatibility with the Plugin interface
2019-02-07 16:30:42 +00:00
// Uhh it turned empty, but we're still using it to ID plugins
type Plugin interface {
2016-03-10 18:37:07 +00:00
}