Fix jan and papiez plugins.

Yay, more locks. I wonder if there's a better way…
master
Robert Gerus 2015-12-12 13:13:19 +01:00
parent 54728173b2
commit 2b86f24cec
4 changed files with 13 additions and 6 deletions

View File

@ -2,10 +2,17 @@ package bot
import (
"github.com/arachnist/gorepost/config"
"sync"
)
var cfg *config.Config
var cfgLock sync.Mutex
func Initialize(config *config.Config) {
cfg = config
cfgLock.Unlock()
}
func init() {
cfgLock.Lock()
}

View File

@ -1,5 +1,3 @@
// +build configfix
//
// Copyright 2015 Robert S. Gerus. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
@ -52,6 +50,8 @@ func jan(output func(irc.Message), msg irc.Message) {
func lazyJanInit() {
defer janLock.Unlock()
cfgLock.Lock()
defer cfgLock.Unlock()
var err error
rand.Seed(time.Now().UnixNano())
objects, err = readLines(cfg.LookupString(nil, "DictionaryObjects"))

View File

@ -1,5 +1,3 @@
// +build configfix
//
// Copyright 2015 Robert S. Gerus. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
@ -35,6 +33,8 @@ func papiez(output func(irc.Message), msg irc.Message) {
func lazyPapiezInit() {
defer papiezLock.Unlock()
cfgLock.Lock()
defer cfgLock.Unlock()
var err error
rand.Seed(time.Now().UnixNano())
adjectives, err = readLines(cfg.LookupString(nil, "DictionaryAdjectives"))

View File

@ -257,7 +257,7 @@ var eventTests = []struct {
},
},
},
/* {
{
desc: "papież",
in: irc.Message{
Command: "PRIVMSG",
@ -336,7 +336,7 @@ var eventTests = []struct {
Trailing: "Jan Paweł II predicate małe specified-object",
},
},
}, */
},
{
desc: "roll multiple",
in: irc.Message{