mirror of https://github.com/velour/catbase.git
Initial version of factoids seems to work. Probably some bugs to work out. Added
some $vars.
This commit is contained in:
parent
94063c3967
commit
6f3c817e7f
|
@ -2,7 +2,10 @@ package bot
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
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
|
||||
func (b *Bot) Filter(message Message, input string) string {
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
if strings.Contains(input, "$NICK") {
|
||||
nick := strings.ToUpper(message.User.Name)
|
||||
input = strings.Replace(input, "$NICK", nick, -1)
|
||||
} else if strings.Contains(input, "$nick") {
|
||||
}
|
||||
|
||||
if strings.Contains(input, "$nick") {
|
||||
nick := message.User.Name
|
||||
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
|
||||
}
|
||||
|
||||
|
|
3
main.go
3
main.go
|
@ -46,8 +46,9 @@ func main() {
|
|||
b.AddHandler("talker", plugins.NewTalkerPlugin(b))
|
||||
b.AddHandler("beers", plugins.NewBeersPlugin(b))
|
||||
b.AddHandler("remember", plugins.NewRememberPlugin(b))
|
||||
b.AddHandler("factoid", plugins.NewFactoidPlugin(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) {
|
||||
b.MsgRecieved(conn, line)
|
||||
|
|
Loading…
Reference in New Issue