flokati/modules/modules.go

59 lines
1014 B
Go
Raw Normal View History

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"
"time"
2016-02-26 21:14:21 +00:00
"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)
2016-02-26 21:14:21 +00:00
)
func Init(ch chan string, mods, params string) {
time.Sleep(5 * time.Second)
2016-02-26 21:14:21 +00:00
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)
}
}
2016-02-26 21:14:21 +00:00
for _, param := range strings.Split(params, "!") {
kv := strings.Split(param, ":")
ModParams[kv[0]] = kv[1]
}
for _, fn := range RunFuncs {
go fn()
}
2016-02-26 21:14:21 +00:00
}
func HandleMessage(m *irc.Message) {
for _, fn := range MsgFuncs {
2016-02-26 21:14:21 +00:00
fn(m)
}
}
func contains(sa []string, s string) bool {
for _, a := range sa {
if a == s {
return true
}
}
return false
}