From 029d3a2c18ab9ec0fa9791b940c0fb12ec4715ac Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Wed, 13 Oct 2021 22:49:56 +0800 Subject: [PATCH] feat: onebot 12 style mention [disabled] --- coolq/cqcode.go | 8 ++++++++ internal/base/feature.go | 8 +++++--- server/http.go | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index ec1819b..ef4aa78 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -748,8 +748,16 @@ func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m inte return nil, err } return message.NewFace(int32(id)), nil + case "mention": + if !base.AcceptOneBot12Message { + return nil, errors.New("unsupported onebot 12 style") + } + fallthrough case "at": qq := d["qq"] + if base.AcceptOneBot12Message && qq == "" { + qq = d["user_id"] + } if qq == "all" { return message.AtAll(), nil } diff --git a/internal/base/feature.go b/internal/base/feature.go index 810e189..0dce6f1 100644 --- a/internal/base/feature.go +++ b/internal/base/feature.go @@ -30,8 +30,10 @@ func nocheck(_ io.ReadSeeker) (bool, string) { return true, "" } -// todo: enable in v1.1.0 -// onebot v12 feature +// todo: enable all in v1.1.0 + +// onebot 12 feature const ( - AcceptOneBotV12HTTPEndPoint = false + AcceptOneBot12HTTPEndPoint = false + AcceptOneBot12Message = false ) diff --git a/server/http.go b/server/http.go index 5f7be02..a8dba28 100644 --- a/server/http.go +++ b/server/http.go @@ -118,7 +118,7 @@ func (s *httpServer) ServeHTTP(writer http.ResponseWriter, request *http.Request } var response global.MSG - if base.AcceptOneBotV12HTTPEndPoint && request.URL.Path == "/" { + if base.AcceptOneBot12HTTPEndPoint && request.URL.Path == "/" { action := strings.TrimSuffix(ctx.Get("action").Str, "_async") log.Debugf("HTTPServer接收到API调用: %v", action) response = s.api.callAPI(action, ctx.Get("params"))