-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.go
More file actions
33 lines (25 loc) · 744 Bytes
/
task.go
File metadata and controls
33 lines (25 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"time"
"github.com/lrstanley/girc"
)
var (
// updateFrequency is the number of times in a timer
// to update the user. An updateFrequency of 10 means every 10%.
// An updateFrequency of 4 means every 25%
updateFrequency = 2
)
func RunTimer(c *girc.Client, user, channel, msg string, d time.Duration) {
interval := d / time.Duration(updateFrequency)
for step := 1; step <= updateFrequency; step++ {
time.Sleep(interval)
// No need to tell us it's at 100%; that's what the next thing is
if step < updateFrequency {
c.Cmd.Messagef(user, "timebox is %d%% complete", step*(100/updateFrequency))
}
}
c.Cmd.Messagef(channel, "%s: %s", user, msg)
if channel != user {
c.Cmd.Message(user, msg)
}
}