Improved coffee module
This commit is contained in:
parent
813939cddc
commit
3fcf313799
|
@ -8,7 +8,6 @@ package modules
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -31,6 +30,7 @@ var (
|
|||
|
||||
func init() {
|
||||
MsgHandlers["coffee"] = coffeeHandleMessage
|
||||
r.names = make(map[string]bool)
|
||||
xlog.Info("Coffee module initialized")
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,6 @@ func coffeeHandleMessage(m *irc.Message) {
|
|||
func (r *Receivers) addReceivers(newNames []string) {
|
||||
r.mux.Lock()
|
||||
if r.running {
|
||||
SayCh <- "*\nEs wird gerade Kaffee zubereitet."
|
||||
if newNames != nil {
|
||||
r.addNames(newNames)
|
||||
}
|
||||
|
@ -62,34 +61,40 @@ func (r *Receivers) addReceivers(newNames []string) {
|
|||
if newNames != nil {
|
||||
r.addNames(newNames)
|
||||
}
|
||||
go makeCoffee()
|
||||
go r.makeCoffee()
|
||||
}
|
||||
r.mux.Unlock()
|
||||
}
|
||||
|
||||
func (r *Receivers) makeCoffee() {
|
||||
r.mux.Lock()
|
||||
r.running = true
|
||||
r.mux.Unlock()
|
||||
printAction("setzt Kaffee auf.")
|
||||
time.Sleep(time.Second * 30)
|
||||
printAction("stellt eine frische Kanne Kaffee in den Raum.")
|
||||
r.mux.Lock()
|
||||
if len(r.names) != 0 {
|
||||
var users string
|
||||
var count int = 0
|
||||
for i, _ := range r.names {
|
||||
count++
|
||||
users += i
|
||||
/*if i < len(rec)-2 {
|
||||
if count < len(r.names)-1 {
|
||||
users += ", "
|
||||
} else if i == len(rec)-2 {
|
||||
} else if count == len(r.names)-1 {
|
||||
users += " und "
|
||||
}*/
|
||||
}
|
||||
SayCh <- "*\ngibt " + users + " einen frischen, richtig schwarzen, richtig leckeren Kaffee."
|
||||
}
|
||||
printAction("gibt " + users + " einen frischen, richtig schwarzen, richtig leckeren Kaffee.")
|
||||
}
|
||||
r.mux.Unlock()
|
||||
time.Sleep(10 * time.Second)
|
||||
SayCh <- "*\nProst! (c)"
|
||||
|
||||
r.mux.Lock()
|
||||
r.names = make(map[string]bool)
|
||||
r.running = false
|
||||
|
||||
r.mux.Unlock()
|
||||
}
|
||||
|
||||
|
@ -104,30 +109,3 @@ func printAction(s string) {
|
|||
SayCh <- fmt.Sprintf("%s\n%s", "*", msg)
|
||||
}
|
||||
|
||||
//func (r *Receivers) coffeeMake(rec []string) {
|
||||
// if *running {
|
||||
// // TODO: add new recipients to map
|
||||
// // no if rec == nil add the sender, else add the sender and rec
|
||||
// SayCh <- "*\nEs wird gerade Kaffee zubereitet."
|
||||
// } else {
|
||||
// printAction("setzt Kaffee auf.")
|
||||
// time.Sleep(30 * time.Second)
|
||||
// printAction("stellt 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)"
|
||||
// }
|
||||
//}
|
||||
|
|
Loading…
Reference in New Issue