flokati/modules/modules.go

55 lines
867 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())
BotNick 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 *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
}