add /send_new_year_to_chat

This commit is contained in:
2022-11-26 16:59:35 +07:00
parent 84389e11bd
commit cb7c313386
3 changed files with 59 additions and 46 deletions
+15 -5
View File
@@ -138,6 +138,12 @@ func run() {
w.WriteHeader(http.StatusOK)
_, _ = fmt.Fprintf(w, `{"result":"ok"}`)
})
http.HandleFunc("/send_new_year_to_chat", func(w http.ResponseWriter, r *http.Request) {
sendNewYearToChat(bot, opts.ChatID, imageService)
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)
@@ -191,11 +197,7 @@ func run() {
send(bot, tgbot.NewMessage(chatID, messages.WeatherMessage(w)))
case commands.NewYear:
url := imageService.GetRandomImageURL()
message := imageService.GetRandomMessage()
msg := tgbot.NewPhotoShare(chatID, url)
msg.Caption = messages.NewYearMessage(message)
send(bot, msg)
sendNewYearToChat(bot, chatID, imageService)
default:
}
@@ -234,3 +236,11 @@ func sendTomorrowLessonsToChat(bot *tgbot.BotAPI, chatID int64, prefix string) {
),
)
}
func sendNewYearToChat(bot *tgbot.BotAPI, chatID int64, imageService new_year_service.NewYearService) {
url := imageService.GetRandomImageURL()
message := imageService.GetRandomMessage()
msg := tgbot.NewPhotoShare(chatID, url)
msg.Caption = messages.NewYearMessage(message)
send(bot, msg)
}