This might be entertaining on occasion

This commit is contained in:
skkiesel 2018-06-16 17:25:33 -04:00
parent c639d460ac
commit f03fdb4d4e
3 changed files with 221 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import (
"github.com/velour/catbase/plugins/babbler"
"github.com/velour/catbase/plugins/beers"
"github.com/velour/catbase/plugins/counter"
"github.com/velour/catbase/plugins/couldashouldwoulda"
"github.com/velour/catbase/plugins/db"
"github.com/velour/catbase/plugins/dice"
"github.com/velour/catbase/plugins/emojifyme"
@ -78,6 +79,7 @@ func main() {
b.AddHandler("rpgORdie", rpgORdie.New(b))
b.AddHandler("sisyphus", sisyphus.New(b))
b.AddHandler("tell", tell.New(b))
b.AddHandler("couldashouldwoulda", couldashouldwoulda.New(b))
// catches anything left, will always return true
b.AddHandler("factoid", fact.New(b))
b.AddHandler("db", db.New(b))

View File

@ -0,0 +1,85 @@
// © 2013 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
package couldashouldawoulda
import (
"fmt"
"math/rand"
"strings"
"github.com/velour/catbase/bot"
"github.com/velour/catbase/bot/msg"
"github.com/velour/catbase/config"
)
type CSWPlugin struct {
Bot bot.Bot
Config *config.Config
}
func New(bot bot.Bot) *CSWPlugin {
return &CSWPlugin{
Bot: bot,
}
}
func (p *CSWPlugin) Message(message msg.Message) bool {
if !message.Command {
return false
}
lowercase := strings.ToLower(message.Body)
tokens := strings.Fields(lowercase)
if len(tokens) < 3 {
return false
}
could := tokens[0] == "could"
should := tokens[0] == "should"
would := tokens[0] == "would"
if could || should || would {
ors := strings.Count(lowercase, " or ")
var responses []string
if ors == 0 || could {
responses = []string{"Yes.", "No.", "Maybe.", "For fucks sake, how should I know?"}
} else if ors == 1 {
responses = []string{"The former.", "The latter.", "Obviously the former.", "Clearly the latter.", "Can't it be both?"}
} else {
responses = make([]string, ors*2)
for i := 0; i < ors; i++ {
responses[i*2] = fmt.Sprintf("I'd say option %d.", i+1)
responses[i*2+1] = "You'd be an idiot not to choose the "
if i == 0 {
responses[i*2+1] += " 1st"
} else if i == 1 {
responses[i*2+1] += " 2nd"
} else if i == 2 {
responses[i*2+1] += " 3rd"
} else {
responses[i*2+1] += fmt.Sprintf(" %dth", i+1)
}
}
}
p.Bot.SendMessage(message.Channel, responses[rand.Intn(len(responses))])
return true
}
return false
}
func (p *CSWPlugin) Help(channel string, parts []string) {}
func (p *CSWPlugin) Event(kind string, message msg.Message) bool {
return false
}
func (p *CSWPlugin) BotMessage(message msg.Message) bool {
return false
}
func (p *CSWPlugin) RegisterWeb() *string {
return nil
}

View File

@ -0,0 +1,134 @@
// © 2013 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
package couldashouldawoulda
import (
"strings"
"testing"
"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) msg.Message {
isCmd := strings.HasPrefix(payload, "!")
if isCmd {
payload = payload[1:]
}
return msg.Message{
User: &user.User{Name: "tester"},
Channel: "test",
Body: payload,
Command: isCmd,
}
}
func Test0(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
res := c.Message(makeMessage("!should I drink a beer?"))
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
possibilities := []string{"Yes.", "No.", "Maybe.", "For fucks sake, how should I know?"}
match := false
for _, possibility := range possibilities {
if strings.Contains(mb.Messages[0], possibility) {
match = true
break
}
}
assert.True(t, match)
}
func Test1(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
res := c.Message(makeMessage("!should I drink a beer or a bourbon?"))
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
possibilities := []string{"The former.", "The latter.", "Obviously the former.", "Clearly the latter.", "Can't it be both?"}
match := false
for _, possibility := range possibilities {
if strings.Contains(mb.Messages[0], possibility) {
match = true
break
}
}
assert.True(t, match)
}
func Test2(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
res := c.Message(makeMessage("!could I drink a beer or a bourbon?"))
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
possibilities := []string{"Yes.", "No.", "Maybe.", "For fucks sake, how should I know?"}
match := false
for _, possibility := range possibilities {
if strings.Contains(mb.Messages[0], possibility) {
match = true
break
}
}
assert.True(t, match)
}
func Test3(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
res := c.Message(makeMessage("!would I die if I drank too much bourbon?"))
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
possibilities := []string{"Yes.", "No.", "Maybe.", "For fucks sake, how should I know?"}
match := false
for _, possibility := range possibilities {
if strings.Contains(mb.Messages[0], possibility) {
match = true
break
}
}
assert.True(t, match)
}
func Test4(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
res := c.Message(makeMessage("!would I die or be sick if I drank all the bourbon?"))
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
possibilities := []string{"The former.", "The latter.", "Obviously the former.", "Clearly the latter.", "Can't it be both?"}
match := false
for _, possibility := range possibilities {
if strings.Contains(mb.Messages[0], possibility) {
match = true
break
}
}
assert.True(t, match)
}
func Test5(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
res := c.Message(makeMessage("!should I have another beer or bourbon or tequila?"))
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
possibilities := []string{"I'd say option", "You'd be an idiot not to choose the"}
match := false
for _, possibility := range possibilities {
if strings.Contains(mb.Messages[0], possibility) {
match = true
break
}
}
assert.True(t, match)
}