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