randomise timer, add some comments
This commit is contained in:
parent
b2065f86a7
commit
645fb64db3
7
main.go
7
main.go
|
@ -15,6 +15,7 @@ package main
|
|||
* regexp to help parse messages.
|
||||
* sync to make things concurrency safe
|
||||
* time to sleep for some time before reducing the counter
|
||||
* rand to randomise the timer ticks
|
||||
*/
|
||||
import (
|
||||
"bufio"
|
||||
|
@ -24,6 +25,7 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
/*
|
||||
|
@ -141,7 +143,8 @@ func getCounter() int {
|
|||
func countdown(conn *net.Conn, reset chan int) {
|
||||
locked := false
|
||||
for {
|
||||
timer := time.NewTimer(time.Duration(maxTime) * time.Second) // TODO randomise a bit, longer times
|
||||
duration := rand.Intn(maxTime-minTime) + minTime
|
||||
timer := time.NewTimer(time.Duration(duration) * time.Second) // TODO randomise a bit, longer times
|
||||
select {
|
||||
case <-timer.C: // on a timer timeout
|
||||
if !locked {
|
||||
|
@ -251,7 +254,7 @@ func main() {
|
|||
sendMessage(&conn, channel, "The timer is locked! You can't press the button.")
|
||||
}
|
||||
} else if msgContent == ",reset" {
|
||||
// TODO maybe check
|
||||
// TODO maybe check some kind of auth on doing this
|
||||
reset <- 0
|
||||
sendMessage(&conn, channel, "Timer reset!")
|
||||
} else if msgContent == ",count" {
|
||||
|
|
Loading…
Reference in New Issue