Improve talker to disable nick length constraints

This commit is contained in:
Chris Sexton 2016-01-15 09:43:31 -05:00
parent 003c0fb8eb
commit 25f32918b1
2 changed files with 9 additions and 4 deletions

View File

@ -28,6 +28,7 @@ type Config struct {
UntappdToken string UntappdToken string
UntappdFreq int UntappdFreq int
UntappdChannels []string UntappdChannels []string
EnforceNicks bool
WelcomeMsgs []string WelcomeMsgs []string
TwitterConsumerKey string TwitterConsumerKey string
TwitterConsumerSecret string TwitterConsumerSecret string

View File

@ -4,10 +4,11 @@ package plugins
import ( import (
"fmt" "fmt"
"github.com/chrissexton/alepale/bot"
"math/rand" "math/rand"
"strings" "strings"
"time" "time"
"github.com/chrissexton/alepale/bot"
) )
var goatse []string = []string{ var goatse []string = []string{
@ -39,12 +40,14 @@ var goatse []string = []string{
} }
type TalkerPlugin struct { type TalkerPlugin struct {
Bot *bot.Bot Bot *bot.Bot
enforceNicks bool
} }
func NewTalkerPlugin(bot *bot.Bot) *TalkerPlugin { func NewTalkerPlugin(bot *bot.Bot) *TalkerPlugin {
return &TalkerPlugin{ return &TalkerPlugin{
Bot: bot, Bot: bot,
enforceNicks: bot.Config.EnforceNicks,
} }
} }
@ -53,6 +56,7 @@ func (p *TalkerPlugin) Message(message bot.Message) bool {
body := message.Body body := message.Body
lowermessage := strings.ToLower(body) lowermessage := strings.ToLower(body)
// TODO: This ought to be space split afterwards to remove any punctuation
if strings.HasPrefix(lowermessage, "say") { if strings.HasPrefix(lowermessage, "say") {
msg := strings.TrimSpace(body[3:]) msg := strings.TrimSpace(body[3:])
p.Bot.SendMessage(channel, msg) p.Bot.SendMessage(channel, msg)
@ -73,7 +77,7 @@ func (p *TalkerPlugin) Message(message bot.Message) bool {
return true return true
} }
if len(message.User.Name) != 9 { if p.enforceNicks && len(message.User.Name) != 9 {
msg := fmt.Sprintf("Hey %s, we really like to have 9 character nicks because we're crazy OCD and stuff.", msg := fmt.Sprintf("Hey %s, we really like to have 9 character nicks because we're crazy OCD and stuff.",
message.User.Name) message.User.Name)
p.Bot.SendMessage(message.Channel, msg) p.Bot.SendMessage(message.Channel, msg)