2019-04-13 12:31:28 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-04-20 14:59:08 +02:00
|
|
|
// "fmt"
|
|
|
|
"flag"
|
2019-04-13 12:31:28 +02:00
|
|
|
"github.com/go-ini/ini"
|
2019-04-20 14:59:08 +02:00
|
|
|
// "time"
|
|
|
|
log "github.com/sirupsen/logrus"
|
2019-04-13 12:31:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var cfg *ini.File
|
|
|
|
var err error
|
2019-04-14 22:38:13 +02:00
|
|
|
var mygiteabot *GiteaBot
|
2019-04-13 12:31:28 +02:00
|
|
|
|
2019-04-20 14:59:08 +02:00
|
|
|
var verboseFlag = flag.Bool("v", false, "Display additional information")
|
|
|
|
|
2019-04-13 12:31:28 +02:00
|
|
|
func init() {
|
2019-04-14 22:51:52 +02:00
|
|
|
|
2019-04-20 14:59:08 +02:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if !*verboseFlag {
|
|
|
|
log.SetLevel(log.InfoLevel)
|
|
|
|
} else {
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.SetFormatter(&log.TextFormatter{
|
|
|
|
FullTimestamp: true,
|
|
|
|
TimestampFormat: "2006-01-02 15:04:05",
|
|
|
|
})
|
2019-04-14 22:51:52 +02:00
|
|
|
//Load config
|
2019-04-13 12:31:28 +02:00
|
|
|
cfg, err = ini.Load("config.ini")
|
|
|
|
if err != nil {
|
2019-04-20 14:59:08 +02:00
|
|
|
log.Fatalf("Fail to read file: %v", err)
|
2019-04-13 12:31:28 +02:00
|
|
|
}
|
|
|
|
|
2019-04-14 20:43:16 +02:00
|
|
|
matrixUser := cfg.Section("matrix").Key("matrix_user").String()
|
|
|
|
matrixPass := cfg.Section("matrix").Key("matrix_pass").String()
|
2019-04-13 12:31:28 +02:00
|
|
|
|
2019-04-19 21:35:01 +02:00
|
|
|
mygiteabot = NewGiteaBot(matrixUser, matrixPass, "./tokens.db")
|
2019-04-13 12:31:28 +02:00
|
|
|
|
2019-04-14 20:43:16 +02:00
|
|
|
if err != nil {
|
2019-04-20 14:59:08 +02:00
|
|
|
log.Fatal(err)
|
2019-04-14 20:43:16 +02:00
|
|
|
}
|
|
|
|
}
|
2019-04-13 12:31:28 +02:00
|
|
|
|
2019-04-14 20:43:16 +02:00
|
|
|
func main() {
|
2019-04-13 12:31:28 +02:00
|
|
|
|
2019-04-20 14:59:08 +02:00
|
|
|
log.Info("Starting POST-listener")
|
2019-04-18 21:27:49 +02:00
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
mygiteabot.Sync()
|
|
|
|
// Optional: Wait a period of time before trying to sync again.
|
|
|
|
}
|
|
|
|
}()
|
2019-04-13 12:31:28 +02:00
|
|
|
setupListener()
|
|
|
|
}
|