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

26
main.go
View File

@ -16,7 +16,7 @@ import (
"code.dnix.de/an/flokatilib/modules"
"code.dnix.de/an/xlog"
"flokatirc/version"
"mmflokati/version"
"github.com/42wim/matterbridge/matterclient"
)
@ -26,6 +26,7 @@ var (
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")
)
@ -46,16 +47,25 @@ 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
sayCh <- "town-square\n" + SoftwareInfo()
go func() {
for {
var targets string
line := strings.Split(<-sayCh, "\n")
@ -64,15 +74,25 @@ func main() {
}
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)
}
}()
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})
}
}()
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())
}