diff --git a/main.go b/main.go index 44bed25..8dfcb1f 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,7 @@ var ( channels = flag.String("chan", "#test", "Channels to join") nsname = flag.String("nsname", "NickServ", "NickServ name") nspass = flag.String("nspass", "", "NickServ password") + mods = flag.String("mods", "", "Modules to load") params = flag.String("params", "", "Module params") ) @@ -57,7 +58,7 @@ func main() { //mods := strings.Split(*modules, ",") //TODO: implement more robust list parsing - modules.Init(sayCh, *params) + modules.Init(sayCh, *mods, *params) go func() { for { diff --git a/modules/announcements.go b/modules/announcements.go index a73ac8b..be2b1db 100644 --- a/modules/announcements.go +++ b/modules/announcements.go @@ -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) { diff --git a/modules/coffee.go b/modules/coffee.go index f1773ce..05a0207 100644 --- a/modules/coffee.go +++ b/modules/coffee.go @@ -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) } - diff --git a/modules/fortune.go b/modules/fortune.go index b71172d..b0cd8d4 100644 --- a/modules/fortune.go +++ b/modules/fortune.go @@ -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) { diff --git a/modules/fuzzytime.go b/modules/fuzzytime.go index b6197f7..802a66c 100644 --- a/modules/fuzzytime.go +++ b/modules/fuzzytime.go @@ -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) { diff --git a/modules/gogs.go b/modules/gogs.go index ccd36ed..026c657 100644 --- a/modules/gogs.go +++ b/modules/gogs.go @@ -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() { diff --git a/modules/modules.go b/modules/modules.go index 482d3df..c7fc4cc 100644 --- a/modules/modules.go +++ b/modules/modules.go @@ -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 +} diff --git a/modules/rss.go b/modules/rss.go index 93685a4..62d76e7 100644 --- a/modules/rss.go +++ b/modules/rss.go @@ -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() { diff --git a/modules/sc.go b/modules/sc.go index 3d50d51..4952943 100644 --- a/modules/sc.go +++ b/modules/sc.go @@ -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) { diff --git a/modules/stoll.go b/modules/stoll.go index 59a6931..8b2a840 100644 --- a/modules/stoll.go +++ b/modules/stoll.go @@ -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) { diff --git a/modules/twitch.go b/modules/twitch.go index a94bda3..e2d2f48 100644 --- a/modules/twitch.go +++ b/modules/twitch.go @@ -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) { diff --git a/modules/weather.go b/modules/weather.go index dce2019..a63486b 100644 --- a/modules/weather.go +++ b/modules/weather.go @@ -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() { diff --git a/util/util.go b/util/util.go index a3d1d0b..90c5357 100644 --- a/util/util.go +++ b/util/util.go @@ -6,6 +6,7 @@ import ( "bytes" "math/rand" "strconv" + "strings" "time" ) @@ -52,3 +53,14 @@ func Random(min, max int) int { rand.Seed(time.Now().Unix()) return rand.Intn(max-min) + min } + +func ReplaceUmlauts(s string) string { + ret := strings.Replace(s, "Ä", "Ae", -1) + ret = strings.Replace(ret, "Ö", "Oe", -1) + ret = strings.Replace(ret, "Ü", "Ue", -1) + ret = strings.Replace(ret, "ä", "ae", -1) + ret = strings.Replace(ret, "ö", "oe", -1) + ret = strings.Replace(ret, "ü", "ue", -1) + ret = strings.Replace(ret, "ß", "ss", -1) + return ret +}