From bde8e7dae0cb6e1e016d3d375f48787d058278e5 Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Sun, 4 Sep 2022 22:32:58 +0700 Subject: [PATCH] add server and update /help --- main.go | 15 ++++++++++++++- messages/messages.go | 6 ++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 3a885ea..e141d29 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "log" "math/rand" + "net/http" "os" "strings" "student_bot/commands" @@ -101,6 +102,18 @@ func run() { log.Panicln(err) } + go func() { + http.HandleFunc("/send_today_lessons_to_chat", func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = fmt.Fprintf(w, `{"result":"ok"}`) + }) + + port := ":10001" + log.Println("Server is start up! port", port) + log.Fatal(http.ListenAndServe(port, nil)) + }() + log.Println("Bot is start up!") for update := range updates { @@ -129,7 +142,7 @@ func run() { send(bot, tgbot.NewMessage(chatId, messages.StartMessage())) case commands.Help: - send(bot, tgbot.NewMessage(chatId, messages.HelpMessage())) + send(bot, tgbot.NewMessage(chatId, messages.HelpMessage(chatId))) case commands.Ping: send(bot, tgbot.NewMessage(chatId, messages.PongMessage())) diff --git a/messages/messages.go b/messages/messages.go index 76c8420..24ef9a2 100644 --- a/messages/messages.go +++ b/messages/messages.go @@ -3,6 +3,7 @@ package messages import ( "fmt" "math/rand" + "strconv" "strings" "student_bot/new_year_service" "student_bot/parser" @@ -27,14 +28,15 @@ func ThanksMessage() string { return thanksMessages[rand.Intn(len(thanksMessages)-1)] } -func HelpMessage() string { +func HelpMessage(chatID int64) string { return "Вот чем я могу вам помочь (v1.0.4), отправь:\n\n" + "- /ping отобью pong\n" + "- /today_lessons покажу расписание на сегодня\n" + "- /tomorrow_lessons покажу расписание на завтра\n" + "- /weather покажу погоду у универа\n" + "- /new_year - посчитаю количество дней до нового года\n" + - "\nНу а больше я пока ничего не умею" + "\nНу а больше я пока ничего не умею" + + "\nВаш chatID: " + strconv.FormatInt(chatID, 10) } func PongMessage() string {