Initial version of factoids seems to work. Probably some bugs to work out. Added

some $vars.
This commit is contained in:
Chris Sexton 2012-08-26 15:14:09 -04:00
parent 94063c3967
commit 6f3c817e7f
2 changed files with 26 additions and 2 deletions

View File

@ -2,7 +2,10 @@ package bot
import ( import (
"fmt" "fmt"
"math/rand"
"strconv"
"strings" "strings"
"time"
) )
import irc "github.com/fluffle/goirc/client" import irc "github.com/fluffle/goirc/client"
@ -140,13 +143,33 @@ func (b *Bot) MsgRecieved(conn *irc.Conn, line *irc.Line) {
// Take an input string and mutate it based on $vars in the string // Take an input string and mutate it based on $vars in the string
func (b *Bot) Filter(message Message, input string) string { func (b *Bot) Filter(message Message, input string) string {
rand.Seed(time.Now().Unix())
if strings.Contains(input, "$NICK") { if strings.Contains(input, "$NICK") {
nick := strings.ToUpper(message.User.Name) nick := strings.ToUpper(message.User.Name)
input = strings.Replace(input, "$NICK", nick, -1) input = strings.Replace(input, "$NICK", nick, -1)
} else if strings.Contains(input, "$nick") { }
if strings.Contains(input, "$nick") {
nick := message.User.Name nick := message.User.Name
input = strings.Replace(input, "$nick", nick, -1) input = strings.Replace(input, "$nick", nick, -1)
} }
if strings.Contains(input, "$someone") {
someone := b.Users[rand.Intn(len(b.Users))].Name
input = strings.Replace(input, "$someone", someone, -1)
}
for strings.Contains(input, "$digit") {
num := strconv.Itoa(rand.Intn(9))
input = strings.Replace(input, "$digit", num, 1)
}
for strings.Contains(input, "$nonzero") {
num := strconv.Itoa(rand.Intn(8) + 1)
input = strings.Replace(input, "$nonzero", num, 1)
}
return input return input
} }

View File

@ -46,8 +46,9 @@ func main() {
b.AddHandler("talker", plugins.NewTalkerPlugin(b)) b.AddHandler("talker", plugins.NewTalkerPlugin(b))
b.AddHandler("beers", plugins.NewBeersPlugin(b)) b.AddHandler("beers", plugins.NewBeersPlugin(b))
b.AddHandler("remember", plugins.NewRememberPlugin(b)) b.AddHandler("remember", plugins.NewRememberPlugin(b))
b.AddHandler("factoid", plugins.NewFactoidPlugin(b))
b.AddHandler("skeleton", plugins.NewSkeletonPlugin(b)) b.AddHandler("skeleton", plugins.NewSkeletonPlugin(b))
// catches anything left, will always return true
b.AddHandler("factoid", plugins.NewFactoidPlugin(b))
c.AddHandler("ACTION", func(conn *irc.Conn, line *irc.Line) { c.AddHandler("ACTION", func(conn *irc.Conn, line *irc.Line) {
b.MsgRecieved(conn, line) b.MsgRecieved(conn, line)