feat(channels/qq_obv11): OneBot v11 渠道插件(正/反 WS 双模式 + CQ 媒体 + 限频,stdlib 自研 WS)

This commit is contained in:
Aska committed 2026-09-06 06:46:43 +08:00
1 parent f9f5a78a02
commit 7831b0ea1b
11 files changed
+2526

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
package qq_obv11
// This file implements the client role of the OneBot v11 WebSocket channel: the
// adapter dials out to a OneBot (正向) WebSocket endpoint, authenticating with
// an access token when configured.
import (
"context"
"errors"
"fmt"
"net/url"
"strings"
)
// connectClient dials the configured OneBot WebSocket endpoint and installs the
// resulting connection as the active session.
func (a *Adapter) connectClient(ctx context.Context) error {
if a.cfg.RemoteURL == "" {
return errors.New("qq-obv11: client mode requires remoteURL")
}
target := appendQueryToken(a.cfg.RemoteURL, a.cfg.AccessToken)
conn, err := dialWS(ctx, a.cfg.DialContext, target, a.cfg.AccessToken)
if err != nil {
return fmt.Errorf("qq-obv11: dial onebot ws %s: %w", a.cfg.RemoteURL, err)
}
a.setConn(conn)
a.log.Info("connected to onebot ws (client mode)", "url", a.cfg.RemoteURL)
return nil
}
// appendQueryToken adds an access_token query parameter to a URL, preserving any
// existing query string.
func appendQueryToken(rawURL, token string) string {
if token == "" {
return rawURL
}
sep := "?"
if strings.Contains(rawURL, "?") {
sep = "&"
}
return rawURL + sep + "access_token=" + url.QueryEscape(token)
}