init code
This commit is contained in:
9
internal/services/tele/chat/helper/wrap.go
Normal file
9
internal/services/tele/chat/helper/wrap.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package helper
|
||||
|
||||
func Pre(msg string) string {
|
||||
return "<pre>" + msg + "</pre>"
|
||||
}
|
||||
|
||||
func Code(msg string) string {
|
||||
return "<code>" + msg + "</code>"
|
||||
}
|
||||
39
internal/services/tele/chat/reply.go
Normal file
39
internal/services/tele/chat/reply.go
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user