flokati/modules/modules.go

59 lines
906 B
Go

// vi:ts=4:sts=4:sw=4:noet:tw=72
//
// flokatirc
//
// Copyright (c) 2015,2016 Andreas Neue <an@dnix.de>
package modules
import (
"strings"
"time"
)
var (
SayCh chan string
MsgFuncs = make(map[string]func(*Message))
RunFuncs = make(map[string]func())
BotNick string
)
type Message struct {
From string
Channel string
Text string
}
func Init(ch chan string, mods string) {
time.Sleep(5 * time.Second)
SayCh = ch
for mod, _ := range MsgFuncs {
if !contains(strings.Split(mods, ","), mod) {
delete(MsgFuncs, mod)
}
}
for mod, _ := range RunFuncs {
if !contains(strings.Split(mods, ","), mod) {
delete(RunFuncs, mod)
}
}
for _, fn := range RunFuncs {
go fn()
}
}
func HandleMessage(m *Message) {
for _, fn := range MsgFuncs {
fn(m)
}
}
func contains(sa []string, s string) bool {
for _, a := range sa {
if a == s {
return true
}
}
return false
}