From fe8343300afa8f1201090fc165db52ae3472e639 Mon Sep 17 00:00:00 2001 From: an Date: Wed, 28 Jun 2017 12:23:37 +0200 Subject: [PATCH] Initial commit --- Dockerfile | 20 +++++++++++ LICENSE | 20 ++++++++--- Makefile | 43 ++++++++++++++++++++++++ dockerbuild.sh-dist | 6 ++++ main.go | 81 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 Dockerfile create mode 100644 Makefile create mode 100755 dockerbuild.sh-dist create mode 100644 main.go diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ae10e78 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM ubuntu:15.10 +MAINTAINER Andreas Neue + +RUN apt-get -y --force-yes update +RUN apt-get -y --force-yes upgrade +RUN apt-get install -y ca-certificates +RUN apt-get install -y fortune vim +RUN apt-get clean + +RUN mkdir /flokatirc + +COPY flokatirc /flokatirc/flokatirc +COPY newsfeeds.conf /flokatirc/newsfeeds.conf +COPY fortunes /flokatirc/fortunes + +ENV PATH $PATH:/flokatirc + +WORKDIR /flokatirc + +CMD [ "/flokatirc/flokatirc", "-server=irc.dnix.de:6667", "-name=Flokati", "-chan=#test", "-nsname=N", "-nspass=t0ps3cr37" ] diff --git a/LICENSE b/LICENSE index 472ac23..6c768bc 100644 --- a/LICENSE +++ b/LICENSE @@ -1,8 +1,20 @@ MIT License -Copyright (c) +Copyright (c) 2017 Andreas Neue -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..47ff5c0 --- /dev/null +++ b/Makefile @@ -0,0 +1,43 @@ +GOPATH := ${PWD}:${GOPATH} +export GOPATH + +default: build + +build: genversion genbuilddate test + go build -v mmflokati + +build-win: test genversion + GOOS=windows GOARCH=amd64 go build -v -o mmflokati.exe mmflokati + +docker: build + ./dockerbuild.sh + +genversion: + ./genversion.sh + +genbuilddate: + ./genbuilddate.sh + +fmt: + go fmt ./... + +fix: + go fix ./... + +imports: + find . -type f -name "*.go" -exec goimports -w {} \; + +doc: + godoc -http=:6060 -index + +test: + go test ./... + +commit: + git commit -a -F changes.log + rm changes.log + touch changes.log + ./genversion.sh + +push: + git push diff --git a/dockerbuild.sh-dist b/dockerbuild.sh-dist new file mode 100755 index 0000000..3b07f12 --- /dev/null +++ b/dockerbuild.sh-dist @@ -0,0 +1,6 @@ +#!/bin/sh +VERSION=`git rev-parse --abbrev-ref HEAD` +BUILD=`git rev-list HEAD --count` +echo $VERSION-$BUILD +docker build -t dr.dnix.de/flokatirc:$VERSION-$BUILD -f Dockerfile . +docker push dr.dnix.de/flokatirc:$VERSION-$BUILD diff --git a/main.go b/main.go new file mode 100644 index 0000000..7d9c829 --- /dev/null +++ b/main.go @@ -0,0 +1,81 @@ +// vi:ts=4:sts=4:sw=4:noet:tw=72 +// +// flokatirc +// +// Copyright (c) 2015,2016 Andreas Neue + +package main + +import ( + "flag" + "strings" + "time" + + "code.dnix.de/an/xlog" + + //"flokatirc/version" + + //"code.dnix.de/an/flokatilib/modules" + + "github.com/42wim/matterbridge/matterclient" +) + +var ( + name = flag.String("name", "matterbot", "Bot name") + pass = flag.String("pass", "", "Password") + team = flag.String("team", "", "Team name") + server = flag.String("server", "mm.example.com", "Server address") + mods = flag.String("mods", "", "Modules to load") +) + +func init() { + flag.Parse() +} + +var ( + sayCh chan string +) + +func main() { + sayCh = make(chan string, 1024) + + xlog.Init(xlog.DEBUG) + + //xlog.Info("%s started", SoftwareInfo()) + xlog.Info("Started") + xlog.Info("Connecting ...") + + bot := matterclient.New(*name, *pass, *team, *server) + err := bot.Login() + if err != nil { + xlog.Error(err.Error()) + } + + xlog.Info("Connected") + + //mods := strings.Split(*modules, ",") + //TODO: implement more robust list parsing + + //modules.Init(sayCh, *mods, *params) + //modules.ModParams["_nick"] = *name + + for { + var targets string + line := strings.Split(<-sayCh, "\n") + if len(line) < 2 { + continue + } + targets = line[0] + for _, tar := range strings.Split(targets, ",") { + teamId := bot.GetTeamId() + chId := bot.GetChannelId(tar, teamId) + bot.PostMessage(chId, line[1]) + } + time.Sleep(1 * time.Second) + } +} + +//func SoftwareInfo() string { +// return fmt.Sprintf("flokatirc %s-%s (built %s [%s])", version.FlokatiVersion, +// version.FlokatiBuild, version.FlokatiBuilddate, runtime.Version()) +//}