From df956513c2421e41cb2834bd4b7358dce94fc176 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Mon, 6 Nov 2017 14:32:49 -0500 Subject: [PATCH] sisyphus: config-ize timing --- config/config.go | 4 ++++ example_config.lua | 11 ++++++++++- plugins/sisyphus/sisyphus.go | 20 ++++++++++---------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/config/config.go b/config/config.go index 9f29b79..360e3be 100644 --- a/config/config.go +++ b/config/config.go @@ -103,6 +103,10 @@ type Config struct { Inventory struct { Max int } + Sisyphus struct { + MinDecrement int + MinPush int + } } func init() { diff --git a/example_config.lua b/example_config.lua index 969ac2e..58e3d74 100644 --- a/example_config.lua +++ b/example_config.lua @@ -105,5 +105,14 @@ config = { }, DBPath = "stats.db" }, - HttpAddr = "127.0.0.1:1337" + HttpAddr = "127.0.0.1:1337", + Inventory = { + Max = 5 + }, + Sisyphus = { + MinDecrement = 10, + MinPush = 1 + } +} + } \ No newline at end of file diff --git a/plugins/sisyphus/sisyphus.go b/plugins/sisyphus/sisyphus.go index 44f236f..2ba8343 100644 --- a/plugins/sisyphus/sisyphus.go +++ b/plugins/sisyphus/sisyphus.go @@ -29,7 +29,6 @@ type game struct { who string start time.Time size int - hardness int current int nextPush time.Time nextDec time.Time @@ -41,13 +40,12 @@ type game struct { func NewRandomGame(bot bot.Bot, channel, who string) *game { size := rand.Intn(9) + 2 g := game{ - channel: channel, - bot: bot, - who: who, - start: time.Now(), - size: size, - hardness: rand.Intn(9) + 1, - current: size / 2, + channel: channel, + bot: bot, + who: who, + start: time.Now(), + size: size, + current: size / 2, } g.id = bot.SendMessage(channel, g.toMessageString()) @@ -61,7 +59,8 @@ func (g *game) scheduleDecrement() { if g.timers[0] != nil { g.timers[0].Stop() } - g.nextDec = time.Now().Add(time.Duration((60 + rand.Intn(60*5))) * time.Second) + minDec := g.bot.Config().Sisyphus.MinDecrement + g.nextDec = time.Now().Add(time.Duration((60 + rand.Intn(60*minDec))) * time.Minute) go func() { t := time.NewTimer(g.nextDec.Sub(time.Now())) g.timers[0] = t @@ -76,7 +75,8 @@ func (g *game) schedulePush() { if g.timers[1] != nil { g.timers[1].Stop() } - g.nextPush = time.Now().Add(time.Duration(rand.Intn(60)+1) * time.Minute) + minPush := g.bot.Config().Sisyphus.MinPush + g.nextPush = time.Now().Add(time.Duration(rand.Intn(60)+minPush) * time.Minute) go func() { t := time.NewTimer(g.nextPush.Sub(time.Now())) g.timers[1] = t