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
|
|
|
|
|
2016-03-30 14:00:20 +00:00
|
|
|
import (
|
|
|
|
"github.com/jmoiron/sqlx"
|
2016-04-01 14:20:03 +00:00
|
|
|
"github.com/velour/catbase/bot/msg"
|
|
|
|
"github.com/velour/catbase/bot/user"
|
2016-03-30 14:00:20 +00:00
|
|
|
"github.com/velour/catbase/config"
|
|
|
|
)
|
|
|
|
|
2019-02-05 15:54:13 +00:00
|
|
|
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
|
|
|
|
)
|
|
|
|
|
2019-02-05 17:25:31 +00:00
|
|
|
type Kind int
|
|
|
|
type Callback func(Kind, msg.Message, ...interface{}) bool
|
2019-02-15 18:22:54 +00:00
|
|
|
type CallbackMap map[string]map[Kind][]Callback
|
2019-02-05 15:54:13 +00:00
|
|
|
|
2019-02-05 16:20:43 +00:00
|
|
|
// Bot interface serves to allow mocking of the actual bot
|
2016-03-30 14:00:20 +00:00
|
|
|
type Bot interface {
|
2019-02-05 16:20:43 +00:00
|
|
|
// Config allows access to the bot's configuration system
|
2016-03-30 14:00:20 +00:00
|
|
|
Config() *config.Config
|
2019-02-05 16:20:43 +00:00
|
|
|
// DB gives access to the current database
|
2016-03-30 14:00:20 +00:00
|
|
|
DB() *sqlx.DB
|
2019-02-05 16:20:43 +00:00
|
|
|
// Who lists users in a particular channel
|
2016-04-01 14:20:03 +00:00
|
|
|
Who(string) []user.User
|
2019-02-05 16:20:43 +00:00
|
|
|
// AddPlugin registers a new plugin handler
|
2019-02-05 21:10:36 +00:00
|
|
|
AddPlugin(Plugin)
|
2019-02-05 15:54:13 +00:00
|
|
|
// First arg should be one of bot.Message/Reply/Action/etc
|
2019-02-05 18:33:18 +00:00
|
|
|
Send(Kind, ...interface{}) (string, error)
|
2019-02-05 15:54:13 +00:00
|
|
|
// First arg should be one of bot.Message/Reply/Action/etc
|
2019-02-06 03:52:49 +00:00
|
|
|
Receive(Kind, msg.Message, ...interface{}) bool
|
2019-02-05 15:54:13 +00:00
|
|
|
// Register a callback
|
2019-02-05 18:58:12 +00:00
|
|
|
Register(Plugin, Kind, Callback)
|
2019-02-05 15:54:13 +00:00
|
|
|
|
2016-04-01 14:20:03 +00:00
|
|
|
Filter(msg.Message, string) string
|
|
|
|
LastMessage(string) (msg.Message, error)
|
2019-02-05 15:54:13 +00:00
|
|
|
|
2016-04-01 14:20:03 +00:00
|
|
|
CheckAdmin(string) bool
|
2017-07-24 19:09:27 +00:00
|
|
|
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)
|
2016-03-30 14:00:20 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 16:20:43 +00:00
|
|
|
// Connector represents a server connection to a chat service
|
2016-03-10 18:37:07 +00:00
|
|
|
type Connector interface {
|
2019-02-06 03:52:49 +00:00
|
|
|
RegisterEvent(Callback)
|
2016-03-10 18:37:07 +00:00
|
|
|
|
2019-02-05 18:33:18 +00:00
|
|
|
Send(Kind, ...interface{}) (string, error)
|
2019-02-05 15:54:13 +00:00
|
|
|
|
2017-07-24 19:09:27 +00:00
|
|
|
GetEmojiList() map[string]string
|
2017-09-07 04:32:53 +00:00
|
|
|
Serve() error
|
2016-04-21 15:19:38 +00:00
|
|
|
|
|
|
|
Who(string) []string
|
2016-03-10 18:37:07 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 16:20:43 +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
|
2019-02-05 15:54:13 +00:00
|
|
|
type Plugin interface {
|
2016-03-10 18:37:07 +00:00
|
|
|
}
|