1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-06-30 20:03:24 +00:00

Compare commits

...

8 Commits

Author SHA1 Message Date
b3152bb514 update MiraiGo. 2020-11-13 19:55:57 +08:00
9a018e2a47 doc update. 2020-11-13 19:51:03 +08:00
998b8cb146 feature custom server address. 2020-11-13 19:47:54 +08:00
7e3f94ad2e Merge pull request #412 from wdvxdr1123/dev
修改代码样式
2020-11-13 18:51:31 +08:00
f9dc22f2e5 update MiraiGo. 2020-11-13 18:48:39 +08:00
0ce54ac21b Merge remote-tracking branch 'upstream/dev' into dev 2020-11-13 17:27:13 +08:00
06ac2fcb0c 🎨 clear code 2020-11-13 17:27:01 +08:00
30f1f3199a update MiraiGo. 2020-11-13 16:19:00 +08:00
8 changed files with 140 additions and 183 deletions

View File

@ -807,7 +807,7 @@ func (bot *CQBot) CQGetVersionInfo() MSG {
"version": Version, "version": Version,
"protocol": func() int { "protocol": func() int {
switch client.SystemDeviceInfo.Protocol { switch client.SystemDeviceInfo.Protocol {
case client.AndroidPad: case client.IPad:
return 0 return 0
case client.AndroidPhone: case client.AndroidPhone:
return 1 return 1

View File

@ -112,8 +112,20 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
| 值 | 类型 | 限制 | | 值 | 类型 | 限制 |
| ---- | ------------- | ----------------------------------------------------- | | ---- | ------------- | ----------------------------------------------------- |
| 0 | Android Pad | 无法接收 `group_notify` 事件、无法接收口令红包 | | 0 | iPad | 无 |
| 1 | Android Phone | 无 | | 1 | Android Phone | 无 |
| 2 | Android Watch | 除了 `Android Pad` 有的限制外还包括: 无法接收撤回消息 | | 2 | Android Watch | 无法接收 `group_notify` 事件、无法接收口令红包、无法接收撤回消息 |
> 注意, 根据协议的不同, 各类消息有所限制 > 注意, 根据协议的不同, 各类消息有所限制
## 自定义服务器IP
> 某些海外服务器使用默认地址可能会存在链路问题,此功能可以指定 go-cqhttp 连接哪些地址以达到最优化.
将文件 `address.txt` 创建到 `go-cqhttp` 工作目录, 并键入 `IP:PORT` 以换行符为分割即可.
示例:
````
1.1.1.1:53
1.1.2.2:8899
````

View File

@ -10,10 +10,12 @@ import (
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"io/ioutil" "io/ioutil"
"net"
"net/url" "net/url"
"os" "os"
"path" "path"
"runtime" "runtime"
"strconv"
"strings" "strings"
) )
@ -110,6 +112,24 @@ func DelFile(path string) bool {
} }
} }
func ReadAddrFile(path string) []*net.TCPAddr {
d, err := ioutil.ReadFile(path)
if err != nil {
return nil
}
str := string(d)
lines := strings.Split(str, "\n")
var ret []*net.TCPAddr
for _, l := range lines {
ip := strings.Split(l, ":")
if len(ip) == 2 {
port, _ := strconv.Atoi(ip[1])
ret = append(ret, &net.TCPAddr{IP: net.ParseIP(ip[0]), Port: port})
}
}
return ret
}
type WriteCounter struct { type WriteCounter struct {
Total uint64 Total uint64
} }

2
go.mod
View File

@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
go 1.14 go 1.14
require ( require (
github.com/Mrs4s/MiraiGo v0.0.0-20201112150130-58e7c82fd2dd github.com/Mrs4s/MiraiGo v0.0.0-20201113113825-c1739dba15c9
github.com/dustin/go-humanize v1.0.0 github.com/dustin/go-humanize v1.0.0
github.com/getlantern/go-update v0.0.0-20190510022740-79c495ab728c github.com/getlantern/go-update v0.0.0-20190510022740-79c495ab728c
github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9 // indirect github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9 // indirect

4
go.sum
View File

@ -1,7 +1,7 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Mrs4s/MiraiGo v0.0.0-20201112150130-58e7c82fd2dd h1:n1llMhWgT5s/dBWtbg0NwDzXFAKWfwr1ZXxaErZkLfc= github.com/Mrs4s/MiraiGo v0.0.0-20201113113825-c1739dba15c9 h1:7mFBaoEz2HCIkUqfiW1EtpsZEhxfupEda8+EMeuNS+4=
github.com/Mrs4s/MiraiGo v0.0.0-20201112150130-58e7c82fd2dd/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs= github.com/Mrs4s/MiraiGo v0.0.0-20201113113825-c1739dba15c9/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

12
main.go
View File

@ -226,8 +226,8 @@ func main() {
log.Info("开始尝试登录并同步消息...") log.Info("开始尝试登录并同步消息...")
log.Infof("使用协议: %v", func() string { log.Infof("使用协议: %v", func() string {
switch client.SystemDeviceInfo.Protocol { switch client.SystemDeviceInfo.Protocol {
case client.AndroidPad: case client.IPad:
return "Android Pad" return "iPad"
case client.AndroidPhone: case client.AndroidPhone:
return "Android Phone" return "Android Phone"
case client.AndroidWatch: case client.AndroidWatch:
@ -246,6 +246,14 @@ func main() {
log.Debug("Protocol -> " + e.Message) log.Debug("Protocol -> " + e.Message)
} }
}) })
if global.PathExists("address.txt") {
log.Infof("检测到 address.txt 文件. 将覆盖目标IP.")
addr := global.ReadAddrFile("address.txt")
if len(addr) > 0 {
cli.SetCustomServer(addr)
}
log.Infof("读取到 %v 个自定义地址.", len(addr))
}
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) bool { cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) bool {
if !conf.UseSSOAddress { if !conf.UseSSOAddress {
log.Infof("收到服务器地址更新通知, 根据配置文件已忽略.") log.Infof("收到服务器地址更新通知, 根据配置文件已忽略.")

View File

@ -239,6 +239,7 @@ func (s *webServer) Dologin() {
rsp, err := cli.Login() rsp, err := cli.Login()
if err != nil { if err != nil {
log.Errorf("重连失败: %v", err) log.Errorf("重连失败: %v", err)
cli.Disconnect()
continue continue
} }
if !rsp.Success { if !rsp.Success {
@ -339,8 +340,8 @@ func (s *webServer) DoReLogin() { // TODO: 协议层的 ReLogin
log.Info("开始尝试登录并同步消息...") log.Info("开始尝试登录并同步消息...")
log.Infof("使用协议: %v", func() string { log.Infof("使用协议: %v", func() string {
switch client.SystemDeviceInfo.Protocol { switch client.SystemDeviceInfo.Protocol {
case client.AndroidPad: case client.IPad:
return "Android Pad" return "iPad"
case client.AndroidPhone: case client.AndroidPhone:
return "Android Phone" return "Android Phone"
case client.AndroidWatch: case client.AndroidWatch:

View File

@ -161,78 +161,78 @@ func (s *httpServer) HandleActions(c *gin.Context) {
} }
} }
func (s *httpServer) GetLoginInfo(c *gin.Context) { func GetLoginInfo(s *httpServer, c *gin.Context) {
c.JSON(200, s.bot.CQGetLoginInfo()) c.JSON(200, s.bot.CQGetLoginInfo())
} }
func (s *httpServer) GetFriendList(c *gin.Context) { func GetFriendList(s *httpServer, c *gin.Context) {
c.JSON(200, s.bot.CQGetFriendList()) c.JSON(200, s.bot.CQGetFriendList())
} }
func (s *httpServer) GetGroupList(c *gin.Context) { func GetGroupList(s *httpServer, c *gin.Context) {
nc := getParamOrDefault(c, "no_cache", "false") nc := getParamOrDefault(c, "no_cache", "false")
c.JSON(200, s.bot.CQGetGroupList(nc == "true")) c.JSON(200, s.bot.CQGetGroupList(nc == "true"))
} }
func (s *httpServer) GetGroupInfo(c *gin.Context) { func GetGroupInfo(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
c.JSON(200, s.bot.CQGetGroupInfo(gid)) c.JSON(200, s.bot.CQGetGroupInfo(gid))
} }
func (s *httpServer) GetGroupMemberList(c *gin.Context) { func GetGroupMemberList(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
nc := getParamOrDefault(c, "no_cache", "false") nc := getParamOrDefault(c, "no_cache", "false")
c.JSON(200, s.bot.CQGetGroupMemberList(gid, nc == "true")) c.JSON(200, s.bot.CQGetGroupMemberList(gid, nc == "true"))
} }
func (s *httpServer) GetGroupMemberInfo(c *gin.Context) { func GetGroupMemberInfo(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64) uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
c.JSON(200, s.bot.CQGetGroupMemberInfo(gid, uid)) c.JSON(200, s.bot.CQGetGroupMemberInfo(gid, uid))
} }
func (s *httpServer) GetGroupFileSystemInfo(c *gin.Context) { func GetGroupFileSystemInfo(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
c.JSON(200, s.bot.CQGetGroupFileSystemInfo(gid)) c.JSON(200, s.bot.CQGetGroupFileSystemInfo(gid))
} }
func (s *httpServer) GetGroupRootFiles(c *gin.Context) { func GetGroupRootFiles(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
c.JSON(200, s.bot.CQGetGroupRootFiles(gid)) c.JSON(200, s.bot.CQGetGroupRootFiles(gid))
} }
func (s *httpServer) GetGroupFilesByFolderId(c *gin.Context) { func GetGroupFilesByFolderId(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
folderId := getParam(c, "folder_id") folderId := getParam(c, "folder_id")
c.JSON(200, s.bot.CQGetGroupFilesByFolderId(gid, folderId)) c.JSON(200, s.bot.CQGetGroupFilesByFolderId(gid, folderId))
} }
func (s *httpServer) GetGroupFileUrl(c *gin.Context) { func GetGroupFileUrl(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
fid := getParam(c, "file_id") fid := getParam(c, "file_id")
busid, _ := strconv.ParseInt(getParam(c, "busid"), 10, 32) busid, _ := strconv.ParseInt(getParam(c, "busid"), 10, 32)
c.JSON(200, s.bot.CQGetGroupFileUrl(gid, fid, int32(busid))) c.JSON(200, s.bot.CQGetGroupFileUrl(gid, fid, int32(busid)))
} }
func (s *httpServer) SendMessage(c *gin.Context) { func SendMessage(s *httpServer, c *gin.Context) {
if getParam(c, "message_type") == "private" { if getParam(c, "message_type") == "private" {
s.SendPrivateMessage(c) SendPrivateMessage(s, c)
return return
} }
if getParam(c, "message_type") == "group" { if getParam(c, "message_type") == "group" {
s.SendGroupMessage(c) SendGroupMessage(s, c)
return return
} }
if getParam(c, "group_id") != "" { if getParam(c, "group_id") != "" {
s.SendGroupMessage(c) SendGroupMessage(s, c)
return return
} }
if getParam(c, "user_id") != "" { if getParam(c, "user_id") != "" {
s.SendPrivateMessage(c) SendPrivateMessage(s, c)
} }
} }
func (s *httpServer) SendPrivateMessage(c *gin.Context) { func SendPrivateMessage(s *httpServer, c *gin.Context) {
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64) uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
msg, t := getParamWithType(c, "message") msg, t := getParamWithType(c, "message")
autoEscape := global.EnsureBool(getParam(c, "auto_escape"), false) autoEscape := global.EnsureBool(getParam(c, "auto_escape"), false)
@ -243,7 +243,7 @@ func (s *httpServer) SendPrivateMessage(c *gin.Context) {
c.JSON(200, s.bot.CQSendPrivateMessage(uid, msg, autoEscape)) c.JSON(200, s.bot.CQSendPrivateMessage(uid, msg, autoEscape))
} }
func (s *httpServer) SendGroupMessage(c *gin.Context) { func SendGroupMessage(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
msg, t := getParamWithType(c, "message") msg, t := getParamWithType(c, "message")
autoEscape := global.EnsureBool(getParam(c, "auto_escape"), false) autoEscape := global.EnsureBool(getParam(c, "auto_escape"), false)
@ -254,34 +254,34 @@ func (s *httpServer) SendGroupMessage(c *gin.Context) {
c.JSON(200, s.bot.CQSendGroupMessage(gid, msg, autoEscape)) c.JSON(200, s.bot.CQSendGroupMessage(gid, msg, autoEscape))
} }
func (s *httpServer) SendGroupForwardMessage(c *gin.Context) { func SendGroupForwardMessage(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
msg := getParam(c, "messages") msg := getParam(c, "messages")
c.JSON(200, s.bot.CQSendGroupForwardMessage(gid, gjson.Parse(msg))) c.JSON(200, s.bot.CQSendGroupForwardMessage(gid, gjson.Parse(msg)))
} }
func (s *httpServer) GetImage(c *gin.Context) { func GetImage(s *httpServer, c *gin.Context) {
file := getParam(c, "file") file := getParam(c, "file")
c.JSON(200, s.bot.CQGetImage(file)) c.JSON(200, s.bot.CQGetImage(file))
} }
func (s *httpServer) GetMessage(c *gin.Context) { func GetMessage(s *httpServer, c *gin.Context) {
mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 32) mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 32)
c.JSON(200, s.bot.CQGetMessage(int32(mid))) c.JSON(200, s.bot.CQGetMessage(int32(mid)))
} }
func (s *httpServer) GetGroupHonorInfo(c *gin.Context) { func GetGroupHonorInfo(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
c.JSON(200, s.bot.CQGetGroupHonorInfo(gid, getParam(c, "type"))) c.JSON(200, s.bot.CQGetGroupHonorInfo(gid, getParam(c, "type")))
} }
func (s *httpServer) ProcessFriendRequest(c *gin.Context) { func ProcessFriendRequest(s *httpServer, c *gin.Context) {
flag := getParam(c, "flag") flag := getParam(c, "flag")
approve := getParamOrDefault(c, "approve", "true") approve := getParamOrDefault(c, "approve", "true")
c.JSON(200, s.bot.CQProcessFriendRequest(flag, approve == "true")) c.JSON(200, s.bot.CQProcessFriendRequest(flag, approve == "true"))
} }
func (s *httpServer) ProcessGroupRequest(c *gin.Context) { func ProcessGroupRequest(s *httpServer, c *gin.Context) {
flag := getParam(c, "flag") flag := getParam(c, "flag")
subType := getParam(c, "sub_type") subType := getParam(c, "sub_type")
if subType == "" { if subType == "" {
@ -291,103 +291,103 @@ func (s *httpServer) ProcessGroupRequest(c *gin.Context) {
c.JSON(200, s.bot.CQProcessGroupRequest(flag, subType, getParam(c, "reason"), approve == "true")) c.JSON(200, s.bot.CQProcessGroupRequest(flag, subType, getParam(c, "reason"), approve == "true"))
} }
func (s *httpServer) SetGroupCard(c *gin.Context) { func SetGroupCard(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64) uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
c.JSON(200, s.bot.CQSetGroupCard(gid, uid, getParam(c, "card"))) c.JSON(200, s.bot.CQSetGroupCard(gid, uid, getParam(c, "card")))
} }
func (s *httpServer) SetSpecialTitle(c *gin.Context) { func SetSpecialTitle(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64) uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
c.JSON(200, s.bot.CQSetGroupSpecialTitle(gid, uid, getParam(c, "special_title"))) c.JSON(200, s.bot.CQSetGroupSpecialTitle(gid, uid, getParam(c, "special_title")))
} }
func (s *httpServer) SetGroupKick(c *gin.Context) { func SetGroupKick(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64) uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
msg := getParam(c, "message") msg := getParam(c, "message")
c.JSON(200, s.bot.CQSetGroupKick(gid, uid, msg)) c.JSON(200, s.bot.CQSetGroupKick(gid, uid, msg))
} }
func (s *httpServer) SetGroupBan(c *gin.Context) { func SetGroupBan(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64) uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
i, _ := strconv.ParseInt(getParamOrDefault(c, "duration", "1800"), 10, 64) i, _ := strconv.ParseInt(getParamOrDefault(c, "duration", "1800"), 10, 64)
c.JSON(200, s.bot.CQSetGroupBan(gid, uid, uint32(i))) c.JSON(200, s.bot.CQSetGroupBan(gid, uid, uint32(i)))
} }
func (s *httpServer) SetWholeBan(c *gin.Context) { func SetWholeBan(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
c.JSON(200, s.bot.CQSetGroupWholeBan(gid, getParamOrDefault(c, "enable", "true") == "true")) c.JSON(200, s.bot.CQSetGroupWholeBan(gid, getParamOrDefault(c, "enable", "true") == "true"))
} }
func (s *httpServer) SetGroupName(c *gin.Context) { func SetGroupName(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
c.JSON(200, s.bot.CQSetGroupName(gid, getParam(c, "group_name"))) c.JSON(200, s.bot.CQSetGroupName(gid, getParam(c, "group_name")))
} }
func (s *httpServer) SetGroupAdmin(c *gin.Context) { func SetGroupAdmin(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64) uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
c.JSON(200, s.bot.CQSetGroupAdmin(gid, uid, getParamOrDefault(c, "enable", "true") == "true")) c.JSON(200, s.bot.CQSetGroupAdmin(gid, uid, getParamOrDefault(c, "enable", "true") == "true"))
} }
func (s *httpServer) SendGroupNotice(c *gin.Context) { func SendGroupNotice(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
c.JSON(200, s.bot.CQSetGroupMemo(gid, getParam(c, "content"))) c.JSON(200, s.bot.CQSetGroupMemo(gid, getParam(c, "content")))
} }
func (s *httpServer) SetGroupLeave(c *gin.Context) { func SetGroupLeave(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
c.JSON(200, s.bot.CQSetGroupLeave(gid)) c.JSON(200, s.bot.CQSetGroupLeave(gid))
} }
func (s *httpServer) GetForwardMessage(c *gin.Context) { func GetForwardMessage(s *httpServer, c *gin.Context) {
resId := getParam(c, "message_id") resId := getParam(c, "message_id")
c.JSON(200, s.bot.CQGetForwardMessage(resId)) c.JSON(200, s.bot.CQGetForwardMessage(resId))
} }
func (s *httpServer) GetGroupSystemMessage(c *gin.Context) { func GetGroupSystemMessage(s *httpServer, c *gin.Context) {
c.JSON(200, s.bot.CQGetGroupSystemMessages()) c.JSON(200, s.bot.CQGetGroupSystemMessages())
} }
func (s *httpServer) DeleteMessage(c *gin.Context) { func DeleteMessage(s *httpServer, c *gin.Context) {
mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 32) mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 32)
c.JSON(200, s.bot.CQDeleteMessage(int32(mid))) c.JSON(200, s.bot.CQDeleteMessage(int32(mid)))
} }
func (s *httpServer) CanSendImage(c *gin.Context) { func CanSendImage(s *httpServer, c *gin.Context) {
c.JSON(200, s.bot.CQCanSendImage()) c.JSON(200, s.bot.CQCanSendImage())
} }
func (s *httpServer) CanSendRecord(c *gin.Context) { func CanSendRecord(s *httpServer, c *gin.Context) {
c.JSON(200, s.bot.CQCanSendRecord()) c.JSON(200, s.bot.CQCanSendRecord())
} }
func (s *httpServer) GetStatus(c *gin.Context) { func GetStatus(s *httpServer, c *gin.Context) {
c.JSON(200, s.bot.CQGetStatus()) c.JSON(200, s.bot.CQGetStatus())
} }
func (s *httpServer) GetVersionInfo(c *gin.Context) { func GetVersionInfo(s *httpServer, c *gin.Context) {
c.JSON(200, s.bot.CQGetVersionInfo()) c.JSON(200, s.bot.CQGetVersionInfo())
} }
func (s *httpServer) ReloadEventFilter(c *gin.Context) { func ReloadEventFilter(s *httpServer, c *gin.Context) {
c.JSON(200, s.bot.CQReloadEventFilter()) c.JSON(200, s.bot.CQReloadEventFilter())
} }
func (s *httpServer) GetVipInfo(c *gin.Context) { func GetVipInfo(s *httpServer, c *gin.Context) {
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64) uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
c.JSON(200, s.bot.CQGetVipInfo(uid)) c.JSON(200, s.bot.CQGetVipInfo(uid))
} }
func (s *httpServer) GetStrangerInfo(c *gin.Context) { func GetStrangerInfo(s *httpServer, c *gin.Context) {
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64) uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
c.JSON(200, s.bot.CQGetStrangerInfo(uid)) c.JSON(200, s.bot.CQGetStrangerInfo(uid))
} }
func (s *httpServer) HandleQuickOperation(c *gin.Context) { func HandleQuickOperation(s *httpServer, c *gin.Context) {
if c.Request.Method != "POST" { if c.Request.Method != "POST" {
c.AbortWithStatus(404) c.AbortWithStatus(404)
return return
@ -398,17 +398,17 @@ func (s *httpServer) HandleQuickOperation(c *gin.Context) {
} }
} }
func (s *httpServer) OcrImage(c *gin.Context) { func OcrImage(s *httpServer, c *gin.Context) {
img := getParam(c, "image") img := getParam(c, "image")
c.JSON(200, s.bot.CQOcrImage(img)) c.JSON(200, s.bot.CQOcrImage(img))
} }
func (s *httpServer) GetWordSlices(c *gin.Context) { func GetWordSlices(s *httpServer, c *gin.Context) {
content := getParam(c, "content") content := getParam(c, "content")
c.JSON(200, s.bot.CQGetWordSlices(content)) c.JSON(200, s.bot.CQGetWordSlices(content))
} }
func (s *httpServer) SetGroupPortrait(c *gin.Context) { func SetGroupPortrait(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
file := getParam(c, "file") file := getParam(c, "file")
cache := getParam(c, "cache") cache := getParam(c, "cache")
@ -464,132 +464,48 @@ func getParamWithType(c *gin.Context, k string) (string, gjson.Type) {
} }
var httpApi = map[string]func(s *httpServer, c *gin.Context){ var httpApi = map[string]func(s *httpServer, c *gin.Context){
"get_login_info": func(s *httpServer, c *gin.Context) { "get_login_info": GetLoginInfo,
s.GetLoginInfo(c) "get_friend_list": GetFriendList,
}, "get_group_list": GetGroupList,
"get_friend_list": func(s *httpServer, c *gin.Context) { "get_group_info": GetGroupInfo,
s.GetFriendList(c) "get_group_member_list": GetGroupMemberList,
}, "get_group_member_info": GetGroupMemberInfo,
"get_group_list": func(s *httpServer, c *gin.Context) { "get_group_file_system_info": GetGroupFileSystemInfo,
s.GetGroupList(c) "get_group_root_files": GetGroupRootFiles,
}, "get_group_files_by_folder": GetGroupFilesByFolderId,
"get_group_info": func(s *httpServer, c *gin.Context) { "get_group_file_url": GetGroupFileUrl,
s.GetGroupInfo(c) "send_msg": SendMessage,
}, "send_group_msg": SendGroupMessage,
"get_group_member_list": func(s *httpServer, c *gin.Context) { "send_group_forward_msg": SendGroupForwardMessage,
s.GetGroupMemberList(c) "send_private_msg": SendPrivateMessage,
}, "delete_msg": DeleteMessage,
"get_group_member_info": func(s *httpServer, c *gin.Context) { "set_friend_add_request": ProcessFriendRequest,
s.GetGroupMemberInfo(c) "set_group_add_request": ProcessGroupRequest,
}, "set_group_card": SetGroupCard,
"get_group_file_system_info": func(s *httpServer, c *gin.Context) { "set_group_special_title": SetSpecialTitle,
s.GetGroupFileSystemInfo(c) "set_group_kick": SetGroupKick,
}, "set_group_ban": SetGroupBan,
"get_group_root_files": func(s *httpServer, c *gin.Context) { "set_group_whole_ban": SetWholeBan,
s.GetGroupRootFiles(c) "set_group_name": SetGroupName,
}, "set_group_admin": SetGroupAdmin,
"get_group_files_by_folder": func(s *httpServer, c *gin.Context) { "_send_group_notice": SendGroupNotice,
s.GetGroupFilesByFolderId(c) "set_group_leave": SetGroupLeave,
}, "get_image": GetImage,
"get_group_file_url": func(s *httpServer, c *gin.Context) { "get_forward_msg": GetForwardMessage,
s.GetGroupFileUrl(c) "get_msg": GetMessage,
}, "get_group_system_msg": GetGroupSystemMessage,
"send_msg": func(s *httpServer, c *gin.Context) { "get_group_honor_info": GetGroupHonorInfo,
s.SendMessage(c) "can_send_image": CanSendImage,
}, "can_send_record": CanSendRecord,
"send_group_msg": func(s *httpServer, c *gin.Context) { "get_status": GetStatus,
s.SendGroupMessage(c) "get_version_info": GetVersionInfo,
}, "_get_vip_info": GetVipInfo,
"send_group_forward_msg": func(s *httpServer, c *gin.Context) { "get_stranger_info": GetStrangerInfo,
s.SendGroupForwardMessage(c) "reload_event_filter": ReloadEventFilter,
}, "set_group_portrait": SetGroupPortrait,
"send_private_msg": func(s *httpServer, c *gin.Context) { ".handle_quick_operation": HandleQuickOperation,
s.SendPrivateMessage(c) ".ocr_image": OcrImage,
}, ".get_word_slices": GetWordSlices,
"delete_msg": func(s *httpServer, c *gin.Context) {
s.DeleteMessage(c)
},
"set_friend_add_request": func(s *httpServer, c *gin.Context) {
s.ProcessFriendRequest(c)
},
"set_group_add_request": func(s *httpServer, c *gin.Context) {
s.ProcessGroupRequest(c)
},
"set_group_card": func(s *httpServer, c *gin.Context) {
s.SetGroupCard(c)
},
"set_group_special_title": func(s *httpServer, c *gin.Context) {
s.SetSpecialTitle(c)
},
"set_group_kick": func(s *httpServer, c *gin.Context) {
s.SetGroupKick(c)
},
"set_group_ban": func(s *httpServer, c *gin.Context) {
s.SetGroupBan(c)
},
"set_group_whole_ban": func(s *httpServer, c *gin.Context) {
s.SetWholeBan(c)
},
"set_group_name": func(s *httpServer, c *gin.Context) {
s.SetGroupName(c)
},
"set_group_admin": func(s *httpServer, c *gin.Context) {
s.SetGroupAdmin(c)
},
"_send_group_notice": func(s *httpServer, c *gin.Context) {
s.SendGroupNotice(c)
},
"set_group_leave": func(s *httpServer, c *gin.Context) {
s.SetGroupLeave(c)
},
"get_image": func(s *httpServer, c *gin.Context) {
s.GetImage(c)
},
"get_forward_msg": func(s *httpServer, c *gin.Context) {
s.GetForwardMessage(c)
},
"get_msg": func(s *httpServer, c *gin.Context) {
s.GetMessage(c)
},
"get_group_system_msg": func(s *httpServer, c *gin.Context) {
s.GetGroupSystemMessage(c)
},
"get_group_honor_info": func(s *httpServer, c *gin.Context) {
s.GetGroupHonorInfo(c)
},
"can_send_image": func(s *httpServer, c *gin.Context) {
s.CanSendImage(c)
},
"can_send_record": func(s *httpServer, c *gin.Context) {
s.CanSendRecord(c)
},
"get_status": func(s *httpServer, c *gin.Context) {
s.GetStatus(c)
},
"get_version_info": func(s *httpServer, c *gin.Context) {
s.GetVersionInfo(c)
},
"_get_vip_info": func(s *httpServer, c *gin.Context) {
s.GetVipInfo(c)
},
"get_stranger_info": func(s *httpServer, c *gin.Context) {
s.GetStrangerInfo(c)
},
"reload_event_filter": func(s *httpServer, c *gin.Context) {
s.ReloadEventFilter(c)
},
"set_group_portrait": func(s *httpServer, c *gin.Context) {
s.SetGroupPortrait(c)
},
".handle_quick_operation": func(s *httpServer, c *gin.Context) {
s.HandleQuickOperation(c)
},
".ocr_image": func(s *httpServer, c *gin.Context) {
s.OcrImage(c)
},
".get_word_slices": func(s *httpServer, c *gin.Context) {
s.GetWordSlices(c)
},
} }
func (s *httpServer) ShutDown() { func (s *httpServer) ShutDown() {