mirror of https://github.com/velour/catbase.git
Compare commits
No commits in common. "55a206760fabfb1f8058a0738cd20478cd2cb6f1" and "a6847a996fcf9ac13f1a55a670147677992d8026" have entirely different histories.
55a206760f
...
a6847a996f
|
@ -14,7 +14,6 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -42,7 +41,6 @@ type BeersPlugin struct {
|
|||
db *sqlx.DB
|
||||
|
||||
untapdCache map[int]bool
|
||||
handlers bot.HandlerTable
|
||||
}
|
||||
|
||||
type untappdUser struct {
|
||||
|
@ -72,7 +70,7 @@ func New(b bot.Bot) *BeersPlugin {
|
|||
untapdCache: make(map[int]bool),
|
||||
}
|
||||
|
||||
p.register()
|
||||
b.Register(p, bot.Message, p.message)
|
||||
b.Register(p, bot.Help, p.help)
|
||||
|
||||
p.registerWeb()
|
||||
|
@ -90,86 +88,89 @@ func New(b bot.Bot) *BeersPlugin {
|
|||
return p
|
||||
}
|
||||
|
||||
func (p *BeersPlugin) register() {
|
||||
p.handlers = bot.HandlerTable{
|
||||
{Kind: bot.Message, IsCmd: false,
|
||||
Regex: regexp.MustCompile(`(?i)^beers?\s?(?P<operator>(\+=|-=|=))\s?(?P<amount>\d+)$`),
|
||||
Handler: func(r bot.Request) bool {
|
||||
op := r.Values["operator"]
|
||||
count, _ := strconv.Atoi(r.Values["amount"])
|
||||
nick := r.Msg.User.Name
|
||||
// Message responds to the bot hook on recieving messages.
|
||||
// This function returns true if the plugin responds in a meaningful way to the users message.
|
||||
// Otherwise, the function returns false and the bot continues execution of other plugins.
|
||||
func (p *BeersPlugin) message(c bot.Connector, kind bot.Kind, message msg.Message, args ...interface{}) bool {
|
||||
parts := strings.Fields(message.Body)
|
||||
|
||||
switch op {
|
||||
case "=":
|
||||
if len(parts) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
channel := message.Channel
|
||||
user := message.User
|
||||
nick := user.Name
|
||||
|
||||
// respond to the beers type of queries
|
||||
parts[0] = strings.ToLower(parts[0]) // support iPhone/Android saying "Beers"
|
||||
if parts[0] == "beers" {
|
||||
if len(parts) == 3 {
|
||||
|
||||
// try to get a count out of parts[2]
|
||||
count, err := strconv.Atoi(parts[2])
|
||||
if err != nil {
|
||||
// if it's not a number, maybe it's a nick!
|
||||
p.b.Send(c, bot.Message, channel, "Sorry, that didn't make any sense.")
|
||||
}
|
||||
|
||||
if count < 0 {
|
||||
// you can't be negative
|
||||
msg := fmt.Sprintf("Sorry %s, you can't have negative beers!", nick)
|
||||
p.b.Send(c, bot.Message, channel, msg)
|
||||
return true
|
||||
}
|
||||
if parts[1] == "+=" {
|
||||
p.addBeers(nick, count)
|
||||
p.randomReply(c, channel)
|
||||
} else if parts[1] == "=" {
|
||||
if count == 0 {
|
||||
p.puke(r.Conn, nick, r.Msg.Channel)
|
||||
p.puke(c, nick, channel)
|
||||
} else {
|
||||
p.setBeers(nick, count)
|
||||
p.randomReply(r.Conn, r.Msg.Channel)
|
||||
p.randomReply(c, channel)
|
||||
}
|
||||
return true
|
||||
case "+=":
|
||||
p.addBeers(nick, count)
|
||||
p.randomReply(r.Conn, r.Msg.Channel)
|
||||
return true
|
||||
case "-=":
|
||||
p.addBeers(nick, -count)
|
||||
p.randomReply(r.Conn, r.Msg.Channel)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}},
|
||||
{Kind: bot.Message, IsCmd: false,
|
||||
Regex: regexp.MustCompile(`(?i)^beers?\s?(?P<operator>(\+\+|--))$`),
|
||||
Handler: func(r bot.Request) bool {
|
||||
op := r.Values["operator"]
|
||||
nick := r.Msg.User.Name
|
||||
if op == "++" {
|
||||
p.addBeers(nick, 1)
|
||||
} else {
|
||||
p.addBeers(nick, -1)
|
||||
p.b.Send(c, bot.Message, channel, "I don't know your math.")
|
||||
}
|
||||
p.randomReply(r.Conn, r.Msg.Channel)
|
||||
return true
|
||||
}},
|
||||
{Kind: bot.Message, IsCmd: true,
|
||||
Regex: regexp.MustCompile(`(?i)^beers( (?P<who>\S+))?$`),
|
||||
Handler: func(r bot.Request) bool {
|
||||
who := r.Values["who"]
|
||||
if who == "" {
|
||||
who = r.Msg.User.Name
|
||||
}
|
||||
if p.doIKnow(who) {
|
||||
p.reportCount(r.Conn, who, r.Msg.Channel, false)
|
||||
} else if len(parts) == 2 {
|
||||
if p.doIKnow(parts[1]) {
|
||||
p.reportCount(c, parts[1], channel, false)
|
||||
} else {
|
||||
msg := fmt.Sprintf("Sorry, I don't know %s.", who)
|
||||
p.b.Send(r.Conn, bot.Message, r.Msg.Channel, msg)
|
||||
msg := fmt.Sprintf("Sorry, I don't know %s.", parts[1])
|
||||
p.b.Send(c, bot.Message, channel, msg)
|
||||
}
|
||||
} else if len(parts) == 1 {
|
||||
p.reportCount(c, nick, channel, true)
|
||||
}
|
||||
return true
|
||||
}},
|
||||
{Kind: bot.Message, IsCmd: true,
|
||||
Regex: regexp.MustCompile(`(?i)^puke$`),
|
||||
Handler: func(r bot.Request) bool {
|
||||
p.puke(r.Conn, r.Msg.User.Name, r.Msg.Channel)
|
||||
return true
|
||||
}},
|
||||
{Kind: bot.Message, IsCmd: true,
|
||||
Regex: regexp.MustCompile(`(?i)^` +
|
||||
strings.Join(p.c.GetArray("beers.imbibewords", []string{"imbibe", "quaff"}), "|") + `$`),
|
||||
Handler: func(r bot.Request) bool {
|
||||
p.addBeers(r.Msg.User.Name, 1)
|
||||
p.randomReply(r.Conn, r.Msg.Channel)
|
||||
return true
|
||||
}},
|
||||
{Kind: bot.Message, IsCmd: true,
|
||||
Regex: regexp.MustCompile(`(?i)^reguntappd (?P<who>\S+)$`),
|
||||
Handler: func(r bot.Request) bool {
|
||||
chanNick := r.Msg.User.Name
|
||||
channel := r.Msg.Channel
|
||||
untappdNick := r.Values["who"]
|
||||
|
||||
// no matter what, if we're in here, then we've responded
|
||||
return true
|
||||
} else if parts[0] == "puke" {
|
||||
p.puke(c, nick, channel)
|
||||
return true
|
||||
}
|
||||
|
||||
if message.Command && parts[0] == "imbibe" {
|
||||
p.addBeers(nick, 1)
|
||||
p.randomReply(c, channel)
|
||||
return true
|
||||
}
|
||||
|
||||
if message.Command && parts[0] == "reguntappd" {
|
||||
chanNick := message.User.Name
|
||||
channel := message.Channel
|
||||
|
||||
if len(parts) < 2 {
|
||||
p.b.Send(c, bot.Message, channel, "You must also provide a user name.")
|
||||
} else if len(parts) == 3 {
|
||||
chanNick = parts[2]
|
||||
} else if len(parts) == 4 {
|
||||
chanNick = parts[2]
|
||||
channel = parts[3]
|
||||
}
|
||||
u := untappdUser{
|
||||
untappdUser: untappdNick,
|
||||
untappdUser: parts[1],
|
||||
chanNick: chanNick,
|
||||
channel: channel,
|
||||
}
|
||||
|
@ -186,7 +187,7 @@ func (p *BeersPlugin) register() {
|
|||
log.Error().Err(err).Msgf("Error registering untappd")
|
||||
}
|
||||
if count > 0 {
|
||||
p.b.Send(r.Conn, bot.Message, channel, "I'm already watching you.")
|
||||
p.b.Send(c, bot.Message, channel, "I'm already watching you.")
|
||||
return true
|
||||
}
|
||||
_, err = p.db.Exec(`insert into untappd (
|
||||
|
@ -202,32 +203,28 @@ func (p *BeersPlugin) register() {
|
|||
)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("Error registering untappd")
|
||||
p.b.Send(r.Conn, bot.Message, channel, "I can't see.")
|
||||
p.b.Send(c, bot.Message, channel, "I can't see.")
|
||||
return true
|
||||
}
|
||||
|
||||
p.b.Send(r.Conn, bot.Message, channel, "I'll be watching you.")
|
||||
p.b.Send(c, bot.Message, channel, "I'll be watching you.")
|
||||
|
||||
p.checkUntappd(r.Conn, channel)
|
||||
p.checkUntappd(c, channel)
|
||||
|
||||
return true
|
||||
}},
|
||||
{Kind: bot.Message, IsCmd: true,
|
||||
Regex: regexp.MustCompile(`(?i)^checkuntappd$`),
|
||||
Handler: func(r bot.Request) bool {
|
||||
}
|
||||
|
||||
if message.Command && parts[0] == "checkuntappd" {
|
||||
log.Info().
|
||||
Str("user", r.Msg.User.Name).
|
||||
Str("user", message.User.Name).
|
||||
Msgf("Checking untappd at request of user.")
|
||||
p.checkUntappd(r.Conn, r.Msg.Channel)
|
||||
p.checkUntappd(c, channel)
|
||||
return true
|
||||
}},
|
||||
}
|
||||
p.b.RegisterTable(p, p.handlers)
|
||||
}
|
||||
|
||||
// Message responds to the bot hook on recieving messages.
|
||||
// This function returns true if the plugin responds in a meaningful way to the users message.
|
||||
// Otherwise, the function returns false and the bot continues execution of other plugins.
|
||||
return false
|
||||
}
|
||||
|
||||
// Help responds to help requests. Every plugin must implement a help function.
|
||||
func (p *BeersPlugin) help(c bot.Connector, kind bot.Kind, message msg.Message, args ...interface{}) bool {
|
||||
msg := "Beers: imbibe by using either beers +=,=,++ or with the !imbibe/drink " +
|
||||
|
@ -283,7 +280,11 @@ func (p *BeersPlugin) puke(c bot.Connector, user string, channel string) {
|
|||
}
|
||||
|
||||
func (p *BeersPlugin) doIKnow(nick string) bool {
|
||||
count := p.getBeers(nick)
|
||||
var count int
|
||||
err := p.db.QueryRow(`select count(*) from beers where nick = ?`, nick).Scan(&count)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return count > 0
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
package beers
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -16,45 +15,27 @@ import (
|
|||
"github.com/velour/catbase/plugins/counter"
|
||||
)
|
||||
|
||||
func makeMessage(payload string, r *regexp.Regexp) bot.Request {
|
||||
func makeMessage(payload string) (bot.Connector, bot.Kind, msg.Message) {
|
||||
isCmd := strings.HasPrefix(payload, "!")
|
||||
if isCmd {
|
||||
payload = payload[1:]
|
||||
}
|
||||
c := &cli.CliPlugin{}
|
||||
values := bot.ParseValues(r, payload)
|
||||
return bot.Request{
|
||||
Conn: c,
|
||||
Kind: bot.Message,
|
||||
Values: values,
|
||||
Msg: msg.Message{
|
||||
return c, bot.Message, msg.Message{
|
||||
User: &user.User{Name: "tester"},
|
||||
Channel: "test",
|
||||
Body: payload,
|
||||
Command: isCmd,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func testMessage(p *BeersPlugin, msg string) bool {
|
||||
for _, h := range p.handlers {
|
||||
if h.Regex.MatchString(msg) {
|
||||
req := makeMessage(msg, h.Regex)
|
||||
if h.Handler(req) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func makeBeersPlugin(t *testing.T) (*BeersPlugin, *bot.MockBot) {
|
||||
mb := bot.NewMockBot()
|
||||
counter.New(mb)
|
||||
mb.DB().MustExec(`delete from counter; delete from counter_alias;`)
|
||||
b := New(mb)
|
||||
counter.MkAlias(mb.DB(), "beer", ":beer:")
|
||||
counter.MkAlias(mb.DB(), "beers", ":beer:")
|
||||
b.message(makeMessage("!mkalias beer :beer:"))
|
||||
b.message(makeMessage("!mkalias beers :beer:"))
|
||||
return b, mb
|
||||
}
|
||||
|
||||
|
@ -71,9 +52,9 @@ func TestCounter(t *testing.T) {
|
|||
|
||||
func TestImbibe(t *testing.T) {
|
||||
b, mb := makeBeersPlugin(t)
|
||||
testMessage(b, "imbibe")
|
||||
b.message(makeMessage("!imbibe"))
|
||||
assert.Len(t, mb.Messages, 1)
|
||||
testMessage(b, "imbibe")
|
||||
b.message(makeMessage("!imbibe"))
|
||||
assert.Len(t, mb.Messages, 2)
|
||||
it, err := counter.GetUserItem(mb.DB(), "tester", itemName)
|
||||
assert.Nil(t, err)
|
||||
|
@ -81,17 +62,26 @@ func TestImbibe(t *testing.T) {
|
|||
}
|
||||
func TestEq(t *testing.T) {
|
||||
b, mb := makeBeersPlugin(t)
|
||||
testMessage(b, "beers = 3")
|
||||
b.message(makeMessage("!beers = 3"))
|
||||
assert.Len(t, mb.Messages, 1)
|
||||
it, err := counter.GetUserItem(mb.DB(), "tester", itemName)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 3, it.Count)
|
||||
}
|
||||
|
||||
func TestEqNeg(t *testing.T) {
|
||||
b, mb := makeBeersPlugin(t)
|
||||
b.message(makeMessage("!beers = -3"))
|
||||
assert.Len(t, mb.Messages, 1)
|
||||
it, err := counter.GetUserItem(mb.DB(), "tester", itemName)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 0, it.Count)
|
||||
}
|
||||
|
||||
func TestEqZero(t *testing.T) {
|
||||
b, mb := makeBeersPlugin(t)
|
||||
testMessage(b, "beers += 5")
|
||||
testMessage(b, "beers = 0")
|
||||
b.message(makeMessage("beers += 5"))
|
||||
b.message(makeMessage("!beers = 0"))
|
||||
assert.Len(t, mb.Messages, 2)
|
||||
assert.Contains(t, mb.Messages[1], "reversal of fortune")
|
||||
it, err := counter.GetUserItem(mb.DB(), "tester", itemName)
|
||||
|
@ -101,9 +91,9 @@ func TestEqZero(t *testing.T) {
|
|||
|
||||
func TestBeersPlusEq(t *testing.T) {
|
||||
b, mb := makeBeersPlugin(t)
|
||||
testMessage(b, "beers += 5")
|
||||
b.message(makeMessage("beers += 5"))
|
||||
assert.Len(t, mb.Messages, 1)
|
||||
testMessage(b, "beers += 5")
|
||||
b.message(makeMessage("beers += 5"))
|
||||
assert.Len(t, mb.Messages, 2)
|
||||
it, err := counter.GetUserItem(mb.DB(), "tester", itemName)
|
||||
assert.Nil(t, err)
|
||||
|
@ -112,11 +102,11 @@ func TestBeersPlusEq(t *testing.T) {
|
|||
|
||||
func TestPuke(t *testing.T) {
|
||||
b, mb := makeBeersPlugin(t)
|
||||
testMessage(b, "beers += 5")
|
||||
b.message(makeMessage("beers += 5"))
|
||||
it, err := counter.GetUserItem(mb.DB(), "tester", itemName)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 5, it.Count)
|
||||
testMessage(b, "puke")
|
||||
b.message(makeMessage("puke"))
|
||||
it, err = counter.GetUserItem(mb.DB(), "tester", itemName)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 0, it.Count)
|
||||
|
@ -124,15 +114,13 @@ func TestPuke(t *testing.T) {
|
|||
|
||||
func TestBeersReport(t *testing.T) {
|
||||
b, mb := makeBeersPlugin(t)
|
||||
testMessage(b, "beers += 5")
|
||||
b.message(makeMessage("beers += 5"))
|
||||
it, err := counter.GetUserItem(mb.DB(), "tester", itemName)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 5, it.Count)
|
||||
testMessage(b, "beers")
|
||||
if assert.Len(t, mb.Messages, 2) {
|
||||
b.message(makeMessage("beers"))
|
||||
assert.Contains(t, mb.Messages[1], "5 beers")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHelp(t *testing.T) {
|
||||
b, mb := makeBeersPlugin(t)
|
||||
|
|
|
@ -3,27 +3,27 @@
|
|||
package dice
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
"github.com/velour/catbase/bot"
|
||||
"github.com/velour/catbase/bot/msg"
|
||||
)
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
// This is a dice plugin to serve as an example and quick copy/paste for new plugins.
|
||||
|
||||
type DicePlugin struct {
|
||||
Bot bot.Bot
|
||||
}
|
||||
|
||||
// New creates a new DicePlugin with the Plugin interface
|
||||
// NewDicePlugin creates a new DicePlugin with the Plugin interface
|
||||
func New(b bot.Bot) *DicePlugin {
|
||||
dp := &DicePlugin{
|
||||
Bot: b,
|
||||
}
|
||||
b.RegisterRegexCmd(dp, bot.Message, rollRegex, dp.rollCmd)
|
||||
b.Register(dp, bot.Message, dp.message)
|
||||
b.Register(dp, bot.Help, dp.help)
|
||||
return dp
|
||||
}
|
||||
|
@ -32,18 +32,28 @@ func rollDie(sides int) int {
|
|||
return rand.Intn(sides) + 1
|
||||
}
|
||||
|
||||
var rollRegex = regexp.MustCompile(`^(?P<number>\d+)d(?P<sides>\d+)$`)
|
||||
// Message responds to the bot hook on recieving messages.
|
||||
// This function returns true if the plugin responds in a meaningful way to the users message.
|
||||
// Otherwise, the function returns false and the bot continues execution of other plugins.
|
||||
func (p *DicePlugin) message(c bot.Connector, kind bot.Kind, message msg.Message, args ...interface{}) bool {
|
||||
if !message.Command {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *DicePlugin) rollCmd(r bot.Request) bool {
|
||||
nDice, _ := strconv.Atoi(r.Values["number"])
|
||||
sides, _ := strconv.Atoi(r.Values["sides"])
|
||||
channel := message.Channel
|
||||
nDice := 0
|
||||
sides := 0
|
||||
|
||||
if n, err := fmt.Sscanf(message.Body, "%dd%d", &nDice, &sides); n != 2 || err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if sides < 2 || nDice < 1 || nDice > 20 {
|
||||
p.Bot.Send(r.Conn, bot.Message, r.Msg.Channel, "You're a dick.")
|
||||
p.Bot.Send(c, bot.Message, channel, "You're a dick.")
|
||||
return true
|
||||
}
|
||||
|
||||
rolls := fmt.Sprintf("%s, you rolled: ", r.Msg.User.Name)
|
||||
rolls := fmt.Sprintf("%s, you rolled: ", message.User.Name)
|
||||
|
||||
for i := 0; i < nDice; i++ {
|
||||
rolls = fmt.Sprintf("%s %d", rolls, rollDie(sides))
|
||||
|
@ -54,8 +64,9 @@ func (p *DicePlugin) rollCmd(r bot.Request) bool {
|
|||
}
|
||||
}
|
||||
|
||||
p.Bot.Send(r.Conn, bot.Message, r.Msg.Channel, rolls)
|
||||
p.Bot.Send(c, bot.Message, channel, rolls)
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
// Help responds to help requests. Every plugin must implement a help function.
|
||||
|
|
|
@ -3,33 +3,26 @@
|
|||
package dice
|
||||
|
||||
import (
|
||||
"github.com/velour/catbase/plugins/cli"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/velour/catbase/plugins/cli"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/velour/catbase/bot"
|
||||
"github.com/velour/catbase/bot/msg"
|
||||
"github.com/velour/catbase/bot/user"
|
||||
)
|
||||
|
||||
func makeMessage(payload string) bot.Request {
|
||||
func makeMessage(payload string) (bot.Connector, bot.Kind, msg.Message) {
|
||||
isCmd := strings.HasPrefix(payload, "!")
|
||||
if isCmd {
|
||||
payload = payload[1:]
|
||||
}
|
||||
values := bot.ParseValues(rollRegex, payload)
|
||||
return bot.Request{
|
||||
Conn: &cli.CliPlugin{},
|
||||
Kind: bot.Message,
|
||||
Values: values,
|
||||
Msg: msg.Message{
|
||||
return &cli.CliPlugin{}, bot.Message, msg.Message{
|
||||
User: &user.User{Name: "tester"},
|
||||
Channel: "test",
|
||||
Body: payload,
|
||||
Command: isCmd,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +30,7 @@ func TestDie(t *testing.T) {
|
|||
mb := bot.NewMockBot()
|
||||
c := New(mb)
|
||||
assert.NotNil(t, c)
|
||||
res := c.rollCmd(makeMessage("1d6"))
|
||||
res := c.message(makeMessage("!1d6"))
|
||||
assert.Len(t, mb.Messages, 1)
|
||||
assert.True(t, res)
|
||||
assert.Contains(t, mb.Messages[0], "tester, you rolled:")
|
||||
|
@ -47,17 +40,44 @@ func TestDice(t *testing.T) {
|
|||
mb := bot.NewMockBot()
|
||||
c := New(mb)
|
||||
assert.NotNil(t, c)
|
||||
res := c.rollCmd(makeMessage("5d6"))
|
||||
res := c.message(makeMessage("!5d6"))
|
||||
assert.Len(t, mb.Messages, 1)
|
||||
assert.True(t, res)
|
||||
assert.Contains(t, mb.Messages[0], "tester, you rolled:")
|
||||
}
|
||||
|
||||
func TestNotCommand(t *testing.T) {
|
||||
mb := bot.NewMockBot()
|
||||
c := New(mb)
|
||||
assert.NotNil(t, c)
|
||||
res := c.message(makeMessage("1d6"))
|
||||
assert.False(t, res)
|
||||
assert.Len(t, mb.Messages, 0)
|
||||
}
|
||||
|
||||
func TestBadDice(t *testing.T) {
|
||||
mb := bot.NewMockBot()
|
||||
c := New(mb)
|
||||
assert.NotNil(t, c)
|
||||
res := c.message(makeMessage("!aued6"))
|
||||
assert.False(t, res)
|
||||
assert.Len(t, mb.Messages, 0)
|
||||
}
|
||||
|
||||
func TestBadSides(t *testing.T) {
|
||||
mb := bot.NewMockBot()
|
||||
c := New(mb)
|
||||
assert.NotNil(t, c)
|
||||
res := c.message(makeMessage("!1daoeu"))
|
||||
assert.False(t, res)
|
||||
assert.Len(t, mb.Messages, 0)
|
||||
}
|
||||
|
||||
func TestLotsOfDice(t *testing.T) {
|
||||
mb := bot.NewMockBot()
|
||||
c := New(mb)
|
||||
assert.NotNil(t, c)
|
||||
res := c.rollCmd(makeMessage("100d100"))
|
||||
res := c.message(makeMessage("!100d100"))
|
||||
assert.True(t, res)
|
||||
assert.Len(t, mb.Messages, 1)
|
||||
assert.Contains(t, mb.Messages[0], "You're a dick.")
|
||||
|
|
Loading…
Reference in New Issue