package main

import (
	"flag"
	"fmt"
	"os"
	"time"

	"watn3y.de/bloaterbot/commands/gaypoints"
	"watn3y.de/bloaterbot/commands/notify"
	"watn3y.de/bloaterbot/config"
	"watn3y.de/bloaterbot/webserver"

	"github.com/rs/zerolog"
	"github.com/rs/zerolog/log"
)

func main() {
	fmt.Println("Starting bloaterbot...")

	configureLogger()

	encodeConfig := flag.Bool("generate-example-config", false, "Generates a example config to config.toml.example")
	flag.Parse()
	if *encodeConfig {
		config.EncodeToml()
		os.Exit(0)
	}

	config.LoadConfig()

	gaypoints.InitDB()

	notify.InitDB()

	go webserver.RunServer()

	bot()

}

func configureLogger() {
	output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.DateTime}

	log.Logger = zerolog.New(output).With().Timestamp().Caller().Logger()

	//! note that we overwrite the loglevel after loading the config in config/config.go:53. This is just the default
	zerolog.SetGlobalLevel(zerolog.TraceLevel)

	log.Info().Msg("Started logger")

}