58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
// vi:ts=4:sts=4:sw=4:noet:tw=72
|
|
//
|
|
// flokatirc coffee module
|
|
//
|
|
// Copyright (c) 2016 Daniel Aberger <da@ixab.de>
|
|
|
|
package modules
|
|
|
|
import (
|
|
"log"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/sorcix/irc"
|
|
)
|
|
|
|
func init() {
|
|
MsgHandlers["coffee"] = coffeeHandleMessage
|
|
log.Println("Initializing coffee module")
|
|
}
|
|
|
|
func coffeeHandleMessage(m *irc.Message) {
|
|
tok := strings.Split(strings.Trim(m.Trailing, " "), " ")
|
|
if len(tok) < 1 {
|
|
return
|
|
}
|
|
switch strings.ToLower(tok[0]) {
|
|
case "!kaffee":
|
|
switch len(tok) {
|
|
case 1:
|
|
go coffeeMake(nil)
|
|
default:
|
|
go coffeeMake(tok[1:])
|
|
}
|
|
default:
|
|
}
|
|
}
|
|
|
|
func coffeeMake(rec []string) {
|
|
SayCh <- "*\nsetzt Kaffee auf."
|
|
time.Sleep(30 * time.Second)
|
|
SayCh <- "*\nstellt eine frische Kanne Kaffee in den Raum."
|
|
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 "
|
|
}
|
|
}
|
|
SayCh <- "*\ngibt " + users + " einen frischen, richtig schwarzen, richtig leckeren Kaffee."
|
|
}
|
|
time.Sleep(10 * time.Second)
|
|
SayCh <- "*\nProst! (c)"
|
|
}
|