diff --git a/internal/controller/pipes/qq_onebot/onebot.go b/internal/controller/pipes/qq_onebot/onebot.go index 2a9ddc2..561e7d2 100644 --- a/internal/controller/pipes/qq_onebot/onebot.go +++ b/internal/controller/pipes/qq_onebot/onebot.go @@ -165,7 +165,7 @@ func (c *Client) SendMsg(targetType string, targetID int64, msg string, hasAt bo } if actionLogEnabled() { - postLog.Debug(fmt.Sprintf("[OneBot] SendMsg -> %s (%s): %s", endpoint, targetType, message)) + postLog.Debug(fmt.Sprintf("[qq_onebot] SendMsg -> %s (%s): %s", endpoint, targetType, message)) } respBody, err := c.sendRequest(http.MethodPost, endpoint, reqBody) @@ -186,7 +186,7 @@ func (c *Client) RecallMsg(msgID int64) (*APIResponse, error) { } if actionLogEnabled() { - postLog.Debug(fmt.Sprintf("[OneBot] RecallMsg -> /delete_msg: %d", msgID)) + postLog.Debug(fmt.Sprintf("[qq_onebot] RecallMsg -> /delete_msg: %d", msgID)) } respBody, err := c.sendRequest(http.MethodPost, "/delete_msg", reqBody) @@ -200,7 +200,7 @@ func (c *Client) RecallMsg(msgID int64) (*APIResponse, error) { // GetGroupList retrieves the list of joined groups from OneBot. func (c *Client) GetGroupList() (*APIResponse, error) { if actionLogEnabled() { - postLog.Debug("[OneBot] GetGroupList -> /get_group_list") + postLog.Debug("[qq_onebot] GetGroupList -> /get_group_list") } respBody, err := c.sendRequest(http.MethodGet, "/get_group_list", nil) @@ -221,7 +221,7 @@ func (c *Client) GetGroupInfo(groupID int64) (*APIResponse, error) { } if actionLogEnabled() { - postLog.Debug(fmt.Sprintf("[OneBot] GetGroupInfo -> /get_group_info: %d", groupID)) + postLog.Debug(fmt.Sprintf("[qq_onebot] GetGroupInfo -> /get_group_info: %d", groupID)) } respBody, err := c.sendRequest(http.MethodPost, "/get_group_info", reqBody) @@ -235,7 +235,7 @@ func (c *Client) GetGroupInfo(groupID int64) (*APIResponse, error) { // GetFriendsList retrieves the friends list from OneBot. func (c *Client) GetFriendsList() (*APIResponse, error) { if actionLogEnabled() { - postLog.Debug("[OneBot] GetFriendsList -> /get_friend_list") + postLog.Debug("[qq_onebot] GetFriendsList -> /get_friend_list") } respBody, err := c.sendRequest(http.MethodGet, "/get_friend_list", nil) @@ -259,7 +259,7 @@ func (c *Client) Listen(onEvent func(raw []byte)) { c.listenOnce(onEvent) - postLog.Warning("[OneBot] WebSocket disconnected, reconnecting in 5s...") + postLog.Warning("[qq_onebot] WebSocket disconnected, reconnecting in 5s...") select { case <-c.stopCh: return @@ -282,7 +282,7 @@ func (c *Client) listenOnce(onEvent func(raw []byte)) { dialer.Proxy = netproxy.ProxyFunc(c.useProxy) conn, _, err := dialer.Dial(wsURL, header) if err != nil { - postLog.Error(fmt.Sprintf("[OneBot] Failed to connect to OneBot WebSocket: %v", err)) + postLog.Error(fmt.Sprintf("[qq_onebot] Failed to connect to OneBot WebSocket: %v", err)) return } @@ -298,7 +298,7 @@ func (c *Client) listenOnce(onEvent func(raw []byte)) { conn.Close() }() - postLog.Info(fmt.Sprintf("[OneBot] Connected to OneBot WebSocket at %s", wsURL)) + postLog.Info(fmt.Sprintf("[qq_onebot] Connected to OneBot WebSocket at %s", wsURL)) for { select { @@ -309,7 +309,7 @@ func (c *Client) listenOnce(onEvent func(raw []byte)) { _, msgBytes, err := conn.ReadMessage() if err != nil { - postLog.Error(fmt.Sprintf("[OneBot] WebSocket read error: %v", err)) + postLog.Error(fmt.Sprintf("[qq_onebot] WebSocket read error: %v", err)) return } diff --git a/internal/controller/pipes/qq_onebot/qq.go b/internal/controller/pipes/qq_onebot/qq.go index 970e296..697643d 100644 --- a/internal/controller/pipes/qq_onebot/qq.go +++ b/internal/controller/pipes/qq_onebot/qq.go @@ -56,15 +56,15 @@ func (q *QQController) Start() error { return nil } if q.onebotClient == nil { - postLog.Warning("QQ (OneBot) controller enabled but OneBot client is nil") + postLog.Warning("[qq_onebot] QQ (OneBot) controller enabled but OneBot client is nil") return nil } - postLog.Info("QQ (OneBot) controller started, connecting to OneBot WebSocket...") + postLog.Info("[qq_onebot] QQ (OneBot) controller started, connecting to OneBot WebSocket...") go func() { defer func() { if r := recover(); r != nil { - postLog.Error(fmt.Sprintf("OneBot WS listener panic recovered: %v", r)) + postLog.Error("[qq_onebot] OneBot WS listener panic recovered: " + fmt.Sprintf("%v", r)) } }() q.onebotClient.Listen(q.handleOneBotEvent) @@ -78,7 +78,7 @@ func (q *QQController) Stop() { if q.onebotClient != nil { q.onebotClient.Stop() } - postLog.Info("QQ (OneBot) controller stopped") + postLog.Info("[qq_onebot] QQ (OneBot) controller stopped") } // IsEnabled returns whether the controller is enabled. @@ -96,7 +96,7 @@ func (q *QQController) IsMarkdown() bool { func (q *QQController) handleOneBotEvent(raw []byte) { var ev oneBotEvent if err := json.Unmarshal(raw, &ev); err != nil { - postLog.Debug("Failed to parse OneBot WS event: " + err.Error()) + postLog.Debug("[qq_onebot] Failed to parse OneBot WS event: " + err.Error()) return } @@ -111,13 +111,13 @@ func (q *QQController) handleOneBotEvent(raw []byte) { showAction := debugMode && cfg.Debug.ShowOneBotAction if debugMode && cfg.Debug.ShowOneBotMsg { - postLog.Debug("OneBot WS event received: " + string(raw)) + postLog.Debug("[qq_onebot] OneBot WS event received: " + string(raw)) } // Only handle message events; ignore notice/request/meta_event. if ev.PostType != "message" { if showAction { - postLog.Debug("Ignoring OneBot WS event: " + string(raw)) + postLog.Debug("[qq_onebot] Ignoring OneBot WS event: " + string(raw)) } return } @@ -128,7 +128,7 @@ func (q *QQController) handleOneBotEvent(raw []byte) { } if q.isSelfMessage(ev) && debugMode && cfg.Debug.OneBotIgnoreSelfMsg { if showAction { - postLog.Debug("Ignoring OneBot WS self message: " + string(raw)) + postLog.Debug("[qq_onebot] Ignoring OneBot WS self message: " + string(raw)) } return } @@ -149,7 +149,7 @@ func (q *QQController) handleOneBotEvent(raw []byte) { response := q.processCommand(cmd) if response == "" { if showAction { - postLog.Debug("OneBot WS command discarded: " + string(raw)) + postLog.Debug("[qq_onebot] OneBot WS command discarded: " + string(raw)) } return } @@ -157,11 +157,11 @@ func (q *QQController) handleOneBotEvent(raw []byte) { // Reply in the same chat. if ev.MessageType == "private" { if _, err := q.onebotClient.SendMsg("private", ev.UserID, response, false, 0); err != nil { - postLog.Warning("Failed to send OneBot private reply: " + err.Error()) + postLog.Warning("[qq_onebot] Failed to send OneBot private reply: " + err.Error()) } } else { if _, err := q.onebotClient.SendMsg("group", ev.GroupID, response, false, 0); err != nil { - postLog.Warning("Failed to send OneBot group reply: " + err.Error()) + postLog.Warning("[qq_onebot] Failed to send OneBot group reply: " + err.Error()) } } } @@ -180,7 +180,7 @@ func (q *QQController) processCommand(cmd controller.Command) string { atMention := fmt.Sprintf("[CQ:at,qq=%d]", q.cfg.BotQQID) if !strings.Contains(text, atMention) { if cfg != nil && cfg.System.DebugMode && cfg.Debug.ShowOneBotAction { - postLog.Debug("OneBot WS message ignored (no @mention): " + text) + postLog.Debug("[qq_onebot] OneBot WS message ignored (no @mention): " + text) } return "" // Not mentioned, ignore. } @@ -205,7 +205,7 @@ func (q *QQController) processCommand(cmd controller.Command) string { postLog.Debug(fmt.Sprintf("[qq_onebot] 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("OneBot command processing failed: " + err.Error()) + postLog.Error("[qq_onebot] OneBot command processing failed: " + err.Error()) return "" } return response @@ -342,34 +342,34 @@ func (q *QQController) SendAlert(alert controller.Alert) error { func (q *QQController) sendGroupMessage(groupID string, message string) { if q.onebotClient == nil { - postLog.Warning("Cannot send QQ group message: OneBot client not initialized") + postLog.Warning("[qq_onebot] Cannot send QQ group message: OneBot client not initialized") return } var groupIDInt int64 if _, err := fmt.Sscanf(groupID, "%d", &groupIDInt); err != nil || groupIDInt == 0 { - postLog.Warning(fmt.Sprintf("Invalid QQ group ID: %s", groupID)) + postLog.Warning("[qq_onebot] Invalid QQ group ID: " + groupID) return } if _, err := q.onebotClient.SendMsg("group", groupIDInt, message, false, 0); err != nil { - postLog.Warning(fmt.Sprintf("Failed to send QQ group message to %s: %v", groupID, err)) + postLog.Warning("[qq_onebot] Failed to send QQ group message to " + groupID + ": " + err.Error()) } } func (q *QQController) sendPrivateMessage(userID string, message string) { if q.onebotClient == nil { - postLog.Warning("Cannot send QQ private message: OneBot client not initialized") + postLog.Warning("[qq_onebot] Cannot send QQ private message: OneBot client not initialized") return } var userIDInt int64 if _, err := fmt.Sscanf(userID, "%d", &userIDInt); err != nil || userIDInt == 0 { - postLog.Warning(fmt.Sprintf("Invalid QQ user ID: %s", userID)) + postLog.Warning("[qq_onebot] Invalid QQ user ID: " + userID) return } if _, err := q.onebotClient.SendMsg("private", userIDInt, message, false, 0); err != nil { - postLog.Warning(fmt.Sprintf("Failed to send QQ private message to %s: %v", userID, err)) + postLog.Warning("[qq_onebot] Failed to send QQ private message to " + userID + ": " + err.Error()) } }