mmflokati/main.go

79 lines
1.5 KiB
Go
Raw Normal View History

2017-06-28 10:23:37 +00:00
// vi:ts=4:sts=4:sw=4:noet:tw=72
//
// flokatirc
//
// Copyright (c) 2015,2016 Andreas Neue <an@dnix.de>
package main
import (
"flag"
2017-06-28 11:07:36 +00:00
"fmt"
"runtime"
2017-06-28 10:23:37 +00:00
"strings"
"time"
2017-06-28 11:07:36 +00:00
"code.dnix.de/an/flokatilib/modules"
2017-06-28 10:23:37 +00:00
"code.dnix.de/an/xlog"
2017-06-28 11:07:36 +00:00
"flokatirc/version"
2017-06-28 10:23:37 +00:00
"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)
2017-06-28 11:07:36 +00:00
xlog.Info("%s started", SoftwareInfo())
2017-06-28 10:23:37 +00:00
xlog.Info("Connecting ...")
bot := matterclient.New(*name, *pass, *team, *server)
err := bot.Login()
if err != nil {
xlog.Error(err.Error())
}
xlog.Info("Connected")
2017-06-28 11:07:36 +00:00
modules.Init(sayCh, *mods)
modules.BotNick = *name
2017-06-28 10:23:37 +00:00
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)
}
}
2017-06-28 11:07:36 +00:00
func SoftwareInfo() string {
return fmt.Sprintf("flokatirc %s-%s (built %s [%s])", version.FlokatiVersion,
version.FlokatiBuild, version.FlokatiBuilddate, runtime.Version())
}