2016-08-09 00:44:28 +00:00
|
|
|
// © 2013 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
|
|
|
|
|
|
|
|
package twitch
|
|
|
|
|
|
|
|
import (
|
2019-05-27 23:21:53 +00:00
|
|
|
"github.com/velour/catbase/plugins/cli"
|
2016-08-09 00:44:28 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/velour/catbase/bot"
|
|
|
|
"github.com/velour/catbase/bot/msg"
|
|
|
|
"github.com/velour/catbase/bot/user"
|
|
|
|
)
|
|
|
|
|
2022-08-09 12:12:17 +00:00
|
|
|
func makeRequest(payload string) bot.Request {
|
|
|
|
c, k, m := makeMessage(payload)
|
|
|
|
return bot.Request{
|
|
|
|
Conn: c,
|
|
|
|
Kind: k,
|
|
|
|
Msg: m,
|
|
|
|
Values: nil,
|
|
|
|
Args: nil,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-27 23:21:53 +00:00
|
|
|
func makeMessage(payload string) (bot.Connector, bot.Kind, msg.Message) {
|
2016-08-09 00:44:28 +00:00
|
|
|
isCmd := strings.HasPrefix(payload, "!")
|
|
|
|
if isCmd {
|
|
|
|
payload = payload[1:]
|
|
|
|
}
|
2019-05-27 23:21:53 +00:00
|
|
|
return &cli.CliPlugin{}, bot.Message, msg.Message{
|
2016-08-09 00:44:28 +00:00
|
|
|
User: &user.User{Name: "tester"},
|
|
|
|
Channel: "test",
|
|
|
|
Body: payload,
|
|
|
|
Command: isCmd,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-18 21:43:44 +00:00
|
|
|
func makeTwitchPlugin(t *testing.T) (*Twitch, *bot.MockBot) {
|
2016-08-09 00:44:28 +00:00
|
|
|
mb := bot.NewMockBot()
|
|
|
|
c := New(mb)
|
2019-01-22 00:16:57 +00:00
|
|
|
mb.Config().Set("twitch.clientid", "fake")
|
2022-08-31 17:20:16 +00:00
|
|
|
mb.Config().Set("twitch.secret", "fake")
|
2022-08-09 12:12:17 +00:00
|
|
|
c.c.SetArray("Twitch.Channels", []string{"test"})
|
|
|
|
c.c.SetArray("Twitch.test.Users", []string{"drseabass"})
|
2016-08-09 00:44:28 +00:00
|
|
|
assert.NotNil(t, c)
|
|
|
|
|
|
|
|
c.twitchList["drseabass"] = &Twitcher{
|
2019-02-06 02:13:35 +00:00
|
|
|
name: "drseabass",
|
|
|
|
gameID: "",
|
2016-08-09 00:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return c, mb
|
|
|
|
}
|