parsemode

This commit is contained in:
ScuroNeko 2024-12-17 15:31:37 +03:00
parent 186ad8e95b
commit c5b7ca8ae8
3 changed files with 25 additions and 3 deletions

20
bot.go
View File

@ -9,6 +9,14 @@ import (
"strings" "strings"
) )
type ParseMode string
const (
ParseMDV2 ParseMode = "MarkdownV2"
ParseHTML ParseMode = "HTML"
ParseMD ParseMode = "Markdown"
)
type Bot struct { type Bot struct {
token string token string
logger *Logger logger *Logger
@ -186,12 +194,24 @@ func (ctx *MsgContext) Answer(text string) {
_, err := ctx.Bot.SendMessage(&SendMessageP{ _, err := ctx.Bot.SendMessage(&SendMessageP{
ChatID: ctx.Msg.Chat.ID, ChatID: ctx.Msg.Chat.ID,
Text: text, Text: text,
ParseMode: "markdown",
}) })
if err != nil { if err != nil {
ctx.Bot.logger.Error(err) ctx.Bot.logger.Error(err)
} }
} }
func (ctx *MsgContext) Error(err error) {
_, sendErr := ctx.Bot.SendMessage(&SendMessageP{
ChatID: ctx.Msg.Chat.ID,
Text: err.Error(),
})
if sendErr != nil {
ctx.Bot.logger.Error(sendErr)
}
}
func (b *Bot) Logger() *Logger { func (b *Bot) Logger() *Logger {
return b.logger return b.logger
} }

View File

@ -54,7 +54,7 @@ type SendMessageP struct {
ChatID int `json:"chat_id"` ChatID int `json:"chat_id"`
MessageThreadID int `json:"message_thread_id,omitempty"` MessageThreadID int `json:"message_thread_id,omitempty"`
Text string `json:"text"` Text string `json:"text"`
ParseMode string `json:"parse_mode,omitempty"` ParseMode ParseMode `json:"parse_mode,omitempty"`
Entities []*MessageEntity `json:"entities,omitempty"` Entities []*MessageEntity `json:"entities,omitempty"`
LinkPreviewOptions *LinkPreviewOptions `json:"link_preview_options,omitempty"` LinkPreviewOptions *LinkPreviewOptions `json:"link_preview_options,omitempty"`
DisableNotifications bool `json:"disable_notifications,omitempty"` DisableNotifications bool `json:"disable_notifications,omitempty"`

View File

@ -49,6 +49,8 @@ type Message struct {
From *User `json:"from,omitempty"` From *User `json:"from,omitempty"`
Chat *Chat `json:"chat,omitempty"` Chat *Chat `json:"chat,omitempty"`
Text string `json:"text"` Text string `json:"text"`
ReplyToMessage *Message `json:"reply_to_message"`
} }
type InaccessableMessage struct { type InaccessableMessage struct {