2016-02-15 23:17:42 +00:00
|
|
|
// vi:ts=4:sts=4:sw=4:noet:tw=72
|
|
|
|
//
|
|
|
|
// flokatirc coffee module
|
|
|
|
//
|
|
|
|
// Copyright (c) 2016 Daniel Aberger <da@ixab.de>
|
|
|
|
|
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2016-03-12 12:09:25 +00:00
|
|
|
"code.dnix.de/an/xlog"
|
|
|
|
|
2016-02-15 23:17:42 +00:00
|
|
|
"github.com/sorcix/irc"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2016-02-16 06:57:14 +00:00
|
|
|
MsgHandlers["coffee"] = coffeeHandleMessage
|
2016-03-12 17:12:40 +00:00
|
|
|
xlog.Info("Coffee module initialized")
|
2016-02-15 23:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func coffeeHandleMessage(m *irc.Message) {
|
2016-02-28 09:31:20 +00:00
|
|
|
tok := strings.Split(strings.Trim(m.Trailing, " "), " ")
|
2016-02-15 23:17:42 +00:00
|
|
|
if len(tok) < 1 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
switch tok[0] {
|
|
|
|
case "!kaffee":
|
|
|
|
switch len(tok) {
|
|
|
|
case 1:
|
|
|
|
go coffeeMake(nil)
|
|
|
|
default:
|
|
|
|
go coffeeMake(tok[1:])
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func coffeeMake(rec []string) {
|
2016-02-16 06:57:14 +00:00
|
|
|
SayCh <- "*\nsetzt Kaffee auf."
|
2016-02-15 23:17:42 +00:00
|
|
|
time.Sleep(30 * time.Second)
|
2016-02-16 06:57:14 +00:00
|
|
|
SayCh <- "*\nstellt eine frische Kanne Kaffee in den Raum."
|
2016-02-15 23:17:42 +00:00
|
|
|
if rec != nil {
|
|
|
|
var users string
|
|
|
|
for i, v := range rec {
|
|
|
|
users += v
|
|
|
|
if i < len(rec)-2 {
|
|
|
|
users += ", "
|
|
|
|
} else if i == len(rec)-2 {
|
|
|
|
users += " und "
|
|
|
|
}
|
|
|
|
}
|
2016-02-16 06:57:14 +00:00
|
|
|
SayCh <- "*\ngibt " + users + " einen frischen, richtig schwarzen, richtig leckeren Kaffee."
|
2016-02-15 23:17:42 +00:00
|
|
|
}
|
|
|
|
time.Sleep(10 * time.Second)
|
2016-02-16 06:57:14 +00:00
|
|
|
SayCh <- "*\nProst! (c)"
|
2016-02-15 23:17:42 +00:00
|
|
|
}
|