mirror of https://github.com/velour/catbase.git
sisyphus: config-ize timing
This commit is contained in:
parent
827879b72d
commit
df956513c2
|
@ -103,6 +103,10 @@ type Config struct {
|
|||
Inventory struct {
|
||||
Max int
|
||||
}
|
||||
Sisyphus struct {
|
||||
MinDecrement int
|
||||
MinPush int
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -29,7 +29,6 @@ type game struct {
|
|||
who string
|
||||
start time.Time
|
||||
size int
|
||||
hardness int
|
||||
current int
|
||||
nextPush time.Time
|
||||
nextDec time.Time
|
||||
|
@ -46,7 +45,6 @@ func NewRandomGame(bot bot.Bot, channel, who string) *game {
|
|||
who: who,
|
||||
start: time.Now(),
|
||||
size: size,
|
||||
hardness: rand.Intn(9) + 1,
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue