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

24
bot.go
View File

@ -9,6 +9,14 @@ import (
"strings"
)
type ParseMode string
const (
ParseMDV2 ParseMode = "MarkdownV2"
ParseHTML ParseMode = "HTML"
ParseMD ParseMode = "Markdown"
)
type Bot struct {
token string
logger *Logger
@ -184,14 +192,26 @@ func (b *Bot) Debug(debug bool) *Bot {
func (ctx *MsgContext) Answer(text string) {
_, err := ctx.Bot.SendMessage(&SendMessageP{
ChatID: ctx.Msg.Chat.ID,
Text: text,
ChatID: ctx.Msg.Chat.ID,
Text: text,
ParseMode: "markdown",
})
if err != nil {
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 {
return b.logger
}

View File

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

View File

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