New mod management, new parameter -mods
This commit is contained in:
parent
1dad661ceb
commit
7bffa566c5
3
main.go
3
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 {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -14,20 +14,43 @@ import (
|
|||
|
||||
var (
|
||||
SayCh chan string
|
||||
MsgHandlers = make(map[string]func(*irc.Message))
|
||||
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() {
|
||||
|
|
12
util/util.go
12
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue