From 4ceacc38d540e9695a81b426780629b64e3ddb40 Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Mon, 27 Feb 2023 15:17:27 +0800 Subject: [PATCH] onebot: move to pkg/onebot --- coolq/api.go | 2 +- coolq/bot.go | 2 +- coolq/cqcode.go | 26 ++++++++++++++----------- global/terminal/double_click.go | 1 - global/terminal/double_click_windows.go | 3 --- go.mod | 2 +- go.sum | 4 ++-- internal/selfupdate/update_others.go | 1 - modules/api/api.go | 2 +- modules/api/caller.go | 2 +- {internal => pkg}/onebot/onebot.go | 0 {internal => pkg}/onebot/spec.go | 0 {internal => pkg}/onebot/supported.go | 0 server/http.go | 2 +- server/middlewares.go | 2 +- server/websocket.go | 2 +- 16 files changed, 25 insertions(+), 26 deletions(-) rename {internal => pkg}/onebot/onebot.go (100%) rename {internal => pkg}/onebot/spec.go (100%) rename {internal => pkg}/onebot/supported.go (100%) diff --git a/coolq/api.go b/coolq/api.go index 50a90a8..f54ac67 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -28,9 +28,9 @@ import ( "github.com/Mrs4s/go-cqhttp/internal/cache" "github.com/Mrs4s/go-cqhttp/internal/download" "github.com/Mrs4s/go-cqhttp/internal/msg" - "github.com/Mrs4s/go-cqhttp/internal/onebot" "github.com/Mrs4s/go-cqhttp/internal/param" "github.com/Mrs4s/go-cqhttp/modules/filter" + "github.com/Mrs4s/go-cqhttp/pkg/onebot" ) type guildMemberPageToken struct { diff --git a/coolq/bot.go b/coolq/bot.go index 531c0f6..512a1e6 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -27,7 +27,7 @@ import ( "github.com/Mrs4s/go-cqhttp/internal/base" "github.com/Mrs4s/go-cqhttp/internal/mime" "github.com/Mrs4s/go-cqhttp/internal/msg" - "github.com/Mrs4s/go-cqhttp/internal/onebot" + "github.com/Mrs4s/go-cqhttp/pkg/onebot" ) // CQBot CQBot结构体,存储Bot实例相关配置 diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 4dfdf48..74e8697 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -31,8 +31,8 @@ import ( "github.com/Mrs4s/go-cqhttp/internal/download" "github.com/Mrs4s/go-cqhttp/internal/mime" "github.com/Mrs4s/go-cqhttp/internal/msg" - "github.com/Mrs4s/go-cqhttp/internal/onebot" "github.com/Mrs4s/go-cqhttp/internal/param" + "github.com/Mrs4s/go-cqhttp/pkg/onebot" ) // TODO: move this file to internal/msg, internal/onebot @@ -538,8 +538,11 @@ func (bot *CQBot) at(id, name string) (m any, err error) { } // convertV11 ConvertElement11 -func (bot *CQBot) convertV11(elem msg.Element) (m any, err error, failed bool) { // nolint +func (bot *CQBot) convertV11(elem msg.Element) (m any, ok bool, err error) { switch elem.Type { + default: + // not ok + return case "at": qq := elem.Get("qq") if qq == "all" { @@ -549,24 +552,25 @@ func (bot *CQBot) convertV11(elem msg.Element) (m any, err error, failed bool) { m, err = bot.at(qq, elem.Get("name")) case "record": m, err = bot.voice(elem) - default: - failed = true } + ok = true return } // convertV12 ConvertElement12 -func (bot *CQBot) convertV12(elem msg.Element) (m any, err error, failed bool) { // nolint +func (bot *CQBot) convertV12(elem msg.Element) (m any, ok bool, err error) { switch elem.Type { + default: + // not ok + return case "mention": m, err = bot.at(elem.Get("user_id"), elem.Get("name")) case "mention_all": m = message.AtAll() case "voice": m, err = bot.voice(elem) - default: - failed = true } + ok = true return } @@ -576,16 +580,16 @@ func (bot *CQBot) convertV12(elem msg.Element) (m any, err error, failed bool) { // // message.IMessageElement []message.IMessageElement nil func (bot *CQBot) ConvertElement(spec *onebot.Spec, elem msg.Element, sourceType message.SourceType) (m any, err error) { - var failed bool + var ok bool switch spec.Version { case 11: - m, err, failed = bot.convertV11(elem) + m, ok, err = bot.convertV11(elem) case 12: - m, err, failed = bot.convertV12(elem) + m, ok, err = bot.convertV12(elem) default: panic("invalid onebot version:" + strconv.Itoa(spec.Version)) } - if !failed { + if ok { return m, err } diff --git a/global/terminal/double_click.go b/global/terminal/double_click.go index ff56452..53f0e36 100644 --- a/global/terminal/double_click.go +++ b/global/terminal/double_click.go @@ -1,5 +1,4 @@ //go:build !windows -// +build !windows package terminal diff --git a/global/terminal/double_click_windows.go b/global/terminal/double_click_windows.go index 4c3f4e8..b75367b 100644 --- a/global/terminal/double_click_windows.go +++ b/global/terminal/double_click_windows.go @@ -1,6 +1,3 @@ -//go:build windows -// +build windows - package terminal import ( diff --git a/go.mod b/go.mod index aa779fe..1c7cc23 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.20 require ( github.com/FloatTech/sqlite v1.5.7 github.com/Microsoft/go-winio v0.6.0 - github.com/Mrs4s/MiraiGo v0.0.0-20230220070519-af032dec9677 + github.com/Mrs4s/MiraiGo v0.0.0-20230223093528-5a89d8a9bff2 github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc github.com/fumiama/go-base16384 v1.6.1 diff --git a/go.sum b/go.sum index 7e947cb..6a32498 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b h1:tvciXWq2nuvTbFeJG github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs= github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg= github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE= -github.com/Mrs4s/MiraiGo v0.0.0-20230220070519-af032dec9677 h1:ekVLExixkpJybGXsRyQorPZJN7k2b5ZqH+pOgPVfAJM= -github.com/Mrs4s/MiraiGo v0.0.0-20230220070519-af032dec9677/go.mod h1:mU3fBFU+7eO0kaGes7YRKtzIDtwIU84nSSwTV7NK2b0= +github.com/Mrs4s/MiraiGo v0.0.0-20230223093528-5a89d8a9bff2 h1:dXIxqB73+Ur2S6kUB5M6eIh/vTUAL4FWfIXvSPb2dus= +github.com/Mrs4s/MiraiGo v0.0.0-20230223093528-5a89d8a9bff2/go.mod h1:mU3fBFU+7eO0kaGes7YRKtzIDtwIU84nSSwTV7NK2b0= github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d h1:/Xuj3fIiMY2ls1TwvPKmaqQrtJsPY+c9s+0lOScVHd8= github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d/go.mod h1:2Ie+hdBFQpQFDHfeklgxoFmQRCE7O+KwFpISeXq7OwA= github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e h1:wR3MXQ3VbUlPKOOUwLOYgh/QaJThBTYtsl673O3lqSA= diff --git a/internal/selfupdate/update_others.go b/internal/selfupdate/update_others.go index 1bd535d..40bb616 100644 --- a/internal/selfupdate/update_others.go +++ b/internal/selfupdate/update_others.go @@ -1,5 +1,4 @@ //go:build !windows -// +build !windows package selfupdate diff --git a/modules/api/api.go b/modules/api/api.go index acac76d..e260e80 100644 --- a/modules/api/api.go +++ b/modules/api/api.go @@ -5,7 +5,7 @@ package api import ( "github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/global" - "github.com/Mrs4s/go-cqhttp/internal/onebot" + "github.com/Mrs4s/go-cqhttp/pkg/onebot" ) func (c *Caller) call(action string, spec *onebot.Spec, p Getter) global.MSG { diff --git a/modules/api/caller.go b/modules/api/caller.go index 344920b..2d3acf8 100644 --- a/modules/api/caller.go +++ b/modules/api/caller.go @@ -6,7 +6,7 @@ import ( "github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/global" - "github.com/Mrs4s/go-cqhttp/internal/onebot" + "github.com/Mrs4s/go-cqhttp/pkg/onebot" ) //go:generate go run ./../../cmd/api-generator -pkg api -path=./../../coolq/api.go,./../../coolq/api_v12.go -o api.go diff --git a/internal/onebot/onebot.go b/pkg/onebot/onebot.go similarity index 100% rename from internal/onebot/onebot.go rename to pkg/onebot/onebot.go diff --git a/internal/onebot/spec.go b/pkg/onebot/spec.go similarity index 100% rename from internal/onebot/spec.go rename to pkg/onebot/spec.go diff --git a/internal/onebot/supported.go b/pkg/onebot/supported.go similarity index 100% rename from internal/onebot/supported.go rename to pkg/onebot/supported.go diff --git a/server/http.go b/server/http.go index 98c59e3..9020d98 100644 --- a/server/http.go +++ b/server/http.go @@ -26,10 +26,10 @@ import ( "github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/global" - "github.com/Mrs4s/go-cqhttp/internal/onebot" "github.com/Mrs4s/go-cqhttp/modules/api" "github.com/Mrs4s/go-cqhttp/modules/config" "github.com/Mrs4s/go-cqhttp/modules/filter" + "github.com/Mrs4s/go-cqhttp/pkg/onebot" ) // HTTPServer HTTP通信相关配置 diff --git a/server/middlewares.go b/server/middlewares.go index c996343..e130cf5 100644 --- a/server/middlewares.go +++ b/server/middlewares.go @@ -8,8 +8,8 @@ import ( "github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/global" - "github.com/Mrs4s/go-cqhttp/internal/onebot" "github.com/Mrs4s/go-cqhttp/modules/api" + "github.com/Mrs4s/go-cqhttp/pkg/onebot" "golang.org/x/time/rate" ) diff --git a/server/websocket.go b/server/websocket.go index f5ef674..baaa471 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -22,10 +22,10 @@ import ( "github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/global" - "github.com/Mrs4s/go-cqhttp/internal/onebot" "github.com/Mrs4s/go-cqhttp/modules/api" "github.com/Mrs4s/go-cqhttp/modules/config" "github.com/Mrs4s/go-cqhttp/modules/filter" + "github.com/Mrs4s/go-cqhttp/pkg/onebot" ) type webSocketServer struct {