some cleanup
This commit is contained in:
parent
11eccdd3a8
commit
514688e72b
47
main.go
47
main.go
@ -50,7 +50,8 @@ func main() {
|
||||
}
|
||||
|
||||
if update.Message != nil {
|
||||
go sendButtonAndDelete(update.Message.Chat.ID, update.Message.ID, update.Message.Text)
|
||||
go sendButton(update.Message.Chat.ID, update.Message.ID, update.Message.Text)
|
||||
go DeleteMessage(update.Message.Chat.ID, update.Message.ID)
|
||||
} else if update.CallbackQuery != nil {
|
||||
go markButtonChecked(update.CallbackQuery.Message.Chat.ID, update.CallbackQuery.Message.ID, update.CallbackQuery.Data)
|
||||
go answerCallbackQuery(update.CallbackQuery.ID)
|
||||
@ -86,12 +87,7 @@ func markButtonChecked(chatID int, messageID int, text string) {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
log.Println(string(body))
|
||||
logBody(resp.Body)
|
||||
}
|
||||
|
||||
func answerCallbackQuery(callbackQueryID string) {
|
||||
@ -101,27 +97,25 @@ func answerCallbackQuery(callbackQueryID string) {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
log.Println(string(body))
|
||||
logBody(resp.Body)
|
||||
}
|
||||
|
||||
func sendButtonAndDelete(chatID int, messageID int, text string) {
|
||||
func sendButton(chatID int, messageID int, text string) {
|
||||
url := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", apiToken)
|
||||
sendMsgFmt := `
|
||||
{
|
||||
"chat_id": "%d",
|
||||
"text": "ok",
|
||||
"reply_markup": {
|
||||
"inline_keyboard": [[
|
||||
"inline_keyboard": [
|
||||
[
|
||||
{
|
||||
"text": "%s",
|
||||
"callback_data": "%s"
|
||||
}
|
||||
]]
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
`
|
||||
sendMsgReq := fmt.Sprintf(sendMsgFmt, chatID, text, text)
|
||||
@ -130,19 +124,26 @@ func sendButtonAndDelete(chatID int, messageID int, text string) {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
logBody(resp.Body)
|
||||
}
|
||||
log.Println(string(body))
|
||||
func DeleteMessage(chatID int, messageID int) {
|
||||
deleteUrl := fmt.Sprintf("https://api.telegram.org/bot%s/deleteMessage?chat_id=%d&message_id=%d", apiToken, chatID, messageID)
|
||||
resp, err = http.Get(deleteUrl)
|
||||
resp, err := http.Get(deleteUrl)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
body, err = io.ReadAll(resp.Body)
|
||||
logBody(resp.Body)
|
||||
}
|
||||
|
||||
func logBody(respBody io.ReadCloser) {
|
||||
defer func() {
|
||||
err := respBody.Close()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}()
|
||||
body, err := io.ReadAll(respBody)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user