summaryrefslogtreecommitdiffstats
path: root/bot/papiez.go
diff options
context:
space:
mode:
Diffstat (limited to 'bot/papiez.go')
-rw-r--r--bot/papiez.go23
1 files changed, 18 insertions, 5 deletions
diff --git a/bot/papiez.go b/bot/papiez.go
index 1f028b8..ca573f0 100644
--- a/bot/papiez.go
+++ b/bot/papiez.go
@@ -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()
+}