59 lines
1014 B
Go
59 lines
1014 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"
|
|
|
|
"github.com/sorcix/irc"
|
|
)
|
|
|
|
var (
|
|
SayCh chan string
|
|
MsgFuncs = make(map[string]func(*irc.Message))
|
|
RunFuncs = make(map[string]func())
|
|
ModParams = make(map[string]string)
|
|
)
|
|
|
|
func Init(ch chan string, mods, params 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 _, param := range strings.Split(params, "!") {
|
|
kv := strings.Split(param, ":")
|
|
ModParams[kv[0]] = kv[1]
|
|
}
|
|
for _, fn := range RunFuncs {
|
|
go fn()
|
|
}
|
|
}
|
|
|
|
func HandleMessage(m *irc.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
|
|
}
|