Make mattermost frontend fully operative

This commit is contained in:
an 2017-06-28 23:27:33 +02:00
parent 1968427185
commit 0a0a10ed29
1 changed files with 39 additions and 19 deletions

58
main.go
View File

@ -16,17 +16,18 @@ import (
"code.dnix.de/an/flokatilib/modules"
"code.dnix.de/an/xlog"
"flokatirc/version"
"mmflokati/version"
"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")
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")
channels = flag.String("channels", "", "Channels to join")
mods = flag.String("mods", "", "Modules to load")
)
func init() {
@ -46,33 +47,52 @@ func main() {
xlog.Info("Connecting ...")
bot := matterclient.New(*name, *pass, *team, *server)
bot.SetLogLevel("debug")
err := bot.Login()
if err != nil {
xlog.Error(err.Error())
}
teamId := bot.GetTeamId()
for _, ch := range strings.Split(*channels, ",") {
xlog.Debug("Joining %s", ch)
bot.JoinChannel(bot.GetChannelId(ch, teamId))
}
xlog.Info("Connected")
modules.Init(sayCh, *mods)
modules.BotNick = *name
for {
var targets string
line := strings.Split(<-sayCh, "\n")
if len(line) < 2 {
continue
sayCh <- "town-square\n" + SoftwareInfo()
go func() {
for {
var targets string
line := strings.Split(<-sayCh, "\n")
if len(line) < 2 {
continue
}
targets = line[0]
for _, tar := range strings.Split(targets, ",") {
chId := bot.GetChannelId(tar, teamId)
bot.PostMessage(chId, line[1])
}
time.Sleep(1 * time.Second)
}
targets = line[0]
for _, tar := range strings.Split(targets, ",") {
teamId := bot.GetTeamId()
chId := bot.GetChannelId(tar, teamId)
bot.PostMessage(chId, line[1])
}()
go func() {
for {
mm := <-bot.MessageChan
xlog.Debug("got msg: %v %v :: %v", mm.Username, mm.Channel, mm.Text)
modules.HandleMessage(&modules.Message{From: mm.Username, Channel: mm.Channel, Text: mm.Text})
}
time.Sleep(1 * time.Second)
}
}()
bot.StatusLoop()
}
func SoftwareInfo() string {
return fmt.Sprintf("flokatirc %s-%s (built %s [%s])", version.FlokatiVersion,
return fmt.Sprintf("mmflokati %s-%s (built %s [%s])", version.FlokatiVersion,
version.FlokatiBuild, version.FlokatiBuilddate, runtime.Version())
}