forked from an/flokati
85 lines
1.6 KiB
Go
85 lines
1.6 KiB
Go
// vi:ts=4:sts=4:sw=4:noet:tw=72
|
|
|
|
package sc
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/sorcix/irc"
|
|
)
|
|
|
|
var sayCh chan string
|
|
|
|
func Init(ch chan string) {
|
|
log.Println("Initializing saytime module")
|
|
sayCh = ch
|
|
}
|
|
|
|
func HandleMessage(m *irc.Message) {
|
|
tok := strings.Split(m.Trailing, " ")
|
|
if len(tok) < 1 {
|
|
return
|
|
}
|
|
switch tok[0] {
|
|
case "!time":
|
|
show()
|
|
//case "!q":
|
|
// show()
|
|
default:
|
|
}
|
|
}
|
|
|
|
func show() {
|
|
t := time.Now()
|
|
h := t.Hour()
|
|
tzcorrect := 1
|
|
h = h + tzcorrect
|
|
m := t.Minute()
|
|
s := "Es ist "
|
|
switch {
|
|
case m < 3:
|
|
s += fmt.Sprintf("%s Uhr\n", sayhour(h))
|
|
case m < 8:
|
|
s += fmt.Sprintf("fünf nach %s\n", sayhour(h))
|
|
case m < 13:
|
|
s += fmt.Sprintf("zehn nach %s\n", sayhour(h))
|
|
case m < 18:
|
|
s += fmt.Sprintf("viertel nach %s\n", sayhour(h))
|
|
case m < 23:
|
|
s += fmt.Sprintf("zwanzig nach %s\n", sayhour(h))
|
|
case m < 28:
|
|
s += fmt.Sprintf("fünf vor halb %s\n", sayhour(h+1))
|
|
case m < 33:
|
|
s += fmt.Sprintf("halb %s\n", sayhour(h+1))
|
|
case m < 38:
|
|
s += fmt.Sprintf("fünf nach halb %s\n", sayhour(h+1))
|
|
case m < 43:
|
|
s += fmt.Sprintf("zehn nach halb %s\n", sayhour(h+1))
|
|
case m < 48:
|
|
s += fmt.Sprintf("viertel vor %s\n", sayhour(h+1))
|
|
case m < 53:
|
|
s += fmt.Sprintf("zehn vor %s\n", sayhour(h+1))
|
|
case m < 58:
|
|
s += fmt.Sprintf("fünf vor %s\n", sayhour(h+1))
|
|
default:
|
|
s += fmt.Sprintf("%s Uhr\n", sayhour(h+1))
|
|
}
|
|
sayCh <- fmt.Sprintf("*\n%s", s)
|
|
|
|
}
|
|
|
|
func sayhour(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]
|
|
}
|