2016-02-26 21:14:21 +00:00
|
|
|
// vi:ts=4:sts=4:sw=4:noet:tw=72
|
|
|
|
//
|
|
|
|
// flokatirc
|
|
|
|
//
|
|
|
|
// Copyright (c) 2015,2016 Andreas Neue <an@dnix.de>
|
|
|
|
|
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/sorcix/irc"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2016-03-19 22:49:41 +00:00
|
|
|
SayCh chan string
|
|
|
|
MsgFuncs = make(map[string]func(*irc.Message))
|
|
|
|
RunFuncs = make(map[string]func())
|
|
|
|
ModParams = make(map[string]string)
|
2016-02-26 21:14:21 +00:00
|
|
|
)
|
|
|
|
|
2016-03-19 22:49:41 +00:00
|
|
|
func Init(ch chan string, mods, params string) {
|
2016-02-26 21:14:21 +00:00
|
|
|
SayCh = ch
|
2016-03-19 22:49:41 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2016-02-26 21:14:21 +00:00
|
|
|
for _, param := range strings.Split(params, "!") {
|
|
|
|
kv := strings.Split(param, ":")
|
|
|
|
ModParams[kv[0]] = kv[1]
|
|
|
|
}
|
2016-03-19 22:49:41 +00:00
|
|
|
for _, fn := range RunFuncs {
|
|
|
|
go fn()
|
|
|
|
}
|
2016-02-26 21:14:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func HandleMessage(m *irc.Message) {
|
2016-03-19 22:49:41 +00:00
|
|
|
for _, fn := range MsgFuncs {
|
2016-02-26 21:14:21 +00:00
|
|
|
fn(m)
|
|
|
|
}
|
|
|
|
}
|
2016-03-19 22:49:41 +00:00
|
|
|
|
|
|
|
func contains(sa []string, s string) bool {
|
|
|
|
for _, a := range sa {
|
|
|
|
if a == s {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|