From 5a6f0f2b2e79575e1979a9cd7f86c1ff8c4dae94 Mon Sep 17 00:00:00 2001 From: totanvix Date: Tue, 28 Nov 2023 03:59:15 +0000 Subject: [PATCH] debug --- .devcontainer/devcontainer.json | 9 ++++++- README.md | 2 ++ api/hook/index.go | 3 +++ api/index.go | 3 --- api/trip/index.go | 44 --------------------------------- utils/bot/bot.go | 4 +++ 6 files changed, 17 insertions(+), 48 deletions(-) delete mode 100644 api/trip/index.go diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4fbc4e2..8bfc778 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -22,5 +22,12 @@ // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. "remoteUser": "root", - "initializeCommand": "git config --global alias.co checkout && git config --global alias.br branch && git config --global alias.ci commit && git config --global alias.st status" + "initializeCommand": "git config --global alias.co checkout && git config --global alias.br branch && git config --global alias.ci commit && git config --global alias.st status", + "customizations": { + "vscode": { + "extensions": [ + "rangav.vscode-thunder-client" + ] + } + } } diff --git a/README.md b/README.md index cc4a396..e2851eb 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [Zeril Bot](https://t.me/zerill_bot) is my practice using Go +## Development + ## Lesson Learned * Go and things in Go * Vercel Serverless Function diff --git a/api/hook/index.go b/api/hook/index.go index a333370..43030bb 100644 --- a/api/hook/index.go +++ b/api/hook/index.go @@ -2,6 +2,7 @@ package hook import ( "encoding/json" + "fmt" "net/http" "zeril-bot/utils/bot" "zeril-bot/utils/structs" @@ -15,6 +16,8 @@ func Handler(w http.ResponseWriter, r *http.Request) { panic(err) } + fmt.Println("Handler") + fmt.Println(data) telegram := telegram.New(&http.Client{}, telegram.BASE_URL) bot := bot.NewBot(telegram, data) diff --git a/api/index.go b/api/index.go index 21bd870..28cb469 100644 --- a/api/index.go +++ b/api/index.go @@ -3,7 +3,6 @@ package api import ( "net/http" "zeril-bot/api/hook" - "zeril-bot/api/trip" "zeril-bot/api/url" "zeril-bot/utils/middleware" @@ -24,8 +23,6 @@ func Handler(wri http.ResponseWriter, req *http.Request) { }) r.Post("/api/hook", hook.Handler) r.Get("/url", url.Handler) - r.Get("/trip", trip.Handler) - r.Post("/trip", trip.Handler) r.ServeHTTP(wri, req) } diff --git a/api/trip/index.go b/api/trip/index.go deleted file mode 100644 index 4844108..0000000 --- a/api/trip/index.go +++ /dev/null @@ -1,44 +0,0 @@ -package trip - -import ( - "encoding/json" - "net/http" - "zeril-bot/utils/redis" -) - -type data struct { - Url string `json:"url"` -} - -func Handler(w http.ResponseWriter, r *http.Request) { - method := r.Method - - if method == http.MethodPost { - var d data - // Try to decode the request body into the struct. If there is an error, - // respond to the client with the error message and a 400 status code. - err := json.NewDecoder(r.Body).Decode(&d) - if err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - - redis.Set("trip", d.Url, 0) - Response(w, d.Url) - - } else { - url := redis.Get("trip") - Response(w, url.Val()) - } -} - -func Response(w http.ResponseWriter, url string) { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - resp := make(map[string]string) - resp["url"] = url - - jsonResp, _ := json.Marshal(resp) - w.Write(jsonResp) - return -} diff --git a/utils/bot/bot.go b/utils/bot/bot.go index 8b48cf6..8edfa7a 100644 --- a/utils/bot/bot.go +++ b/utils/bot/bot.go @@ -2,6 +2,7 @@ package bot import ( "errors" + "fmt" "log" "strings" "time" @@ -88,6 +89,9 @@ func (b Bot) resolveCommand() error { data := b.getTelegramData() + fmt.Println("resolveCommand") + fmt.Println(data) + switch data.Command { case "/start", "/start@zerill_bot": err = b.sendStartMessage(data)