flokati/modules/modules.go

60 lines
923 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
)
var (
2017-06-28 11:08:23 +00:00
SayCh chan string
2017-06-28 21:28:39 +00:00
MsgFuncs = make(map[string]func(*Message))
2017-06-28 11:08:23 +00:00
RunFuncs = make(map[string]func())
BotNick string
2019-08-24 05:37:39 +00:00
BotName string
2016-02-26 21:14:21 +00:00
)
2017-06-28 21:28:39 +00:00
type Message struct {
From string
Channel string
Text string
}
2017-06-28 11:08:23 +00:00
func Init(ch chan string, mods 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)
}
}
for _, fn := range RunFuncs {
go fn()
}
2016-02-26 21:14:21 +00:00
}
2017-06-28 21:28:39 +00:00
func HandleMessage(m *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
}