2018-06-16 21:25:33 +00:00
|
|
|
// © 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
|
|
|
|
}
|
|
|
|
|
2019-02-05 19:41:38 +00:00
|
|
|
func New(b bot.Bot) *CSWPlugin {
|
|
|
|
csw := &CSWPlugin{
|
|
|
|
Bot: b,
|
2018-06-16 21:25:33 +00:00
|
|
|
}
|
2019-02-05 19:41:38 +00:00
|
|
|
b.Register(csw, bot.Message, csw.message)
|
|
|
|
return csw
|
2018-06-16 21:25:33 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 19:41:38 +00:00
|
|
|
func (p *CSWPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
|
2018-06-16 21:25:33 +00:00
|
|
|
if !message.Command {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
lowercase := strings.ToLower(message.Body)
|
|
|
|
tokens := strings.Fields(lowercase)
|
|
|
|
|
|
|
|
if len(tokens) < 3 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
could := tokens[0] == "could"
|
2018-06-22 18:25:43 +00:00
|
|
|
should := tokens[0] == "should"
|
2018-06-16 21:25:33 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-05 15:54:13 +00:00
|
|
|
p.Bot.Send(bot.Message, message.Channel, responses[rand.Intn(len(responses))])
|
2018-06-16 21:25:33 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *CSWPlugin) RegisterWeb() *string {
|
|
|
|
return nil
|
|
|
|
}
|