2016-02-15 23:17:42 +00:00
|
|
|
// vi:ts=4:sts=4:sw=4:noet:tw=72
|
|
|
|
|
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2016-03-19 22:49:41 +00:00
|
|
|
MsgFuncs["fuzzytime"] = fuzzytimeHandleMessage
|
2016-02-15 23:17:42 +00:00
|
|
|
}
|
|
|
|
|
2017-06-28 21:28:39 +00:00
|
|
|
func fuzzytimeHandleMessage(m *Message) {
|
|
|
|
tok := strings.Split(m.Text, " ")
|
2016-02-15 23:17:42 +00:00
|
|
|
if len(tok) < 1 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
switch tok[0] {
|
|
|
|
case "!time":
|
2017-06-28 21:28:39 +00:00
|
|
|
fuzzytimeShow(m.Channel)
|
2016-02-15 23:17:42 +00:00
|
|
|
//case "!q":
|
|
|
|
// show()
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-28 21:28:39 +00:00
|
|
|
func fuzzytimeShow(channel string) {
|
2016-02-15 23:17:42 +00:00
|
|
|
t := time.Now()
|
|
|
|
h := t.Hour()
|
|
|
|
tzcorrect := 1
|
|
|
|
h = h + tzcorrect // XXX: This should not be hardcoded
|
|
|
|
m := t.Minute()
|
|
|
|
s := "Es ist "
|
|
|
|
switch {
|
|
|
|
case m < 3:
|
|
|
|
s += fmt.Sprintf("%s Uhr\n", fuzzytimeSayHour(h))
|
|
|
|
case m < 8:
|
|
|
|
s += fmt.Sprintf("fünf nach %s\n", fuzzytimeSayHour(h))
|
|
|
|
case m < 13:
|
|
|
|
s += fmt.Sprintf("zehn nach %s\n", fuzzytimeSayHour(h))
|
|
|
|
case m < 18:
|
|
|
|
s += fmt.Sprintf("viertel nach %s\n", fuzzytimeSayHour(h))
|
|
|
|
case m < 23:
|
|
|
|
s += fmt.Sprintf("zwanzig nach %s\n", fuzzytimeSayHour(h))
|
|
|
|
case m < 28:
|
|
|
|
s += fmt.Sprintf("fünf vor halb %s\n", fuzzytimeSayHour(h+1))
|
|
|
|
case m < 33:
|
|
|
|
s += fmt.Sprintf("halb %s\n", fuzzytimeSayHour(h+1))
|
|
|
|
case m < 38:
|
|
|
|
s += fmt.Sprintf("fünf nach halb %s\n", fuzzytimeSayHour(h+1))
|
|
|
|
case m < 43:
|
|
|
|
s += fmt.Sprintf("zehn nach halb %s\n", fuzzytimeSayHour(h+1))
|
|
|
|
case m < 48:
|
|
|
|
s += fmt.Sprintf("viertel vor %s\n", fuzzytimeSayHour(h+1))
|
|
|
|
case m < 53:
|
|
|
|
s += fmt.Sprintf("zehn vor %s\n", fuzzytimeSayHour(h+1))
|
|
|
|
case m < 58:
|
|
|
|
s += fmt.Sprintf("fünf vor %s\n", fuzzytimeSayHour(h+1))
|
|
|
|
default:
|
|
|
|
s += fmt.Sprintf("%s Uhr\n", fuzzytimeSayHour(h+1))
|
|
|
|
}
|
2017-06-28 21:28:39 +00:00
|
|
|
SayCh <- fmt.Sprintf("%s\n%s", channel, s)
|
2016-02-15 23:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func fuzzytimeSayHour(h int) string {
|
|
|
|
words := [...]string{"zwölf", "eins", "zwei", "drei", "vier", "fünf", "sechs", "sieben", "acht", "neun", "zehn", "elf"}
|
|
|
|
for {
|
|
|
|
if h > 11 {
|
|
|
|
h = h - 12
|
|
|
|
} else {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return words[h]
|
|
|
|
}
|