-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponse.go
More file actions
35 lines (32 loc) · 1 KB
/
response.go
File metadata and controls
35 lines (32 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package go_libonebot
import (
"errors"
"github.com/FishZe/go-libonebot/connect"
"github.com/FishZe/go-libonebot/protocol"
"github.com/FishZe/go-libonebot/util"
)
var (
// ErrorConnectionUUIDNotFound 连接UUID未找到
ErrorConnectionUUIDNotFound = errors.New("connection uuid not found")
)
// sendResponse 发送一个响应
func (b *Bot) sendResponse(e any, request *protocol.Request) error {
// 检查Response是否合法
// 要返回客户端要求的Echo
err := protocol.ResponseCheck(request, e)
if err != nil {
// 不是合法的响应 返回一个20001 bad handler 错误
util.Logger.Warning("response check error: " + err.Error())
_ = b.sendResponse(protocol.NewEmptyResponse(protocol.ResponseCodeBadHandler), request)
return err
}
// 通过连接UUID发送
if c, ok := b.connections.Load(request.ConnectionUUID); ok {
if err = (*(c.(*connect.Connection))).SendResponse(e); err != nil {
return err
}
return nil
}
// 未找到连接 返回错误
return ErrorConnectionUUIDNotFound
}