1
0
mirror of https://github.com/pinpox/gitea-matrix-bot synced 2024-11-22 19:31:58 +01:00

Emacs test

This commit is contained in:
Pablo Ovelleiro Corral 2019-05-15 10:21:00 +02:00
parent b0100f50f0
commit 76960a5320
No known key found for this signature in database
GPG Key ID: F7C1D57C8464E825

83
main.go

@ -14,62 +14,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()
matrixPass := cfg.Section("matrix").Key("matrix_pass").String()
matrixHost := cfg.Section("matrix").Key("matrix_pass").String()
dbPath := cfg.Section("bot").Key("db_path").String()
matrixUser := cfg.Section("matrix").Key("matrix_user").String()
//Set up the bot
matrixPass := cfg.Section("matrix").Key("matrix_pass").String()
matrixHost := cfg.Section("matrix").Key("matrix_pass").String()
dbPath := cfg.Section("bot").Key("db_path").String()
// func NewGiteaBot(user, pass, host, string, DBPath string) *GiteaBot {
mygiteabot = NewGiteaBot(matrixUser, matrixPass, matrixHost, dbPath)
//Set up the bot
if err != nil {
log.Fatal(err)
}
// func NewGiteaBot(user, pass, host, string, DBPath string) *GiteaBot {
mygiteabot = NewGiteaBot(matrixUser, matrixPass, matrixHost, dbPath)
log.Debug("Bot created")
if err != nil {
log.Fatal(err)
}
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()
}