mirror of
https://code.dnix.de/da/flokatirc
synced 2026-07-27 08:39:45 +02:00
Rework of module system.
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
// vi:ts=4:sts=4:sw=4:noet:tw=72
|
||||
|
||||
package modules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/sorcix/irc"
|
||||
)
|
||||
|
||||
func init() {
|
||||
msgHandlers["fuzzytime"] = fuzzytimeHandleMessage
|
||||
log.Println("Initializing fuzzytime module")
|
||||
}
|
||||
|
||||
func fuzzytimeHandleMessage(m *irc.Message) {
|
||||
tok := strings.Split(m.Trailing, " ")
|
||||
if len(tok) < 1 {
|
||||
return
|
||||
}
|
||||
switch tok[0] {
|
||||
case "!time":
|
||||
fuzzytimeShow()
|
||||
//case "!q":
|
||||
// show()
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
func fuzzytimeShow() {
|
||||
log.Println("timeshow")
|
||||
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))
|
||||
}
|
||||
log.Println("saying now:", s)
|
||||
sayCh <- fmt.Sprintf("*\n%s", 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]
|
||||
}
|
||||
Reference in New Issue
Block a user