forked from an/flokati
78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
// vi:ts=4:sts=4:sw=4:noet:tw=72
|
|
|
|
package modules
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func init() {
|
|
MsgFuncs["fuzzytime"] = fuzzytimeHandleMessage
|
|
}
|
|
|
|
func fuzzytimeHandleMessage(m *Message) {
|
|
tok := strings.Split(m.Text, " ")
|
|
if len(tok) < 1 {
|
|
return
|
|
}
|
|
switch tok[0] {
|
|
case "!time":
|
|
fuzzytimeShow(m.Channel)
|
|
//case "!q":
|
|
// show()
|
|
default:
|
|
}
|
|
}
|
|
|
|
func fuzzytimeShow(channel string) {
|
|
t := time.Now()
|
|
h := t.Hour()
|
|
_, o := t.Zone()
|
|
h = h + o
|
|
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))
|
|
}
|
|
SayCh <- fmt.Sprintf("%s\n%s", channel, s)
|
|
}
|
|
|
|
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]
|
|
}
|