Make mattermost frontend fully operative
This commit is contained in:
parent
1968427185
commit
0a0a10ed29
26
main.go
26
main.go
|
@ -16,7 +16,7 @@ import (
|
||||||
"code.dnix.de/an/flokatilib/modules"
|
"code.dnix.de/an/flokatilib/modules"
|
||||||
"code.dnix.de/an/xlog"
|
"code.dnix.de/an/xlog"
|
||||||
|
|
||||||
"flokatirc/version"
|
"mmflokati/version"
|
||||||
|
|
||||||
"github.com/42wim/matterbridge/matterclient"
|
"github.com/42wim/matterbridge/matterclient"
|
||||||
)
|
)
|
||||||
|
@ -26,6 +26,7 @@ var (
|
||||||
pass = flag.String("pass", "", "Password")
|
pass = flag.String("pass", "", "Password")
|
||||||
team = flag.String("team", "", "Team name")
|
team = flag.String("team", "", "Team name")
|
||||||
server = flag.String("server", "mm.example.com", "Server address")
|
server = flag.String("server", "mm.example.com", "Server address")
|
||||||
|
channels = flag.String("channels", "", "Channels to join")
|
||||||
mods = flag.String("mods", "", "Modules to load")
|
mods = flag.String("mods", "", "Modules to load")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,16 +47,25 @@ func main() {
|
||||||
xlog.Info("Connecting ...")
|
xlog.Info("Connecting ...")
|
||||||
|
|
||||||
bot := matterclient.New(*name, *pass, *team, *server)
|
bot := matterclient.New(*name, *pass, *team, *server)
|
||||||
|
bot.SetLogLevel("debug")
|
||||||
err := bot.Login()
|
err := bot.Login()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xlog.Error(err.Error())
|
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")
|
xlog.Info("Connected")
|
||||||
|
|
||||||
modules.Init(sayCh, *mods)
|
modules.Init(sayCh, *mods)
|
||||||
modules.BotNick = *name
|
modules.BotNick = *name
|
||||||
|
|
||||||
|
sayCh <- "town-square\n" + SoftwareInfo()
|
||||||
|
|
||||||
|
go func() {
|
||||||
for {
|
for {
|
||||||
var targets string
|
var targets string
|
||||||
line := strings.Split(<-sayCh, "\n")
|
line := strings.Split(<-sayCh, "\n")
|
||||||
|
@ -64,15 +74,25 @@ func main() {
|
||||||
}
|
}
|
||||||
targets = line[0]
|
targets = line[0]
|
||||||
for _, tar := range strings.Split(targets, ",") {
|
for _, tar := range strings.Split(targets, ",") {
|
||||||
teamId := bot.GetTeamId()
|
|
||||||
chId := bot.GetChannelId(tar, teamId)
|
chId := bot.GetChannelId(tar, teamId)
|
||||||
bot.PostMessage(chId, line[1])
|
bot.PostMessage(chId, line[1])
|
||||||
}
|
}
|
||||||
time.Sleep(1 * time.Second)
|
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 {
|
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())
|
version.FlokatiBuild, version.FlokatiBuilddate, runtime.Version())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue