diff --git a/.dockerignore b/.dockerignore index 42061c0..6c50d70 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ -README.md \ No newline at end of file +README.md +.vscode \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..600d2d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode \ No newline at end of file diff --git a/go.mod b/go.mod index 2b262ff..6d000e2 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/Masterminds/goutils v1.1.0 // indirect github.com/Masterminds/semver v1.4.2 // indirect github.com/Masterminds/sprig v2.20.0+incompatible + github.com/go-kit/kit v0.8.0 github.com/google/uuid v1.1.1 // indirect github.com/huandu/xstrings v1.2.0 // indirect github.com/imdario/mergo v0.3.7 // indirect diff --git a/main.go b/main.go index ba7ad1f..8201613 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "git.fromouter.space/mcg/mlp-server-tools/draftbot" "git.fromouter.space/hamcha/tg" + "github.com/go-kit/kit/log" "github.com/spf13/viper" ) @@ -24,6 +25,7 @@ func checkErr(err error, msg string, args ...interface{}) { var api *tg.Telegram var botname string var tgapi *tgInterface +var logger log.Logger func main() { viper.AutomaticEnv() @@ -55,6 +57,10 @@ func main() { initTemplates() + logger = log.NewLogfmtLogger(os.Stderr) + logger = log.With(logger, "ts", log.DefaultTimestampUTC) + logger = log.With(logger, "caller", log.DefaultCaller) + // Ignore CA errors http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} @@ -65,8 +71,9 @@ func main() { usermap: make(map[string]int64), } bot := draftbot.NewDraftBot(tgapi, botname) + bot.Logger = logger tgapi.Bind(bot) - api.HandleWebhook(bind, webhookPath, webhook) + logger.Log("err", api.HandleWebhook(bind, webhookPath, webhook)) } func webhook(update tg.APIUpdate) { @@ -77,15 +84,15 @@ func webhook(update tg.APIUpdate) { } switch msg.Chat.Type { case tg.ChatTypeGroup, tg.ChatTypeSupergroup: - if isCommand(msg, "/newdraft") { - tgapi.StartDraft(msg.Chat, msg.User) + if isCommand(msg, "newdraft") { + tgapi.NewDraft(msg.Chat, msg.User) return } - if isCommand(msg, "/join") { + if isCommand(msg, "join") { tgapi.JoinDraft(msg.Chat, msg.User) return } - if isCommand(msg, "/begindraft") { + if isCommand(msg, "startdraft") { tgapi.StartDraft(msg.Chat, msg.User) return }