Dictionaries for "jan" are now configurable.
parent
68d23ad4f9
commit
421c9394a7
|
@ -0,0 +1 @@
|
|||
object
|
|
@ -0,0 +1 @@
|
|||
predicate
|
|
@ -9,5 +9,7 @@
|
|||
"LinkTitleDelimiter":" | ",
|
||||
"SecuredChannels":["#securechan-1","#securechan-2"],
|
||||
"NotSeenMessage":"nope, never",
|
||||
"DictionaryObjects":".dicts/objects",
|
||||
"DictionaryVerbs":".dicts/verbs",
|
||||
"Nick":"gorepost"
|
||||
}
|
||||
|
|
16
bot/jan.go
16
bot/jan.go
|
@ -8,13 +8,16 @@ import (
|
|||
"log"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
cfg "github.com/arachnist/gorepost/config"
|
||||
"github.com/arachnist/gorepost/irc"
|
||||
)
|
||||
|
||||
var objects []string
|
||||
var predicates []string
|
||||
var janLock sync.Mutex
|
||||
|
||||
func jan(output func(irc.Message), msg irc.Message) {
|
||||
args := strings.Split(msg.Trailing, " ")
|
||||
|
@ -42,18 +45,25 @@ func jan(output func(irc.Message), msg irc.Message) {
|
|||
output(reply(msg, str))
|
||||
}
|
||||
|
||||
func init() {
|
||||
func lazyJanInit() {
|
||||
defer janLock.Unlock()
|
||||
var err error
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
objects, err = readLines("/home/repost/rzeczowniki")
|
||||
objects, err = readLines(cfg.LookupString(nil, "DictionaryObjects"))
|
||||
if err != nil {
|
||||
log.Println("failed to read objects", err)
|
||||
return
|
||||
}
|
||||
predicates, err = readLines("/home/repost/czasowniki")
|
||||
predicates, err = readLines(cfg.LookupString(nil, "DictionaryVerbs"))
|
||||
if err != nil {
|
||||
log.Println("failed to read predicates", err)
|
||||
return
|
||||
}
|
||||
addCallback("PRIVMSG", "jan", jan)
|
||||
}
|
||||
|
||||
func init() {
|
||||
janLock.Lock()
|
||||
log.Println("Defering \"jan\" initialization")
|
||||
go lazyJanInit()
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue