Add some personality by responding to thanks/negative remarks/why

This commit is contained in:
Zachary Seguin 2017-06-02 22:48:33 -04:00
parent dfb56be55f
commit 463cb54488
2 changed files with 67 additions and 0 deletions

View File

@ -15,6 +15,7 @@ import (
_ "git.uwaterloo.ca/csc/cscsysbot/plugins/club"
_ "git.uwaterloo.ca/csc/cscsysbot/plugins/ping"
_ "git.uwaterloo.ca/csc/cscsysbot/plugins/greetings"
_ "git.uwaterloo.ca/csc/cscsysbot/plugins/personality"
// Backgrounds tasks
_ "git.uwaterloo.ca/csc/cscsysbot/plugins/background"

View File

@ -0,0 +1,66 @@
package personality
import (
"fmt"
"math/rand"
"regexp"
"github.com/go-chat-bot/bot"
)
const (
botPattern = "(?i)cscsysbot"
thanksPattern = "(?i)(thanks?|thank you)"
negativePattern = "(?i)(you suck|u suck|you're (wrong|incorrect)|ur (wrong|incorrect)|that'?s (wrong|incorrect))"
whyPattern = "(?i)why"
)
var (
botRe = regexp.MustCompile(botPattern)
thanksRe = regexp.MustCompile(thanksPattern)
thanksResponses = []string{
"You're welcome %s",
"It's my pleasure %s",
"I'm here to serve you %s",
"No problem %s",
"Anytime %s",
}
negativeRe = regexp.MustCompile(negativePattern)
negativeResponses = []string{
"I'm sorry to dissapoint you %s",
"Sorry %s",
"I promise I'll do better next time %s",
}
whyRe = regexp.MustCompile(whyPattern)
whyResponses = []string{
"That is a good question %s",
"I don't know why %s",
"I'm unsure as well %s",
}
)
func responseTemplate(re *regexp.Regexp, responses []string) (func(*bot.PassiveCmd) (string, error)) {
return func(command *bot.PassiveCmd) (string, error) {
if botRe.MatchString(command.Raw) && re.MatchString(command.Raw) {
return fmt.Sprintf(responses[rand.Intn(len(responses))], command.User.Nick), nil
}
return "", nil
}
}
func init() {
bot.RegisterPassiveCommand(
"personality_thanks",
responseTemplate(thanksRe, thanksResponses))
bot.RegisterPassiveCommand(
"personality_negative",
responseTemplate(negativeRe, negativeResponses))
bot.RegisterPassiveCommand(
"personality_why",
responseTemplate(whyRe, whyResponses))
}