2026-04-05 10:36:22 +08:00
|
|
|
package onebot
|
|
|
|
|
|
2026-07-26 22:19:41 +08:00
|
|
|
const (
|
|
|
|
|
// AccountType OneBot 账号类型标识
|
|
|
|
|
AccountType = "onebot"
|
|
|
|
|
// RuleType 发送 OneBot 消息的规则类型标识
|
|
|
|
|
RuleType = "onebot"
|
|
|
|
|
)
|
|
|
|
|
|
2026-04-05 10:36:22 +08:00
|
|
|
type OneBotConfig struct {
|
2026-07-26 22:19:41 +08:00
|
|
|
SendGroups []int64 `json:"send_groups"` // 群号列表
|
|
|
|
|
SendUsers []int64 `json:"send_users"` // 好友 QQ 号列表
|
|
|
|
|
Msg string `json:"msg"`
|
2026-04-05 10:36:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type OneBotAccount struct {
|
|
|
|
|
URL string `json:"url"` // 例如 "http://localhost:5700"
|
|
|
|
|
Token string `json:"token"` // 例如 "your_token_here"
|
|
|
|
|
}
|
2026-07-26 22:19:41 +08:00
|
|
|
|
|
|
|
|
// apiResponse OneBot HTTP API 的通用响应信封
|
|
|
|
|
type apiResponse struct {
|
|
|
|
|
Status string `json:"status"`
|
|
|
|
|
Retcode int `json:"retcode"`
|
|
|
|
|
Message string `json:"message"`
|
|
|
|
|
Wording string `json:"wording"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// err 把 OneBot 返回的业务错误转换成 Go error
|
|
|
|
|
func (r *apiResponse) err() error {
|
|
|
|
|
if r.Status == "ok" && r.Retcode == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
detail := r.Wording
|
|
|
|
|
if detail == "" {
|
|
|
|
|
detail = r.Message
|
|
|
|
|
}
|
|
|
|
|
if detail == "" {
|
|
|
|
|
detail = "请检查 OneBot 地址与 Token"
|
|
|
|
|
}
|
|
|
|
|
return &APIError{Status: r.Status, Retcode: r.Retcode, Detail: detail}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// APIError OneBot 返回的业务错误
|
|
|
|
|
type APIError struct {
|
|
|
|
|
Status string
|
|
|
|
|
Retcode int
|
|
|
|
|
Detail string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e *APIError) Error() string {
|
|
|
|
|
return "OneBot 返回错误(status=" + e.Status + "): " + e.Detail
|
|
|
|
|
}
|