Dictionaries for "jan" are now configurable.

configurable-file-paths
Robert Gerus 2015-12-09 08:47:18 +01:00
parent 68d23ad4f9
commit 421c9394a7
5 changed files with 77 additions and 3 deletions

1
bot/.dicts/objects Normal file
View File

@ -0,0 +1 @@
object

1
bot/.dicts/verbs Normal file
View File

@ -0,0 +1 @@
predicate

View File

@ -9,5 +9,7 @@
"LinkTitleDelimiter":" | ", "LinkTitleDelimiter":" | ",
"SecuredChannels":["#securechan-1","#securechan-2"], "SecuredChannels":["#securechan-1","#securechan-2"],
"NotSeenMessage":"nope, never", "NotSeenMessage":"nope, never",
"DictionaryObjects":".dicts/objects",
"DictionaryVerbs":".dicts/verbs",
"Nick":"gorepost" "Nick":"gorepost"
} }

View File

@ -8,13 +8,16 @@ import (
"log" "log"
"math/rand" "math/rand"
"strings" "strings"
"sync"
"time" "time"
cfg "github.com/arachnist/gorepost/config"
"github.com/arachnist/gorepost/irc" "github.com/arachnist/gorepost/irc"
) )
var objects []string var objects []string
var predicates []string var predicates []string
var janLock sync.Mutex
func jan(output func(irc.Message), msg irc.Message) { func jan(output func(irc.Message), msg irc.Message) {
args := strings.Split(msg.Trailing, " ") args := strings.Split(msg.Trailing, " ")
@ -42,18 +45,25 @@ func jan(output func(irc.Message), msg irc.Message) {
output(reply(msg, str)) output(reply(msg, str))
} }
func init() { func lazyJanInit() {
defer janLock.Unlock()
var err error var err error
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
objects, err = readLines("/home/repost/rzeczowniki") objects, err = readLines(cfg.LookupString(nil, "DictionaryObjects"))
if err != nil { if err != nil {
log.Println("failed to read objects", err) log.Println("failed to read objects", err)
return return
} }
predicates, err = readLines("/home/repost/czasowniki") predicates, err = readLines(cfg.LookupString(nil, "DictionaryVerbs"))
if err != nil { if err != nil {
log.Println("failed to read predicates", err) log.Println("failed to read predicates", err)
return return
} }
addCallback("PRIVMSG", "jan", jan) addCallback("PRIVMSG", "jan", jan)
} }
func init() {
janLock.Lock()
log.Println("Defering \"jan\" initialization")
go lazyJanInit()
}

View File

@ -257,6 +257,66 @@ var eventTests = []struct {
}, },
}, },
}, },
{
desc: "jan without args",
in: irc.Message{
Command: "PRIVMSG",
Trailing: ":jan",
Params: []string{"#testchan-1"},
Prefix: &irc.Prefix{
Name: "idontexist",
User: "test",
Host: "framework",
},
},
expectedOut: []irc.Message{
{
Command: "PRIVMSG",
Params: []string{"#testchan-1"},
Trailing: "Jan Paweł II predicate małe object",
},
},
},
{
desc: "jan predicate",
in: irc.Message{
Command: "PRIVMSG",
Trailing: ":jan predicate-ł",
Params: []string{"#testchan-1"},
Prefix: &irc.Prefix{
Name: "idontexist",
User: "test",
Host: "framework",
},
},
expectedOut: []irc.Message{
{
Command: "PRIVMSG",
Params: []string{"#testchan-1"},
Trailing: "Jan Paweł II predicate-ł małe object",
},
},
},
{
desc: "jan object",
in: irc.Message{
Command: "PRIVMSG",
Trailing: ":jan specified-object",
Params: []string{"#testchan-1"},
Prefix: &irc.Prefix{
Name: "idontexist",
User: "test",
Host: "framework",
},
},
expectedOut: []irc.Message{
{
Command: "PRIVMSG",
Params: []string{"#testchan-1"},
Trailing: "Jan Paweł II predicate małe specified-object",
},
},
},
} }
func TestPlugins(t *testing.T) { func TestPlugins(t *testing.T) {