mirror of https://github.com/velour/catbase.git
bot: rename a few things
This commit is contained in:
parent
2e20971dd1
commit
d85c855d47
10
bot/bot.go
10
bot/bot.go
|
@ -42,7 +42,7 @@ type bot struct {
|
|||
// filters registered by plugins
|
||||
filters map[string]func(string) string
|
||||
|
||||
callbacks map[string][]Callback
|
||||
callbacks CallbackMap
|
||||
}
|
||||
|
||||
// Variable represents a $var replacement
|
||||
|
@ -74,7 +74,7 @@ func New(config *config.Config, connector Connector) Bot {
|
|||
logOut: logOut,
|
||||
httpEndPoints: make(map[string]string),
|
||||
filters: make(map[string]func(string) string),
|
||||
callbacks: make(map[string][]Callback),
|
||||
callbacks: make(CallbackMap),
|
||||
}
|
||||
|
||||
bot.migrateDB()
|
||||
|
@ -250,7 +250,9 @@ func (b *bot) RegisterFilter(name string, f func(string) string) {
|
|||
}
|
||||
|
||||
// Send a message to the connection
|
||||
func (b *bot) Send(int, ...interface{}) (error, string) { return nil, "" }
|
||||
func (b *bot) Send(kind Kind, args ...interface{}) (error, string) { return nil, "" }
|
||||
|
||||
// Register a callback
|
||||
func (b *bot) Register(int, Callback) {}
|
||||
func (b *bot) Register(name string, kind Kind, cb Callback) {
|
||||
b.callbacks[name][kind] = append(b.callbacks[name][kind], cb)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
"github.com/velour/catbase/bot/msg"
|
||||
)
|
||||
|
||||
func (b *bot) Receive(kind int, msg msg.Message, args ...interface{}) {
|
||||
func (b *bot) Receive(kind Kind, msg msg.Message, args ...interface{}) {
|
||||
panic("I don't know what to do here yet")
|
||||
}
|
||||
|
||||
|
@ -54,8 +54,8 @@ func (b *bot) EventReceived(msg msg.Message) {
|
|||
}
|
||||
}
|
||||
|
||||
func (b *bot) runCallback(plugin string, evt int, message msg.Message, args ...interface{}) bool {
|
||||
for _, cb := range b.callbacks[plugin] {
|
||||
func (b *bot) runCallback(plugin string, evt Kind, message msg.Message, args ...interface{}) bool {
|
||||
for _, cb := range b.callbacks[plugin][evt] {
|
||||
if cb(evt, message) {
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -30,9 +30,9 @@ const (
|
|||
SelfMessage
|
||||
)
|
||||
|
||||
type kind int
|
||||
|
||||
type Callback func(int, msg.Message, ...interface{}) bool
|
||||
type Kind int
|
||||
type Callback func(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 {
|
||||
|
@ -45,11 +45,11 @@ type Bot interface {
|
|||
// AddPlugin registers a new plugin handler
|
||||
AddPlugin(string, Plugin)
|
||||
// First arg should be one of bot.Message/Reply/Action/etc
|
||||
Send(int, ...interface{}) (error, string)
|
||||
Send(Kind, ...interface{}) (error, string)
|
||||
// First arg should be one of bot.Message/Reply/Action/etc
|
||||
Receive(int, msg.Message, ...interface{})
|
||||
Receive(Kind, msg.Message, ...interface{})
|
||||
// Register a callback
|
||||
Register(int, Callback)
|
||||
Register(string, Kind, Callback)
|
||||
|
||||
Filter(msg.Message, string) string
|
||||
LastMessage(string) (msg.Message, error)
|
||||
|
@ -65,7 +65,7 @@ type Connector interface {
|
|||
RegisterMessageReceived(func(message msg.Message))
|
||||
RegisterReplyMessageReceived(func(msg.Message, string))
|
||||
|
||||
Send(int, ...interface{}) (error, string)
|
||||
Send(Kind, ...interface{}) (error, string)
|
||||
|
||||
GetEmojiList() map[string]string
|
||||
Serve() error
|
||||
|
|
14
bot/mock.go
14
bot/mock.go
|
@ -29,7 +29,7 @@ type MockBot struct {
|
|||
func (mb *MockBot) Config() *config.Config { return mb.Cfg }
|
||||
func (mb *MockBot) DB() *sqlx.DB { return mb.Cfg.DB }
|
||||
func (mb *MockBot) Who(string) []user.User { return []user.User{} }
|
||||
func (mb *MockBot) Send(kind int, args ...interface{}) (error, string) {
|
||||
func (mb *MockBot) Send(kind Kind, args ...interface{}) (error, string) {
|
||||
switch kind {
|
||||
case Message:
|
||||
mb.Messages = append(mb.Messages, args[1].(string))
|
||||
|
@ -46,12 +46,12 @@ func (mb *MockBot) Send(kind int, args ...interface{}) (error, string) {
|
|||
}
|
||||
return fmt.Errorf("Mesasge type unhandled"), "ERROR"
|
||||
}
|
||||
func (mb *MockBot) AddPlugin(name string, f Plugin) {}
|
||||
func (mb *MockBot) Register(kind int, cb Callback) {}
|
||||
func (mb *MockBot) Receive(kind int, msg msg.Message, args ...interface{}) {}
|
||||
func (mb *MockBot) Filter(msg msg.Message, s string) string { return s }
|
||||
func (mb *MockBot) LastMessage(ch string) (msg.Message, error) { return msg.Message{}, nil }
|
||||
func (mb *MockBot) CheckAdmin(nick string) bool { return false }
|
||||
func (mb *MockBot) AddPlugin(name string, f Plugin) {}
|
||||
func (mb *MockBot) Register(name string, kind Kind, cb Callback) {}
|
||||
func (mb *MockBot) Receive(kind Kind, msg msg.Message, args ...interface{}) {}
|
||||
func (mb *MockBot) Filter(msg msg.Message, s string) string { return s }
|
||||
func (mb *MockBot) LastMessage(ch string) (msg.Message, error) { return msg.Message{}, nil }
|
||||
func (mb *MockBot) CheckAdmin(nick string) bool { return false }
|
||||
|
||||
func (mb *MockBot) react(channel, reaction string, message msg.Message) (error, string) {
|
||||
mb.Reactions = append(mb.Reactions, reaction)
|
||||
|
|
|
@ -66,7 +66,7 @@ func (i *Irc) RegisterReplyMessageReceived(f func(msg.Message, string)) {
|
|||
i.replyMessageReceived = f
|
||||
}
|
||||
|
||||
func (i *Irc) Send(kind int, args ...interface{}) (error, string) {
|
||||
func (i *Irc) Send(kind bot.Kind, args ...interface{}) (error, string) {
|
||||
switch kind {
|
||||
case bot.Reply:
|
||||
case bot.Message:
|
||||
|
|
Loading…
Reference in New Issue