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.
|
* regexp to help parse messages.
|
||||||
* sync to make things concurrency safe
|
* sync to make things concurrency safe
|
||||||
* time to sleep for some time before reducing the counter
|
* time to sleep for some time before reducing the counter
|
||||||
|
* rand to randomise the timer ticks
|
||||||
*/
|
*/
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
@ -24,6 +25,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
"math/rand"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -141,7 +143,8 @@ func getCounter() int {
|
||||||
func countdown(conn *net.Conn, reset chan int) {
|
func countdown(conn *net.Conn, reset chan int) {
|
||||||
locked := false
|
locked := false
|
||||||
for {
|
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 {
|
select {
|
||||||
case <-timer.C: // on a timer timeout
|
case <-timer.C: // on a timer timeout
|
||||||
if !locked {
|
if !locked {
|
||||||
|
@ -251,7 +254,7 @@ func main() {
|
||||||
sendMessage(&conn, channel, "The timer is locked! You can't press the button.")
|
sendMessage(&conn, channel, "The timer is locked! You can't press the button.")
|
||||||
}
|
}
|
||||||
} else if msgContent == ",reset" {
|
} else if msgContent == ",reset" {
|
||||||
// TODO maybe check
|
// TODO maybe check some kind of auth on doing this
|
||||||
reset <- 0
|
reset <- 0
|
||||||
sendMessage(&conn, channel, "Timer reset!")
|
sendMessage(&conn, channel, "Timer reset!")
|
||||||
} else if msgContent == ",count" {
|
} else if msgContent == ",count" {
|
||||||
|
|
Loading…
Reference in New Issue