From c62ea5990561e3d396ca8a6b7bc904d2a4ef7333 Mon Sep 17 00:00:00 2001 From: Andreas Neue Date: Fri, 26 Feb 2016 22:14:21 +0100 Subject: [PATCH 1/5] Fix: modules.go added. --- modules/fuzzytime.go | 3 --- modules/modules.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 modules/modules.go diff --git a/modules/fuzzytime.go b/modules/fuzzytime.go index 38a09c3..4ce52cb 100644 --- a/modules/fuzzytime.go +++ b/modules/fuzzytime.go @@ -31,7 +31,6 @@ func fuzzytimeHandleMessage(m *irc.Message) { } func fuzzytimeShow() { - log.Println("timeshow") t := time.Now() h := t.Hour() tzcorrect := 1 @@ -66,9 +65,7 @@ func fuzzytimeShow() { default: s += fmt.Sprintf("%s Uhr\n", fuzzytimeSayHour(h+1)) } - log.Println("saying now:", s) SayCh <- fmt.Sprintf("*\n%s", s) - } func fuzzytimeSayHour(h int) string { diff --git a/modules/modules.go b/modules/modules.go new file mode 100644 index 0000000..ee61d66 --- /dev/null +++ b/modules/modules.go @@ -0,0 +1,35 @@ +// vi:ts=4:sts=4:sw=4:noet:tw=72 +// +// flokatirc +// +// Copyright (c) 2015,2016 Andreas Neue + +package modules + +import ( + "log" + "strings" + + "github.com/sorcix/irc" +) + +var ( + SayCh chan string + MsgHandlers = make(map[string]func(*irc.Message)) + ModParams = make(map[string]string) +) + +func Init(ch chan string, params string) { + SayCh = ch + for _, param := range strings.Split(params, "!") { + kv := strings.Split(param, ":") + ModParams[kv[0]] = kv[1] + log.Println(kv[0], kv[1]) + } +} + +func HandleMessage(m *irc.Message) { + for _, fn := range MsgHandlers { + fn(m) + } +} From 66843c000e57484cb95ccf6360fe52feb2a6b25f Mon Sep 17 00:00:00 2001 From: Andreas Neue Date: Sun, 28 Feb 2016 10:31:20 +0100 Subject: [PATCH 2/5] Prevent coffee-module from serving coffee to names consisting of whitespace. --- modules/coffee.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/coffee.go b/modules/coffee.go index 03c51c9..4801721 100644 --- a/modules/coffee.go +++ b/modules/coffee.go @@ -20,7 +20,7 @@ func init() { } func coffeeHandleMessage(m *irc.Message) { - tok := strings.Split(m.Trailing, " ") + tok := strings.Split(strings.Trim(m.Trailing, " "), " ") if len(tok) < 1 { return } From 4dcacaec15bad4213e35e08451a4eed318e7db30 Mon Sep 17 00:00:00 2001 From: Andreas Neue Date: Sun, 28 Feb 2016 12:34:38 +0100 Subject: [PATCH 3/5] Disclose go version in info message. --- main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index f9a96da..55ebdee 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "flag" "fmt" "log" + "runtime" "strings" "time" @@ -139,5 +140,6 @@ func HandleMessage(m *irc.Message) { } func SoftwareInfo() string { - return fmt.Sprintf("flokatirc %s-%s (built %s)", version.FlokatiVersion, version.FlokatiBuild, version.FlokatiBuilddate) + return fmt.Sprintf("flokatirc %s-%s (built %s [%])", version.FlokatiVersion, + version.FlokatiBuild, version.FlokatiBuilddate, runtime.Version()) } From 7f79bc154cd769cac0bdf6006994adf16368079e Mon Sep 17 00:00:00 2001 From: Andreas Neue Date: Sun, 28 Feb 2016 12:38:32 +0100 Subject: [PATCH 4/5] Make rss module less chatty. --- main.go | 2 +- modules/rss.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 55ebdee..5a8cbc7 100644 --- a/main.go +++ b/main.go @@ -140,6 +140,6 @@ func HandleMessage(m *irc.Message) { } func SoftwareInfo() string { - return fmt.Sprintf("flokatirc %s-%s (built %s [%])", version.FlokatiVersion, + return fmt.Sprintf("flokatirc %s-%s (built %s [%s])", version.FlokatiVersion, version.FlokatiBuild, version.FlokatiBuilddate, runtime.Version()) } diff --git a/modules/rss.go b/modules/rss.go index 4000082..10b4a5f 100644 --- a/modules/rss.go +++ b/modules/rss.go @@ -66,7 +66,7 @@ func rssPollFeed(uri string, timeout int, cr xmlx.CharsetFunc) { } func rssChanHandler(feed *gorss.Feed, newchannels []*gorss.Channel) { - SayCh <- fmt.Sprintf("%s\n[RSS] %d new channel(s) in %s", "*", len(newchannels), feed.Url) + //SayCh <- fmt.Sprintf("%s\n[RSS] %d new channel(s) in %s", "*", len(newchannels), feed.Url) } func rssItemHandler(feed *gorss.Feed, ch *gorss.Channel, newitems []*gorss.Item) { From 3ac6bf23932f7b6f177bbc59d52b956131f9c009 Mon Sep 17 00:00:00 2001 From: Andreas Neue Date: Sun, 28 Feb 2016 13:00:08 +0100 Subject: [PATCH 5/5] Version info as ctcp action. --- main.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 5a8cbc7..d68c647 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ import ( "github.com/nickvanw/ircx" "github.com/sorcix/irc" + "github.com/sorcix/irc/ctcp" "flokatirc/modules" "flokatirc/version" @@ -106,9 +107,9 @@ func ConnectHandler(s ircx.Sender, m *irc.Message) { Params: []string{ch}, }) } - time.Sleep(5 * time.Second) - //sayCh <- fmt.Sprintf("%s\n\001ACTION running on %s", "*", SoftwareInfo()) - sayCh <- fmt.Sprintf("%s\n%s", "*", SoftwareInfo()) + time.Sleep(2 * time.Second) + msg := ctcp.Encode(ctcp.ACTION, fmt.Sprintf("running on %s", SoftwareInfo())) + sayCh <- fmt.Sprintf("%s\n%s", "*", msg) } func PingHandler(s ircx.Sender, m *irc.Message) { @@ -133,8 +134,9 @@ func HandleMessage(m *irc.Message) { } switch tok[0] { case "!version": - //sayCh <- fmt.Sprintf("%s\n\001ACTION running on %s", "*", SoftwareInfo()) - sayCh <- fmt.Sprintf("%s\n%s", "*", SoftwareInfo()) + msg := ctcp.Encode(ctcp.ACTION, fmt.Sprintf("running on %s", SoftwareInfo())) + sayCh <- fmt.Sprintf("%s\n%s", "*", msg) + //sayCh <- fmt.Sprintf("%s\n%s", "*", SoftwareInfo()) default: } }