forked from an/flokati
New mod management, new parameter -mods
This commit is contained in:
parent
1dad661ceb
commit
7bffa566c5
13 changed files with 57 additions and 43 deletions
|
@ -5,16 +5,13 @@ package modules
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"code.dnix.de/an/xlog"
|
||||
|
||||
"github.com/sorcix/irc"
|
||||
)
|
||||
|
||||
var ()
|
||||
|
||||
func init() {
|
||||
MsgHandlers["announcements"] = anncouncementsHandleMessage
|
||||
xlog.Info("Announcements module initialized")
|
||||
MsgFuncs["announcements"] = anncouncementsHandleMessage
|
||||
}
|
||||
|
||||
func anncouncementsHandleMessage(m *irc.Message) {
|
||||
|
|
|
@ -12,8 +12,6 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"code.dnix.de/an/xlog"
|
||||
|
||||
"github.com/sorcix/irc"
|
||||
"github.com/sorcix/irc/ctcp"
|
||||
)
|
||||
|
@ -29,9 +27,8 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
MsgHandlers["coffee"] = coffeeHandleMessage
|
||||
MsgFuncs["coffee"] = coffeeHandleMessage
|
||||
r.names = make(map[string]bool)
|
||||
xlog.Info("Coffee module initialized")
|
||||
}
|
||||
|
||||
func coffeeHandleMessage(m *irc.Message) {
|
||||
|
@ -108,4 +105,3 @@ func printAction(s string) {
|
|||
msg := ctcp.Encode(ctcp.ACTION, fmt.Sprintf(s))
|
||||
SayCh <- fmt.Sprintf("%s\n%s", "*", msg)
|
||||
}
|
||||
|
||||
|
|
|
@ -8,14 +8,11 @@ import (
|
|||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"code.dnix.de/an/xlog"
|
||||
|
||||
"github.com/sorcix/irc"
|
||||
)
|
||||
|
||||
func init() {
|
||||
MsgHandlers["fortune"] = fortuneHandleMessage
|
||||
xlog.Info("Fortune module initialized")
|
||||
MsgFuncs["fortune"] = fortuneHandleMessage
|
||||
}
|
||||
|
||||
func fortuneHandleMessage(m *irc.Message) {
|
||||
|
|
|
@ -7,14 +7,11 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"code.dnix.de/an/xlog"
|
||||
|
||||
"github.com/sorcix/irc"
|
||||
)
|
||||
|
||||
func init() {
|
||||
MsgHandlers["fuzzytime"] = fuzzytimeHandleMessage
|
||||
xlog.Info("Fuzzytime module initialized")
|
||||
MsgFuncs["fuzzytime"] = fuzzytimeHandleMessage
|
||||
}
|
||||
|
||||
func fuzzytimeHandleMessage(m *irc.Message) {
|
||||
|
|
|
@ -8,8 +8,6 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"code.dnix.de/an/xlog"
|
||||
|
||||
"github.com/sorcix/irc"
|
||||
)
|
||||
|
||||
|
@ -18,8 +16,8 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
MsgHandlers["gogs"] = gogsHandleMessage
|
||||
xlog.Info("Gogs module initialized")
|
||||
MsgFuncs["gogs"] = gogsHandleMessage
|
||||
RunFuncs["gogs"] = gogsConfig
|
||||
}
|
||||
|
||||
func gogsConfig() {
|
||||
|
|
|
@ -13,21 +13,44 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
SayCh chan string
|
||||
MsgHandlers = make(map[string]func(*irc.Message))
|
||||
ModParams = make(map[string]string)
|
||||
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, params string) {
|
||||
func Init(ch chan string, mods, params string) {
|
||||
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 MsgHandlers {
|
||||
for _, fn := range MsgFuncs {
|
||||
fn(m)
|
||||
}
|
||||
}
|
||||
|
||||
func contains(sa []string, s string) bool {
|
||||
for _, a := range sa {
|
||||
if a == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -24,9 +24,8 @@ import (
|
|||
var hideOutput = true
|
||||
|
||||
func init() {
|
||||
MsgHandlers["rss"] = rssHandleMessage
|
||||
go rssRun()
|
||||
xlog.Info("RSS module initialized")
|
||||
MsgFuncs["rss"] = rssHandleMessage
|
||||
RunFuncs["rss"] = rssRun
|
||||
}
|
||||
|
||||
func rssRun() {
|
||||
|
|
|
@ -48,9 +48,8 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
MsgHandlers["sc"] = scHandleMessage
|
||||
go scScrapeLoop()
|
||||
xlog.Info("SC module initialized")
|
||||
MsgFuncs["sc"] = scHandleMessage
|
||||
RunFuncs["sc"] = scScrapeLoop
|
||||
}
|
||||
|
||||
func scHandleMessage(m *irc.Message) {
|
||||
|
|
|
@ -7,8 +7,6 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"code.dnix.de/an/xlog"
|
||||
|
||||
"github.com/sorcix/irc"
|
||||
)
|
||||
|
||||
|
@ -522,8 +520,7 @@ var quotes = [][]string{
|
|||
}
|
||||
|
||||
func init() {
|
||||
MsgHandlers["stoll"] = stollHandleMessage
|
||||
xlog.Info("Stoll module initialized")
|
||||
MsgFuncs["stoll"] = stollHandleMessage
|
||||
}
|
||||
|
||||
func stollHandleMessage(m *irc.Message) {
|
||||
|
|
|
@ -137,9 +137,8 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
MsgHandlers["twitch"] = twitchHandleMessage
|
||||
go pollStreamData()
|
||||
xlog.Info("Twitch module initialized")
|
||||
MsgFuncs["twitch"] = twitchHandleMessage
|
||||
RunFuncs["twitch"] = pollStreamData
|
||||
}
|
||||
|
||||
func twitchHandleMessage(m *irc.Message) {
|
||||
|
|
|
@ -71,9 +71,8 @@ type WeatherObject struct {
|
|||
}
|
||||
|
||||
func init() {
|
||||
MsgHandlers["weather"] = weatherHandleMessage
|
||||
go weatherConfig()
|
||||
xlog.Info("Weather module initialized")
|
||||
MsgFuncs["weather"] = weatherHandleMessage
|
||||
RunFuncs["weather"] = weatherConfig
|
||||
}
|
||||
|
||||
func weatherConfig() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue