func TestHelp(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) c.Help("channel", []string{}) assert.Len(t, mb.Messages, 1) }
func makePlugin(t *testing.T) (*RememberPlugin, *Factoid, *bot.MockBot) { mb := bot.NewMockBot() f := New(mb) // for DB table p := NewRemember(mb) assert.NotNil(t, p) return p, f, mb }
func makePlugin(t *testing.T) (*LeftpadPlugin, *bot.MockBot) { mb := bot.NewMockBot() counter.New(mb) p := New(mb) assert.NotNil(t, p) return p, mb }
func makeBeersPlugin(t *testing.T) (*BeersPlugin, *bot.MockBot) { mb := bot.NewMockBot() counter.New(mb) b := New(mb) assert.NotNil(t, b) return b, mb }
func TestBabblerMerge(t *testing.T) { mb := bot.NewMockBot() c := New(mb) c.config.Babbler.DefaultUsers = []string{"seabass"} assert.NotNil(t, c) seabass := makeMessage("<seabass> This is a message") seabass.User = &user.User{Name: "seabass"} res := c.Message(seabass) assert.Len(t, c.babblers, 1) assert.Len(t, mb.Messages, 0) seabass.Body = "<seabass> This is another message" res = c.Message(seabass) seabass.Body = "<seabass> This is a long message" res = c.Message(seabass) res = c.Message(makeMessage("!merge babbler seabass into seabass2")) assert.True(t, res) assert.Len(t, mb.Messages, 1) assert.Contains(t, mb.Messages[0], "mooooiggged") res = c.Message(makeMessage("!seabass2 says")) assert.True(t, res) assert.Len(t, mb.Messages, 2) assert.Contains(t, mb.Messages[1], "<seabass2> this is") assert.Contains(t, mb.Messages[1], "message") }
func TestSay(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) res := c.Message(makeMessage("say hello")) assert.Len(t, mb.Messages, 0) assert.False(t, res) }
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 TestNonJoinEvent(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) res := c.Event("SPLURT", makeMessage("hello there")) assert.Len(t, mb.Messages, 0) assert.False(t, res) }
func TestCounterOne(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) c.Message(makeMessage("test++")) assert.Len(t, mb.Messages, 1) assert.Equal(t, mb.Messages[0], "tester has 1 test.") }
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 TestReminderParse(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) res := c.Message(makeMessage("!remind testuser in unparseable don't fail this test")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "Easy cowboy, not sure I can parse that duration.") }
func TestSayCommand(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) res := c.Message(makeMessage("!say hello")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "hello") }
func TestNoSayings(t *testing.T) { mb := bot.NewMockBot() c := New(mb) c.sayings = []string{} assert.NotNil(t, c) res := c.Event("JOIN", makeMessage("hello there")) assert.Len(t, mb.Messages, 0) assert.False(t, res) }
func TestLotsOfDice(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) 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.") }
func TestDice(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) 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 TestNineChars(t *testing.T) { mb := bot.NewMockBot() c := New(mb) c.enforceNicks = true assert.NotNil(t, c) res := c.Message(makeMessage("hello there")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "OCD") }
func TestBabblerNoBabbler(t *testing.T) { mb := bot.NewMockBot() c := New(mb) c.config.Babbler.DefaultUsers = []string{"seabass"} assert.NotNil(t, c) res := c.Message(makeMessage("!seabass2 says")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "could not find babbler: seabass2") }
func TestCounterFour(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) for i := 0; i < 4; i++ { c.Message(makeMessage("test++")) } assert.Len(t, mb.Messages, 4) assert.Equal(t, mb.Messages[3], "tester has 4 test.") }
func TestBabblerNothingSaid(t *testing.T) { mb := bot.NewMockBot() c := New(mb) c.config.Babbler.DefaultUsers = []string{"seabass"} assert.NotNil(t, c) res := c.Message(makeMessage("!seabass says")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "Ze ain't said nothin") }
func TestWelcome(t *testing.T) { mb := bot.NewMockBot() c := New(mb) c.sayings = []string{"Hi"} assert.NotNil(t, c) res := c.Event("JOIN", makeMessage("hello there")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "Hi") }
func TestGoatseWithNickCommand(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) res := c.Message(makeMessage("!g****e seabass")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "g o a t s e") assert.Contains(t, mb.Messages[0], "seabass") }
func TestReminder(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) res := c.Message(makeMessage("!remind testuser in 1s don't fail this test")) time.Sleep(2 * time.Second) assert.Len(t, mb.Messages, 2) assert.True(t, res) assert.Contains(t, mb.Messages[0], "Sure tester, I'll remind testuser.") assert.Contains(t, mb.Messages[1], "Hey testuser, tester wanted you to be reminded: don't fail this test") }
func TestFriendCounterDecrement(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) for i := 0; i < 4; i++ { c.Message(makeMessage("other.test++")) assert.Equal(t, mb.Messages[i], fmt.Sprintf("other has %d test.", i+1)) } c.Message(makeMessage("other.test--")) assert.Len(t, mb.Messages, 5) assert.Equal(t, mb.Messages[4], "other has 3 test.") }
func TestClear(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) for i := 0; i < 4; i++ { c.Message(makeMessage("test++")) assert.Equal(t, mb.Messages[i], fmt.Sprintf("tester has %d test.", i+1)) } res := c.Message(makeMessage("!clear test")) assert.True(t, res) assert.Len(t, mb.Actions, 1) assert.Equal(t, mb.Actions[0], "chops a few test out of his brain") }
func makeTwitchPlugin(t *testing.T) (*TwitchPlugin, *bot.MockBot) { mb := bot.NewMockBot() c := New(mb) c.config.Twitch.Users = map[string][]string{"test": []string{"drseabass"}} assert.NotNil(t, c) c.twitchList["drseabass"] = &Twitcher{ name: "drseabass", game: "", } return c, mb }
func TestCount(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) for i := 0; i < 4; i++ { c.Message(makeMessage("test++")) assert.Equal(t, mb.Messages[i], fmt.Sprintf("tester has %d test.", i+1)) } res := c.Message(makeMessage("!count test")) assert.True(t, res) assert.Len(t, mb.Messages, 5) assert.Equal(t, mb.Messages[4], "tester has 4 test.") }
func TestBabblerBatch(t *testing.T) { mb := bot.NewMockBot() c := New(mb) c.config.Babbler.DefaultUsers = []string{"seabass"} assert.NotNil(t, c) seabass := makeMessage("batch learn for seabass This is a message! This is another message. This is not a long message? This is not a message! This is not another message. This is a long message?") res := c.Message(seabass) assert.Len(t, c.babblers, 2) assert.Len(t, mb.Messages, 1) res = c.Message(makeMessage("!seabass says")) assert.Len(t, mb.Messages, 2) assert.True(t, res) assert.Contains(t, mb.Messages[1], "this is") assert.Contains(t, mb.Messages[1], "message") }
func TestDecrementZero(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) for i := 0; i < 4; i++ { c.Message(makeMessage("test++")) assert.Equal(t, mb.Messages[i], fmt.Sprintf("tester has %d test.", i+1)) } j := 4 for i := 4; i > 0; i-- { c.Message(makeMessage("test--")) assert.Equal(t, mb.Messages[j], fmt.Sprintf("tester has %d test.", i-1)) j++ } assert.Len(t, mb.Messages, 8) assert.Equal(t, mb.Messages[7], "tester has 0 test.") }
func TestBabblerBadSeed(t *testing.T) { mb := bot.NewMockBot() c := New(mb) c.config.Babbler.DefaultUsers = []string{"seabass"} assert.NotNil(t, c) seabass := makeMessage("This is a message") seabass.User = &user.User{Name: "seabass"} res := c.Message(seabass) assert.Len(t, c.babblers, 1) seabass.Body = "This is another message" res = c.Message(seabass) seabass.Body = "This is a long message" res = c.Message(seabass) res = c.Message(makeMessage("!seabass says long message")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "try seabass says [seed-token]") }
func TestInspectMe(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) for i := 0; i < 4; i++ { c.Message(makeMessage("test++")) assert.Equal(t, mb.Messages[i], fmt.Sprintf("tester has %d test.", i+1)) } for i := 0; i < 2; i++ { c.Message(makeMessage("f***s++")) assert.Equal(t, mb.Messages[i+4], fmt.Sprintf("tester has %d f***s.", i+1)) } for i := 0; i < 20; i++ { c.Message(makeMessage("cheese++")) assert.Equal(t, mb.Messages[i+6], fmt.Sprintf("tester has %d cheese.", i+1)) } res := c.Message(makeMessage("!inspect me")) assert.True(t, res) assert.Len(t, mb.Messages, 27) assert.Equal(t, mb.Messages[26], "tester has the following counters: test: 4, f***s: 2, cheese: 20.") }