1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-04 19:17:37 +08:00

onebot: move to pkg/onebot

This commit is contained in:
wdvxdr 2023-02-27 15:17:27 +08:00
parent 1dba273b61
commit 4ceacc38d5
16 changed files with 25 additions and 26 deletions

View File

@ -28,9 +28,9 @@ import (
"github.com/Mrs4s/go-cqhttp/internal/cache" "github.com/Mrs4s/go-cqhttp/internal/cache"
"github.com/Mrs4s/go-cqhttp/internal/download" "github.com/Mrs4s/go-cqhttp/internal/download"
"github.com/Mrs4s/go-cqhttp/internal/msg" "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/internal/param"
"github.com/Mrs4s/go-cqhttp/modules/filter" "github.com/Mrs4s/go-cqhttp/modules/filter"
"github.com/Mrs4s/go-cqhttp/pkg/onebot"
) )
type guildMemberPageToken struct { type guildMemberPageToken struct {

View File

@ -27,7 +27,7 @@ import (
"github.com/Mrs4s/go-cqhttp/internal/base" "github.com/Mrs4s/go-cqhttp/internal/base"
"github.com/Mrs4s/go-cqhttp/internal/mime" "github.com/Mrs4s/go-cqhttp/internal/mime"
"github.com/Mrs4s/go-cqhttp/internal/msg" "github.com/Mrs4s/go-cqhttp/internal/msg"
"github.com/Mrs4s/go-cqhttp/internal/onebot" "github.com/Mrs4s/go-cqhttp/pkg/onebot"
) )
// CQBot CQBot结构体,存储Bot实例相关配置 // CQBot CQBot结构体,存储Bot实例相关配置

View File

@ -31,8 +31,8 @@ import (
"github.com/Mrs4s/go-cqhttp/internal/download" "github.com/Mrs4s/go-cqhttp/internal/download"
"github.com/Mrs4s/go-cqhttp/internal/mime" "github.com/Mrs4s/go-cqhttp/internal/mime"
"github.com/Mrs4s/go-cqhttp/internal/msg" "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/internal/param"
"github.com/Mrs4s/go-cqhttp/pkg/onebot"
) )
// TODO: move this file to internal/msg, internal/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 // 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 { switch elem.Type {
default:
// not ok
return
case "at": case "at":
qq := elem.Get("qq") qq := elem.Get("qq")
if qq == "all" { 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")) m, err = bot.at(qq, elem.Get("name"))
case "record": case "record":
m, err = bot.voice(elem) m, err = bot.voice(elem)
default:
failed = true
} }
ok = true
return return
} }
// convertV12 ConvertElement12 // 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 { switch elem.Type {
default:
// not ok
return
case "mention": case "mention":
m, err = bot.at(elem.Get("user_id"), elem.Get("name")) m, err = bot.at(elem.Get("user_id"), elem.Get("name"))
case "mention_all": case "mention_all":
m = message.AtAll() m = message.AtAll()
case "voice": case "voice":
m, err = bot.voice(elem) m, err = bot.voice(elem)
default:
failed = true
} }
ok = true
return return
} }
@ -576,16 +580,16 @@ func (bot *CQBot) convertV12(elem msg.Element) (m any, err error, failed bool) {
// //
// message.IMessageElement []message.IMessageElement nil // message.IMessageElement []message.IMessageElement nil
func (bot *CQBot) ConvertElement(spec *onebot.Spec, elem msg.Element, sourceType message.SourceType) (m any, err error) { 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 { switch spec.Version {
case 11: case 11:
m, err, failed = bot.convertV11(elem) m, ok, err = bot.convertV11(elem)
case 12: case 12:
m, err, failed = bot.convertV12(elem) m, ok, err = bot.convertV12(elem)
default: default:
panic("invalid onebot version:" + strconv.Itoa(spec.Version)) panic("invalid onebot version:" + strconv.Itoa(spec.Version))
} }
if !failed { if ok {
return m, err return m, err
} }

View File

@ -1,5 +1,4 @@
//go:build !windows //go:build !windows
// +build !windows
package terminal package terminal

View File

@ -1,6 +1,3 @@
//go:build windows
// +build windows
package terminal package terminal
import ( import (

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.20
require ( require (
github.com/FloatTech/sqlite v1.5.7 github.com/FloatTech/sqlite v1.5.7
github.com/Microsoft/go-winio v0.6.0 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/syncx v0.0.0-20221202055724-5f842c53020e
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc
github.com/fumiama/go-base16384 v1.6.1 github.com/fumiama/go-base16384 v1.6.1

4
go.sum
View File

@ -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/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 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE= 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-20230223093528-5a89d8a9bff2 h1:dXIxqB73+Ur2S6kUB5M6eIh/vTUAL4FWfIXvSPb2dus=
github.com/Mrs4s/MiraiGo v0.0.0-20230220070519-af032dec9677/go.mod h1:mU3fBFU+7eO0kaGes7YRKtzIDtwIU84nSSwTV7NK2b0= 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 h1:/Xuj3fIiMY2ls1TwvPKmaqQrtJsPY+c9s+0lOScVHd8=
github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d/go.mod h1:2Ie+hdBFQpQFDHfeklgxoFmQRCE7O+KwFpISeXq7OwA= 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= github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e h1:wR3MXQ3VbUlPKOOUwLOYgh/QaJThBTYtsl673O3lqSA=

View File

@ -1,5 +1,4 @@
//go:build !windows //go:build !windows
// +build !windows
package selfupdate package selfupdate

View File

@ -5,7 +5,7 @@ package api
import ( import (
"github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/coolq"
"github.com/Mrs4s/go-cqhttp/global" "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 { func (c *Caller) call(action string, spec *onebot.Spec, p Getter) global.MSG {

View File

@ -6,7 +6,7 @@ import (
"github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/coolq"
"github.com/Mrs4s/go-cqhttp/global" "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 //go:generate go run ./../../cmd/api-generator -pkg api -path=./../../coolq/api.go,./../../coolq/api_v12.go -o api.go

View File

@ -26,10 +26,10 @@ import (
"github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/coolq"
"github.com/Mrs4s/go-cqhttp/global" "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/api"
"github.com/Mrs4s/go-cqhttp/modules/config" "github.com/Mrs4s/go-cqhttp/modules/config"
"github.com/Mrs4s/go-cqhttp/modules/filter" "github.com/Mrs4s/go-cqhttp/modules/filter"
"github.com/Mrs4s/go-cqhttp/pkg/onebot"
) )
// HTTPServer HTTP通信相关配置 // HTTPServer HTTP通信相关配置

View File

@ -8,8 +8,8 @@ import (
"github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/coolq"
"github.com/Mrs4s/go-cqhttp/global" "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/api"
"github.com/Mrs4s/go-cqhttp/pkg/onebot"
"golang.org/x/time/rate" "golang.org/x/time/rate"
) )

View File

@ -22,10 +22,10 @@ import (
"github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/coolq"
"github.com/Mrs4s/go-cqhttp/global" "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/api"
"github.com/Mrs4s/go-cqhttp/modules/config" "github.com/Mrs4s/go-cqhttp/modules/config"
"github.com/Mrs4s/go-cqhttp/modules/filter" "github.com/Mrs4s/go-cqhttp/modules/filter"
"github.com/Mrs4s/go-cqhttp/pkg/onebot"
) )
type webSocketServer struct { type webSocketServer struct {