Dictionary for "papież" is now configurable.
parent
3d21ac9c7b
commit
dbe204ba5c
|
@ -0,0 +1 @@
|
|||
adjective
|
|
@ -11,5 +11,6 @@
|
|||
"NotSeenMessage":"nope, never",
|
||||
"DictionaryObjects":".dicts/objects",
|
||||
"DictionaryVerbs":".dicts/verbs",
|
||||
"DictionaryAdjectives":".dicts/adjectives",
|
||||
"Nick":"gorepost"
|
||||
}
|
||||
|
|
|
@ -8,12 +8,15 @@ import (
|
|||
"log"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
cfg "github.com/arachnist/gorepost/config"
|
||||
"github.com/arachnist/gorepost/irc"
|
||||
)
|
||||
|
||||
var adverbs []string
|
||||
var adjectives []string
|
||||
var papiezLock sync.RWMutex
|
||||
|
||||
func papiez(output func(irc.Message), msg irc.Message) {
|
||||
args := strings.Split(msg.Trailing, " ")
|
||||
|
@ -21,18 +24,28 @@ func papiez(output func(irc.Message), msg irc.Message) {
|
|||
return
|
||||
}
|
||||
|
||||
choice := "Papież " + adverbs[rand.Intn(len(adverbs))]
|
||||
papiezLock.RLock()
|
||||
defer papiezLock.RUnlock()
|
||||
|
||||
choice := "Papież " + adjectives[rand.Intn(len(adjectives))]
|
||||
|
||||
output(reply(msg, choice))
|
||||
}
|
||||
|
||||
func init() {
|
||||
func lazyPapiezInit() {
|
||||
defer papiezLock.Unlock()
|
||||
var err error
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
adverbs, err = readLines("/home/repost/przymiotniki")
|
||||
adjectives, err = readLines(cfg.LookupString(nil, "DictionaryAdjectives"))
|
||||
if err != nil {
|
||||
log.Println("failed to read adverbs", err)
|
||||
log.Println("failed to read adjectives", err)
|
||||
return
|
||||
}
|
||||
addCallback("PRIVMSG", "papiez", papiez)
|
||||
}
|
||||
|
||||
func init() {
|
||||
papiezLock.Lock()
|
||||
log.Println("Defering \"papiez\" initialization")
|
||||
go lazyPapiezInit()
|
||||
}
|
||||
|
|
|
@ -257,6 +257,26 @@ var eventTests = []struct {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "papież",
|
||||
in: irc.Message{
|
||||
Command: "PRIVMSG",
|
||||
Trailing: ":papież",
|
||||
Params: []string{"#testchan-1"},
|
||||
Prefix: &irc.Prefix{
|
||||
Name: "idontexist",
|
||||
User: "test",
|
||||
Host: "framework",
|
||||
},
|
||||
},
|
||||
expectedOut: []irc.Message{
|
||||
{
|
||||
Command: "PRIVMSG",
|
||||
Params: []string{"#testchan-1"},
|
||||
Trailing: "Papież adjective",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "jan without args",
|
||||
in: irc.Message{
|
||||
|
|
Loading…
Reference in New Issue