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

Compare commits

...

15 Commits

Author SHA1 Message Date
a52ae1c828 update MiraiGo. 2020-11-14 19:07:08 +08:00
b8ec05e1c1 feature private poke. 2020-11-14 19:03:36 +08:00
2cbf23bceb trim for custom ip file. 2020-11-14 18:54:17 +08:00
3e5c2bc8e3 update MiraiGo. 2020-11-14 15:18:41 +08:00
69a2360d02 Merge pull request #413 from wdvxdr1123/dev
add some gift id
2020-11-14 12:47:13 +08:00
5b0ede5346 add some gift id 2020-11-13 22:32:00 +08:00
80af002668 Merge remote-tracking branch 'upstream/dev' into dev 2020-11-13 21:03:50 +08:00
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
13 changed files with 210 additions and 189 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

@ -56,6 +56,7 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
bot.Client.OnGroupMuted(bot.groupMutedEvent) bot.Client.OnGroupMuted(bot.groupMutedEvent)
bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent) bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent)
bot.Client.OnGroupNotify(bot.groupNotifyEvent) bot.Client.OnGroupNotify(bot.groupNotifyEvent)
bot.Client.OnFriendNotify(bot.friendNotifyEvent)
bot.Client.OnFriendMessageRecalled(bot.friendRecallEvent) bot.Client.OnFriendMessageRecalled(bot.friendRecallEvent)
bot.Client.OnReceivedOfflineFile(bot.offlineFileEvent) bot.Client.OnReceivedOfflineFile(bot.offlineFileEvent)
bot.Client.OnJoinGroup(bot.joinGroupEvent) bot.Client.OnJoinGroup(bot.joinGroupEvent)
@ -235,6 +236,10 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in
newElem = append(newElem, fm) newElem = append(newElem, fm)
continue continue
} }
if i, ok := elem.(*PokeElement); ok {
bot.Client.SendFriendPoke(i.Target)
return 0
}
if i, ok := elem.(*message.VoiceElement); ok { if i, ok := elem.(*message.VoiceElement); ok {
fv, err := bot.Client.UploadPrivatePtt(target, i.Data) fv, err := bot.Client.UploadPrivatePtt(target, i.Data)
if err != nil { if err != nil {

View File

@ -65,7 +65,7 @@ func (e *MusicElement) Type() message.ElementType {
return message.Service return message.Service
} }
var GiftId = []message.GroupGift{ var GiftId = [...]message.GroupGift{
message.SweetWink, message.SweetWink,
message.HappyCola, message.HappyCola,
message.LuckyBracelet, message.LuckyBracelet,
@ -75,6 +75,11 @@ var GiftId = []message.GroupGift{
message.RainbowCandy, message.RainbowCandy,
message.Stronger, message.Stronger,
message.LoveMicrophone, message.LoveMicrophone,
message.HoldingYourHand,
message.CuteCat,
message.MysteryMask,
message.ImBusy,
message.LoveMask,
} }
func (e *PokeElement) Type() message.ElementType { func (e *PokeElement) Type() message.ElementType {
@ -429,9 +434,6 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
} }
case "poke": case "poke":
if !group {
return nil, errors.New("todo") // TODO: private poke
}
t, _ := strconv.ParseInt(d["qq"], 10, 64) t, _ := strconv.ParseInt(d["qq"], 10, 64)
return &PokeElement{Target: t}, nil return &PokeElement{Target: t}, nil
case "gift": case "gift":
@ -440,7 +442,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
} }
t, _ := strconv.ParseInt(d["qq"], 10, 64) t, _ := strconv.ParseInt(d["qq"], 10, 64)
id, _ := strconv.Atoi(d["id"]) id, _ := strconv.Atoi(d["id"])
if id < 0 || id >= 9 { if id < 0 || id >= 14 {
return nil, errors.New("invalid gift id") return nil, errors.New("invalid gift id")
} }
return &GiftElement{Target: t, GiftId: GiftId[id]}, nil return &GiftElement{Target: t, GiftId: GiftId[id]}, nil

View File

@ -220,7 +220,7 @@ func (bot *CQBot) groupRecallEvent(c *client.QQClient, e *client.GroupMessageRec
}) })
} }
func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.IGroupNotifyEvent) { func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.INotifyEvent) {
group := c.FindGroup(e.From()) group := c.FindGroup(e.From())
switch notify := e.(type) { switch notify := e.(type) {
case *client.GroupPokeNotifyEvent: case *client.GroupPokeNotifyEvent:
@ -279,6 +279,24 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.IGroupNotifyEven
} }
} }
func (bot *CQBot) friendNotifyEvent(c *client.QQClient, e client.INotifyEvent) {
friend := c.FindFriend(e.From())
switch notify := e.(type) {
case *client.FriendPokeNotifyEvent:
log.Infof("好友 %v 戳了戳你.", friend.Nickname)
bot.dispatchEventMessage(MSG{
"post_type": "notice",
"notice_type": "notify",
"sub_type": "poke",
"self_id": c.Uin,
"user_id": notify.Sender,
"sender_id": notify.Sender,
"target_id": notify.Receiver,
"time": time.Now().Unix(),
})
}
}
func (bot *CQBot) friendRecallEvent(c *client.QQClient, e *client.FriendMessageRecalledEvent) { func (bot *CQBot) friendRecallEvent(c *client.QQClient, e *client.FriendMessageRecalledEvent) {
f := c.FindFriend(e.FriendUin) f := c.FindFriend(e.FriendUin)
gid := ToGlobalId(e.FriendUin, e.MessageId) gid := ToGlobalId(e.FriendUin, e.MessageId)

View File

@ -112,8 +112,21 @@ 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` 事件、无法接收口令红包、无法接收撤回消息 |
| 3 | MacOS | 无 |
> 注意, 根据协议的不同, 各类消息有所限制 > 注意, 根据协议的不同, 各类消息有所限制
## 自定义服务器IP
> 某些海外服务器使用默认地址可能会存在链路问题,此功能可以指定 go-cqhttp 连接哪些地址以达到最优化.
将文件 `address.txt` 创建到 `go-cqhttp` 工作目录, 并键入 `IP:PORT` 以换行符为分割即可.
示例:
````
1.1.1.1:53
1.1.2.2:8899
````

View File

@ -98,6 +98,12 @@ Type: `gift`
| 6 | 彩虹糖果 | | 6 | 彩虹糖果 |
| 7 | 坚强 | | 7 | 坚强 |
| 8 | 告白话筒 | | 8 | 告白话筒 |
| 9 | 牵你的手 |
| 10 | 可爱猫咪 |
| 11 | 神秘面具 |
| 12 | 我超忙的 |
| 13 | 爱心口罩 |
示例: `[CQ:gift,qq=123456,id=8]` 示例: `[CQ:gift,qq=123456,id=8]`

View File

@ -119,5 +119,29 @@ enable ws?(Y/n)
*注:此时构建后的文件名为*`main`(Linux)或`main.exe`(Windows) *注:此时构建后的文件名为*`main`(Linux)或`main.exe`(Windows)
## 更新
### 方法一
从[release] (https://github.com/Mrs4s/go-cqhttp/releases)界面下载最新版本的go-cqhttp
并替换之前的版本
### 方法二
使用更新参数在命令行中打开go-cqhttp所在目录
#### windows
输入指令
`go-cqhttp.exe update`
如果在国内连接github下载速度可能很慢可以使用镜像源下载
`go-cqhttp.exe update https://github.rc1844.workers.dev`
几个可用的镜像源
- `https://hub.fastgit.org`
- `https://github.com.cnpmjs.org`
- `https://github.bajins.com`
- `https://github.rc1844.workers.dev`
#### linux
方法与windows基本一致`go-cqhttp.exe` 替换为 `./go-cqhttp`即可

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(strings.TrimSpace(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-20201114110437-3d349df7362e
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

8
go.sum
View File

@ -1,7 +1,11 @@
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-20201114105236-1ea9f982fee4 h1:0qoqKkSLTnWBS2rZm95ey9YYbCo4sujO4Kk2frw27yY=
github.com/Mrs4s/MiraiGo v0.0.0-20201112150130-58e7c82fd2dd/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs= github.com/Mrs4s/MiraiGo v0.0.0-20201114105236-1ea9f982fee4/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs=
github.com/Mrs4s/MiraiGo v0.0.0-20201114105600-231b2d89dbb9 h1:evnR9D9rXcBTUzioFf7XlXX4KbZBhc0/Urp09yV01dc=
github.com/Mrs4s/MiraiGo v0.0.0-20201114105600-231b2d89dbb9/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs=
github.com/Mrs4s/MiraiGo v0.0.0-20201114110437-3d349df7362e h1:cE3YcEtd9LWqtR4nyxciRg/qLaJ6jW9eO8I6ZW7oNDw=
github.com/Mrs4s/MiraiGo v0.0.0-20201114110437-3d349df7362e/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=

14
main.go
View File

@ -226,12 +226,14 @@ 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:
return "Android Watch" return "Android Watch"
case client.MacOS:
return "MacOS"
} }
return "未知" return "未知"
}()) }())
@ -246,6 +248,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,12 +340,14 @@ 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:
return "Android Watch" return "Android Watch"
case client.MacOS:
return "MacOS"
} }
return "未知" return "未知"
}()) }())

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() {