40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package chat
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"gopkg.in/telebot.v3"
|
|
"me.thuanle/bbot/internal/services/tele/chat/helper"
|
|
)
|
|
|
|
func ReplyMessage(context telebot.Context, formattedText string, opts ...interface{}) error {
|
|
if opts == nil {
|
|
return context.Reply(formattedText, telebot.ModeHTML, telebot.NoPreview)
|
|
}
|
|
return context.Reply(formattedText, append(opts, telebot.ModeHTML, telebot.NoPreview)...)
|
|
}
|
|
|
|
func ReplyMessagef(context telebot.Context, menu *telebot.ReplyMarkup, format string, v ...interface{}) error {
|
|
if menu != nil {
|
|
return ReplyMessage(context, fmt.Sprintf(format, v...), menu)
|
|
} else {
|
|
return ReplyMessage(context, fmt.Sprintf(format, v...))
|
|
}
|
|
}
|
|
|
|
func ReplyMessageCode(context telebot.Context, message string) error {
|
|
return ReplyMessage(context, helper.Code(message))
|
|
}
|
|
|
|
func ReplyMessagePre(context telebot.Context, message string) error {
|
|
return ReplyMessage(context, helper.Pre(message))
|
|
}
|
|
|
|
func ReplyMessageJson(context telebot.Context, obj any) error {
|
|
jsonStr, err := json.MarshalIndent(obj, "", " ")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ReplyMessagePre(context, string(jsonStr))
|
|
}
|