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

Compare commits

...

48 Commits

Author SHA1 Message Date
efdd6bd16a style: move coolq.MSG to global package 2021-09-17 19:08:05 +08:00
6d19f07eb4 fix: incorrect unsafe usage in upstream lib
Updates #1070
2021-09-17 15:37:09 +08:00
760bb175c7 fix: incorrect del friend argument
Fixes #1070
2021-09-17 14:47:00 +08:00
4da5d9ebfb Merge pull request #1026 from Shigma/patch-3
enhance help
2021-09-16 19:42:59 +08:00
a6f82d85be fix #1058 2021-09-16 19:37:05 +08:00
c62f193005 Merge branch 'dev' of github.com:/Mrs4s/go-cqhttp into dev 2021-09-16 18:27:58 +08:00
f386a9b94e doc: delete_unidirectional_friend 2021-09-16 18:27:42 +08:00
48afb44287 Merge pull request #1050 from wdvxdr1123/avx2
feat: use avx2 base64
2021-09-16 18:24:44 +08:00
75fe0294ac fix: make lint happy 2021-09-16 18:19:49 +08:00
1290a3dd10 fix: unidirectional friend cache missing. 2021-09-16 18:08:45 +08:00
59209068bf feat: delete_unidirectional_friend. 2021-09-16 18:01:24 +08:00
757661bcf7 doc: get_unidirectional_friend_list. 2021-09-16 17:37:43 +08:00
b8bf3f9711 feat: get_unidirectional_friend_list api. 2021-09-16 17:33:38 +08:00
eadd688e5a doc: fix typo. 2021-09-16 17:22:04 +08:00
8c89d3c432 doc: image subtype. 2021-09-16 17:21:09 +08:00
cfaa18b131 fix: relogin error. 2021-09-16 17:11:38 +08:00
c975975e30 feat: group image subtype support. 2021-09-16 17:10:12 +08:00
ec4ecb1093 docs: fix newline in MINE 2021-09-16 16:48:17 +08:00
b01ea99d1a docs: MINE scan 2021-09-16 16:43:52 +08:00
8c94c810d6 fix relogin default value error. 2021-09-15 14:34:18 +08:00
7485b51c48 update retry message. 2021-09-15 13:45:04 +08:00
449ae96c8f fix env conf load. 2021-09-15 13:43:39 +08:00
7f26df3ac7 feat: use avx2 base64 2021-09-14 15:12:32 +08:00
bfea93312a fix: panic on setting servers.
Fixes #1039
2021-09-02 19:17:01 +08:00
f8dfa8db2c style: simply send msg. 2021-08-29 22:48:03 +08:00
74fd4bbf35 Merge pull request #1030 from 502647092/patch-1
fix: 修复环境变量初始化错误
2021-08-29 01:49:13 +08:00
16db68e054 Merge pull request #1022 from asjdf/master
update fs.go
2021-08-28 19:46:16 +08:00
346e01c4e9 fix: 修复环境变量初始化错误
Close #1025
2021-08-26 17:08:32 +08:00
a69d52821f Merge pull request #1027 from Yukari316/dev
fix /mark_msg_as_read api param type error
2021-08-25 22:31:48 +08:00
d70c2a0b70 Merge branch 'Mrs4s:dev' into dev 2021-08-25 22:30:06 +08:00
46d0d58865 feat: add nosilk tag.
Updates: #1024
2021-08-25 22:29:10 +08:00
d1ca68ed32 dep: drop jsoniter.
reduce binary size about 1 MB.
2021-08-25 22:25:59 +08:00
c8958b2a42 fix /mark_msg_as_read api param type error 2021-08-25 22:25:49 +08:00
d98ad55826 dep: drop jsoniter.
reduce binary size about 1 MB.
2021-08-25 16:24:35 +08:00
8ac460dde9 Update main.go 2021-08-25 15:17:58 +08:00
520cdd90bb fix #1023. 2021-08-24 09:41:26 +08:00
5fb3233a44 fix /send_group_forward_msg api unable to get params from non-json request. 2021-08-23 15:20:22 +08:00
c61a913c49 update fs.go 2021-08-23 14:02:51 +08:00
24c1192fa6 Merge pull request #1019 from Ink-33/alert
NoMoreDoubleClick
2021-08-22 15:56:28 +08:00
8773e19d2c style: remove useless code 2021-08-22 15:40:06 +08:00
8d6978a60d feat: alert windows user when double click 2021-08-22 15:05:14 +08:00
385443ee2d chore: update dependencies 2021-08-22 02:42:45 +08:00
7f0826b594 feat(server): support long polling timeout. 2021-08-21 12:55:01 +08:00
dc48958292 fix go mod. 2021-08-20 23:04:37 +08:00
e820a2a152 fix #1016. 2021-08-20 22:47:43 +08:00
022eb9fd3b all: bump go1.17 & support windows/arm64. 2021-08-18 14:01:31 +08:00
11a5dbb64a fix(coolq): wrong target on send music share.
Fixes: #1011
2021-08-18 13:25:56 +08:00
78d76f55e2 fix(scf): always flush the writer. 2021-08-16 16:05:33 +08:00
29 changed files with 813 additions and 540 deletions

View File

@ -22,15 +22,13 @@ jobs:
goarch: arm
- goos: darwin
goarch: "386"
- goos: windows
goarch: arm64
fail-fast: true
steps:
- uses: actions/checkout@v2
- name: Setup Go environment
uses: actions/setup-go@v2.1.3
with:
go-version: 1.16
go-version: 1.17
- name: Cache downloaded module
uses: actions/cache@v2
with:

View File

@ -12,7 +12,7 @@ jobs:
- name: Setup Go environment
uses: actions/setup-go@v2.1.3
with:
go-version: 1.16
go-version: 1.17
- name: golangci-lint
uses: golangci/golangci-lint-action@v2

View File

@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.16.2'
go-version: '1.17'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2

View File

@ -38,6 +38,7 @@ builds:
- 386
- amd64
- arm
- arm64
goarm:
- 7
mod_timestamp: "{{ .CommitTimestamp }}"

View File

@ -1,4 +1,4 @@
FROM golang:1.16-alpine AS builder
FROM golang:1.17-alpine AS builder
RUN go env -w GO111MODULE=auto \
&& go env -w CGO_ENABLED=0 \

View File

@ -3,6 +3,7 @@ package coolq
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"math"
"os"
@ -17,6 +18,7 @@ import (
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Mrs4s/MiraiGo/utils"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
@ -39,16 +41,16 @@ func init() {
// CQGetLoginInfo 获取登录号信息
//
// https://git.io/Jtz1I
func (bot *CQBot) CQGetLoginInfo() MSG {
return OK(MSG{"user_id": bot.Client.Uin, "nickname": bot.Client.Nickname})
func (bot *CQBot) CQGetLoginInfo() global.MSG {
return OK(global.MSG{"user_id": bot.Client.Uin, "nickname": bot.Client.Nickname})
}
// CQGetQiDianAccountInfo 获取企点账号信息
func (bot *CQBot) CQGetQiDianAccountInfo() MSG {
func (bot *CQBot) CQGetQiDianAccountInfo() global.MSG {
if bot.Client.QiDian == nil {
return Failed(100, "QIDIAN_PROTOCOL_REQUEST", "请使用企点协议")
}
return OK(MSG{
return OK(global.MSG{
"master_id": bot.Client.QiDian.MasterUin,
"ext_name": bot.Client.QiDian.ExtName,
"create_time": bot.Client.QiDian.CreateTime,
@ -58,10 +60,10 @@ func (bot *CQBot) CQGetQiDianAccountInfo() MSG {
// CQGetFriendList 获取好友列表
//
// https://git.io/Jtz1L
func (bot *CQBot) CQGetFriendList() MSG {
fs := make([]MSG, 0, len(bot.Client.FriendList))
func (bot *CQBot) CQGetFriendList() global.MSG {
fs := make([]global.MSG, 0, len(bot.Client.FriendList))
for _, f := range bot.Client.FriendList {
fs = append(fs, MSG{
fs = append(fs, global.MSG{
"nickname": f.Nickname,
"remark": f.Remark,
"user_id": f.Uin,
@ -70,10 +72,51 @@ func (bot *CQBot) CQGetFriendList() MSG {
return OK(fs)
}
// CQGetUnidirectionalFriendList 获取单向好友列表
//
//
func (bot *CQBot) CQGetUnidirectionalFriendList() global.MSG {
list, err := bot.Client.GetUnidirectionalFriendList()
if err != nil {
log.Errorf("获取单向好友列表时出现错误: %v", err)
return Failed(100, "API_ERROR", err.Error())
}
fs := make([]global.MSG, 0, len(list))
for _, f := range list {
fs = append(fs, global.MSG{
"nickname": f.Nickname,
"user_id": f.Uin,
"source": f.Source,
})
}
return OK(fs)
}
// CQDeleteUnidirectionalFriend 删除单向好友
//
//
func (bot *CQBot) CQDeleteUnidirectionalFriend(uin int64) global.MSG {
list, err := bot.Client.GetUnidirectionalFriendList()
if err != nil {
log.Errorf("获取单向好友列表时出现错误: %v", err)
return Failed(100, "API_ERROR", err.Error())
}
for _, f := range list {
if f.Uin == uin {
if err = bot.Client.DeleteUnidirectionalFriend(uin); err != nil {
log.Errorf("删除单向好友时出现错误: %v", err)
return Failed(100, "API_ERROR", err.Error())
}
return OK(nil)
}
}
return Failed(100, "FRIEND_NOT_FOUND", "好友不存在")
}
// CQDeleteFriend 删除好友
//
//
func (bot *CQBot) CQDeleteFriend(uin int64) MSG {
func (bot *CQBot) CQDeleteFriend(uin int64) global.MSG {
if bot.Client.FindFriend(uin) == nil {
return Failed(100, "FRIEND_NOT_FOUND", "好友不存在")
}
@ -87,13 +130,13 @@ func (bot *CQBot) CQDeleteFriend(uin int64) MSG {
// CQGetGroupList 获取群列表
//
// https://git.io/Jtz1t
func (bot *CQBot) CQGetGroupList(noCache bool) MSG {
gs := make([]MSG, 0, len(bot.Client.GroupList))
func (bot *CQBot) CQGetGroupList(noCache bool) global.MSG {
gs := make([]global.MSG, 0, len(bot.Client.GroupList))
if noCache {
_ = bot.Client.ReloadGroupList()
}
for _, g := range bot.Client.GroupList {
gs = append(gs, MSG{
gs = append(gs, global.MSG{
"group_id": g.Code,
"group_name": g.Name,
"group_memo": g.Memo,
@ -109,7 +152,7 @@ func (bot *CQBot) CQGetGroupList(noCache bool) MSG {
// CQGetGroupInfo 获取群信息
//
// https://git.io/Jtz1O
func (bot *CQBot) CQGetGroupInfo(groupID int64, noCache bool) MSG {
func (bot *CQBot) CQGetGroupInfo(groupID int64, noCache bool) global.MSG {
group := bot.Client.FindGroup(groupID)
if group == nil || noCache {
group, _ = bot.Client.GetGroupInfo(groupID)
@ -122,7 +165,7 @@ func (bot *CQBot) CQGetGroupInfo(groupID int64, noCache bool) MSG {
}
for _, g := range info {
if g.Code == groupID {
return OK(MSG{
return OK(global.MSG{
"group_id": g.Code,
"group_name": g.Name,
"group_memo": g.Memo,
@ -134,7 +177,7 @@ func (bot *CQBot) CQGetGroupInfo(groupID int64, noCache bool) MSG {
}
}
} else {
return OK(MSG{
return OK(global.MSG{
"group_id": group.Code,
"group_name": group.Name,
"group_memo": group.Memo,
@ -150,7 +193,7 @@ func (bot *CQBot) CQGetGroupInfo(groupID int64, noCache bool) MSG {
// CQGetGroupMemberList 获取群成员列表
//
// https://git.io/Jtz13
func (bot *CQBot) CQGetGroupMemberList(groupID int64, noCache bool) MSG {
func (bot *CQBot) CQGetGroupMemberList(groupID int64, noCache bool) global.MSG {
group := bot.Client.FindGroup(groupID)
if group == nil {
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
@ -163,7 +206,7 @@ func (bot *CQBot) CQGetGroupMemberList(groupID int64, noCache bool) MSG {
}
group.Members = t
}
members := make([]MSG, 0, len(group.Members))
members := make([]global.MSG, 0, len(group.Members))
for _, m := range group.Members {
members = append(members, convertGroupMemberInfo(groupID, m))
}
@ -173,7 +216,7 @@ func (bot *CQBot) CQGetGroupMemberList(groupID int64, noCache bool) MSG {
// CQGetGroupMemberInfo 获取群成员信息
//
// https://git.io/Jtz1s
func (bot *CQBot) CQGetGroupMemberInfo(groupID, userID int64, noCache bool) MSG {
func (bot *CQBot) CQGetGroupMemberInfo(groupID, userID int64, noCache bool) global.MSG {
group := bot.Client.FindGroup(groupID)
if group == nil {
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
@ -198,7 +241,7 @@ func (bot *CQBot) CQGetGroupMemberInfo(groupID, userID int64, noCache bool) MSG
// CQGetGroupFileSystemInfo 扩展API-获取群文件系统信息
//
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%E4%BF%A1%E6%81%AF
func (bot *CQBot) CQGetGroupFileSystemInfo(groupID int64) MSG {
func (bot *CQBot) CQGetGroupFileSystemInfo(groupID int64) global.MSG {
fs, err := bot.Client.GetGroupFileSystem(groupID)
if err != nil {
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
@ -210,7 +253,7 @@ func (bot *CQBot) CQGetGroupFileSystemInfo(groupID int64) MSG {
// CQGetGroupRootFiles 扩展API-获取群根目录文件列表
//
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%A0%B9%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6%E5%88%97%E8%A1%A8
func (bot *CQBot) CQGetGroupRootFiles(groupID int64) MSG {
func (bot *CQBot) CQGetGroupRootFiles(groupID int64) global.MSG {
fs, err := bot.Client.GetGroupFileSystem(groupID)
if err != nil {
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
@ -221,7 +264,7 @@ func (bot *CQBot) CQGetGroupRootFiles(groupID int64) MSG {
log.Errorf("获取群 %v 根目录文件失败: %v", groupID, err)
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
}
return OK(MSG{
return OK(global.MSG{
"files": files,
"folders": folders,
})
@ -230,7 +273,7 @@ func (bot *CQBot) CQGetGroupRootFiles(groupID int64) MSG {
// CQGetGroupFilesByFolderID 扩展API-获取群子目录文件列表
//
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%AD%90%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6%E5%88%97%E8%A1%A8
func (bot *CQBot) CQGetGroupFilesByFolderID(groupID int64, folderID string) MSG {
func (bot *CQBot) CQGetGroupFilesByFolderID(groupID int64, folderID string) global.MSG {
fs, err := bot.Client.GetGroupFileSystem(groupID)
if err != nil {
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
@ -241,7 +284,7 @@ func (bot *CQBot) CQGetGroupFilesByFolderID(groupID int64, folderID string) MSG
log.Errorf("获取群 %v 根目录 %v 子文件失败: %v", groupID, folderID, err)
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
}
return OK(MSG{
return OK(global.MSG{
"files": files,
"folders": folders,
})
@ -250,12 +293,12 @@ func (bot *CQBot) CQGetGroupFilesByFolderID(groupID int64, folderID string) MSG
// CQGetGroupFileURL 扩展API-获取群文件资源链接
//
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%96%87%E4%BB%B6%E8%B5%84%E6%BA%90%E9%93%BE%E6%8E%A5
func (bot *CQBot) CQGetGroupFileURL(groupID int64, fileID string, busID int32) MSG {
func (bot *CQBot) CQGetGroupFileURL(groupID int64, fileID string, busID int32) global.MSG {
url := bot.Client.GetGroupFileUrl(groupID, fileID, busID)
if url == "" {
return Failed(100, "FILE_SYSTEM_API_ERROR")
}
return OK(MSG{
return OK(global.MSG{
"url": url,
})
}
@ -263,7 +306,7 @@ func (bot *CQBot) CQGetGroupFileURL(groupID int64, fileID string, busID int32) M
// CQUploadGroupFile 扩展API-上传群文件
//
// https://docs.go-cqhttp.org/api/#%E4%B8%8A%E4%BC%A0%E7%BE%A4%E6%96%87%E4%BB%B6
func (bot *CQBot) CQUploadGroupFile(groupID int64, file, name, folder string) MSG {
func (bot *CQBot) CQUploadGroupFile(groupID int64, file, name, folder string) global.MSG {
if !global.PathExists(file) {
log.Errorf("上传群文件 %v 失败: 文件不存在", file)
return Failed(100, "FILE_NOT_FOUND", "文件不存在")
@ -286,7 +329,7 @@ func (bot *CQBot) CQUploadGroupFile(groupID int64, file, name, folder string) MS
// CQGroupFileCreateFolder 拓展API-创建群文件文件夹
//
//
func (bot *CQBot) CQGroupFileCreateFolder(groupID int64, parentID, name string) MSG {
func (bot *CQBot) CQGroupFileCreateFolder(groupID int64, parentID, name string) global.MSG {
fs, err := bot.Client.GetGroupFileSystem(groupID)
if err != nil {
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
@ -302,7 +345,7 @@ func (bot *CQBot) CQGroupFileCreateFolder(groupID int64, parentID, name string)
// CQGroupFileDeleteFolder 拓展API-删除群文件文件夹
//
//
func (bot *CQBot) CQGroupFileDeleteFolder(groupID int64, id string) MSG {
func (bot *CQBot) CQGroupFileDeleteFolder(groupID int64, id string) global.MSG {
fs, err := bot.Client.GetGroupFileSystem(groupID)
if err != nil {
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
@ -318,7 +361,7 @@ func (bot *CQBot) CQGroupFileDeleteFolder(groupID int64, id string) MSG {
// CQGroupFileDeleteFile 拓展API-删除群文件
//
//
func (bot *CQBot) CQGroupFileDeleteFile(groupID int64, id string, busID int32) MSG {
func (bot *CQBot) CQGroupFileDeleteFile(groupID int64, id string, busID int32) global.MSG {
fs, err := bot.Client.GetGroupFileSystem(groupID)
if err != nil {
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
@ -334,7 +377,7 @@ func (bot *CQBot) CQGroupFileDeleteFile(groupID int64, id string, busID int32) M
// CQGetWordSlices 隐藏API-获取中文分词
//
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E4%B8%AD%E6%96%87%E5%88%86%E8%AF%8D-%E9%9A%90%E8%97%8F-api
func (bot *CQBot) CQGetWordSlices(content string) MSG {
func (bot *CQBot) CQGetWordSlices(content string) global.MSG {
slices, err := bot.Client.GetWordSegmentation(content)
if err != nil {
return Failed(100, "WORD_SEGMENTATION_API_ERROR", err.Error())
@ -342,13 +385,13 @@ func (bot *CQBot) CQGetWordSlices(content string) MSG {
for i := 0; i < len(slices); i++ {
slices[i] = strings.ReplaceAll(slices[i], "\u0000", "")
}
return OK(MSG{"slices": slices})
return OK(global.MSG{"slices": slices})
}
// CQSendGroupMessage 发送群消息
//
// https://git.io/Jtz1c
func (bot *CQBot) CQSendGroupMessage(groupID int64, m gjson.Result, autoEscape bool) MSG {
func (bot *CQBot) CQSendGroupMessage(groupID int64, m gjson.Result, autoEscape bool) global.MSG {
group := bot.Client.FindGroup(groupID)
if group == nil {
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
@ -366,40 +409,34 @@ func (bot *CQBot) CQSendGroupMessage(groupID int64, m gjson.Result, autoEscape b
}
}
var elem []message.IMessageElement
if m.Type == gjson.JSON {
elem := bot.ConvertObjectMessage(m, true)
fixAt(elem)
mid := bot.SendGroupMessage(groupID, &message.SendingMessage{Elements: elem})
if mid == -1 {
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
}
log.Infof("发送群 %v(%v) 的消息: %v (%v)", group.Name, groupID, limitedString(ToStringMessage(elem, groupID)), mid)
return OK(MSG{"message_id": mid})
}
elem = bot.ConvertObjectMessage(m, true)
} else {
str := m.String()
if str == "" {
log.Warn("群消息发送失败: 信息为空.")
return Failed(100, "EMPTY_MSG_ERROR", "消息为空")
}
var elem []message.IMessageElement
if autoEscape {
elem = append(elem, message.NewText(str))
elem = []message.IMessageElement{message.NewText(str)}
} else {
elem = bot.ConvertStringMessage(str, true)
}
}
fixAt(elem)
mid := bot.SendGroupMessage(groupID, &message.SendingMessage{Elements: elem})
if mid == -1 {
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
}
log.Infof("发送群 %v(%v) 的消息: %v (%v)", group.Name, groupID, limitedString(str), mid)
return OK(MSG{"message_id": mid})
log.Infof("发送群 %v(%v) 的消息: %v (%v)", group.Name, groupID, limitedString(m.String()), mid)
return OK(global.MSG{"message_id": mid})
}
// CQSendGroupForwardMessage 扩展API-发送合并转发(群)
//
// https://docs.go-cqhttp.org/api/#%E5%8F%91%E9%80%81%E5%90%88%E5%B9%B6%E8%BD%AC%E5%8F%91-%E7%BE%A4
func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) global.MSG {
if m.Type != gjson.JSON {
return Failed(100)
}
@ -414,7 +451,7 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
return true
})
var resolveElement = func(elems []message.IMessageElement) []message.IMessageElement {
resolveElement := func(elems []message.IMessageElement) []message.IMessageElement {
for i, elem := range elems {
switch elem.(type) {
case *LocalImageElement, *LocalVideoElement:
@ -521,7 +558,7 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
log.Warnf("合并转发(群)消息发送失败: 账号可能被风控.")
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
}
return OK(MSG{
return OK(global.MSG{
"message_id": bot.InsertGroupMessage(ret),
})
}
@ -531,38 +568,33 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
// CQSendPrivateMessage 发送私聊消息
//
// https://git.io/Jtz1l
func (bot *CQBot) CQSendPrivateMessage(userID int64, groupID int64, m gjson.Result, autoEscape bool) MSG {
func (bot *CQBot) CQSendPrivateMessage(userID int64, groupID int64, m gjson.Result, autoEscape bool) global.MSG {
var elem []message.IMessageElement
if m.Type == gjson.JSON {
elem := bot.ConvertObjectMessage(m, false)
elem = bot.ConvertObjectMessage(m, false)
} else {
str := m.String()
if str == "" {
return Failed(100, "EMPTY_MSG_ERROR", "消息为空")
}
if autoEscape {
elem = []message.IMessageElement{message.NewText(str)}
} else {
elem = bot.ConvertStringMessage(str, false)
}
}
mid := bot.SendPrivateMessage(userID, groupID, &message.SendingMessage{Elements: elem})
if mid == -1 {
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
}
log.Infof("发送好友 %v(%v) 的消息: %v (%v)", userID, userID, limitedString(m.String()), mid)
return OK(MSG{"message_id": mid})
}
str := m.String()
if str == "" {
return Failed(100, "EMPTY_MSG_ERROR", "消息为空")
}
var elem []message.IMessageElement
if autoEscape {
elem = append(elem, message.NewText(str))
} else {
elem = bot.ConvertStringMessage(str, false)
}
mid := bot.SendPrivateMessage(userID, groupID, &message.SendingMessage{Elements: elem})
if mid == -1 {
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
}
log.Infof("发送好友 %v(%v) 的消息: %v (%v)", userID, userID, limitedString(str), mid)
return OK(MSG{"message_id": mid})
return OK(global.MSG{"message_id": mid})
}
// CQSetGroupCard 设置群名片(群备注)
//
// https://git.io/Jtz1B
func (bot *CQBot) CQSetGroupCard(groupID, userID int64, card string) MSG {
func (bot *CQBot) CQSetGroupCard(groupID, userID int64, card string) global.MSG {
if g := bot.Client.FindGroup(groupID); g != nil {
if m := g.FindMember(userID); m != nil {
m.EditCard(card)
@ -575,7 +607,7 @@ func (bot *CQBot) CQSetGroupCard(groupID, userID int64, card string) MSG {
// CQSetGroupSpecialTitle 设置群组专属头衔
//
// https://git.io/Jtz10
func (bot *CQBot) CQSetGroupSpecialTitle(groupID, userID int64, title string) MSG {
func (bot *CQBot) CQSetGroupSpecialTitle(groupID, userID int64, title string) global.MSG {
if g := bot.Client.FindGroup(groupID); g != nil {
if m := g.FindMember(userID); m != nil {
m.EditSpecialTitle(title)
@ -588,7 +620,7 @@ func (bot *CQBot) CQSetGroupSpecialTitle(groupID, userID int64, title string) MS
// CQSetGroupName 设置群名
//
// https://git.io/Jtz12
func (bot *CQBot) CQSetGroupName(groupID int64, name string) MSG {
func (bot *CQBot) CQSetGroupName(groupID int64, name string) global.MSG {
if g := bot.Client.FindGroup(groupID); g != nil {
g.UpdateName(name)
return OK(nil)
@ -599,7 +631,7 @@ func (bot *CQBot) CQSetGroupName(groupID int64, name string) MSG {
// CQSetGroupMemo 扩展API-发送群公告
//
// https://docs.go-cqhttp.org/api/#%E5%8F%91%E9%80%81%E7%BE%A4%E5%85%AC%E5%91%8A
func (bot *CQBot) CQSetGroupMemo(groupID int64, msg string, img string) MSG {
func (bot *CQBot) CQSetGroupMemo(groupID int64, msg string, img string) global.MSG {
if g := bot.Client.FindGroup(groupID); g != nil {
if g.SelfPermission() == client.Member {
return Failed(100, "PERMISSION_DENIED", "权限不足")
@ -627,7 +659,7 @@ func (bot *CQBot) CQSetGroupMemo(groupID int64, msg string, img string) MSG {
// CQSetGroupKick 群组踢人
//
// https://git.io/Jtz1V
func (bot *CQBot) CQSetGroupKick(groupID, userID int64, msg string, block bool) MSG {
func (bot *CQBot) CQSetGroupKick(groupID, userID int64, msg string, block bool) global.MSG {
if g := bot.Client.FindGroup(groupID); g != nil {
if m := g.FindMember(userID); m != nil {
err := m.Kick(msg, block)
@ -643,7 +675,7 @@ func (bot *CQBot) CQSetGroupKick(groupID, userID int64, msg string, block bool)
// CQSetGroupBan 群组单人禁言
//
// https://git.io/Jtz1w
func (bot *CQBot) CQSetGroupBan(groupID, userID int64, duration uint32) MSG {
func (bot *CQBot) CQSetGroupBan(groupID, userID int64, duration uint32) global.MSG {
if g := bot.Client.FindGroup(groupID); g != nil {
if m := g.FindMember(userID); m != nil {
err := m.Mute(duration)
@ -662,7 +694,7 @@ func (bot *CQBot) CQSetGroupBan(groupID, userID int64, duration uint32) MSG {
// CQSetGroupWholeBan 群组全员禁言
//
// https://git.io/Jtz1o
func (bot *CQBot) CQSetGroupWholeBan(groupID int64, enable bool) MSG {
func (bot *CQBot) CQSetGroupWholeBan(groupID int64, enable bool) global.MSG {
if g := bot.Client.FindGroup(groupID); g != nil {
g.MuteAll(enable)
return OK(nil)
@ -673,7 +705,7 @@ func (bot *CQBot) CQSetGroupWholeBan(groupID int64, enable bool) MSG {
// CQSetGroupLeave 退出群组
//
// https://git.io/Jtz1K
func (bot *CQBot) CQSetGroupLeave(groupID int64) MSG {
func (bot *CQBot) CQSetGroupLeave(groupID int64) global.MSG {
if g := bot.Client.FindGroup(groupID); g != nil {
g.Quit()
return OK(nil)
@ -684,7 +716,7 @@ func (bot *CQBot) CQSetGroupLeave(groupID int64) MSG {
// CQGetAtAllRemain 扩展API-获取群 @全体成员 剩余次数
//
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4-%E5%85%A8%E4%BD%93%E6%88%90%E5%91%98-%E5%89%A9%E4%BD%99%E6%AC%A1%E6%95%B0
func (bot *CQBot) CQGetAtAllRemain(groupID int64) MSG {
func (bot *CQBot) CQGetAtAllRemain(groupID int64) global.MSG {
if g := bot.Client.FindGroup(groupID); g != nil {
i, err := bot.Client.GetAtAllRemain(groupID)
if err != nil {
@ -698,7 +730,7 @@ func (bot *CQBot) CQGetAtAllRemain(groupID int64) MSG {
// CQProcessFriendRequest 处理加好友请求
//
// https://git.io/Jtz11
func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) MSG {
func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) global.MSG {
req, ok := bot.friendReqCache.Load(flag)
if !ok {
return Failed(100, "FLAG_NOT_FOUND", "FLAG不存在")
@ -714,7 +746,7 @@ func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) MSG {
// CQProcessGroupRequest 处理加群请求/邀请
//
// https://git.io/Jtz1D
func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bool) MSG {
func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bool) global.MSG {
msgs, err := bot.Client.GetGroupSystemMessages()
if err != nil {
log.Errorf("获取群系统消息失败: %v", err)
@ -758,7 +790,7 @@ func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bo
// CQDeleteMessage 撤回消息
//
// https:// git.io/Jtz1y
func (bot *CQBot) CQDeleteMessage(messageID int32) MSG {
func (bot *CQBot) CQDeleteMessage(messageID int32) global.MSG {
msg := bot.GetMessage(messageID)
if msg == nil {
return Failed(100, "MESSAGE_NOT_FOUND", "消息不存在")
@ -789,7 +821,7 @@ func (bot *CQBot) CQDeleteMessage(messageID int32) MSG {
// CQSetGroupAdmin 群组设置管理员
//
// https://git.io/Jtz1S
func (bot *CQBot) CQSetGroupAdmin(groupID, userID int64, enable bool) MSG {
func (bot *CQBot) CQSetGroupAdmin(groupID, userID int64, enable bool) global.MSG {
group := bot.Client.FindGroup(groupID)
if group == nil || group.OwnerUin != bot.Client.Uin {
return Failed(100, "PERMISSION_DENIED", "群不存在或权限不足")
@ -811,12 +843,12 @@ func (bot *CQBot) CQSetGroupAdmin(groupID, userID int64, enable bool) MSG {
// CQGetVipInfo 扩展API-获取VIP信息
//
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96vip%E4%BF%A1%E6%81%AF
func (bot *CQBot) CQGetVipInfo(userID int64) MSG {
func (bot *CQBot) CQGetVipInfo(userID int64) global.MSG {
vip, err := bot.Client.GetVipInfo(userID)
if err != nil {
return Failed(100, "VIP_API_ERROR", err.Error())
}
msg := MSG{
msg := global.MSG{
"user_id": vip.Uin,
"nickname": vip.Name,
"level": vip.Level,
@ -831,11 +863,11 @@ func (bot *CQBot) CQGetVipInfo(userID int64) MSG {
// CQGetGroupHonorInfo 获取群荣誉信息
//
// https://git.io/Jtz1H
func (bot *CQBot) CQGetGroupHonorInfo(groupID int64, t string) MSG {
msg := MSG{"group_id": groupID}
convertMem := func(memList []client.HonorMemberInfo) (ret []MSG) {
func (bot *CQBot) CQGetGroupHonorInfo(groupID int64, t string) global.MSG {
msg := global.MSG{"group_id": groupID}
convertMem := func(memList []client.HonorMemberInfo) (ret []global.MSG) {
for _, mem := range memList {
ret = append(ret, MSG{
ret = append(ret, global.MSG{
"user_id": mem.Uin,
"nickname": mem.Name,
"avatar": mem.Avatar,
@ -847,7 +879,7 @@ func (bot *CQBot) CQGetGroupHonorInfo(groupID int64, t string) MSG {
if t == "talkative" || t == "all" {
if honor, err := bot.Client.GetGroupHonorInfo(groupID, client.Talkative); err == nil {
if honor.CurrentTalkative.Uin != 0 {
msg["current_talkative"] = MSG{
msg["current_talkative"] = global.MSG{
"user_id": honor.CurrentTalkative.Uin,
"nickname": honor.CurrentTalkative.Name,
"avatar": honor.CurrentTalkative.Avatar,
@ -888,12 +920,12 @@ func (bot *CQBot) CQGetGroupHonorInfo(groupID int64, t string) MSG {
// CQGetStrangerInfo 获取陌生人信息
//
// https://git.io/Jtz17
func (bot *CQBot) CQGetStrangerInfo(userID int64) MSG {
func (bot *CQBot) CQGetStrangerInfo(userID int64) global.MSG {
info, err := bot.Client.GetSummaryInfo(userID)
if err != nil {
return Failed(100, "SUMMARY_API_ERROR", err.Error())
}
return OK(MSG{
return OK(global.MSG{
"user_id": info.Uin,
"nickname": info.Nickname,
"qid": info.Qid,
@ -915,7 +947,7 @@ func (bot *CQBot) CQGetStrangerInfo(userID int64) MSG {
// CQHandleQuickOperation 隐藏API-对事件执行快速操作
//
// https://git.io/Jtz15
func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) global.MSG {
postType := context.Get("post_type").Str
switch postType {
@ -930,16 +962,16 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
at := operation.Get("at_sender").Bool() && !isAnonymous && msgType == "group"
if at && reply.IsArray() {
// 在 reply 数组头部插入CQ码
replySegments := make([]MSG, 0)
segments := make([]MSG, 0)
segments = append(segments, MSG{
replySegments := make([]global.MSG, 0)
segments := make([]global.MSG, 0)
segments = append(segments, global.MSG{
"type": "at",
"data": MSG{
"data": global.MSG{
"qq": context.Get("sender.user_id").Int(),
},
})
err := json.UnmarshalFromString(reply.Raw, &replySegments)
err := json.Unmarshal(utils.S2B(reply.Raw), &replySegments)
if err != nil {
log.WithError(err).Warnf("处理 at_sender 过程中发生错误")
return Failed(-1, "处理 at_sender 过程中发生错误", err.Error())
@ -947,13 +979,13 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
segments = append(segments, replySegments...)
modified, err := json.MarshalToString(segments)
modified, err := json.Marshal(segments)
if err != nil {
log.WithError(err).Warnf("处理 at_sender 过程中发生错误")
return Failed(-1, "处理 at_sender 过程中发生错误", err.Error())
}
reply = gjson.Parse(modified)
reply = gjson.Parse(utils.B2S(modified))
} else if at && reply.Type == gjson.String {
reply = gjson.Parse(fmt.Sprintf(
"\"[CQ:at,qq=%d]%s\"",
@ -991,10 +1023,10 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
reqType := context.Get("request_type").Str
if operation.Get("approve").Exists() {
if reqType == "friend" {
bot.CQProcessFriendRequest(context.Get("flag").Str, operation.Get("approve").Bool())
bot.CQProcessFriendRequest(context.Get("flag").String(), operation.Get("approve").Bool())
}
if reqType == "group" {
bot.CQProcessGroupRequest(context.Get("flag").Str, context.Get("sub_type").Str, operation.Get("reason").Str, operation.Get("approve").Bool())
bot.CQProcessGroupRequest(context.Get("flag").String(), context.Get("sub_type").Str, operation.Get("reason").Str, operation.Get("approve").Bool())
}
}
}
@ -1004,7 +1036,7 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
// CQGetImage 获取图片(修改自OneBot)
//
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E5%9B%BE%E7%89%87%E4%BF%A1%E6%81%AF
func (bot *CQBot) CQGetImage(file string) MSG {
func (bot *CQBot) CQGetImage(file string) global.MSG {
if !global.PathExists(path.Join(global.ImagePath, file)) {
return Failed(100)
}
@ -1012,7 +1044,7 @@ func (bot *CQBot) CQGetImage(file string) MSG {
if err == nil {
r := binary.NewReader(b)
r.ReadBytes(16)
msg := MSG{
msg := global.MSG{
"size": r.ReadInt32(),
"filename": r.ReadString(),
"url": r.ReadString(),
@ -1035,7 +1067,7 @@ func (bot *CQBot) CQGetImage(file string) MSG {
// CQDownloadFile 扩展API-下载文件到缓存目录
//
// https://docs.go-cqhttp.org/api/#%E4%B8%8B%E8%BD%BD%E6%96%87%E4%BB%B6%E5%88%B0%E7%BC%93%E5%AD%98%E7%9B%AE%E5%BD%95
func (bot *CQBot) CQDownloadFile(url string, headers map[string]string, threadCount int) MSG {
func (bot *CQBot) CQDownloadFile(url string, headers map[string]string, threadCount int) global.MSG {
hash := md5.Sum([]byte(url))
file := path.Join(global.CachePath, hex.EncodeToString(hash[:])+".cache")
if global.PathExists(file) {
@ -1049,7 +1081,7 @@ func (bot *CQBot) CQDownloadFile(url string, headers map[string]string, threadCo
return Failed(100, "DOWNLOAD_FILE_ERROR", err.Error())
}
abs, _ := filepath.Abs(file)
return OK(MSG{
return OK(global.MSG{
"file": abs,
})
}
@ -1057,16 +1089,16 @@ func (bot *CQBot) CQDownloadFile(url string, headers map[string]string, threadCo
// CQGetForwardMessage 获取合并转发消息
//
// https://git.io/Jtz1F
func (bot *CQBot) CQGetForwardMessage(resID string) MSG {
func (bot *CQBot) CQGetForwardMessage(resID string) global.MSG {
m := bot.Client.GetForwardMessage(resID)
if m == nil {
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
}
r := make([]MSG, 0, len(m.Nodes))
r := make([]global.MSG, 0, len(m.Nodes))
for _, n := range m.Nodes {
bot.checkMedia(n.Message)
r = append(r, MSG{
"sender": MSG{
r = append(r, global.MSG{
"sender": global.MSG{
"user_id": n.SenderId,
"nickname": n.SenderName,
},
@ -1074,7 +1106,7 @@ func (bot *CQBot) CQGetForwardMessage(resID string) MSG {
"content": ToFormattedMessage(n.Message, 0, false),
})
}
return OK(MSG{
return OK(global.MSG{
"messages": r,
})
}
@ -1082,7 +1114,7 @@ func (bot *CQBot) CQGetForwardMessage(resID string) MSG {
// CQGetMessage 获取消息
//
// https://git.io/Jtz1b
func (bot *CQBot) CQGetMessage(messageID int32) MSG {
func (bot *CQBot) CQGetMessage(messageID int32) global.MSG {
msg := bot.GetMessage(messageID)
if msg == nil {
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
@ -1090,7 +1122,7 @@ func (bot *CQBot) CQGetMessage(messageID int32) MSG {
sender := msg["sender"].(message.Sender)
gid, isGroup := msg["group"]
raw := msg["message"].(string)
return OK(MSG{
return OK(global.MSG{
"message_id": messageID,
"real_id": msg["message-id"],
"message_seq": msg["message-id"],
@ -1102,7 +1134,7 @@ func (bot *CQBot) CQGetMessage(messageID int32) MSG {
}
return "private"
}(),
"sender": MSG{
"sender": global.MSG{
"user_id": sender.Uin,
"nickname": sender.Nickname,
},
@ -1120,7 +1152,7 @@ func (bot *CQBot) CQGetMessage(messageID int32) MSG {
// CQGetGroupSystemMessages 扩展API-获取群文件系统消息
//
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E7%B3%BB%E7%BB%9F%E6%B6%88%E6%81%AF
func (bot *CQBot) CQGetGroupSystemMessages() MSG {
func (bot *CQBot) CQGetGroupSystemMessages() global.MSG {
msg, err := bot.Client.GetGroupSystemMessages()
if err != nil {
log.Warnf("获取群系统消息失败: %v", err)
@ -1132,7 +1164,7 @@ func (bot *CQBot) CQGetGroupSystemMessages() MSG {
// CQGetGroupMessageHistory 获取群消息历史记录
//
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%B6%88%E6%81%AF%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95
func (bot *CQBot) CQGetGroupMessageHistory(groupID int64, seq int64) MSG {
func (bot *CQBot) CQGetGroupMessageHistory(groupID int64, seq int64) global.MSG {
if g := bot.Client.FindGroup(groupID); g == nil {
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
}
@ -1148,7 +1180,7 @@ func (bot *CQBot) CQGetGroupMessageHistory(groupID int64, seq int64) MSG {
log.Warnf("获取群历史消息失败: %v", err)
return Failed(100, "MESSAGES_API_ERROR", err.Error())
}
ms := make([]MSG, 0, len(msg))
ms := make([]global.MSG, 0, len(msg))
for _, m := range msg {
id := m.Id
bot.checkMedia(m.Elements)
@ -1159,7 +1191,7 @@ func (bot *CQBot) CQGetGroupMessageHistory(groupID int64, seq int64) MSG {
t["message_id"] = id
ms = append(ms, t)
}
return OK(MSG{
return OK(global.MSG{
"messages": ms,
})
}
@ -1167,22 +1199,22 @@ func (bot *CQBot) CQGetGroupMessageHistory(groupID int64, seq int64) MSG {
// CQGetOnlineClients 扩展API-获取当前账号在线客户端列表
//
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E8%B4%A6%E5%8F%B7%E5%9C%A8%E7%BA%BF%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%88%97%E8%A1%A8
func (bot *CQBot) CQGetOnlineClients(noCache bool) MSG {
func (bot *CQBot) CQGetOnlineClients(noCache bool) global.MSG {
if noCache {
if err := bot.Client.RefreshStatus(); err != nil {
log.Warnf("刷新客户端状态时出现问题 %v", err)
return Failed(100, "REFRESH_STATUS_ERROR", err.Error())
}
}
d := make([]MSG, 0, len(bot.Client.OnlineClients))
d := make([]global.MSG, 0, len(bot.Client.OnlineClients))
for _, oc := range bot.Client.OnlineClients {
d = append(d, MSG{
d = append(d, global.MSG{
"app_id": oc.AppId,
"device_name": oc.DeviceName,
"device_kind": oc.DeviceKind,
})
}
return OK(MSG{
return OK(global.MSG{
"clients": d,
})
}
@ -1190,21 +1222,21 @@ func (bot *CQBot) CQGetOnlineClients(noCache bool) MSG {
// CQCanSendImage 检查是否可以发送图片(此处永远返回true)
//
// https://git.io/Jtz1N
func (bot *CQBot) CQCanSendImage() MSG {
return OK(MSG{"yes": true})
func (bot *CQBot) CQCanSendImage() global.MSG {
return OK(global.MSG{"yes": true})
}
// CQCanSendRecord 检查是否可以发送语音(此处永远返回true)
//
// https://git.io/Jtz1x
func (bot *CQBot) CQCanSendRecord() MSG {
return OK(MSG{"yes": true})
func (bot *CQBot) CQCanSendRecord() global.MSG {
return OK(global.MSG{"yes": true})
}
// CQOcrImage 扩展API-图片OCR
//
// https://docs.go-cqhttp.org/api/#%E5%9B%BE%E7%89%87-ocr
func (bot *CQBot) CQOcrImage(imageID string) MSG {
func (bot *CQBot) CQOcrImage(imageID string) global.MSG {
img, err := bot.makeImageOrVideoElem(map[string]string{"file": imageID}, false, true)
if err != nil {
log.Warnf("load image error: %v", err)
@ -1221,7 +1253,7 @@ func (bot *CQBot) CQOcrImage(imageID string) MSG {
// CQSetGroupPortrait 扩展API-设置群头像
//
// https://docs.go-cqhttp.org/api/#%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%A4%B4%E5%83%8F
func (bot *CQBot) CQSetGroupPortrait(groupID int64, file, cache string) MSG {
func (bot *CQBot) CQSetGroupPortrait(groupID int64, file, cache string) global.MSG {
if g := bot.Client.FindGroup(groupID); g != nil {
img, err := global.FindFile(file, cache, global.ImagePath)
if err != nil {
@ -1237,7 +1269,7 @@ func (bot *CQBot) CQSetGroupPortrait(groupID int64, file, cache string) MSG {
// CQSetGroupAnonymousBan 群组匿名用户禁言
//
// https://git.io/Jtz1p
func (bot *CQBot) CQSetGroupAnonymousBan(groupID int64, flag string, duration int32) MSG {
func (bot *CQBot) CQSetGroupAnonymousBan(groupID int64, flag string, duration int32) global.MSG {
if flag == "" {
return Failed(100, "INVALID_FLAG", "无效的flag")
}
@ -1260,8 +1292,8 @@ func (bot *CQBot) CQSetGroupAnonymousBan(groupID int64, flag string, duration in
// CQGetStatus 获取运行状态
//
// https://git.io/JtzMe
func (bot *CQBot) CQGetStatus() MSG {
return OK(MSG{
func (bot *CQBot) CQGetStatus() global.MSG {
return OK(global.MSG{
"app_initialized": true,
"app_enabled": true,
"plugins_good": nil,
@ -1275,7 +1307,7 @@ func (bot *CQBot) CQGetStatus() MSG {
// CQSetEssenceMessage 扩展API-设置精华消息
//
// https://docs.go-cqhttp.org/api/#%E8%AE%BE%E7%BD%AE%E7%B2%BE%E5%8D%8E%E6%B6%88%E6%81%AF
func (bot *CQBot) CQSetEssenceMessage(messageID int32) MSG {
func (bot *CQBot) CQSetEssenceMessage(messageID int32) global.MSG {
msg := bot.GetMessage(messageID)
if msg == nil {
return Failed(100, "MESSAGE_NOT_FOUND", "消息不存在")
@ -1295,7 +1327,7 @@ func (bot *CQBot) CQSetEssenceMessage(messageID int32) MSG {
// CQDeleteEssenceMessage 扩展API-移出精华消息
//
// https://docs.go-cqhttp.org/api/#%E7%A7%BB%E5%87%BA%E7%B2%BE%E5%8D%8E%E6%B6%88%E6%81%AF
func (bot *CQBot) CQDeleteEssenceMessage(messageID int32) MSG {
func (bot *CQBot) CQDeleteEssenceMessage(messageID int32) global.MSG {
msg := bot.GetMessage(messageID)
if msg == nil {
return Failed(100, "MESSAGE_NOT_FOUND", "消息不存在")
@ -1315,7 +1347,7 @@ func (bot *CQBot) CQDeleteEssenceMessage(messageID int32) MSG {
// CQGetEssenceMessageList 扩展API-获取精华消息列表
//
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%B2%BE%E5%8D%8E%E6%B6%88%E6%81%AF%E5%88%97%E8%A1%A8
func (bot *CQBot) CQGetEssenceMessageList(groupCode int64) MSG {
func (bot *CQBot) CQGetEssenceMessageList(groupCode int64) global.MSG {
g := bot.Client.FindGroup(groupCode)
if g == nil {
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
@ -1324,9 +1356,9 @@ func (bot *CQBot) CQGetEssenceMessageList(groupCode int64) MSG {
if err != nil {
return Failed(100, "GET_ESSENCE_LIST_FOUND", err.Error())
}
list := make([]MSG, 0, len(msgList))
list := make([]global.MSG, 0, len(msgList))
for _, m := range msgList {
msg := MSG{
msg := global.MSG{
"sender_nick": m.SenderNick,
"sender_time": m.SenderTime,
"operator_time": m.AddDigestTime,
@ -1343,8 +1375,8 @@ func (bot *CQBot) CQGetEssenceMessageList(groupCode int64) MSG {
// CQCheckURLSafely 扩展API-检查链接安全性
//
// https://docs.go-cqhttp.org/api/#%E6%A3%80%E6%9F%A5%E9%93%BE%E6%8E%A5%E5%AE%89%E5%85%A8%E6%80%A7
func (bot *CQBot) CQCheckURLSafely(url string) MSG {
return OK(MSG{
func (bot *CQBot) CQCheckURLSafely(url string) global.MSG {
return OK(global.MSG{
"level": bot.Client.CheckUrlSafely(url),
})
}
@ -1352,9 +1384,9 @@ func (bot *CQBot) CQCheckURLSafely(url string) MSG {
// CQGetVersionInfo 获取版本信息
//
// https://git.io/JtwUs
func (bot *CQBot) CQGetVersionInfo() MSG {
func (bot *CQBot) CQGetVersionInfo() global.MSG {
wd, _ := os.Getwd()
return OK(MSG{
return OK(global.MSG{
"app_name": "go-cqhttp",
"app_version": Version,
"app_full_name": fmt.Sprintf("go-cqhttp-%s_%s_%s-%s", Version, runtime.GOOS, runtime.GOARCH, runtime.Version()),
@ -1390,19 +1422,19 @@ func (bot *CQBot) CQGetVersionInfo() MSG {
// CQGetModelShow 获取在线机型
//
// https://club.vip.qq.com/onlinestatus/set
func (bot *CQBot) CQGetModelShow(modelName string) MSG {
func (bot *CQBot) CQGetModelShow(modelName string) global.MSG {
variants, err := bot.Client.GetModelShow(modelName)
if err != nil {
return Failed(100, "GET_MODEL_SHOW_API_ERROR", "无法获取在线机型")
}
a := make([]MSG, 0, len(variants))
a := make([]global.MSG, 0, len(variants))
for _, v := range variants {
a = append(a, MSG{
a = append(a, global.MSG{
"model_show": v.ModelShow,
"need_pay": v.NeedPay,
})
}
return OK(MSG{
return OK(global.MSG{
"variants": a,
})
}
@ -1410,7 +1442,7 @@ func (bot *CQBot) CQGetModelShow(modelName string) MSG {
// CQSetModelShow 设置在线机型
//
// https://club.vip.qq.com/onlinestatus/set
func (bot *CQBot) CQSetModelShow(modelName string, modelShow string) MSG {
func (bot *CQBot) CQSetModelShow(modelName string, modelShow string) global.MSG {
err := bot.Client.SetModelShow(modelName, modelShow)
if err != nil {
return Failed(100, "SET_MODEL_SHOW_API_ERROR", "无法设置在线机型")
@ -1419,7 +1451,7 @@ func (bot *CQBot) CQSetModelShow(modelName string, modelShow string) MSG {
}
// CQMarkMessageAsRead 标记消息已读
func (bot *CQBot) CQMarkMessageAsRead(msgID int32) MSG {
func (bot *CQBot) CQMarkMessageAsRead(msgID int32) global.MSG {
m := bot.GetMessage(msgID)
if m == nil {
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
@ -1431,17 +1463,17 @@ func (bot *CQBot) CQMarkMessageAsRead(msgID int32) MSG {
if _, ok := m["from-group"]; ok {
return Failed(100, "MSG_TYPE_ERROR", "不支持标记临时会话")
}
bot.Client.MarkPrivateMessageReaded(m["sender"].(*message.Sender).Uin, m["time"].(int64))
bot.Client.MarkPrivateMessageReaded(m["sender"].(message.Sender).Uin, int64(m["time"].(int32)))
return OK(nil)
}
// OK 生成成功返回值
func OK(data interface{}) MSG {
return MSG{"data": data, "retcode": 0, "status": "ok"}
func OK(data interface{}) global.MSG {
return global.MSG{"data": data, "retcode": 0, "status": "ok"}
}
// Failed 生成失败返回值
func Failed(code int, msg ...string) MSG {
func Failed(code int, msg ...string) global.MSG {
m := ""
w := ""
if len(msg) > 0 {
@ -1450,11 +1482,11 @@ func Failed(code int, msg ...string) MSG {
if len(msg) > 1 {
w = msg[1]
}
return MSG{"data": nil, "retcode": code, "msg": m, "wording": w, "status": "failed"}
return global.MSG{"data": nil, "retcode": code, "msg": m, "wording": w, "status": "failed"}
}
func convertGroupMemberInfo(groupID int64, m *client.GroupMemberInfo) MSG {
return MSG{
func convertGroupMemberInfo(groupID int64, m *client.GroupMemberInfo) global.MSG {
return global.MSG{
"group_id": groupID,
"user_id": m.Uin,
"nickname": m.Nickname,

View File

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/gob"
"encoding/hex"
"encoding/json"
"fmt"
"hash/crc32"
"io"
@ -19,7 +20,6 @@ import (
"github.com/Mrs4s/MiraiGo/client"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Mrs4s/MiraiGo/utils"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/syndtr/goleveldb/leveldb"
@ -29,8 +29,6 @@ import (
"github.com/Mrs4s/go-cqhttp/global/config"
)
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// CQBot CQBot结构体,存储Bot实例相关配置
type CQBot struct {
Client *client.QQClient
@ -41,15 +39,11 @@ type CQBot struct {
db *leveldb.DB
friendReqCache sync.Map
tempSessionCache sync.Map
oneWayMsgCache sync.Map
}
// MSG 消息Map
type MSG map[string]interface{}
// Event 事件
type Event struct {
RawMsg MSG
RawMsg global.MSG
once sync.Once
buffer *bytes.Buffer
@ -81,12 +75,27 @@ var ForceFragmented = false
// SkipMimeScan 是否跳过Mime扫描
var SkipMimeScan bool
var lawfulImageTypes = [...]string{"image/png", "image/jpeg", "image/gif", "image/bmp", "image/webp"}
// keep sync with /docs/file.md#MINE
var lawfulImageTypes = [...]string{
"image/bmp",
"image/gif",
"image/jpeg",
"image/png",
"image/webp",
}
var lawfulAudioTypes = [...]string{
"audio/mpeg", "audio/flac", "audio/midi", "audio/ogg",
"audio/ape", "audio/amr", "audio/wav", "audio/aiff",
"audio/mp4", "audio/aac", "audio/x-m4a",
"audio/aac",
"audio/aiff",
"audio/amr",
"audio/ape",
"audio/flac",
"audio/midi",
"audio/mp4",
"audio/mpeg",
"audio/ogg",
"audio/wav",
"audio/x-m4a",
}
// NewQQBot 初始化一个QQBot实例
@ -153,7 +162,7 @@ func NewQQBot(cli *client.QQClient, conf *config.Config) *CQBot {
t := time.NewTicker(time.Second * time.Duration(i))
for {
<-t.C
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"time": time.Now().Unix(),
"self_id": bot.Client.Uin,
"post_type": "meta_event",
@ -174,9 +183,9 @@ func (bot *CQBot) OnEventPush(f func(e *Event)) {
}
// GetMessage 获取给定消息id对应的消息
func (bot *CQBot) GetMessage(mid int32) MSG {
func (bot *CQBot) GetMessage(mid int32) global.MSG {
if bot.db != nil {
m := MSG{}
m := global.MSG{}
data, err := bot.db.Get(binary.ToBytes(mid), nil)
if err == nil {
err = gob.NewDecoder(bytes.NewReader(data)).Decode(&m)
@ -301,7 +310,7 @@ func (bot *CQBot) SendPrivateMessage(target int64, groupID int64, m *message.Sen
for _, e := range m.Elements {
switch i := e.(type) {
case *LocalImageElement, *message.VoiceElement, *LocalVideoElement:
i, err := bot.uploadMedia(i, groupID, false)
i, err := bot.uploadMedia(i, target, false)
if err != nil {
log.Warnf("警告: 私聊 %d 消息%s上传失败: %v", target, e.Type().String(), err)
continue
@ -311,7 +320,7 @@ func (bot *CQBot) SendPrivateMessage(target int64, groupID int64, m *message.Sen
bot.Client.SendFriendPoke(i.Target)
return 0
case *message.MusicShareElement:
bot.Client.SendFriendMusicShare(groupID, i)
bot.Client.SendFriendMusicShare(target, i)
return 0
}
newElem = append(newElem, e)
@ -322,13 +331,31 @@ func (bot *CQBot) SendPrivateMessage(target int64, groupID int64, m *message.Sen
}
m.Elements = newElem
bot.checkMedia(newElem)
// 单向好友是否存在
unidirectionalFriendExists := func() bool {
list, err := bot.Client.GetUnidirectionalFriendList()
if err != nil {
return false
}
for _, f := range list {
if f.Uin == target {
return true
}
}
return false
}
session, ok := bot.tempSessionCache.Load(target)
var id int32 = -1
if bot.Client.FindFriend(target) != nil { // 双向好友
switch {
case bot.Client.FindFriend(target) != nil: // 双向好友
msg := bot.Client.SendPrivateMessage(target, m)
if msg != nil {
id = bot.InsertPrivateMessage(msg)
}
} else if session, ok := bot.tempSessionCache.Load(target); ok || groupID != 0 { // 临时会话
case ok || groupID != 0: // 临时会话
switch {
case groupID != 0 && bot.Client.FindGroup(groupID) == nil:
log.Errorf("错误: 找不到群(%v)", groupID)
@ -353,12 +380,12 @@ func (bot *CQBot) SendPrivateMessage(target int64, groupID int64, m *message.Sen
id = bot.InsertTempMessage(target, msg)
}
}
} else if _, ok := bot.oneWayMsgCache.Load(target); ok { // 单向好友
case unidirectionalFriendExists(): // 单向好友
msg := bot.Client.SendPrivateMessage(target, m)
if msg != nil {
id = bot.InsertPrivateMessage(msg)
}
} else {
default:
nickname := "Unknown"
if summaryInfo, _ := bot.Client.GetSummaryInfo(target); summaryInfo != nil {
nickname = summaryInfo.Nickname
@ -370,7 +397,7 @@ func (bot *CQBot) SendPrivateMessage(target int64, groupID int64, m *message.Sen
// InsertGroupMessage 群聊消息入数据库
func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
val := MSG{
val := global.MSG{
"message-id": m.Id,
"internal-id": m.InternalId,
"group": m.GroupCode,
@ -397,7 +424,7 @@ func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
// InsertPrivateMessage 私聊消息入数据库
func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage) int32 {
val := MSG{
val := global.MSG{
"message-id": m.Id,
"internal-id": m.InternalId,
"target": m.Target,
@ -423,7 +450,7 @@ func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage) int32 {
// InsertTempMessage 临时消息入数据库
func (bot *CQBot) InsertTempMessage(target int64, m *message.TempMessage) int32 {
val := MSG{
val := global.MSG{
"message-id": m.Id,
// FIXME(InsertTempMessage) InternalId missing
"from-group": m.GroupCode,
@ -461,7 +488,7 @@ func (bot *CQBot) Release() {
}
}
func (bot *CQBot) dispatchEventMessage(m MSG) {
func (bot *CQBot) dispatchEventMessage(m global.MSG) {
bot.lock.RLock()
defer bot.lock.RUnlock()
@ -489,9 +516,9 @@ func (bot *CQBot) dispatchEventMessage(m MSG) {
global.PutBuffer(event.buffer)
}
func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) MSG {
func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) global.MSG {
cqm := ToStringMessage(m.Elements, m.GroupCode, true)
gm := MSG{
gm := global.MSG{
"anonymous": nil,
"font": 0,
"group_id": m.GroupCode,
@ -506,7 +533,7 @@ func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) MSG {
}(),
"raw_message": cqm,
"self_id": bot.Client.Uin,
"sender": MSG{
"sender": global.MSG{
"age": 0,
"area": "",
"level": "",
@ -518,12 +545,12 @@ func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) MSG {
"user_id": m.Sender.Uin,
}
if m.Sender.IsAnonymous() {
gm["anonymous"] = MSG{
gm["anonymous"] = global.MSG{
"flag": m.Sender.AnonymousInfo.AnonymousId + "|" + m.Sender.AnonymousInfo.AnonymousNick,
"id": m.Sender.Uin,
"name": m.Sender.AnonymousInfo.AnonymousNick,
}
gm["sender"].(MSG)["nickname"] = "匿名消息"
gm["sender"].(global.MSG)["nickname"] = "匿名消息"
gm["sub_type"] = "anonymous"
} else {
group := bot.Client.FindGroup(m.GroupCode)
@ -541,7 +568,7 @@ func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) MSG {
return nil
}
}
ms := gm["sender"].(MSG)
ms := gm["sender"].(global.MSG)
switch mem.Permission {
case client.Owner:
ms["role"] = "owner"

View File

@ -3,7 +3,6 @@ package coolq
import (
"bytes"
"crypto/md5"
"encoding/base64"
"encoding/hex"
xml2 "encoding/xml"
"errors"
@ -18,11 +17,10 @@ import (
"strings"
"time"
"github.com/gabriel-vasile/mimetype"
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Mrs4s/MiraiGo/utils"
"github.com/gabriel-vasile/mimetype"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
@ -126,8 +124,8 @@ func (e *PokeElement) Type() message.ElementType {
}
// ToArrayMessage 将消息元素数组转为MSG数组以用于消息上报
func ToArrayMessage(e []message.IMessageElement, groupID int64) (r []MSG) {
r = make([]MSG, 0, len(e))
func ToArrayMessage(e []message.IMessageElement, groupID int64) (r []global.MSG) {
r = make([]global.MSG, 0, len(e))
m := &message.SendingMessage{Elements: e}
reply := m.FirstOrNil(func(e message.IMessageElement) bool {
_, ok := e.(*message.ReplyElement)
@ -140,7 +138,7 @@ func ToArrayMessage(e []message.IMessageElement, groupID int64) (r []MSG) {
rid = replyElem.Sender
}
if ExtraReplyData {
r = append(r, MSG{
r = append(r, global.MSG{
"type": "reply",
"data": map[string]string{
"id": strconv.FormatInt(int64(toGlobalID(rid, replyElem.ReplySeq)), 10),
@ -151,71 +149,71 @@ func ToArrayMessage(e []message.IMessageElement, groupID int64) (r []MSG) {
},
})
} else {
r = append(r, MSG{
r = append(r, global.MSG{
"type": "reply",
"data": map[string]string{"id": strconv.FormatInt(int64(toGlobalID(rid, replyElem.ReplySeq)), 10)},
})
}
}
for i, elem := range e {
var m MSG
var m global.MSG
switch o := elem.(type) {
case *message.ReplyElement:
if RemoveReplyAt && i+1 < len(e) && e[i+1].Type() == message.At {
if RemoveReplyAt && i+1 < len(e) {
elem, ok := e[i+1].(*message.AtElement)
if ok && elem.Target == o.Sender {
e[i+1] = nil
}
}
case *message.TextElement:
m = MSG{
m = global.MSG{
"type": "text",
"data": map[string]string{"text": o.Content},
}
case *message.LightAppElement:
m = MSG{
m = global.MSG{
"type": "json",
"data": map[string]string{"data": o.Content},
}
case *message.AtElement:
if o.Target == 0 {
m = MSG{
m = global.MSG{
"type": "at",
"data": map[string]string{"qq": "all"},
}
} else {
m = MSG{
m = global.MSG{
"type": "at",
"data": map[string]string{"qq": strconv.FormatInt(o.Target, 10)},
}
}
case *message.RedBagElement:
m = MSG{
m = global.MSG{
"type": "redbag",
"data": map[string]string{"title": o.Title},
}
case *message.ForwardElement:
m = MSG{
m = global.MSG{
"type": "forward",
"data": map[string]string{"id": o.ResId},
}
case *message.FaceElement:
m = MSG{
m = global.MSG{
"type": "face",
"data": map[string]string{"id": strconv.FormatInt(int64(o.Index), 10)},
}
case *message.VoiceElement:
m = MSG{
m = global.MSG{
"type": "record",
"data": map[string]string{"file": o.Name, "url": o.Url},
}
case *message.ShortVideoElement:
m = MSG{
m = global.MSG{
"type": "video",
"data": map[string]string{"file": o.Name, "url": o.Url},
}
case *message.GroupImageElement:
data := map[string]string{"file": hex.EncodeToString(o.Md5) + ".image", "url": o.Url}
data := map[string]string{"file": hex.EncodeToString(o.Md5) + ".image", "url": o.Url, "subType": strconv.FormatInt(int64(o.ImageBizType), 10)}
switch {
case o.Flash:
data["type"] = "flash"
@ -223,7 +221,7 @@ func ToArrayMessage(e []message.IMessageElement, groupID int64) (r []MSG) {
data["type"] = "show"
data["id"] = strconv.FormatInt(int64(o.EffectID), 10)
}
m = MSG{
m = global.MSG{
"type": "image",
"data": data,
}
@ -232,18 +230,18 @@ func ToArrayMessage(e []message.IMessageElement, groupID int64) (r []MSG) {
if o.Flash {
data["type"] = "flash"
}
m = MSG{
m = global.MSG{
"type": "image",
"data": data,
}
case *message.ServiceElement:
if isOk := strings.Contains(o.Content, "<?xml"); isOk {
m = MSG{
m = global.MSG{
"type": "xml",
"data": map[string]string{"data": o.Content, "resid": strconv.FormatInt(int64(o.Id), 10)},
}
} else {
m = MSG{
m = global.MSG{
"type": "json",
"data": map[string]string{"data": o.Content, "resid": strconv.FormatInt(int64(o.Id), 10)},
}
@ -332,6 +330,7 @@ func ToStringMessage(e []message.IMessageElement, groupID int64, isRaw ...bool)
} else if o.EffectID != 0 {
arg = ",type=show,id=" + strconv.FormatInt(int64(o.EffectID), 10)
}
arg += ",subType=" + strconv.FormatInt(int64(o.ImageBizType), 10)
if ur {
write("[CQ:image,file=%s%s]", hex.EncodeToString(o.Md5)+".image", arg)
} else {
@ -380,7 +379,7 @@ func (bot *CQBot) ConvertStringMessage(raw string, isGroup bool) (r []message.IM
switch {
case customText != "":
var elem *message.ReplyElement
var org MSG
var org global.MSG
sender, senderErr := strconv.ParseInt(d["qq"], 10, 64)
if senderErr != nil && err != nil {
log.Warnf("警告: 自定义 Reply 元素中必须包含 Uin 或 id")
@ -552,7 +551,7 @@ func (bot *CQBot) ConvertObjectMessage(m gjson.Result, isGroup bool) (r []messag
switch {
case customText != "":
var elem *message.ReplyElement
var org MSG
var org global.MSG
sender, senderErr := strconv.ParseInt(e.Get("data.[user_id,qq]").String(), 10, 64)
if senderErr != nil && err != nil {
log.Warnf("警告: 自定义 Reply 元素中必须包含 user_id 或 id")
@ -696,6 +695,8 @@ func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m inte
case *message.GroupImageElement:
img.Flash = flash
img.EffectID = int32(id)
i, _ := strconv.ParseInt(d["subType"], 10, 64)
img.ImageBizType = message.ImageBizType(i)
case *message.FriendImageElement:
img.Flash = flash
}
@ -1116,7 +1117,7 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
return &LocalImageElement{File: fu.Path}, nil
}
if strings.HasPrefix(f, "base64") && !video {
b, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(f, "base64://"))
b, err := global.Base64DecodeString(strings.TrimPrefix(f, "base64://"))
if err != nil {
return nil, err
}

View File

@ -18,8 +18,10 @@ func TestCQBot_ConvertStringMessage(t *testing.T) {
}
}
var bench = `asdfqwerqwerqwer[CQ:face,id=115,text=111]asdfasdfasdfasdfasdfasdfasd[CQ:face,id=217]&#93; 123 &#91;`
var benchArray = gjson.Parse(`[{"type":"text","data":{"text":"asdfqwerqwerqwer"}},{"type":"face","data":{"id":"115","text":"111"}},{"type":"text","data":{"text":"asdfasdfasdfasdfasdfasdfasd"}},{"type":"face","data":{"id":"217"}},{"type":"text","data":{"text":"] "}},{"type":"text","data":{"text":"123"}},{"type":"text","data":{"text":" ["}}]`)
var (
bench = `asdfqwerqwerqwer[CQ:face,id=115,text=111]asdfasdfasdfasdfasdfasdfasd[CQ:face,id=217]&#93; 123 &#91;`
benchArray = gjson.Parse(`[{"type":"text","data":{"text":"asdfqwerqwerqwer"}},{"type":"face","data":{"id":"115","text":"111"}},{"type":"text","data":{"text":"asdfasdfasdfasdfasdfasdfasd"}},{"type":"face","data":{"id":"217"}},{"type":"text","data":{"text":"] "}},{"type":"text","data":{"text":"123"}},{"type":"text","data":{"text":" ["}}]`)
)
func BenchmarkCQBot_ConvertStringMessage(b *testing.B) {
for i := 0; i < b.N; i++ {

View File

@ -36,15 +36,12 @@ func ToFormattedMessage(e []message.IMessageElement, groupID int64, isRaw ...boo
func (bot *CQBot) privateMessageEvent(c *client.QQClient, m *message.PrivateMessage) {
bot.checkMedia(m.Elements)
cqm := ToStringMessage(m.Elements, 0, true)
if !m.Sender.IsFriend {
bot.oneWayMsgCache.Store(m.Sender.Uin, "")
}
id := m.Id
if bot.db != nil {
id = bot.InsertPrivateMessage(m)
}
log.Infof("收到好友 %v(%v) 的消息: %v (%v)", m.Sender.DisplayName(), m.Sender.Uin, cqm, id)
fm := MSG{
fm := global.MSG{
"post_type": func() string {
if m.Sender.Uin == bot.Client.Uin {
return "message_sent"
@ -61,7 +58,7 @@ func (bot *CQBot) privateMessageEvent(c *client.QQClient, m *message.PrivateMess
"font": 0,
"self_id": c.Uin,
"time": time.Now().Unix(),
"sender": MSG{
"sender": global.MSG{
"user_id": m.Sender.Uin,
"nickname": m.Sender.Nickname,
"sex": "unknown",
@ -76,12 +73,12 @@ func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage)
for _, elem := range m.Elements {
if file, ok := elem.(*message.GroupFileElement); ok {
log.Infof("群 %v(%v) 内 %v(%v) 上传了文件: %v", m.GroupName, m.GroupCode, m.Sender.DisplayName(), m.Sender.Uin, file.Name)
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"notice_type": "group_upload",
"group_id": m.GroupCode,
"user_id": m.Sender.Uin,
"file": MSG{
"file": global.MSG{
"id": file.Path,
"name": file.Name,
"size": file.Size,
@ -118,7 +115,7 @@ func (bot *CQBot) tempMessageEvent(c *client.QQClient, e *client.TempMessageEven
id = bot.InsertTempMessage(m.Sender.Uin, m)
}
log.Infof("收到来自群 %v(%v) 内 %v(%v) 的临时会话消息: %v", m.GroupName, m.GroupCode, m.Sender.DisplayName(), m.Sender.Uin, cqm)
tm := MSG{
tm := global.MSG{
"post_type": "message",
"message_type": "private",
"sub_type": "group",
@ -130,7 +127,7 @@ func (bot *CQBot) tempMessageEvent(c *client.QQClient, e *client.TempMessageEven
"font": 0,
"self_id": c.Uin,
"time": time.Now().Unix(),
"sender": MSG{
"sender": global.MSG{
"user_id": m.Sender.Uin,
"group_id": m.GroupCode,
"nickname": m.Sender.Nickname,
@ -161,7 +158,7 @@ func (bot *CQBot) groupMutedEvent(c *client.QQClient, e *client.GroupMuteEvent)
}
}
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"duration": e.Time,
"group_id": e.GroupCode,
@ -184,7 +181,7 @@ func (bot *CQBot) groupRecallEvent(c *client.QQClient, e *client.GroupMessageRec
gid := toGlobalID(e.GroupCode, e.MessageId)
log.Infof("群 %v 内 %v 撤回了 %v 的消息: %v.",
formatGroupName(g), formatMemberName(g.FindMember(e.OperatorUin)), formatMemberName(g.FindMember(e.AuthorUin)), gid)
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"group_id": e.GroupCode,
"notice_type": "group_recall",
@ -203,7 +200,7 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.INotifyEvent) {
sender := group.FindMember(notify.Sender)
receiver := group.FindMember(notify.Receiver)
log.Infof("群 %v 内 %v 戳了戳 %v", formatGroupName(group), formatMemberName(sender), formatMemberName(receiver))
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"group_id": group.Code,
"notice_type": "notify",
@ -218,7 +215,7 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.INotifyEvent) {
sender := group.FindMember(notify.Sender)
luckyKing := group.FindMember(notify.LuckyKing)
log.Infof("群 %v 内 %v 的红包被抢完, %v 是运气王", formatGroupName(group), formatMemberName(sender), formatMemberName(luckyKing))
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"group_id": group.Code,
"notice_type": "notify",
@ -231,7 +228,7 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.INotifyEvent) {
})
case *client.MemberHonorChangedNotifyEvent:
log.Info(notify.Content())
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"group_id": group.Code,
"notice_type": "notify",
@ -267,7 +264,7 @@ func (bot *CQBot) friendNotifyEvent(c *client.QQClient, e client.INotifyEvent) {
} else {
log.Infof("好友 %v 戳了戳你.", friend.Nickname)
}
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"notice_type": "notify",
"sub_type": "poke",
@ -284,7 +281,7 @@ func (bot *CQBot) memberTitleUpdatedEvent(c *client.QQClient, e *client.MemberSp
group := c.FindGroup(e.GroupCode)
mem := group.FindMember(e.Uin)
log.Infof("群 %v(%v) 内成员 %v(%v) 获得了新的头衔: %v", group.Name, group.Code, mem.DisplayName(), mem.Uin, e.NewTitle)
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"notice_type": "notify",
"sub_type": "title",
@ -304,7 +301,7 @@ func (bot *CQBot) friendRecallEvent(c *client.QQClient, e *client.FriendMessageR
} else {
log.Infof("好友 %v 撤回了消息: %v", e.FriendUin, gid)
}
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"notice_type": "friend_recall",
"self_id": c.Uin,
@ -320,11 +317,11 @@ func (bot *CQBot) offlineFileEvent(c *client.QQClient, e *client.OfflineFileEven
return
}
log.Infof("好友 %v(%v) 发送了离线文件 %v", f.Nickname, f.Uin, e.FileName)
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"notice_type": "offline_file",
"user_id": e.Sender,
"file": MSG{
"file": global.MSG{
"name": e.FileName,
"size": e.FileSize,
"url": e.DownloadUrl,
@ -355,7 +352,7 @@ func (bot *CQBot) memberPermissionChangedEvent(c *client.QQClient, e *client.Mem
}
return "unset"
}()
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"notice_type": "group_admin",
"sub_type": st,
@ -368,7 +365,7 @@ func (bot *CQBot) memberPermissionChangedEvent(c *client.QQClient, e *client.Mem
func (bot *CQBot) memberCardUpdatedEvent(c *client.QQClient, e *client.MemberCardUpdatedEvent) {
log.Infof("群 %v 的 %v 更新了名片 %v -> %v", formatGroupName(e.Group), formatMemberName(e.Member), e.OldCard, e.Member.CardName)
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"notice_type": "group_card",
"group_id": e.Group.Code,
@ -398,7 +395,7 @@ func (bot *CQBot) friendRequestEvent(c *client.QQClient, e *client.NewFriendRequ
log.Infof("收到来自 %v(%v) 的好友请求: %v", e.RequesterNick, e.RequesterUin, e.Message)
flag := strconv.FormatInt(e.RequestId, 10)
bot.friendReqCache.Store(flag, e)
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "request",
"request_type": "friend",
"user_id": e.RequesterUin,
@ -412,7 +409,7 @@ func (bot *CQBot) friendRequestEvent(c *client.QQClient, e *client.NewFriendRequ
func (bot *CQBot) friendAddedEvent(c *client.QQClient, e *client.NewFriendEvent) {
log.Infof("添加了新好友: %v(%v)", e.Friend.Nickname, e.Friend.Uin)
bot.tempSessionCache.Delete(e.Friend.Uin)
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"notice_type": "friend_add",
"self_id": c.Uin,
@ -424,7 +421,7 @@ func (bot *CQBot) friendAddedEvent(c *client.QQClient, e *client.NewFriendEvent)
func (bot *CQBot) groupInvitedEvent(c *client.QQClient, e *client.GroupInvitedRequest) {
log.Infof("收到来自群 %v(%v) 内用户 %v(%v) 的加群邀请.", e.GroupName, e.GroupCode, e.InvitorNick, e.InvitorUin)
flag := strconv.FormatInt(e.RequestId, 10)
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "request",
"request_type": "group",
"sub_type": "invite",
@ -440,7 +437,7 @@ func (bot *CQBot) groupInvitedEvent(c *client.QQClient, e *client.GroupInvitedRe
func (bot *CQBot) groupJoinReqEvent(c *client.QQClient, e *client.UserJoinGroupRequest) {
log.Infof("群 %v(%v) 收到来自用户 %v(%v) 的加群请求.", e.GroupName, e.GroupCode, e.RequesterNick, e.RequesterUin)
flag := strconv.FormatInt(e.RequestId, 10)
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "request",
"request_type": "group",
"sub_type": "add",
@ -459,11 +456,11 @@ func (bot *CQBot) otherClientStatusChangedEvent(c *client.QQClient, e *client.Ot
} else {
log.Infof("Bot 账号在客户端 %v (%v) 登出.", e.Client.DeviceName, e.Client.DeviceKind)
}
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"notice_type": "client_status",
"online": e.Online,
"client": MSG{
"client": global.MSG{
"app_id": e.Client.AppId,
"device_name": e.Client.DeviceName,
"device_kind": e.Client.DeviceKind,
@ -496,7 +493,7 @@ func (bot *CQBot) groupEssenceMsg(c *client.QQClient, e *client.GroupDigestEvent
if e.OperatorUin == bot.Client.Uin {
return
}
bot.dispatchEventMessage(MSG{
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"group_id": e.GroupCode,
"notice_type": "essence",
@ -514,8 +511,8 @@ func (bot *CQBot) groupEssenceMsg(c *client.QQClient, e *client.GroupDigestEvent
})
}
func (bot *CQBot) groupIncrease(groupCode, operatorUin, userUin int64) MSG {
return MSG{
func (bot *CQBot) groupIncrease(groupCode, operatorUin, userUin int64) global.MSG {
return global.MSG{
"post_type": "notice",
"notice_type": "group_increase",
"group_id": groupCode,
@ -527,8 +524,8 @@ func (bot *CQBot) groupIncrease(groupCode, operatorUin, userUin int64) MSG {
}
}
func (bot *CQBot) groupDecrease(groupCode, userUin int64, operator *client.GroupMemberInfo) MSG {
return MSG{
func (bot *CQBot) groupDecrease(groupCode, userUin int64, operator *client.GroupMemberInfo) global.MSG {
return global.MSG{
"post_type": "notice",
"notice_type": "group_decrease",
"group_id": groupCode,

View File

@ -32,7 +32,6 @@ heartbeat:
# -1 为关闭心跳
interval: 5
message:
# 上报数据类型
# 可选: string,array
post-format: string
@ -48,6 +47,12 @@ message:
proxy-rewrite: ''
# 是否上报自身消息
report-self-message: false
# 移除服务端的Reply附带的At
remove-reply-at: false
# 为Reply附加更多信息
extra-reply-data: false
# 跳过 Mime 扫描, 忽略错误数据
skip-mime-scan: false
output:
# 日志等级 trace,debug,info,warn,error
@ -149,6 +154,8 @@ database: # 数据库相关设置
> 注4关闭心跳服务可能引起断线请谨慎关闭
> 注5关于MINE扫描 详见[MINE](file.md#MINE)
## 在线状态
| 状态 | 值 |

View File

@ -77,6 +77,7 @@ Type : `image`
| ------- | --------------- | ---------------------------------------------------------------------- |
| `file` | - | 图片文件名 |
| `type` | `flash``show` | 图片类型,`flash` 表示闪照,`show` 表示秀图,默认普通图片 |
| `subType`| - | 图片子类型, 只出现在群聊. |
| `url` | - | 图片 URL |
| `cache` | `0` `1` | 只在通过网络 URL 发送时有效,表示是否使用已缓存的文件,默认 `1` |
| `id` | - | 发送秀图时的特效id默认为40000 |
@ -93,6 +94,21 @@ Type : `image`
| 40004 | 爱你 |
| 40005 | 征友 |
子类型列表:
| value | 说明 |
| ----- | ---- |
| 0 | 正常图片 |
| 1 | 表情包, 在客户端会被分类到表情包图片并缩放显示 |
| 2 | 热图 |
| 3 | 斗图 |
| 4 | 智图? |
| 7 | 贴图 |
| 8 | 自拍 |
| 9 | 贴图广告? |
| 10 | 有待测试 |
| 13 | 热搜图 |
示例: `[CQ:image,file=http://baidu.com/1.jpg,type=show,id=40004]`
> 注意图片总大小不能超过30MBgif总帧数不能超过300帧
@ -1086,6 +1102,34 @@ JSON数组:
`该 API 没有响应数据`
### 获取单向好友列表
终结点: `/get_unidirectional_friend_list`
**响应数据**
数组信息:
| 字段 | 类型 | 说明 |
| ------------- | ------ | -------- |
| `nickname` | string | 昵称 |
| `user_id` | int64 | 用户QQ号 |
| `source` | string | 添加途径 |
> 添加途径为用户显示内容, 如 `精确查找` `QQ群 - xxxx`
### 删除单向好友
终结点: `/delete_unidirectional_friend`
**参数**
| 字段名 | 数据类型 | 默认值 | 说明 |
| ---------- | -------- | ------ | -------- |
| `user_id` | int64 | | 好友ID |
`该 API 没有响应数据`
### 删除好友
终结点: `/delete_friend`
@ -1094,7 +1138,7 @@ JSON数组:
| 字段名 | 数据类型 | 默认值 | 说明 |
| ---------- | -------- | ------ | -------- |
| `id` | int64 | | 好友ID |
| `user_id` | int64 | | 好友ID |
`该 API 没有响应数据`

View File

@ -38,3 +38,31 @@ go-cqhttp 默认生成的文件树如下所示:
| 0x10 | uint32 | 图片源文件大小 |
| 0x14 | string | 图片原名(QQ内部ID) |
| 0x14 + 原名长度 | string | 图片下载链接 |
# MINE
启用MINE检查可以及时发现媒体资源格式错误引起的上传失败(通常表现为请求网页图片但服务端返回404.html)
在配置文件中设置 `skip-mine-scan: false`go-cqhttp 会在上传媒体资源(视频暂不支持)前对MINE进行检查
详细允许类型如下所示:
图片:
> image/bmp
> image/gif
> image/jpeg
> image/png
> image/webp
语音:
> audio/aac
> audio/aiff
> audio/amr
> audio/ape
> audio/flac
> audio/midi
> audio/mp4
> audio/mpeg
> audio/ogg
> audio/wav
> audio/x-m4a

View File

@ -8,7 +8,7 @@ import (
)
func TestVersionNameCompare(t *testing.T) {
var tests = [...]struct {
tests := [...]struct {
current string
remote string
expected bool

View File

@ -1,7 +1,8 @@
//go:build (linux || (windows && !arm) || darwin) && (386 || amd64 || arm || arm64) && !race
// +build linux windows,!arm darwin
//go:build (linux || (windows && !arm && !arm64) || darwin) && (386 || amd64 || arm || arm64) && !race && !nosilk
// +build linux windows,!arm,!arm64 darwin
// +build 386 amd64 arm arm64
// +build !race
// +build !nosilk
package codec

View File

@ -1,5 +1,5 @@
//go:build (!arm && !arm64 && !amd64 && !386) || race || (!windows && !linux && !darwin) || (windows && arm)
// +build !arm,!arm64,!amd64,!386 race !windows,!linux,!darwin windows,arm
//go:build (!arm && !arm64 && !amd64 && !386) || (!windows && !linux && !darwin) || (windows && arm) || (windows && arm64) || race || nosilk
// +build !arm,!arm64,!amd64,!386 !windows,!linux,!darwin windows,arm windows,arm64 race nosilk
package codec

View File

@ -160,7 +160,7 @@ func Get() *Config {
generateConfig()
os.Exit(0)
}
if hasEnvironmentConf {
// type convert tools
toInt64 := func(str string) int64 {
i, _ := strconv.ParseInt(str, 10, 64)
@ -171,10 +171,13 @@ func Get() *Config {
global.SetAtDefault(&config.Account.Uin, toInt64(os.Getenv("GCQ_UIN")), int64(0))
global.SetAtDefault(&config.Account.Password, os.Getenv("GCQ_PWD"), "")
global.SetAtDefault(&config.Account.Status, int32(toInt64(os.Getenv("GCQ_STATUS"))), int32(0))
global.SetAtDefault(&config.Account.ReLogin.Disabled, !global.EnsureBool(os.Getenv("GCQ_RELOGIN"), false), false)
global.SetAtDefault(&config.Account.ReLogin.Disabled, !global.EnsureBool(os.Getenv("GCQ_RELOGIN_DISABLED"), true), false)
global.SetAtDefault(&config.Account.ReLogin.Delay, uint(toInt64(os.Getenv("GCQ_RELOGIN_DELAY"))), uint(0))
global.SetAtDefault(&config.Account.ReLogin.MaxTimes, uint(toInt64(os.Getenv("GCQ_RELOGIN_MAX_TIMES"))), uint(0))
dbConf := &LevelDBConfig{Enable: global.EnsureBool(os.Getenv("GCQ_LEVELDB"), true)}
if config.Database == nil {
config.Database = make(map[string]yaml.Node)
}
config.Database["leveldb"] = func() yaml.Node {
n := &yaml.Node{}
_ = n.Encode(dbConf)
@ -231,6 +234,7 @@ func Get() *Config {
_ = node.Encode(rwsConf)
config.Servers = append(config.Servers, map[string]yaml.Node{"ws-reverse": *node})
}
}
})
return config
}

View File

@ -3,7 +3,6 @@ package global
import (
"bytes"
"crypto/md5"
"encoding/base64"
"encoding/hex"
"errors"
"net"
@ -45,7 +44,7 @@ var (
// PathExists 判断给定path是否存在
func PathExists(path string) bool {
_, err := os.Stat(path)
return err == nil || os.IsExist(err)
return err == nil || errors.Is(err, os.ErrExist)
}
// ReadAllText 读取给定path对应文件无法读取时返回空值
@ -98,7 +97,7 @@ func FindFile(file, cache, p string) (data []byte, err error) {
return nil, err
}
case strings.HasPrefix(file, "base64"):
data, err = base64.StdEncoding.DecodeString(strings.TrimPrefix(file, "base64://"))
data, err = Base64DecodeString(strings.TrimPrefix(file, "base64://"))
if err != nil {
return nil, err
}

View File

@ -8,10 +8,15 @@ import (
"strings"
"sync"
"github.com/Mrs4s/MiraiGo/utils"
"github.com/segmentio/asm/base64"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
)
// MSG 消息Map
type MSG map[string]interface{}
// EnsureBool 判断给定的p是否可表示为合法Bool类型,否则返回defaultVal
//
// 支持的合法类型有
@ -152,3 +157,13 @@ func SplitURL(s string) []string {
result = append(result, s[last:])
return result
}
// Base64DecodeString decode base64 with avx2
// see https://github.com/segmentio/asm/issues/50
// avoid incorrect unsafe usage in origin library
func Base64DecodeString(s string) ([]byte, error) {
e := base64.StdEncoding
dst := make([]byte, e.DecodedLen(len(s)))
n, err := e.Decode(dst, utils.S2B(s))
return dst[:n], err
}

View File

@ -18,11 +18,9 @@ import (
log "github.com/sirupsen/logrus"
)
var (
validTasks = map[string]func(){
var validTasks = map[string]func(){
"dumpstack": dumpStack,
}
)
// SetupMainSignalHandler is for main to use at last
func SetupMainSignalHandler() <-chan struct{} {

View File

@ -7,3 +7,8 @@ package terminal
func RunningByDoubleClick() bool {
return false
}
// NoMoreDoubleClick 提示用户不要双击运行非Windows系统永远返回nil
func NoMoreDoubleClick() error {
return nil
}

View File

@ -4,8 +4,11 @@
package terminal
import (
"os"
"syscall"
"unsafe"
"github.com/pkg/errors"
)
// RunningByDoubleClick 检查是否通过双击直接运行
@ -22,3 +25,43 @@ func RunningByDoubleClick() bool {
}
return true
}
// NoMoreDoubleClick 提示用户不要双击运行,并生成安全启动脚本
func NoMoreDoubleClick() error {
r := boxW(0, "请勿通过双击直接运行本程序, 这将导致一些非预料的后果.\n请在shell中运行./go-cqhttp.exe\n点击确认将释出安全启动脚本点击取消则关闭程序", "警告", 0x00000030|0x00000001)
if r == 2 {
return nil
}
r = boxW(0, "点击确认将覆盖go-cqhttp.bat点击取消则关闭程序", "警告", 0x00000030|0x00000001)
if r == 2 {
return nil
}
f, err := os.OpenFile("go-cqhttp.bat", os.O_CREATE|os.O_RDWR, 0o666)
if err != nil {
return err
}
if err != nil {
return errors.Errorf("打开go-cqhttp.bat失败: %v", err)
}
_ = f.Truncate(0)
_, err = f.WriteString("%Created by go-cqhttp. DO NOT EDIT ME!%\nstart cmd /K go-cqhttp.exe")
if err != nil {
return errors.Errorf("写入go-cqhttp.bat失败: %v", err)
}
f.Close()
boxW(0, "安全启动脚本已生成请双击go-cqhttp.bat启动", "提示", 0x00000040|0x00000000)
return nil
}
// BoxW of Win32 API. Check https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messageboxw for more detail.
func boxW(hwnd uintptr, caption, title string, flags uint) int {
captionPtr, _ := syscall.UTF16PtrFromString(caption)
titlePtr, _ := syscall.UTF16PtrFromString(title)
ret, _, _ := syscall.NewLazyDLL("user32.dll").NewProc("MessageBoxW").Call(
hwnd,
uintptr(unsafe.Pointer(captionPtr)),
uintptr(unsafe.Pointer(titlePtr)),
uintptr(flags))
return int(ret)
}

47
go.mod
View File

@ -1,35 +1,56 @@
module github.com/Mrs4s/go-cqhttp
go 1.16
go 1.17
replace github.com/willf/bitset v1.2.0 => github.com/bits-and-blooms/bitset v1.2.0
require (
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f
github.com/Microsoft/go-winio v0.5.0
github.com/Mrs4s/MiraiGo v0.0.0-20210810070836-6614d2383adb
github.com/Mrs4s/MiraiGo v0.0.0-20210916113136-0238b2382b82
github.com/dustin/go-humanize v1.0.0
github.com/gabriel-vasile/mimetype v1.3.1
github.com/gorilla/websocket v1.4.2
github.com/guonaihong/gout v0.2.1
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/json-iterator/go v1.1.11
github.com/guonaihong/gout v0.2.4
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
github.com/lestrrat-go/strftime v1.0.4 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/pkg/errors v0.9.1
github.com/segmentio/asm v1.0.0
github.com/sirupsen/logrus v1.8.1
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
github.com/stretchr/testify v1.7.0
github.com/syndtr/goleveldb v1.0.0
github.com/tidwall/gjson v1.8.1
github.com/tuotoo/qrcode v0.0.0-20190222102259-ac9c44189bf2
github.com/wdvxdr1123/go-silk v0.0.0-20210316130616-d47b553def60
github.com/willf/bitset v1.2.0 // indirect
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)
replace github.com/willf/bitset v1.2.0 => github.com/bits-and-blooms/bitset v1.2.0
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect
github.com/google/uuid v1.1.1 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/klauspost/cpuid/v2 v2.0.6 // indirect
github.com/lestrrat-go/strftime v1.0.5 // indirect
github.com/maruel/rs v0.0.0-20150922171536-2c81c4312fe4 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
github.com/tidwall/match v1.0.3 // indirect
github.com/tidwall/pretty v1.1.0 // indirect
github.com/willf/bitset v1.2.0 // indirect
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
modernc.org/libc v1.8.1 // indirect
modernc.org/mathutil v1.2.2 // indirect
modernc.org/memory v1.0.4 // indirect
)

50
go.sum
View File

@ -4,8 +4,8 @@ github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f/g
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Microsoft/go-winio v0.5.0 h1:Elr9Wn+sGKPlkaBvwu4mTrxtmOp3F3yV9qhaHbXGjwU=
github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/Mrs4s/MiraiGo v0.0.0-20210810070836-6614d2383adb h1:agCxYd/ZemDwrEYKpnpKqA0cubxfpkQ/b+GpIlIJK0U=
github.com/Mrs4s/MiraiGo v0.0.0-20210810070836-6614d2383adb/go.mod h1:5V3f/+mTYtrI/+hLqbdzZQXuLMl2RyLfx0XYYjCQ90Q=
github.com/Mrs4s/MiraiGo v0.0.0-20210916113136-0238b2382b82 h1:VAav2Z5n41cp2bjskooPXAg9W39qQeEEj3FmYlnS3+E=
github.com/Mrs4s/MiraiGo v0.0.0-20210916113136-0238b2382b82/go.mod h1:EpB6wQ+iaIqLRxVrs6si2J3XGv6wHXMrRXNUnJFaoww=
github.com/bits-and-blooms/bitset v1.2.0 h1:Kn4yilvwNtMACtf1eYDlG8H77R07mZSPbMjLyS07ChA=
github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@ -22,15 +22,15 @@ github.com/gabriel-vasile/mimetype v1.3.1 h1:qevA6c2MtE1RorlScnixeG0VA1H4xrXyhyX
github.com/gabriel-vasile/mimetype v1.3.1/go.mod h1:fA8fi6KUiG7MgQQ+mEWotXoEOvmxRtOJlERCzSmRvr8=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.6.0 h1:Lb3veSYoGaNck69fV2+Vf2juLSsHpMTf3Vk5+X+EDJg=
github.com/gin-gonic/gin v1.6.0/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/gin-gonic/gin v1.7.0 h1:jGB9xAJQ12AIGNB4HguylppmDK1Am9ppF7XnGXXJuoU=
github.com/gin-gonic/gin v1.7.0/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@ -42,15 +42,15 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@ -59,26 +59,26 @@ github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/guonaihong/gout v0.2.1 h1:XnaS92y/Mpcu4MOQU5cx4hTKhbqFznbIE/uUI5sMY9E=
github.com/guonaihong/gout v0.2.1/go.mod h1:JkjNv1G2oRWvFgP/r4DUbYhoeIBB0zMP2j1ID+5CYpU=
github.com/guonaihong/gout v0.2.4 h1:BlWpWWay/Q1LkyIwupEWBZE3PMl4xzzAgMHw+OrZxBs=
github.com/guonaihong/gout v0.2.4/go.mod h1:ISabiAAj0z1h3bOFUKzfRqPMvX0wmcYzIh6i4xIxMPo=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ=
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
github.com/klauspost/cpuid/v2 v2.0.6 h1:dQ5ueTiftKxp0gyjKSx5+8BtPWkyQbd95m8Gys/RarI=
github.com/klauspost/cpuid/v2 v2.0.6/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8=
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is=
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkLibYKgg+SwmyFU9dF2hn6MdTj4=
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA=
github.com/lestrrat-go/strftime v1.0.4 h1:T1Rb9EPkAhgxKqbcMIPguPq8glqXTA1koF8n9BHElA8=
github.com/lestrrat-go/strftime v1.0.4/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g=
github.com/lestrrat-go/strftime v1.0.5 h1:A7H3tT8DhTz8u65w+JRpiBxM4dINQhUXAZnhBa2xeOE=
github.com/lestrrat-go/strftime v1.0.5/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g=
github.com/maruel/rs v0.0.0-20150922171536-2c81c4312fe4 h1:u9jwvcKbQpghIXgNl/EOL8hzhAFXh4ePrEP493W3tNA=
github.com/maruel/rs v0.0.0-20150922171536-2c81c4312fe4/go.mod h1:kcRFpEzolcEklV6rD7W95mG49/sbdX/PlFmd7ni3RvA=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
@ -87,9 +87,8 @@ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHX
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
@ -103,6 +102,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/segmentio/asm v1.0.0 h1:GMF7/2eLkte13LERSOmPI766AJXJDRlsqqiN8T7Mfmk=
github.com/segmentio/asm v1.0.0/go.mod h1:4EUJGaKsB8ImLUwOGORVsNd9vTRDeh44JGsY4aKp5I4=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
@ -131,8 +132,9 @@ github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLY
github.com/wdvxdr1123/go-silk v0.0.0-20210316130616-d47b553def60 h1:lRKf10iIOW0VsH5WDF621ihzR+R2wEBZVtNRHuLLCb4=
github.com/wdvxdr1123/go-silk v0.0.0-20210316130616-d47b553def60/go.mod h1:ecFKZPX81BaB70I6ruUgEwYcDOtuNgJGnjdK+MIl5ko=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI=
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
@ -144,6 +146,7 @@ golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125 h1:Ugb8sMTWuWRC3+sz5WeN/4kejDx9BvIwnPUiJBjJE+8=
@ -157,6 +160,7 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@ -174,8 +178,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6 h1:Vv0JUPWTyeqUq42B2WJ1FeIDjjvGKoA2Ss+Ts0lAVbs=
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
@ -198,10 +202,10 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=

20
main.go
View File

@ -55,7 +55,7 @@ var (
)
func main() {
c := flag.String("c", config.DefaultConfigFile, "configuration filename default is config.hjson")
c := flag.String("c", config.DefaultConfigFile, "configuration filename")
d := flag.Bool("d", false, "running as a daemon")
h := flag.Bool("h", false, "this help")
wd := flag.String("w", "", "cover the working directory")
@ -88,6 +88,8 @@ func main() {
if conf.Output.LogAging > 0 {
rotateOptions = append(rotateOptions, rotatelogs.WithMaxAge(time.Hour*24*time.Duration(conf.Output.LogAging)))
} else {
rotateOptions = append(rotateOptions, rotatelogs.WithMaxAge(time.Hour*24*365*10))
}
if conf.Output.LogForceNew {
rotateOptions = append(rotateOptions, rotatelogs.ForceNewFile())
@ -134,9 +136,12 @@ func main() {
}
}
if terminal.RunningByDoubleClick() && !isFastStart {
log.Warning("警告: 强烈不推荐通过双击直接运行本程序, 这将导致一些非预料的后果.")
log.Warning("将等待10s后启动")
time.Sleep(time.Second * 10)
err := terminal.NoMoreDoubleClick()
if err != nil {
log.Errorf("遇到错误: %v", err)
time.Sleep(time.Second * 5)
}
return
}
if (conf.Account.Uin == 0 || (conf.Account.Password == "" && !conf.Account.Encrypt)) && !global.PathExists("session.token") {
@ -305,6 +310,7 @@ func main() {
time.Sleep(time.Second * time.Duration(conf.Account.ReLogin.Delay))
for {
if conf.Account.ReLogin.Disabled {
log.Warnf("未启用自动重连, 将退出.")
os.Exit(1)
}
if times > conf.Account.ReLogin.MaxTimes && conf.Account.ReLogin.MaxTimes != 0 {
@ -317,6 +323,10 @@ func main() {
} else {
time.Sleep(time.Second)
}
if cli.Online {
log.Infof("登录已完成")
break
}
log.Warnf("尝试重连...")
err := cli.TokenLogin(AccountToken)
if err == nil {
@ -627,7 +637,7 @@ func newClient() *client.QQClient {
log.Infof("检测到 address.txt 文件. 将覆盖目标IP.")
addr := global.ReadAddrFile("address.txt")
if len(addr) > 0 {
cli.SetCustomServer(addr)
c.SetCustomServer(addr)
}
log.Infof("读取到 %v 个自定义地址.", len(addr))
}

View File

@ -13,48 +13,56 @@ type resultGetter interface {
Get(string) gjson.Result
}
type handler func(action string, p resultGetter) coolq.MSG
type handler func(action string, p resultGetter) global.MSG
type apiCaller struct {
bot *coolq.CQBot
handlers []handler
}
func getLoginInfo(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
func getLoginInfo(bot *coolq.CQBot, _ resultGetter) global.MSG {
return bot.CQGetLoginInfo()
}
func getQiDianAccountInfo(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
func getQiDianAccountInfo(bot *coolq.CQBot, _ resultGetter) global.MSG {
return bot.CQGetQiDianAccountInfo()
}
func getFriendList(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
func getFriendList(bot *coolq.CQBot, _ resultGetter) global.MSG {
return bot.CQGetFriendList()
}
func deleteFriend(bot *coolq.CQBot, p resultGetter) coolq.MSG {
return bot.CQDeleteFriend(p.Get("id").Int())
func getUnidirectionalFriendList(bot *coolq.CQBot, _ resultGetter) global.MSG {
return bot.CQGetUnidirectionalFriendList()
}
func getGroupList(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func deleteFriend(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQDeleteFriend(p.Get("[user_id,id].0").Int())
}
func deleteUnidirectionalFriend(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQDeleteUnidirectionalFriend(p.Get("user_id").Int())
}
func getGroupList(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetGroupList(p.Get("no_cache").Bool())
}
func getGroupInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getGroupInfo(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetGroupInfo(p.Get("group_id").Int(), p.Get("no_cache").Bool())
}
func getGroupMemberList(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getGroupMemberList(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetGroupMemberList(p.Get("group_id").Int(), p.Get("no_cache").Bool())
}
func getGroupMemberInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getGroupMemberInfo(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetGroupMemberInfo(
p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("no_cache").Bool(),
)
}
func sendMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func sendMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
autoEscape := global.EnsureBool(p.Get("auto_escape"), false)
if p.Get("message_type").Str == "private" {
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("group_id").Int(), p.Get("message"), autoEscape)
@ -68,28 +76,28 @@ func sendMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
if p.Get("group_id").Int() != 0 {
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), autoEscape)
}
return coolq.MSG{}
return global.MSG{}
}
func sendGroupMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func sendGroupMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"),
global.EnsureBool(p.Get("auto_escape"), false))
}
func sendGroupForwardMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func sendGroupForwardMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQSendGroupForwardMessage(p.Get("group_id").Int(), p.Get("messages"))
}
func sendPrivateMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func sendPrivateMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("group_id").Int(), p.Get("message"),
global.EnsureBool(p.Get("auto_escape"), false))
}
func deleteMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func deleteMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQDeleteMessage(int32(p.Get("message_id").Int()))
}
func setFriendAddRequest(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func setFriendAddRequest(bot *coolq.CQBot, p resultGetter) global.MSG {
apr := true
if p.Get("approve").Exists() {
apr = p.Get("approve").Bool()
@ -97,7 +105,7 @@ func setFriendAddRequest(bot *coolq.CQBot, p resultGetter) coolq.MSG {
return bot.CQProcessFriendRequest(p.Get("flag").Str, apr)
}
func setGroupAddRequest(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func setGroupAddRequest(bot *coolq.CQBot, p resultGetter) global.MSG {
subType := p.Get("sub_type").Str
apr := true
if subType == "" {
@ -109,19 +117,19 @@ func setGroupAddRequest(bot *coolq.CQBot, p resultGetter) coolq.MSG {
return bot.CQProcessGroupRequest(p.Get("flag").Str, subType, p.Get("reason").Str, apr)
}
func setGroupCard(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func setGroupCard(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQSetGroupCard(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("card").Str)
}
func setGroupSpecialTitle(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func setGroupSpecialTitle(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQSetGroupSpecialTitle(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("special_title").Str)
}
func setGroupKick(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func setGroupKick(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQSetGroupKick(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("message").Str, p.Get("reject_add_request").Bool())
}
func setGroupBan(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func setGroupBan(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQSetGroupBan(p.Get("group_id").Int(), p.Get("user_id").Int(), func() uint32 {
if p.Get("duration").Exists() {
return uint32(p.Get("duration").Int())
@ -130,7 +138,7 @@ func setGroupBan(bot *coolq.CQBot, p resultGetter) coolq.MSG {
}())
}
func setGroupWholeBan(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func setGroupWholeBan(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQSetGroupWholeBan(p.Get("group_id").Int(), func() bool {
if p.Get("enable").Exists() {
return p.Get("enable").Bool()
@ -139,11 +147,11 @@ func setGroupWholeBan(bot *coolq.CQBot, p resultGetter) coolq.MSG {
}())
}
func setGroupName(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func setGroupName(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQSetGroupName(p.Get("group_id").Int(), p.Get("group_name").Str)
}
func setGroupAdmin(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func setGroupAdmin(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQSetGroupAdmin(p.Get("group_id").Int(), p.Get("user_id").Int(), func() bool {
if p.Get("enable").Exists() {
return p.Get("enable").Bool()
@ -152,19 +160,19 @@ func setGroupAdmin(bot *coolq.CQBot, p resultGetter) coolq.MSG {
}())
}
func sendGroupNotice(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func sendGroupNotice(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQSetGroupMemo(p.Get("group_id").Int(), p.Get("content").Str, p.Get("image").String())
}
func setGroupLeave(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func setGroupLeave(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQSetGroupLeave(p.Get("group_id").Int())
}
func getImage(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getImage(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetImage(p.Get("file").Str)
}
func getForwardMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getForwardMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
id := p.Get("message_id").Str
if id == "" {
id = p.Get("id").Str
@ -172,11 +180,11 @@ func getForwardMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
return bot.CQGetForwardMessage(id)
}
func getMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetMessage(int32(p.Get("message_id").Int()))
}
func downloadFile(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func downloadFile(bot *coolq.CQBot, p resultGetter) global.MSG {
headers := map[string]string{}
headersToken := p.Get("headers")
if headersToken.IsArray() {
@ -199,11 +207,11 @@ func downloadFile(bot *coolq.CQBot, p resultGetter) coolq.MSG {
return bot.CQDownloadFile(p.Get("url").Str, headers, int(p.Get("thread_count").Int()))
}
func getGroupHonorInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getGroupHonorInfo(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetGroupHonorInfo(p.Get("group_id").Int(), p.Get("type").Str)
}
func setRestart(_ *coolq.CQBot, _ resultGetter) coolq.MSG {
func setRestart(_ *coolq.CQBot, _ resultGetter) global.MSG {
/*
var delay int64
delay = p.Get("delay").Int()
@ -215,115 +223,115 @@ func setRestart(_ *coolq.CQBot, _ resultGetter) coolq.MSG {
Restart <- struct{}{}
}(delay)
*/
return coolq.MSG{"data": nil, "retcode": 99, "msg": "restart un-supported now", "wording": "restart函数暂不兼容", "status": "failed"}
return global.MSG{"data": nil, "retcode": 99, "msg": "restart un-supported now", "wording": "restart函数暂不兼容", "status": "failed"}
}
func canSendImage(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
func canSendImage(bot *coolq.CQBot, _ resultGetter) global.MSG {
return bot.CQCanSendImage()
}
func canSendRecord(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
func canSendRecord(bot *coolq.CQBot, _ resultGetter) global.MSG {
return bot.CQCanSendRecord()
}
func getStrangerInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getStrangerInfo(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetStrangerInfo(p.Get("user_id").Int())
}
func getStatus(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
func getStatus(bot *coolq.CQBot, _ resultGetter) global.MSG {
return bot.CQGetStatus()
}
func getVersionInfo(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
func getVersionInfo(bot *coolq.CQBot, _ resultGetter) global.MSG {
return bot.CQGetVersionInfo()
}
func getGroupSystemMSG(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
func getGroupSystemMSG(bot *coolq.CQBot, _ resultGetter) global.MSG {
return bot.CQGetGroupSystemMessages()
}
func getGroupFileSystemInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getGroupFileSystemInfo(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetGroupFileSystemInfo(p.Get("group_id").Int())
}
func getGroupRootFiles(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getGroupRootFiles(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetGroupRootFiles(p.Get("group_id").Int())
}
func getGroupFilesByFolder(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getGroupFilesByFolder(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetGroupFilesByFolderID(p.Get("group_id").Int(), p.Get("folder_id").Str)
}
func getGroupFileURL(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getGroupFileURL(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetGroupFileURL(p.Get("group_id").Int(), p.Get("file_id").Str, int32(p.Get("busid").Int()))
}
func uploadGroupFile(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func uploadGroupFile(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQUploadGroupFile(p.Get("group_id").Int(), p.Get("file").Str, p.Get("name").Str, p.Get("folder").Str)
}
func groupFileCreateFolder(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func groupFileCreateFolder(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGroupFileCreateFolder(p.Get("group_id").Int(), p.Get("folder_id").Str, p.Get("name").Str)
}
func deleteGroupFolder(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func deleteGroupFolder(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGroupFileDeleteFolder(p.Get("group_id").Int(), p.Get("folder_id").Str)
}
func deleteGroupFile(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func deleteGroupFile(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGroupFileDeleteFile(p.Get("group_id").Int(), p.Get("file_id").Str, int32(p.Get("bus_id").Int()))
}
func getGroupMsgHistory(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getGroupMsgHistory(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetGroupMessageHistory(p.Get("group_id").Int(), p.Get("message_seq").Int())
}
func getVipInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getVipInfo(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetVipInfo(p.Get("user_id").Int())
}
func reloadEventFilter(_ *coolq.CQBot, p resultGetter) coolq.MSG {
func reloadEventFilter(_ *coolq.CQBot, p resultGetter) global.MSG {
addFilter(p.Get("file").String())
return coolq.OK(nil)
}
func getGroupAtAllRemain(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getGroupAtAllRemain(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetAtAllRemain(p.Get("group_id").Int())
}
func ocrImage(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func ocrImage(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQOcrImage(p.Get("image").Str)
}
func getOnlineClients(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getOnlineClients(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetOnlineClients(p.Get("no_cache").Bool())
}
func getWordSlices(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getWordSlices(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetWordSlices(p.Get("content").Str)
}
func setGroupPortrait(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func setGroupPortrait(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQSetGroupPortrait(p.Get("group_id").Int(), p.Get("file").String(), p.Get("cache").String())
}
func setEssenceMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func setEssenceMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQSetEssenceMessage(int32(p.Get("message_id").Int()))
}
func deleteEssenceMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func deleteEssenceMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQDeleteEssenceMessage(int32(p.Get("message_id").Int()))
}
func getEssenceMsgList(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getEssenceMsgList(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetEssenceMessageList(p.Get("group_id").Int())
}
func checkURLSafely(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func checkURLSafely(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQCheckURLSafely(p.Get("url").String())
}
func setGroupAnonymousBan(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func setGroupAnonymousBan(bot *coolq.CQBot, p resultGetter) global.MSG {
obj := p.Get("anonymous")
flag := p.Get("anonymous_flag")
if !flag.Exists() {
@ -338,27 +346,29 @@ func setGroupAnonymousBan(bot *coolq.CQBot, p resultGetter) coolq.MSG {
return bot.CQSetGroupAnonymousBan(p.Get("group_id").Int(), flag.String(), int32(p.Get("duration").Int()))
}
func handleQuickOperation(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func handleQuickOperation(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQHandleQuickOperation(p.Get("context"), p.Get("operation"))
}
func getModelShow(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func getModelShow(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQGetModelShow(p.Get("model").String())
}
func setModelShow(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func setModelShow(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQSetModelShow(p.Get("model").String(), p.Get("model_show").String())
}
func markMSGAsRead(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func markMSGAsRead(bot *coolq.CQBot, p resultGetter) global.MSG {
return bot.CQMarkMessageAsRead(int32(p.Get("message_id").Int()))
}
// API 是go-cqhttp当前支持的所有api的映射表
var API = map[string]func(*coolq.CQBot, resultGetter) coolq.MSG{
var API = map[string]func(*coolq.CQBot, resultGetter) global.MSG{
"get_login_info": getLoginInfo,
"get_friend_list": getFriendList,
"get_unidirectional_friend_list": getUnidirectionalFriendList,
"delete_friend": deleteFriend,
"delete_unidirectional_friend": deleteUnidirectionalFriend,
"get_group_list": getGroupList,
"get_group_info": getGroupInfo,
"get_group_member_list": getGroupMemberList,
@ -420,7 +430,7 @@ var API = map[string]func(*coolq.CQBot, resultGetter) coolq.MSG{
"mark_msg_as_read": markMSGAsRead,
}
func (api *apiCaller) callAPI(action string, p resultGetter) coolq.MSG {
func (api *apiCaller) callAPI(action string, p resultGetter) global.MSG {
for _, fn := range api.handlers {
if ret := fn(action, p); ret != nil {
return ret

View File

@ -5,6 +5,7 @@ import (
"crypto/hmac"
"crypto/sha1"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net/http"
@ -16,7 +17,6 @@ import (
"github.com/Mrs4s/MiraiGo/utils"
"github.com/guonaihong/gout"
"github.com/guonaihong/gout/dataflow"
jsoniter "github.com/json-iterator/go"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
@ -30,8 +30,6 @@ type httpServer struct {
accessToken string
}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// HTTPClient 反向HTTP上报客户端
type HTTPClient struct {
bot *coolq.CQBot
@ -53,13 +51,22 @@ func (h *httpCtx) Get(s string) gjson.Result {
if j.Exists() {
return j
}
validJSONParam := func(p string) bool {
return (strings.HasPrefix(p, "{") || strings.HasPrefix(p, "[")) && gjson.Valid(p)
}
if h.postForm != nil {
if form := h.postForm.Get(s); form != "" {
if validJSONParam(form) {
return gjson.Result{Type: gjson.JSON, Raw: form}
}
return gjson.Result{Type: gjson.String, Str: form}
}
}
if h.query != nil {
if query := h.query.Get(s); query != "" {
if validJSONParam(query) {
return gjson.Result{Type: gjson.JSON, Raw: query}
}
return gjson.Result{Type: gjson.String, Str: query}
}
}

View File

@ -5,6 +5,8 @@ import (
"context"
"os"
"sync"
"sync/atomic"
"time"
"github.com/Mrs4s/go-cqhttp/coolq"
"github.com/Mrs4s/go-cqhttp/global"
@ -21,7 +23,7 @@ var (
func rateLimit(frequency float64, bucketSize int) handler {
limiter := rate.NewLimiter(rate.Limit(frequency), bucketSize)
return func(_ string, _ resultGetter) coolq.MSG {
return func(_ string, _ resultGetter) global.MSG {
_ = limiter.Wait(context.Background())
return nil
}
@ -69,15 +71,23 @@ func longPolling(bot *coolq.CQBot, maxSize int) handler {
}
cond.Signal()
})
return func(action string, p resultGetter) coolq.MSG {
return func(action string, p resultGetter) global.MSG {
if action != "get_updates" {
return nil
}
var (
ok int32
ch = make(chan []interface{}, 1)
timeout = time.Duration(p.Get("timeout").Int()) * time.Second
)
defer close(ch)
go func() {
mutex.Lock()
defer mutex.Unlock()
if queue.Len() == 0 {
cond.Wait()
}
if atomic.CompareAndSwapInt32(&ok, 0, 1) {
limit := int(p.Get("limit").Int())
if limit <= 0 || queue.Len() < limit {
limit = queue.Len()
@ -86,6 +96,18 @@ func longPolling(bot *coolq.CQBot, maxSize int) handler {
for i := 0; i < limit; i++ {
ret[i] = queue.Remove(queue.Front())
}
ch <- ret
}
}()
if timeout != 0 {
select {
case <-time.After(timeout):
atomic.StoreInt32(&ok, 1)
return coolq.OK([]interface{}{})
case ret := <-ch:
return coolq.OK(ret)
}
}
return coolq.OK(<-ch)
}
}

View File

@ -2,6 +2,7 @@ package server
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
@ -86,8 +87,7 @@ func RunLambdaClient(bot *coolq.CQBot, conf *config.LambdaServer) {
case "scf": // tencent serverless function
base := fmt.Sprintf("http://%s:%s/runtime/",
os.Getenv("SCF_RUNTIME_API"),
os.Getenv("SCF_RUNTIME_API_PORT"),
)
os.Getenv("SCF_RUNTIME_API_PORT"))
cli.nextURL = base + "invocation/next"
cli.responseURL = base + "invocation/response"
post, err := http.Post(base+"init/ready", "", nil)
@ -116,23 +116,20 @@ func RunLambdaClient(bot *coolq.CQBot, conf *config.LambdaServer) {
for {
req := cli.next()
if req == nil {
writer := lambdaResponseWriter{statusCode: 200}
_, _ = writer.Write(nil)
continue
}
writer := lambdaResponseWriter{statusCode: 200, header: make(http.Header)}
func() {
defer func() {
if e := recover(); e != nil {
log.Warnf("Lambda 出现不可恢复错误: %v\n%s", e, debug.Stack())
}
}()
writer := lambdaResponseWriter{header: make(http.Header)}
if req != nil {
server.ServeHTTP(&writer, req)
}
}()
if err := writer.flush(); err != nil {
log.Warnf("Lambda 发送响应失败: %v", err)
}
}()
}
}
@ -160,8 +157,8 @@ func (c *lambdaClient) next() *http.Request {
if resp.StatusCode != http.StatusOK {
return nil
}
var req = new(http.Request)
var invoke = new(lambdaInvoke)
req := new(http.Request)
invoke := new(lambdaInvoke)
_ = json.NewDecoder(resp.Body).Decode(invoke)
if invoke.HTTPMethod == "" { // 不是 api 网关
return nil