1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00

server: support ob12 http long polling

This commit is contained in:
wdvxdr 2023-02-19 14:13:18 +08:00
parent 90fa530a02
commit 0e5f3ed555
2 changed files with 9 additions and 5 deletions

View File

@ -17,7 +17,7 @@ type Getter interface {
} }
// Handler 中间件 // Handler 中间件
type Handler func(action string, p Getter) global.MSG type Handler func(action string, spe *onebot.Spec, p Getter) global.MSG
// Caller api route caller // Caller api route caller
type Caller struct { type Caller struct {
@ -28,7 +28,7 @@ type Caller struct {
// Call specific API // Call specific API
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 {
for _, fn := range c.handlers { for _, fn := range c.handlers {
if ret := fn(action, p); ret != nil { if ret := fn(action, spec, p); ret != nil {
return ret return ret
} }
} }

View File

@ -8,6 +8,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/modules/api" "github.com/Mrs4s/go-cqhttp/modules/api"
"golang.org/x/time/rate" "golang.org/x/time/rate"
@ -26,7 +27,7 @@ type MiddleWares struct {
func rateLimit(frequency float64, bucketSize int) api.Handler { func rateLimit(frequency float64, bucketSize int) api.Handler {
limiter := rate.NewLimiter(rate.Limit(frequency), bucketSize) limiter := rate.NewLimiter(rate.Limit(frequency), bucketSize)
return func(_ string, _ api.Getter) global.MSG { return func(_ string, _ *onebot.Spec, _ api.Getter) global.MSG {
_ = limiter.Wait(context.Background()) _ = limiter.Wait(context.Background())
return nil return nil
} }
@ -45,8 +46,11 @@ func longPolling(bot *coolq.CQBot, maxSize int) api.Handler {
} }
cond.Signal() cond.Signal()
}) })
return func(action string, p api.Getter) global.MSG { return func(action string, spec *onebot.Spec, p api.Getter) global.MSG {
if action != "get_updates" { switch {
case spec.Version == 11 && action == "get_updates": // ok
case spec.Version == 12 && action == "get_latest_events": // ok
default:
return nil return nil
} }
var ( var (