mirror of
https://github.com/pinpox/gitea-matrix-bot
synced 2024-11-22 10:21:58 +01:00
Adher to my newly established coding standards.
This commit is contained in:
parent
76960a5320
commit
3b9ee2f12e
86
main.go
86
main.go
@ -2,9 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
"time"
|
||||
|
||||
"github.com/go-ini/ini"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
"time"
|
||||
|
||||
// "time"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -14,63 +16,63 @@ var err error
|
||||
var mygiteabot *GiteaBot
|
||||
|
||||
var (
|
||||
verboseFlag = kingpin.Flag("verbose", "Verbose mode, displays additional information.").Short('v').Default("false").Bool()
|
||||
configFlag = kingpin.Flag("config", "Configuration file to use").Short('c').Default("config.ini").String()
|
||||
initDBFlag = kingpin.Flag("initdb", "Initialize the database. If it exists, it will be overwritten!").Default("false").Bool()
|
||||
syncSecsFlag = kingpin.Flag("sync", "Matrix synchronizing interval").Default("1").Int()
|
||||
verboseFlag = kingpin.Flag("verbose", "Verbose mode, displays additional information.").Short('v').Default("false").Bool()
|
||||
configFlag = kingpin.Flag("config", "Configuration file to use").Short('c').Default("config.ini").String()
|
||||
initDBFlag = kingpin.Flag("initdb", "Initialize the database. If it exists, it will be overwritten!").Default("false").Bool()
|
||||
syncSecsFlag = kingpin.Flag("sync", "Matrix synchronizing interval").Default("1").Int()
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
//Parse flags and set log-level
|
||||
kingpin.Version("1.0.0")
|
||||
kingpin.Parse()
|
||||
//Parse flags and set log-level
|
||||
kingpin.Version("1.0.0")
|
||||
kingpin.Parse()
|
||||
|
||||
if !*verboseFlag {
|
||||
log.SetLevel(log.InfoLevel)
|
||||
} else {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
if !*verboseFlag {
|
||||
log.SetLevel(log.InfoLevel)
|
||||
} else {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
|
||||
log.SetFormatter(&log.TextFormatter{
|
||||
FullTimestamp: true,
|
||||
TimestampFormat: "2006-01-02 15:04:05",
|
||||
})
|
||||
log.SetFormatter(&log.TextFormatter{
|
||||
FullTimestamp: true,
|
||||
TimestampFormat: "2006-01-02 15:04:05",
|
||||
})
|
||||
|
||||
//Load config
|
||||
log.Debugf("Using configuration file %s", *configFlag)
|
||||
cfg, err = ini.Load(*configFlag)
|
||||
//Load config
|
||||
log.Debugf("Using configuration file %s", *configFlag)
|
||||
cfg, err = ini.Load(*configFlag)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Fail to read file: %v", err)
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatalf("Fail to read file: %v", err)
|
||||
}
|
||||
|
||||
matrixUser := cfg.Section("matrix").Key("matrix_user").String()
|
||||
matrixUser := cfg.Section("matrix").Key("matrix_user").String()
|
||||
|
||||
matrixPass := cfg.Section("matrix").Key("matrix_pass").String()
|
||||
matrixHost := cfg.Section("matrix").Key("matrix_pass").String()
|
||||
dbPath := cfg.Section("bot").Key("db_path").String()
|
||||
matrixPass := cfg.Section("matrix").Key("matrix_pass").String()
|
||||
matrixHost := cfg.Section("matrix").Key("matrix_pass").String()
|
||||
dbPath := cfg.Section("bot").Key("db_path").String()
|
||||
|
||||
//Set up the bot
|
||||
//Set up the bot
|
||||
|
||||
// func NewGiteaBot(user, pass, host, string, DBPath string) *GiteaBot {
|
||||
mygiteabot = NewGiteaBot(matrixUser, matrixPass, matrixHost, dbPath)
|
||||
// func NewGiteaBot(user, pass, host, string, DBPath string) *GiteaBot {
|
||||
mygiteabot = NewGiteaBot(matrixUser, matrixPass, matrixHost, dbPath)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Debug("Bot created")
|
||||
log.Debug("Bot created")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
log.Info("Setting up POST-listener")
|
||||
go func() {
|
||||
for {
|
||||
mygiteabot.Sync()
|
||||
time.Sleep(time.Duration(*syncSecsFlag) * time.Second)
|
||||
}
|
||||
}()
|
||||
setupListener()
|
||||
log.Info("Setting up POST-listener")
|
||||
go func() {
|
||||
for {
|
||||
mygiteabot.Sync()
|
||||
time.Sleep(time.Duration(*syncSecsFlag) * time.Second)
|
||||
}
|
||||
}()
|
||||
setupListener()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user