Add some personality by responding to thanks/negative remarks/why
This commit is contained in:
parent
dfb56be55f
commit
463cb54488
|
@ -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"
|
||||
|
|
|
@ -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))
|
||||
}
|
Loading…
Reference in New Issue