From 46e3df72e16a7861cc0939ed26b4b9d3e47fe2fa Mon Sep 17 00:00:00 2001 From: toksikk Date: Thu, 11 Feb 2016 10:15:08 +0100 Subject: [PATCH] added coffee module --- modules/coffee/coffee.go | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 modules/coffee/coffee.go diff --git a/modules/coffee/coffee.go b/modules/coffee/coffee.go new file mode 100644 index 0000000..d4f0578 --- /dev/null +++ b/modules/coffee/coffee.go @@ -0,0 +1,60 @@ +// vi:ts=4:sts=4:sw=4:noet:tw=72 +// +// flokatirc coffee module +// +// Copyright (c) 2016 Daniel Aberger + +package coffee + +import ( + "log" + "strings" + "time" + + "github.com/sorcix/irc" +) + +var ( + sayCh chan string +) + +func Init(ch chan string) { + log.Println("Initializing coffee module") + sayCh = ch +} + +func HandleMessage(m *irc.Message) { + tok := strings.Split(m.Trailing, " ") + if len(tok) < 1 { + return + } + switch tok[0] { + case "!kaffee": + switch len(tok) { + case 1: + go coffee(nil) + default: + go coffee(tok[1:]) + } + default: + } +} +func coffee(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)" +}