package main

import (
	"git.kuschku.de/justJanne/stateless-matrix-bot-framework"
	"net/url"
	"os"
)

func main() {
	var err error

	pushUrl, err := url.Parse(os.Getenv("BOT_PUSHURL"))
	if err != nil {
		panic(err)
	}
	bot := matrixbot.MatrixBot{
		AppName:    "Webhook Bot",
		AppId:      "de.justjanne.webhook_bot",
		ProfileTag: "webhook",
		PushKey:    "webhook",
		PushUrl:    pushUrl,
	}
	bot.HandleFunc("!8ball", handle8ball)
	bot.HandleFunc("!trains", handleTrains)
	err = initTrainHandler()
	if err != nil {
		panic(err)
	}

	err = bot.Login(os.Getenv("BOT_USERNAME"), os.Getenv("BOT_PASSWORD"), os.Getenv("BOT_DEVICEID"))
	if err != nil {
		panic(err)
	}
	err = bot.RegisterPusher()
	if err != nil {
		panic(err)
	}
	go bot.RefreshTask()
	bot.Serve(":8080")
}