kunt

golang IRC bot
git clone git://git.2f30.org/kunt.git
Log | Files | Refs | LICENSE

commit b2ce41e51754270477ea10b16dc7e97e69ef466e
parent 6d69a11d2354d679fa4b135c684f7916116dbbaf
Author: dsp <dsp@2f30.org>
Date:   Tue Apr 29 16:54:45 +0100

Implemented urlupdate fifo command that populates a non-existant directory with the urls+fetched yt titles when appropriate. Also changed the default kuntCtx NetworkName to freenode from grnet

Diffstat:
src/kunt/kunt.go | 54++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 52 insertions(+), 2 deletions(-)
diff --git a/src/kunt/kunt.go b/src/kunt/kunt.go @@ -355,13 +355,63 @@ func fifoCmdParse() { } if n > 0 { buf = buf[0 : n-1] - if string(buf) == "netjoin" { + switch string(buf) { + case "netjoin": kunt.ircCtx.JoinChannels() + case "urlupdate": + updateUrlDbTitles("db/urls-new") + default: + log.Printf("Unknown fifo command:%s\n",string(buf)) } } } } +func updateUrlDbTitles(path string) { + log.Printf("*** starting urlDb update under path %s ***\n",path) + newurlPlain := mapfs.NewPlainMap() + _, err := os.Stat(path) + if err == nil { + log.Printf(" [updateUrlDbTitles] for the db to be updated, please provide a non-existant directory to be populated. %s exists\n",path) + return + } + newurlDb := mapfs.NewMapfs(newurlPlain, "Urls", path, "url") + err = newurlDb.Load() + if err != nil { + log.Printf("error on loading new urlDb: %s\n",err.Error()) + return + } + iter := mapfs.MakeMapIter(urlDb) + whitespacefunc := func(a rune) bool { + return a == '\t' || a == ' ' + } + for { + _, v, ok := iter() + if !ok { + break + } + stringv := strings.TrimSpace(string(v)) + strs := strings.FieldsFunc(stringv, whitespacefunc) + title, ok := resolveYoutubeTitle(strs[0]) + if ok { + stringv = strs[0] + title + "\n" + } else { + stringv = strs[0] + "\n" + } + buf := []byte(stringv) + _, err := newurlDb.Append(buf) + if err != nil { + log.Printf(" [updateUrlDbTitles] %s\n", err.Error()) + return + } + err = newurlDb.Sync() + if err != nil { + log.Fatal(err) + } + } + log.Printf("*** urlDb update finished ***\n") +} + var sslon = flag.Bool("s", false, "SSL support") var quoteDb *mapfs.Mapfs @@ -450,7 +500,7 @@ func main() { } cfg := irc.Config{ - NetworkName: "grnet", + NetworkName: "freenode", Nick: botname, User: "z0mg", RealName: botname,