refactor(qq_onebot): update log messages to use consistent prefix
This commit is contained in:
1 parent
1b11be2427
commit
ba0d8539b3
2 files changed
+28
-28
No files matched your search
@@ -165,7 +165,7 @@ func (c *Client) SendMsg(targetType string, targetID int64, msg string, hasAt bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if actionLogEnabled() {
|
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)
|
respBody, err := c.sendRequest(http.MethodPost, endpoint, reqBody)
|
||||||
@@ -186,7 +186,7 @@ func (c *Client) RecallMsg(msgID int64) (*APIResponse, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if actionLogEnabled() {
|
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)
|
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.
|
// GetGroupList retrieves the list of joined groups from OneBot.
|
||||||
func (c *Client) GetGroupList() (*APIResponse, error) {
|
func (c *Client) GetGroupList() (*APIResponse, error) {
|
||||||
if actionLogEnabled() {
|
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)
|
respBody, err := c.sendRequest(http.MethodGet, "/get_group_list", nil)
|
||||||
@@ -221,7 +221,7 @@ func (c *Client) GetGroupInfo(groupID int64) (*APIResponse, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if actionLogEnabled() {
|
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)
|
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.
|
// GetFriendsList retrieves the friends list from OneBot.
|
||||||
func (c *Client) GetFriendsList() (*APIResponse, error) {
|
func (c *Client) GetFriendsList() (*APIResponse, error) {
|
||||||
if actionLogEnabled() {
|
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)
|
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)
|
c.listenOnce(onEvent)
|
||||||
|
|
||||||
postLog.Warning("[OneBot] WebSocket disconnected, reconnecting in 5s...")
|
postLog.Warning("[qq_onebot] WebSocket disconnected, reconnecting in 5s...")
|
||||||
select {
|
select {
|
||||||
case <-c.stopCh:
|
case <-c.stopCh:
|
||||||
return
|
return
|
||||||
@@ -282,7 +282,7 @@ func (c *Client) listenOnce(onEvent func(raw []byte)) {
|
|||||||
dialer.Proxy = netproxy.ProxyFunc(c.useProxy)
|
dialer.Proxy = netproxy.ProxyFunc(c.useProxy)
|
||||||
conn, _, err := dialer.Dial(wsURL, header)
|
conn, _, err := dialer.Dial(wsURL, header)
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,7 +298,7 @@ func (c *Client) listenOnce(onEvent func(raw []byte)) {
|
|||||||
conn.Close()
|
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 {
|
for {
|
||||||
select {
|
select {
|
||||||
@@ -309,7 +309,7 @@ func (c *Client) listenOnce(onEvent func(raw []byte)) {
|
|||||||
|
|
||||||
_, msgBytes, err := conn.ReadMessage()
|
_, msgBytes, err := conn.ReadMessage()
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,15 +56,15 @@ func (q *QQController) Start() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if q.onebotClient == 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
|
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() {
|
go func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
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)
|
q.onebotClient.Listen(q.handleOneBotEvent)
|
||||||
@@ -78,7 +78,7 @@ func (q *QQController) Stop() {
|
|||||||
if q.onebotClient != nil {
|
if q.onebotClient != nil {
|
||||||
q.onebotClient.Stop()
|
q.onebotClient.Stop()
|
||||||
}
|
}
|
||||||
postLog.Info("QQ (OneBot) controller stopped")
|
postLog.Info("[qq_onebot] QQ (OneBot) controller stopped")
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsEnabled returns whether the controller is enabled.
|
// IsEnabled returns whether the controller is enabled.
|
||||||
@@ -96,7 +96,7 @@ func (q *QQController) IsMarkdown() bool {
|
|||||||
func (q *QQController) handleOneBotEvent(raw []byte) {
|
func (q *QQController) handleOneBotEvent(raw []byte) {
|
||||||
var ev oneBotEvent
|
var ev oneBotEvent
|
||||||
if err := json.Unmarshal(raw, &ev); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,13 +111,13 @@ func (q *QQController) handleOneBotEvent(raw []byte) {
|
|||||||
showAction := debugMode && cfg.Debug.ShowOneBotAction
|
showAction := debugMode && cfg.Debug.ShowOneBotAction
|
||||||
|
|
||||||
if debugMode && cfg.Debug.ShowOneBotMsg {
|
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.
|
// Only handle message events; ignore notice/request/meta_event.
|
||||||
if ev.PostType != "message" {
|
if ev.PostType != "message" {
|
||||||
if showAction {
|
if showAction {
|
||||||
postLog.Debug("Ignoring OneBot WS event: " + string(raw))
|
postLog.Debug("[qq_onebot] Ignoring OneBot WS event: " + string(raw))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ func (q *QQController) handleOneBotEvent(raw []byte) {
|
|||||||
}
|
}
|
||||||
if q.isSelfMessage(ev) && debugMode && cfg.Debug.OneBotIgnoreSelfMsg {
|
if q.isSelfMessage(ev) && debugMode && cfg.Debug.OneBotIgnoreSelfMsg {
|
||||||
if showAction {
|
if showAction {
|
||||||
postLog.Debug("Ignoring OneBot WS self message: " + string(raw))
|
postLog.Debug("[qq_onebot] Ignoring OneBot WS self message: " + string(raw))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -149,7 +149,7 @@ func (q *QQController) handleOneBotEvent(raw []byte) {
|
|||||||
response := q.processCommand(cmd)
|
response := q.processCommand(cmd)
|
||||||
if response == "" {
|
if response == "" {
|
||||||
if showAction {
|
if showAction {
|
||||||
postLog.Debug("OneBot WS command discarded: " + string(raw))
|
postLog.Debug("[qq_onebot] OneBot WS command discarded: " + string(raw))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -157,11 +157,11 @@ func (q *QQController) handleOneBotEvent(raw []byte) {
|
|||||||
// Reply in the same chat.
|
// Reply in the same chat.
|
||||||
if ev.MessageType == "private" {
|
if ev.MessageType == "private" {
|
||||||
if _, err := q.onebotClient.SendMsg("private", ev.UserID, response, false, 0); err != nil {
|
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 {
|
} else {
|
||||||
if _, err := q.onebotClient.SendMsg("group", ev.GroupID, response, false, 0); err != nil {
|
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)
|
atMention := fmt.Sprintf("[CQ:at,qq=%d]", q.cfg.BotQQID)
|
||||||
if !strings.Contains(text, atMention) {
|
if !strings.Contains(text, atMention) {
|
||||||
if cfg != nil && cfg.System.DebugMode && cfg.Debug.ShowOneBotAction {
|
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.
|
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))
|
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 {
|
if err != nil {
|
||||||
postLog.Error("OneBot command processing failed: " + err.Error())
|
postLog.Error("[qq_onebot] OneBot command processing failed: " + err.Error())
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
@@ -342,34 +342,34 @@ func (q *QQController) SendAlert(alert controller.Alert) error {
|
|||||||
|
|
||||||
func (q *QQController) sendGroupMessage(groupID string, message string) {
|
func (q *QQController) sendGroupMessage(groupID string, message string) {
|
||||||
if q.onebotClient == nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var groupIDInt int64
|
var groupIDInt int64
|
||||||
if _, err := fmt.Sscanf(groupID, "%d", &groupIDInt); err != nil || groupIDInt == 0 {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := q.onebotClient.SendMsg("group", groupIDInt, message, false, 0); err != nil {
|
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) {
|
func (q *QQController) sendPrivateMessage(userID string, message string) {
|
||||||
if q.onebotClient == nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var userIDInt int64
|
var userIDInt int64
|
||||||
if _, err := fmt.Sscanf(userID, "%d", &userIDInt); err != nil || userIDInt == 0 {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := q.onebotClient.SendMsg("private", userIDInt, message, false, 0); err != nil {
|
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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user