This commit is contained in:
Daniel Aberger 2016-02-29 15:05:31 +01:00
commit 458b7435d0
5 changed files with 47 additions and 11 deletions

16
main.go
View File

@ -10,11 +10,13 @@ import (
"flag" "flag"
"fmt" "fmt"
"log" "log"
"runtime"
"strings" "strings"
"time" "time"
"github.com/nickvanw/ircx" "github.com/nickvanw/ircx"
"github.com/sorcix/irc" "github.com/sorcix/irc"
"github.com/sorcix/irc/ctcp"
"flokatirc/modules" "flokatirc/modules"
"flokatirc/version" "flokatirc/version"
@ -105,9 +107,9 @@ func ConnectHandler(s ircx.Sender, m *irc.Message) {
Params: []string{ch}, Params: []string{ch},
}) })
} }
time.Sleep(5 * time.Second) time.Sleep(2 * time.Second)
//sayCh <- fmt.Sprintf("%s\n\001ACTION running on %s", "*", SoftwareInfo()) msg := ctcp.Encode(ctcp.ACTION, fmt.Sprintf("running on %s", SoftwareInfo()))
sayCh <- fmt.Sprintf("%s\n%s", "*", SoftwareInfo()) sayCh <- fmt.Sprintf("%s\n%s", "*", msg)
} }
func PingHandler(s ircx.Sender, m *irc.Message) { func PingHandler(s ircx.Sender, m *irc.Message) {
@ -132,12 +134,14 @@ func HandleMessage(m *irc.Message) {
} }
switch tok[0] { switch tok[0] {
case "!version": case "!version":
//sayCh <- fmt.Sprintf("%s\n\001ACTION running on %s", "*", SoftwareInfo()) msg := ctcp.Encode(ctcp.ACTION, fmt.Sprintf("running on %s", SoftwareInfo()))
sayCh <- fmt.Sprintf("%s\n%s", "*", SoftwareInfo()) sayCh <- fmt.Sprintf("%s\n%s", "*", msg)
//sayCh <- fmt.Sprintf("%s\n%s", "*", SoftwareInfo())
default: default:
} }
} }
func SoftwareInfo() string { 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 [%s])", version.FlokatiVersion,
version.FlokatiBuild, version.FlokatiBuilddate, runtime.Version())
} }

View File

@ -20,7 +20,7 @@ func init() {
} }
func coffeeHandleMessage(m *irc.Message) { func coffeeHandleMessage(m *irc.Message) {
tok := strings.Split(m.Trailing, " ") tok := strings.Split(strings.Trim(m.Trailing, " "), " ")
if len(tok) < 1 { if len(tok) < 1 {
return return
} }

View File

@ -31,7 +31,6 @@ func fuzzytimeHandleMessage(m *irc.Message) {
} }
func fuzzytimeShow() { func fuzzytimeShow() {
log.Println("timeshow")
t := time.Now() t := time.Now()
h := t.Hour() h := t.Hour()
tzcorrect := 1 tzcorrect := 1
@ -66,9 +65,7 @@ func fuzzytimeShow() {
default: default:
s += fmt.Sprintf("%s Uhr\n", fuzzytimeSayHour(h+1)) s += fmt.Sprintf("%s Uhr\n", fuzzytimeSayHour(h+1))
} }
log.Println("saying now:", s)
SayCh <- fmt.Sprintf("*\n%s", s) SayCh <- fmt.Sprintf("*\n%s", s)
} }
func fuzzytimeSayHour(h int) string { func fuzzytimeSayHour(h int) string {

35
modules/modules.go Normal file
View File

@ -0,0 +1,35 @@
// vi:ts=4:sts=4:sw=4:noet:tw=72
//
// flokatirc
//
// Copyright (c) 2015,2016 Andreas Neue <an@dnix.de>
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)
}
}

View File

@ -66,7 +66,7 @@ func rssPollFeed(uri string, timeout int, cr xmlx.CharsetFunc) {
} }
func rssChanHandler(feed *gorss.Feed, newchannels []*gorss.Channel) { 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) { func rssItemHandler(feed *gorss.Feed, ch *gorss.Channel, newitems []*gorss.Item) {