Make mattermost frontend fully operative
This commit is contained in:
parent
1968427185
commit
0a0a10ed29
58
main.go
58
main.go
|
@ -16,17 +16,18 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
name = flag.String("name", "matterbot", "Bot name")
|
name = flag.String("name", "matterbot", "Bot name")
|
||||||
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")
|
||||||
mods = flag.String("mods", "", "Modules to load")
|
channels = flag.String("channels", "", "Channels to join")
|
||||||
|
mods = flag.String("mods", "", "Modules to load")
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -46,33 +47,52 @@ 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
|
||||||
|
|
||||||
for {
|
sayCh <- "town-square\n" + SoftwareInfo()
|
||||||
var targets string
|
|
||||||
line := strings.Split(<-sayCh, "\n")
|
go func() {
|
||||||
if len(line) < 2 {
|
for {
|
||||||
continue
|
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()
|
go func() {
|
||||||
chId := bot.GetChannelId(tar, teamId)
|
for {
|
||||||
bot.PostMessage(chId, line[1])
|
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 {
|
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