BeeBot/cmd/beebot/main.go

57 lines
1.2 KiB
Go
Raw Normal View History

2020-04-11 17:51:10 +00:00
package main
import (
"flag"
"fmt"
2021-10-05 22:52:59 +00:00
"os"
2021-10-05 22:52:59 +00:00
beebot "code.chrissexton.org/cws/BeeBot"
"github.com/jzelinskie/geddit"
2021-10-05 22:52:59 +00:00
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
_ "modernc.org/sqlite"
2020-04-11 17:51:10 +00:00
)
const version = 1.0
2020-04-22 14:59:33 +00:00
var userAgent = fmt.Sprintf("BeeBot:%.2f (by u/phlyingpenguin)", version)
var scopes = "identity read edit"
2021-10-05 22:52:59 +00:00
var debug = flag.Bool("debug", false, "Turn debug printing on")
var dbFilePath = flag.String("db", "beebot.db", "Database file path")
var logFilePath = flag.String("log", "beebot.json", "Log file path")
var o *geddit.OAuthSession
2020-04-11 17:51:10 +00:00
func main() {
flag.Parse()
2021-10-05 22:52:59 +00:00
zerolog.SetGlobalLevel(zerolog.InfoLevel)
if *debug {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
2021-10-05 22:52:59 +00:00
consoleWriter := zerolog.ConsoleWriter{Out: os.Stdout}
logFile, err := os.OpenFile(*logFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
2020-04-22 14:59:33 +00:00
if err != nil {
2021-10-05 22:52:59 +00:00
panic(err)
2020-04-22 14:59:33 +00:00
}
2021-10-05 22:52:59 +00:00
multi := zerolog.MultiLevelWriter(consoleWriter, logFile)
2021-10-05 22:52:59 +00:00
log.Logger = zerolog.New(multi).
With().Timestamp().Caller().Stack().
Logger()
2021-10-05 22:52:59 +00:00
log.Info().Msgf("BeeBot v%.2f", version)
2021-10-05 22:52:59 +00:00
b, err := beebot.New(*dbFilePath, *logFilePath, *debug)
2020-04-22 14:59:33 +00:00
if err != nil {
2021-10-05 22:52:59 +00:00
log.Fatal().Err(err).Msg("beebot died")
}
2021-10-05 22:52:59 +00:00
// b.Run()
b.ServeWeb()
2020-04-11 17:51:10 +00:00
}