-
Notifications
You must be signed in to change notification settings - Fork 2
/
beertime.go
40 lines (34 loc) · 902 Bytes
/
beertime.go
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
34
35
36
37
38
39
40
package plugin
/*
usage: !beertime
*/
import (
"fmt"
"github.com/dysfn/gerri/cmd"
"github.com/dysfn/gerri/data"
"math"
"strings"
"time"
)
func timeDelta(weekday string, hour int, minute int) (string, error) {
now := time.Now()
wd := now.Weekday().String()
if wd == weekday {
y, m, d := now.Date()
location := now.Location()
beertime := time.Date(y, m, d, hour, minute, 0, 0, location)
diff := beertime.Sub(now)
if diff.Seconds() > 0 {
return fmt.Sprintf("less than %d minute(s) to go...", int(math.Ceil(diff.Minutes()))), nil
}
return "it's beertime!", nil
}
return fmt.Sprintf("it's only %s...", strings.ToLower(wd)), nil
}
func ReplyBeertime(pm data.Privmsg, config *data.Config) (string, error) {
td, err := timeDelta(config.Beertime.Day, config.Beertime.Hour, config.Beertime.Minute)
if err != nil {
return "", err
}
return cmd.Privmsg(pm.Target, td), nil
}