2016-03-30 14:00:20 +00:00
|
|
|
// © 2016 the CatBase Authors under the WTFPL license. See AUTHORS for the list of authors.
|
|
|
|
|
|
|
|
package bot
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
"github.com/stretchr/testify/mock"
|
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"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MockBot struct {
|
|
|
|
mock.Mock
|
|
|
|
db *sqlx.DB
|
|
|
|
|
2016-05-11 01:15:52 +00:00
|
|
|
Cfg config.Config
|
|
|
|
|
2016-03-30 14:00:20 +00:00
|
|
|
Messages []string
|
|
|
|
Actions []string
|
|
|
|
}
|
|
|
|
|
2016-05-11 01:15:52 +00:00
|
|
|
func (mb *MockBot) Config() *config.Config { return &mb.Cfg }
|
2016-03-30 14:00:20 +00:00
|
|
|
func (mb *MockBot) DBVersion() int64 { return 1 }
|
|
|
|
func (mb *MockBot) DB() *sqlx.DB { return mb.db }
|
2017-10-31 10:22:36 +00:00
|
|
|
func (mb *MockBot) Conn() Connector { return nil }
|
2016-04-01 14:20:03 +00:00
|
|
|
func (mb *MockBot) Who(string) []user.User { return []user.User{} }
|
2016-03-30 14:00:20 +00:00
|
|
|
func (mb *MockBot) AddHandler(name string, f Handler) {}
|
|
|
|
func (mb *MockBot) SendMessage(ch string, msg string) {
|
|
|
|
mb.Messages = append(mb.Messages, msg)
|
|
|
|
}
|
|
|
|
func (mb *MockBot) SendAction(ch string, msg string) {
|
|
|
|
mb.Actions = append(mb.Actions, msg)
|
|
|
|
}
|
2016-04-01 14:20:03 +00:00
|
|
|
func (mb *MockBot) MsgReceived(msg msg.Message) {}
|
|
|
|
func (mb *MockBot) EventReceived(msg msg.Message) {}
|
|
|
|
func (mb *MockBot) Filter(msg msg.Message, s string) string { return "" }
|
|
|
|
func (mb *MockBot) LastMessage(ch string) (msg.Message, error) { return msg.Message{}, nil }
|
2017-09-29 04:58:21 +00:00
|
|
|
func (mb *MockBot) CheckAdmin(nick string) bool { return false }
|
2017-07-25 10:15:44 +00:00
|
|
|
|
|
|
|
func (mb *MockBot) React(channel, reaction string, message msg.Message) {}
|
2017-10-31 10:22:36 +00:00
|
|
|
func (mb *MockBot) Edit(channel, newMessage, identifier string) {}
|
2017-07-25 10:15:44 +00:00
|
|
|
func (mb *MockBot) GetEmojiList() map[string]string { return make(map[string]string) }
|
2017-09-29 04:58:21 +00:00
|
|
|
func (mb *MockBot) RegisterFilter(s string, f func(string) string) {}
|
2017-07-25 10:15:44 +00:00
|
|
|
|
2016-03-30 14:00:20 +00:00
|
|
|
func NewMockBot() *MockBot {
|
|
|
|
db, err := sqlx.Open("sqlite3_custom", ":memory:")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Failed to open database:", err)
|
|
|
|
}
|
|
|
|
b := MockBot{
|
|
|
|
db: db,
|
|
|
|
Messages: make([]string, 0),
|
|
|
|
Actions: make([]string, 0),
|
|
|
|
}
|
|
|
|
return &b
|
|
|
|
}
|