mirror of https://github.com/velour/catbase.git
Taking care of obnoxious users calling first.
This commit is contained in:
parent
ee1962b71c
commit
9b51ce79ba
|
@ -26,5 +26,8 @@
|
||||||
"Joins upset the hivemind's OCD, %s.",
|
"Joins upset the hivemind's OCD, %s.",
|
||||||
"Joins upset the hivemind's CDO, %s.",
|
"Joins upset the hivemind's CDO, %s.",
|
||||||
"%s, I WILL CUT YOU!"
|
"%s, I WILL CUT YOU!"
|
||||||
|
],
|
||||||
|
"BadMsgs": [
|
||||||
|
"I like cron."
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ type Config struct {
|
||||||
TwitterConsumerSecret string
|
TwitterConsumerSecret string
|
||||||
TwitterUserKey string
|
TwitterUserKey string
|
||||||
TwitterUserSecret string
|
TwitterUserSecret string
|
||||||
|
BadMsgs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Readconfig loads the config data out of a JSON file located in cfile
|
// Readconfig loads the config data out of a JSON file located in cfile
|
||||||
|
|
|
@ -60,10 +60,11 @@ func isToday(t time.Time) bool {
|
||||||
func (p *FirstPlugin) Message(message bot.Message) bool {
|
func (p *FirstPlugin) Message(message bot.Message) bool {
|
||||||
// This bot does not reply to anything
|
// This bot does not reply to anything
|
||||||
|
|
||||||
if p.First == nil {
|
if p.First == nil && p.allowed(message) {
|
||||||
p.recordFirst(message)
|
p.recordFirst(message)
|
||||||
} else {
|
return false
|
||||||
if isToday(p.First.Time) {
|
} else if p.First != nil {
|
||||||
|
if isToday(p.First.Time) && p.allowed(message) {
|
||||||
p.recordFirst(message)
|
p.recordFirst(message)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -74,12 +75,24 @@ func (p *FirstPlugin) Message(message bot.Message) bool {
|
||||||
msg := strings.ToLower(message.Body)
|
msg := strings.ToLower(message.Body)
|
||||||
if r.Replace(msg) == "whos on first" {
|
if r.Replace(msg) == "whos on first" {
|
||||||
p.announceFirst(message)
|
p.announceFirst(message)
|
||||||
|
log.Printf("Disallowing %s: %s from first.",
|
||||||
|
message.User.Name, message.Body)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *FirstPlugin) allowed(message bot.Message) bool {
|
||||||
|
for _, msg := range p.Bot.Config.BadMsgs {
|
||||||
|
if strings.ToLower(msg) == strings.ToLower(message.Body) {
|
||||||
|
log.Println("Disallowing first: ", message.User.Name, ":", message.Body)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (p *FirstPlugin) recordFirst(message bot.Message) {
|
func (p *FirstPlugin) recordFirst(message bot.Message) {
|
||||||
log.Println("Recording first: ", message.User.Name, ":", message.Body)
|
log.Println("Recording first: ", message.User.Name, ":", message.Body)
|
||||||
p.First = &FirstEntry{
|
p.First = &FirstEntry{
|
||||||
|
|
Loading…
Reference in New Issue