feat(controller): add source for command handling.

feat(telegram): switch message type to markdown
feat(controller): add welcome message for telegram bot.
This commit is contained in:
2026-08-13 17:07:55 +08:00
parent 8589654ba4
commit f2cc16177c
8 changed files with 90 additions and 65 deletions
+2 -2
View File
@@ -179,12 +179,12 @@ func (q *QQController) processCommand(cmd controller.Command) string {
parsed.ChatID = cmd.ChatID
parsed.ChatType = cmd.ChatType
parsed.SenderID = cmd.SenderID
parsed.Source = "qq_napcat"
// Hand the complete command to the unified processor, which checks group
// vs private, trusted groups, admin permissions, and executes it.
response, err := controller.GetManager().Trigger(parsed, q.cfg.TrustedGroups, q.cfg.Admins, q.cfg.ListenMethod)
cfg := config.GetConfig()
if cfg.System.DebugMode && cfg.Debug.ShowTriggerCmdEcho {
if config.GetConfig().System.DebugMode && config.GetConfig().Debug.ShowTriggerCmdEcho {
postLog.Debug(fmt.Sprintf("[qq_napcat] triggered command: \"/%s\" with args: \"%s\" from chatID: %d and senderID: %d", parsed.Command, strings.Join(parsed.Args, ", "), cmd.ChatID, cmd.SenderID))
}
if err != nil {
+8 -4
View File
@@ -182,8 +182,11 @@ func (c *Client) getUpdates(offset int64, limit, timeout int) ([]Update, error)
}
// SendMessage sends a text message to a chat, splitting it into chunks that
// fit Telegram's 4096-character limit. The text is sent without a parse mode so
// template asterisks render literally.
// fit Telegram's 4096-character limit. All messages are sent with
// parse_mode=Markdown so fenced code blocks and inline formatting render as
// rich text. Templates must stay valid under Telegram's legacy Markdown:
// unpaired '*' or '_' characters (e.g. a lone '*Event: ...' label) make the
// API reject the whole message.
func (c *Client) SendMessage(chatID int64, text string) error {
if strings.TrimSpace(text) == "" {
return nil
@@ -198,8 +201,9 @@ func (c *Client) SendMessage(chatID int64, text string) error {
func (c *Client) sendMessageChunk(chatID int64, text string) error {
params := url.Values{
"chat_id": {strconv.FormatInt(chatID, 10)},
"text": {text},
"chat_id": {strconv.FormatInt(chatID, 10)},
"text": {text},
"parse_mode": {"Markdown"},
}
return c.call("sendMessage", params, nil)
}
@@ -169,10 +169,14 @@ func (t *TelegramController) processCommand(cmd controller.Command) string {
parsed.ChatID = cmd.ChatID
parsed.ChatType = cmd.ChatType
parsed.SenderID = cmd.SenderID
parsed.Source = "telegram"
// Hand the complete command to the unified processor, which checks group
// vs private, trusted groups, admin permissions, and executes it.
response, err := controller.GetManager().Trigger(parsed, t.cfg.TrustedGroups, t.resolvedAdminList(), t.cfg.ListenMethod)
if config.GetConfig().System.DebugMode && config.GetConfig().Debug.ShowTriggerCmdEcho {
postLog.Debug(fmt.Sprintf("[telegram] triggered command: \"/%s\" with args: \"%s\" from chatID: %d and senderID: %d", parsed.Command, strings.Join(parsed.Args, ", "), cmd.ChatID, cmd.SenderID))
}
if err != nil {
postLog.Error("Telegram command processing failed: " + err.Error())
return ""