init code

This commit is contained in:
thuanle
2024-10-24 09:53:23 +07:00
parent a7559b3f9d
commit 92a63c7885
43 changed files with 1115 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
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))
}