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

Compare commits

..

75 Commits

Author SHA1 Message Date
1d7f1cc5d5 add: group_card event. 2020-10-08 23:28:22 +08:00
24937f2386 update go-silk. 2020-10-08 23:06:33 +08:00
73bd756c20 fix #341. 2020-10-08 22:48:47 +08:00
9d58c56b35 fix typo. 2020-10-08 21:38:03 +08:00
6879197107 fix typo. 2020-10-08 15:54:40 +08:00
a979c46563 update MiraiGo. 2020-10-08 15:52:33 +08:00
e8513da090 Merge pull request #345 from wdvxdr1123/dev
feature support silk encoder
2020-10-07 19:32:16 +08:00
2a5f78499b feature support silk encoder 2020-10-06 10:30:52 +08:00
b167231787 Merge
sync
2020-10-06 09:38:48 +08:00
7ae9c2d220 Merge branch 'dev' of https://github.com/Mrs4s/go-cqhttp into dev 2020-10-05 16:49:45 +08:00
31f24525f0 fix filter panic. 2020-10-05 16:42:13 +08:00
51101f02cd Merge pull request #344 from scjtqs/adminApiDev
修复 获取 当前配置的方法名错误问题,增加当前admin api的 doc
2020-10-04 21:35:39 +08:00
4d404eacd9 修复 获取 当前参数的方法名错误问题,增加当前admin api的 doc 2020-10-04 20:01:59 +08:00
ff29e16220 Merge
sync
2020-10-04 12:51:48 +08:00
d4811d53e7 Merge pull request #340 from scjtqs/adminApiDev
fix: 修复 无法关闭 web admin监听的问题
2020-10-04 00:23:02 +08:00
b19b114d3a fix web输入api显示 2020-10-03 17:54:15 +08:00
95c399a003 添加了 admin api 的监听 host支持,验证码提示增加 host+port 2020-10-03 17:43:03 +08:00
e3f0dbc4ac fix: 修复 无法关闭 web admin监听的问题 2020-10-03 17:28:21 +08:00
b0d5589dcd update MiraiGo. 2020-10-03 13:23:50 +08:00
b4d29e270a fix typo. 2020-10-03 13:13:13 +08:00
a5958e0877 fix typo. 2020-10-03 13:05:17 +08:00
cc1093ff57 Merge pull request #333 from scjtqs/adminApiDev
admin api 初版
2020-10-03 12:57:34 +08:00
a712db5d50 Merge pull request #339 from wdvxdr1123/dev
feature support .get_word_slices
2020-10-03 12:55:24 +08:00
030eb6b7c4 feature support [CQ:tts] 2020-10-03 09:59:21 +08:00
6b706ca3ff Merge
Dev
2020-10-02 23:45:49 +08:00
bbf2025350 feature support .get_word_slices 2020-10-02 23:41:02 +08:00
e386a52fed 解决冲突 2020-10-02 20:11:15 +08:00
4c8ae2f08b fix #239 2020-10-02 17:46:02 +08:00
d70e5d91b3 update config. 2020-10-02 17:42:15 +08:00
c2fae1e6f5 update MiraiGo. fix #327 #258 2020-10-02 16:42:38 +08:00
1ce73cb36a Merge branch 'master' into dev 2020-10-02 16:38:35 +08:00
dfbea6ac28 Merge pull request #338 from fkx4-p/patch-1
Update quick_start.md
2020-10-02 16:22:15 +08:00
29d001d60c Merge pull request #337 from wdvxdr1123/dev
Feature:  support [CQ:gift]
2020-10-01 20:43:54 +08:00
93f3786059 Update quick_start.md 2020-10-01 20:25:09 +08:00
e59d0a1bfd Update quick_start.md 2020-10-01 19:54:54 +08:00
5c1ad4ad8e Update quick_start.md 2020-10-01 19:41:14 +08:00
9cd044c402 Merge branch 'dev' of https://github.com/wdvxdr1123/go-cqhttp into dev 2020-10-01 18:12:04 +08:00
add9d3fc20 feature [CQ:gift] 2020-10-01 18:11:28 +08:00
0d1dfeefa1 Merge
Dev
2020-10-01 17:47:55 +08:00
d438543746 Merge pull request #335 from qianjunakasumi/dev
修复机器人已登录但继续尝试登录的缺陷
2020-10-01 11:40:13 +08:00
79b0c95f09 Merge pull request #334 from takayama-lily/master
Update QA.md
2020-10-01 11:39:19 +08:00
f5f3a314eb 修复机器人已登录但继续尝试登录的缺陷 2020-10-01 09:23:55 +08:00
de234c7721 Update QA.md 2020-10-01 08:38:11 +09:00
a6a1de0a00 admin api 初版 2020-09-30 20:10:59 +08:00
062a898383 Merge branch 'dev' 2020-09-29 19:16:15 +08:00
83ce4e58a5 update MiraiGo. fix #329 2020-09-29 19:15:30 +08:00
eef140e922 Merge pull request #328 from wdvxdr1123/dev
fix [CQ:record] & docs set_group_portrait
2020-09-29 18:45:13 +08:00
6581394ae1 fix [CQ:record] & docs set_group_portrait 2020-09-28 18:45:34 +08:00
2e59cb8a17 Merge
sync
2020-09-28 18:37:47 +08:00
b73162238f update MiraiGo. fix #320 2020-09-28 16:26:21 +08:00
1a3cba5425 add sending log limit. 2020-09-28 16:13:37 +08:00
9ecef96205 update MiraiGo. 2020-09-28 16:04:34 +08:00
43ecc25989 upload QA.md 2020-09-27 19:29:34 +08:00
9b41cd8ea2 update MiraiGo. 2020-09-26 21:44:22 +08:00
e0ab2417c4 update MiraiGo. 2020-09-26 21:43:21 +08:00
c7ab32fead update MiraiGo. fix #304 2020-09-25 13:06:50 +08:00
8f5b8375a7 remove 'servers.bin' 2020-09-25 11:27:49 +08:00
9049018d2f update MiraiGo. 2020-09-25 11:26:55 +08:00
fffe64651a Merge branch 'master' into dev 2020-09-25 11:19:12 +08:00
a9d53f038f Merge pull request #316 from XYenon/patch-1
Fix empty message segment
2020-09-24 00:47:01 +08:00
cec81b7ad8 Update cqcode.go 2020-09-23 23:08:11 +08:00
dddb3d2299 Merge pull request #314 from scjtqs/dev4
添加,好友消息和群消息发送成功日志。可用于正则匹配(历史聊天记录
2020-09-23 01:28:18 +08:00
f6d37d460c 修正 array message 遗漏问题 2020-09-23 01:07:50 +08:00
aca6a3cf28 添加,好友消息和群消息发送成功日志。可用于正则匹配(历史聊天记录 2020-09-22 22:47:01 +08:00
d390dd539b update doc. 2020-09-22 21:59:12 +08:00
3269387163 Merge pull request #310 from wdvxdr1123/dev
feature set_group_portrait
2020-09-22 13:15:38 +08:00
cd09a68e0d simplify 2020-09-22 11:39:14 +08:00
d2d408a8e9 feature set_group_portrait
[2020-09-22 10:50:46] [ERROR]: 读取服务器地址时出现错误: %vEOF
2020-09-22 11:17:53 +08:00
995737b0b8 Merge pull request #4 from Mrs4s/dev
Dev
2020-09-22 08:36:00 +08:00
72d62ad7c3 update MiraiGo. 2020-09-21 22:28:34 +08:00
387d33a01b update MiraiGo. fix #307 #306 2020-09-21 21:55:54 +08:00
65811d4e22 Merge pull request #300 from the-25th-Nova/patch-1
修复Docs中Markdown错误
2020-09-20 12:01:42 +08:00
01dd760b5c Fix Markdown 2020-09-20 11:58:37 +08:00
9b77f09d2f Merge pull request #3 from Mrs4s/master
1
2020-09-13 17:58:36 +08:00
ec45d04c81 Merge pull request #2 from Mrs4s/master
sync
2020-09-11 19:11:34 +08:00
19 changed files with 1453 additions and 221 deletions

View File

@ -6,6 +6,7 @@ import (
"path" "path"
"runtime" "runtime"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/Mrs4s/MiraiGo/binary" "github.com/Mrs4s/MiraiGo/binary"
@ -101,6 +102,17 @@ func (bot *CQBot) CQGetGroupMemberInfo(groupId, userId int64) MSG {
return OK(convertGroupMemberInfo(groupId, member)) return OK(convertGroupMemberInfo(groupId, member))
} }
func (bot *CQBot) CQGetWordSlices(content string) MSG {
slices, err := bot.Client.GetWordSegmentation(content)
if err != nil {
return Failed(100)
}
for i := 0; i < len(slices); i++ {
slices[i] = strings.ReplaceAll(slices[i], "\u0000", "")
}
return OK(MSG{"slices": slices})
}
// https://cqhttp.cc/docs/4.15/#/API?id=send_group_msg-%E5%8F%91%E9%80%81%E7%BE%A4%E6%B6%88%E6%81%AF // https://cqhttp.cc/docs/4.15/#/API?id=send_group_msg-%E5%8F%91%E9%80%81%E7%BE%A4%E6%B6%88%E6%81%AF
func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bool) MSG { func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bool) MSG {
var str string var str string
@ -125,6 +137,7 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bo
if mid == -1 { if mid == -1 {
return Failed(100) return Failed(100)
} }
log.Infof("发送群 %v(%v) 的消息: %v (%v)", groupId, groupId, limitedString(m.String()), mid)
return OK(MSG{"message_id": mid}) return OK(MSG{"message_id": mid})
} }
str = func() string { str = func() string {
@ -151,6 +164,7 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bo
if mid == -1 { if mid == -1 {
return Failed(100) return Failed(100)
} }
log.Infof("发送群 %v(%v) 的消息: %v (%v)", groupId, groupId, limitedString(str), mid)
return OK(MSG{"message_id": mid}) return OK(MSG{"message_id": mid})
} }
@ -247,6 +261,7 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape b
if mid == -1 { if mid == -1 {
return Failed(100) return Failed(100)
} }
log.Infof("发送好友 %v(%v) 的消息: %v (%v)", userId, userId, limitedString(m.String()), mid)
return OK(MSG{"message_id": mid}) return OK(MSG{"message_id": mid})
} }
str = func() string { str = func() string {
@ -271,6 +286,7 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape b
if mid == -1 { if mid == -1 {
return Failed(100) return Failed(100)
} }
log.Infof("发送好友 %v(%v) 的消息: %v (%v)", userId, userId, limitedString(str), mid)
return OK(MSG{"message_id": mid}) return OK(MSG{"message_id": mid})
} }
@ -648,11 +664,38 @@ func (bot *CQBot) CQCanSendRecord() MSG {
return OK(MSG{"yes": true}) return OK(MSG{"yes": true})
} }
func (bot *CQBot) CQOcrImage(imageId string) MSG {
img, err := bot.makeImageElem("image", map[string]string{"file": imageId}, true)
if err != nil {
log.Warnf("load image error: %v", err)
return Failed(100)
}
rsp, err := bot.Client.ImageOcr(img)
if err != nil {
log.Warnf("ocr image error: %v", err)
return Failed(100)
}
return OK(rsp)
}
func (bot *CQBot) CQReloadEventFilter() MSG { func (bot *CQBot) CQReloadEventFilter() MSG {
global.BootFilter() global.BootFilter()
return OK(nil) return OK(nil)
} }
func (bot *CQBot) CQSetGroupPortrait(groupId int64, file, cache string) MSG {
if g := bot.Client.FindGroup(groupId); g != nil {
img, err := global.FindFile(file, cache, global.IMAGE_PATH)
if err != nil {
log.Warnf("set group portrait error: %v", err)
return Failed(100)
}
g.UpdateGroupHeadPortrait(img)
return OK(nil)
}
return Failed(100)
}
func (bot *CQBot) CQGetStatus() MSG { func (bot *CQBot) CQGetStatus() MSG {
return OK(MSG{ return OK(MSG{
"app_initialized": true, "app_initialized": true,
@ -727,3 +770,12 @@ func convertGroupMemberInfo(groupId int64, m *client.GroupMemberInfo) MSG {
"card_changeable": false, "card_changeable": false,
} }
} }
func limitedString(str string) string {
if strings.Count(str, "") <= 10 {
return str
}
limited := []rune(str)
limited = limited[:10]
return string(limited) + " ..."
}

View File

@ -66,6 +66,7 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
bot.Client.OnGroupMemberJoined(bot.memberJoinEvent) bot.Client.OnGroupMemberJoined(bot.memberJoinEvent)
bot.Client.OnGroupMemberLeaved(bot.memberLeaveEvent) bot.Client.OnGroupMemberLeaved(bot.memberLeaveEvent)
bot.Client.OnGroupMemberPermissionChanged(bot.memberPermissionChangedEvent) bot.Client.OnGroupMemberPermissionChanged(bot.memberPermissionChangedEvent)
bot.Client.OnGroupMemberCardUpdated(bot.memberCardUpdatedEvent)
bot.Client.OnNewFriendRequest(bot.friendRequestEvent) bot.Client.OnNewFriendRequest(bot.friendRequestEvent)
bot.Client.OnNewFriendAdded(bot.friendAddedEvent) bot.Client.OnNewFriendAdded(bot.friendAddedEvent)
bot.Client.OnGroupInvited(bot.groupInvitedEvent) bot.Client.OnGroupInvited(bot.groupInvitedEvent)
@ -147,6 +148,48 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
} }
} }
} }
if i, ok := elem.(*GiftElement); ok {
bot.Client.SendGroupGift(uint64(groupId), uint64(i.Target), i.GiftId)
return 0
}
if i, ok := elem.(*QQMusicElement); ok {
ret, err := bot.Client.SendGroupRichMessage(groupId, 100497308, 1, 4, client.RichClientInfo{
Platform: 1,
SdkVersion: "0.0.0",
PackageName: "com.tencent.qqmusic",
Signature: "cbd27cd7c861227d013a25b2d10f0799",
}, &message.RichMessage{
Title: i.Title,
Summary: i.Summary,
Url: i.Url,
PictureUrl: i.PictureUrl,
MusicUrl: i.MusicUrl,
})
if err != nil {
log.Warnf("警告: 群 %v 富文本消息发送失败: %v", groupId, err)
return -1
}
return bot.InsertGroupMessage(ret)
}
if i, ok := elem.(*CloudMusicElement); ok {
ret, err := bot.Client.SendGroupRichMessage(groupId, 100495085, 1, 4, client.RichClientInfo{
Platform: 1,
SdkVersion: "0.0.0",
PackageName: "com.netease.cloudmusic",
Signature: "da6b069da1e2982db3e386233f68d76d",
}, &message.RichMessage{
Title: i.Title,
Summary: i.Summary,
Url: i.Url,
PictureUrl: i.PictureUrl,
MusicUrl: i.MusicUrl,
})
if err != nil {
log.Warnf("警告: 群 %v 富文本消息发送失败: %v", groupId, err)
return -1
}
return bot.InsertGroupMessage(ret)
}
newElem = append(newElem, elem) newElem = append(newElem, elem)
} }
m.Elements = newElem m.Elements = newElem

View File

@ -30,6 +30,47 @@ type PokeElement struct {
Target int64 Target int64
} }
type GiftElement struct {
Target int64
GiftId message.GroupGift
}
type MusicElement struct {
Title string
Summary string
Url string
PictureUrl string
MusicUrl string
}
type QQMusicElement struct {
MusicElement
}
type CloudMusicElement struct {
MusicElement
}
func (e *GiftElement) Type() message.ElementType {
return message.At
}
func (e *MusicElement) Type() message.ElementType {
return message.Service
}
var GiftId = []message.GroupGift{
message.SweetWink,
message.HappyCola,
message.LuckyBracelet,
message.Cappuccino,
message.CatWatch,
message.FleeceGloves,
message.RainbowCandy,
message.Stronger,
message.LoveMicrophone,
}
func (e *PokeElement) Type() message.ElementType { func (e *PokeElement) Type() message.ElementType {
return message.At return message.At
} }
@ -58,8 +99,6 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
"type": "text", "type": "text",
"data": map[string]string{"text": o.Content}, "data": map[string]string{"text": o.Content},
} }
case *message.ReplyElement:
continue
case *message.LightAppElement: case *message.LightAppElement:
//m = MSG{ //m = MSG{
// "type": "text", // "type": "text",
@ -144,6 +183,8 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
"data": map[string]string{"data": o.Content, "resid": fmt.Sprintf("%d", o.Id)}, "data": map[string]string{"data": o.Content, "resid": fmt.Sprintf("%d", o.Id)},
} }
} }
default:
continue
} }
r = append(r, m) r = append(r, m)
} }
@ -333,49 +374,40 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
} }
t, _ := strconv.ParseInt(d["qq"], 10, 64) t, _ := strconv.ParseInt(d["qq"], 10, 64)
return &PokeElement{Target: t}, nil return &PokeElement{Target: t}, nil
case "gift":
if !group {
return nil, errors.New("private gift unsupported") // no free private gift
}
t, _ := strconv.ParseInt(d["qq"], 10, 64)
id, _ := strconv.Atoi(d["id"])
if id < 0 || id >= 9 {
return nil, errors.New("invalid gift id")
}
return &GiftElement{Target: t, GiftId: GiftId[id]}, nil
case "tts":
if !group {
return nil, errors.New("private voice unsupported now")
}
data, err := bot.Client.GetTts(d["text"])
ioutil.WriteFile("tts.silk", data, 777)
if err != nil {
return nil, err
}
return &message.VoiceElement{Data: data}, nil
case "record": case "record":
if !group { if !group {
return nil, errors.New("private voice unsupported now") return nil, errors.New("private voice unsupported now")
} }
f := d["file"] f := d["file"]
var data []byte data, err := global.FindFile(f, d["cache"], global.VOICE_PATH)
if strings.HasPrefix(f, "http") || strings.HasPrefix(f, "https") { if err != nil {
b, err := global.GetBytes(f) return nil, err
if err != nil {
return nil, err
}
data = b
}
if strings.HasPrefix(f, "base64") {
b, err := base64.StdEncoding.DecodeString(strings.ReplaceAll(f, "base64://", ""))
if err != nil {
return nil, err
}
data = b
}
if strings.HasPrefix(f, "file") {
fu, err := url.Parse(f)
if err != nil {
return nil, err
}
if strings.HasPrefix(fu.Path, "/") && runtime.GOOS == `windows` {
fu.Path = fu.Path[1:]
}
b, err := ioutil.ReadFile(fu.Path)
if err != nil {
return nil, err
}
data = b
}
if global.PathExists(path.Join(global.VOICE_PATH, f)) {
b, err := ioutil.ReadFile(path.Join(global.VOICE_PATH, f))
if err != nil {
return nil, err
}
data = b
} }
if !global.IsAMRorSILK(data) { if !global.IsAMRorSILK(data) {
return nil, errors.New("unsupported voice file format (please use AMR file for now)") data, err = global.Encoder(data)
if err != nil {
return nil, err
}
} }
return &message.VoiceElement{Data: data}, nil return &message.VoiceElement{Data: data}, nil
case "face": case "face":
@ -417,8 +449,16 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
if d["content"] != "" { if d["content"] != "" {
content = d["content"] content = d["content"]
} }
json := fmt.Sprintf("{\"app\": \"com.tencent.structmsg\",\"desc\": \"音乐\",\"meta\": {\"music\": {\"desc\": \"%s\",\"jumpUrl\": \"%s\",\"musicUrl\": \"%s\",\"preview\": \"%s\",\"tag\": \"QQ音乐\",\"title\": \"%s\"}},\"prompt\": \"[分享]%s\",\"ver\": \"0.0.0.1\",\"view\": \"music\"}", content, jumpUrl, purl, preview, name, name) if purl == "" {
return message.NewLightApp(json), nil purl = "https://www.baidu.com" // fix vip song
}
return &QQMusicElement{MusicElement: MusicElement{
Title: name,
Summary: content,
Url: jumpUrl,
PictureUrl: preview,
MusicUrl: purl,
}}, nil
} }
if d["type"] == "163" { if d["type"] == "163" {
info, err := global.NeteaseMusicSongInfo(d["id"]) info, err := global.NeteaseMusicSongInfo(d["id"])
@ -436,8 +476,13 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
if info.Get("artists.0").Exists() { if info.Get("artists.0").Exists() {
artistName = info.Get("artists.0.name").Str artistName = info.Get("artists.0.name").Str
} }
json := fmt.Sprintf("{\"app\": \"com.tencent.structmsg\",\"desc\":\"音乐\",\"view\":\"music\",\"prompt\":\"[分享]%s\",\"ver\":\"0.0.0.1\",\"meta\":{ \"music\": { \"desc\": \"%s\", \"jumpUrl\": \"%s\", \"musicUrl\": \"%s\", \"preview\": \"%s\", \"tag\": \"网易云音乐\", \"title\":\"%s\"}}}", name, artistName, jumpUrl, musicUrl, picUrl, name) return &CloudMusicElement{MusicElement{
return message.NewLightApp(json), nil Title: name,
Summary: artistName,
Url: jumpUrl,
PictureUrl: picUrl,
MusicUrl: musicUrl,
}}, nil
} }
if d["type"] == "custom" { if d["type"] == "custom" {
xml := fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="2" templateID="1" action="web" brief="[分享] %s" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="2"><audio cover="%s" src="%s"/><title>%s</title><summary>%s</summary></item><source name="音乐" icon="https://i.gtimg.cn/open/app_icon/01/07/98/56/1101079856_100_m.png" url="http://web.p.qq.com/qqmpmobile/aio/app.html?id=1101079856" action="app" a_actionData="com.tencent.qqmusic" i_actionData="tencent1101079856://" appid="1101079856" /></msg>`, xml := fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="2" templateID="1" action="web" brief="[分享] %s" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="2"><audio cover="%s" src="%s"/><title>%s</title><summary>%s</summary></item><source name="音乐" icon="https://i.gtimg.cn/open/app_icon/01/07/98/56/1101079856_100_m.png" url="http://web.p.qq.com/qqmpmobile/aio/app.html?id=1101079856" action="app" a_actionData="com.tencent.qqmusic" i_actionData="tencent1101079856://" appid="1101079856" /></msg>`,

View File

@ -310,6 +310,20 @@ 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{
"post_type": "notice",
"notice_type": "group_card",
"group_id": e.Group.Code,
"user_id": e.Member.Uin,
"card_new": e.Member.CardName,
"card_old": e.OldCard,
"time": time.Now().Unix(),
"self_id": c.Uin,
})
}
func (bot *CQBot) memberJoinEvent(c *client.QQClient, e *client.MemberJoinGroupEvent) { func (bot *CQBot) memberJoinEvent(c *client.QQClient, e *client.MemberJoinGroupEvent) {
log.Infof("新成员 %v 进入了群 %v.", formatMemberName(e.Member), formatGroupName(e.Group)) log.Infof("新成员 %v 进入了群 %v.", formatMemberName(e.Member), formatGroupName(e.Group))
bot.dispatchEventMessage(bot.groupIncrease(e.Group.Code, 0, e.Member.Uin)) bot.dispatchEventMessage(bot.groupIncrease(e.Group.Code, 0, e.Member.Uin))

13
docs/QA.md Normal file
View File

@ -0,0 +1,13 @@
# 常见问题
### Q: 为什么登录的时候出现 `客户端版本过低 请升级客户端`?
### A: 此问题是因为密码输入错误导致的, 信息为服务器返回, 很可能是TX相关的错误, 请检查密码
### Q: 为什么登录的时候出现 `为了您的帐号安全请使用QQ一键登录`?
### A: 因为目前手机协议不支持图片验证码,切换成平板协议登录成功后,再切换回手机协议即可
### Q: 为什么挂一段时间后就会出现 `消息发送失败,账号可能被风控`?
### A: 如果你刚开始使用 go-cqhttp 建议挂机3-7天即可解除风控

232
docs/adminApi.md Normal file
View File

@ -0,0 +1,232 @@
# 管理 API
> 支持跨域
## 公共参数
参数:
| 参数名 | 类型 | 说明 |
| ------ | ------ | ----------- |
| access_token | string | 校验口令config.json中配置 |
## admin/do_restart
### 热重启
> 热重启
> ps: 目前不支持ws部分的修改生效
method`POST/GET`
参数:
| 参数名 | 类型 | 说明 |
| ------ | ---- | ------------------------------------- |
| 无|||
返回:
```json
{"data": {}, "retcode": 0, "status": "ok"}
```
### admin/get_web_write
> 拉取验证码/设备锁
method: `GET`
参数:
| 参数名 | 类型 | 说明 |
| ------ | ------ | ----------- |
| 无|||
返回:
```json
{"data": {"ispic": true,"picbase64":"xxxxx"}, "retcode": 0, "status": "ok"}
```
| 参数名 | 类型 | 说明 |
| ------ | ------ | ----------- |
| ispic| bool| 是否是验证码类型 true是false为不是比如设备锁|
|picbas64| string| 验证码的base64编码内容加上头放入img标签即可显示|
### admin/do_web_write
> web输入验证码/设备锁确认
method: `POST` formdata
参数:
| 参数名 | 类型 | 说明 |
| ------ | ------ | ----------- |
| input | string | 输入的类容 |
返回:
```json
{"data": {}, "retcode": 0, "status": "ok"}
```
### admin/do_restart_docker
> 冷重启
> 注意此api 会直接结束掉进程需要依赖docker/supervisor等进程管理工具来自动拉起
method: `POST`
参数:
| 参数名 |类型 | 说明 |
| ------ | ------ | -----------|
| 无 | | |
返回:
```json
{"data": {}, "retcode": 0, "status": "ok"}
```
### admin/do_config_base
> 基础配置
method: `POST` formdata
参数:
| 参数名 | 类型 | 说明 |
| ------ | ------ | ------------------------------------------------------------ |
| uin | string | qq号 |
| password | string | qq密码 |
| enable_db | string | 是否启动数据库,填 'true' 或者 'false' |
| access_token | string | 授权 token |
返回:
```json
{"data": {}, "retcode": 0, "status": "ok"}
```
### admin/do_config_http
> http服务配置
method: `POST` formdata
参数:
| 参数名 | 类型 | 说明 |
| ------ | ------ | ------------------------------------------------------------ |
| port | string | 服务端口 |
| host | string | 服务监听地址 |
| enable | string | 是否启用 ,填 'true' 或者 'false' |
| timeout | string | http请求超时时间 |
| post_url | string | post上报地址 不需要就填空字符串,或者不填|
| post_secret | string | post上报的secret 不需要就填空字符串,或者不填 |
返回:
```json
{"data": {}, "retcode": 0, "status": "ok"}
```
### admin/do_config_ws
> 正向ws设置
method: `POST` formdata
参数:
| 参数名 | 类型 | 说明 |
| ------ | ------ | ------------------------------------------------------------ |
| port | string | 服务端口 |
| host | string | 服务监听地址 |
| enable | string | 是否启用 ,填 'true' 或者 'false' |
返回:
```json
{"data": {}, "retcode": 0, "status": "ok"}
```
### admin/do_config_reverse
> 反向ws配置
method: `POST` formdata
参数:
| 参数名 | 类型 | 说明 |
| ------ | ------ | ------------------------------------------------------------ |
| port | string | 服务端口 |
| host | string | 服务监听地址 |
| enable | string | 是否启用 ,填 'true' 或者 'false' |
返回:
```json
{"data": {}, "retcode": 0, "status": "ok"}
```
### admin/do_config_json
> 直接修改 config.json配置
method: `POST` formdata
参数:
| 参数名 | 类型 | 说明 |
| ------ | ------ | ------------------------------------------------------------ |
| json | string | 完整的config.json的配合json字符串 |
返回:
```json
{"data": {}, "retcode": 0, "status": "ok"}
```
### admin/get_config_json
> 获取当前 config.json配置
method: `GET`
参数:
| 参数名 | 类型 | 说明 |
| ------ | ------ | ------------------------------------------------------------ |
| 无 | | |
返回:
```json
{"data": {"config":"xxxx"}, "retcode": 0, "status": "ok"}
```
| 参数名 | 类型 | 说明 |
| ------ | ------ | ------------------------------------------------------------ |
| config | string | 完整的config.json的配合json字符串 |

View File

@ -48,6 +48,38 @@ Type: `poke`
示例: `[CQ:poke,qq=123456]` 示例: `[CQ:poke,qq=123456]`
### 礼物
> 注意:仅支持免费礼物,发送群礼物消息无法撤回,返回的 `message id` 恒定为 `0`
Type: `gift`
范围: **发送(仅群聊,接收的时候不是CQ码)**
参数:
| 参数名 |类型 | 说明 |
| ------ | ------ | -----------|
| qq | int64 | 接收礼物的成员 |
| id | int | 礼物的类型 |
目前支持的礼物ID:
| id |类型 |
| ---| ---------|
| 0 | 甜Wink |
| 1 | 快乐肥宅水|
| 2 | 幸运手链 |
| 3 | 卡布奇诺 |
| 4 | 猫咪手表 |
| 5 | 绒绒手套 |
| 6 | 彩虹糖果 |
| 7 | 坚强 |
| 8 | 告白话筒 |
示例: `[CQ:gift,qq=123456,id=8]`
### 合并转发 ### 合并转发
Type: `forward` Type: `forward`
@ -164,9 +196,9 @@ Type: `xml`
示例: `[CQ:xml,data=xxxx]` 示例: `[CQ:xml,data=xxxx]`
####一些xml样例 #### 一些xml样例
####ps:重要xml中的value部分记得html实体化处理后再打加入到cq码中 #### ps:重要xml中的value部分记得html实体化处理后再打加入到cq码中
#### qq音乐 #### qq音乐
@ -255,6 +287,22 @@ Type: `cardimage`
[CQ:cardimage,file=https://i.pixiv.cat/img-master/img/2020/03/25/00/00/08/80334602_p0_master1200.jpg] [CQ:cardimage,file=https://i.pixiv.cat/img-master/img/2020/03/25/00/00/08/80334602_p0_master1200.jpg]
``` ```
### 文本转语音
> 注意通过TX的TTS接口采用的音源与登录账号的性别有关
Type: `tts`
范围: **发送(仅群聊)**
参数:
| 参数名 | 类型 | 说明 |
| ------ | ------ | ----------- |
| text | string | 内容 |
示例: `[CQ:tts,text=这是一条测试消息]`
## API ## API
### 设置群名 ### 设置群名
@ -268,6 +316,28 @@ Type: `cardimage`
| group_id | int64 | 群号 | | group_id | int64 | 群号 |
| group_name | string | 新名 | | group_name | string | 新名 |
### 设置群头像
终结点: `/set_group_portrait`
**参数**
| 字段 | 类型 | 说明 |
| -------- | ------ | ---- |
| group_id | int64 | 群号 |
| file | string | 图片文件名 |
| cache | int | 表示是否使用已缓存的文件 |
[1]`file` 参数支持以下几种格式:
- 绝对路径,例如 `file:///C:\\Users\Richard\Pictures\1.png`,格式使用 [`file` URI](https://tools.ietf.org/html/rfc8089)
- 网络 URL例如 `http://i1.piimg.com/567571/fdd6e7b6d93f1ef0.jpg`
- Base64 编码,例如 `base64://iVBORw0KGgoAAAANSUhEUgAAABQAAAAVCAIAAADJt1n/AAAAKElEQVQ4EWPk5+RmIBcwkasRpG9UM4mhNxpgowFGMARGEwnBIEJVAAAdBgBNAZf+QAAAAABJRU5ErkJggg==`
[2]`cache`参数: 通过网络 URL 发送时有效,`1`表示使用缓存,`0`关闭关闭缓存,默认 为`1`
[3] 目前这个API在登录一段时间后因cookie失效而失效请考虑后使用
### 获取图片信息 ### 获取图片信息
终结点: `/get_image` 终结点: `/get_image`
@ -364,7 +434,21 @@ Type: `cardimage`
| `group_id` | int64 | 群号 | | `group_id` | int64 | 群号 |
| `messages` | forward node[] | 自定义转发消息, 具体看CQCode | | `messages` | forward node[] | 自定义转发消息, 具体看CQCode |
### ### 获取中文分词
终结点: `/.get_word_slices`
**参数**
| 字段 | 类型 | 说明 |
| ------------ | ------ | ------ |
| `content` | string | 内容 |
**响应数据**
| 字段 | 类型 | 说明 |
| ---------- | ----------------- | -------- |
| `slices` | string[] | 词组 |
## 事件 ## 事件
@ -435,4 +519,21 @@ Type: `cardimage`
| `group_id` | int64 | | 群号 | | `group_id` | int64 | | 群号 |
| `sub_type` | string | `honor` | 提示类型 | | `sub_type` | string | `honor` | 提示类型 |
| `user_id` | int64 | | 成员id | | `user_id` | int64 | | 成员id |
| `honor_type` | string | `talkative:龙王` `performer:群聊之火` `emotion:快乐源泉` | 荣誉类型 | | `honor_type` | string | `talkative:龙王` `performer:群聊之火` `emotion:快乐源泉` | 荣誉类型 |
#### 群成员名片更新
> 注意: 此事件不保证时效性,仅在收到消息时校验卡片
**上报数据**
| 字段 | 类型 | 可能的值 | 说明 |
| ------------- | ------ | -------------- | -------------- |
| `post_type` | string | `notice` | 上报类型 |
| `notice_type` | string | `group_card` | 消息类型 |
| `group_id` | int64 | | 群号 |
| `user_id` | int64 | | 成员id |
| `card_new` | int64 | | 新名片 |
| `card_old` | int64 | | 旧名片 |
> PS: 当名片为空时 `card_xx` 字段为空字符串, 并不是昵称

View File

@ -7,7 +7,6 @@ go-cqhttp 默认生成的文件树如下所示:
├── go-cqhttp ├── go-cqhttp
├── config.json ├── config.json
├── device.json ├── device.json
├── servers.bin
├── logs ├── logs
│ └── xx-xx-xx.log │ └── xx-xx-xx.log
└── data └── data
@ -21,7 +20,6 @@ go-cqhttp 默认生成的文件树如下所示:
| go-cqhttp | go-cqhttp可执行文件 | | go-cqhttp | go-cqhttp可执行文件 |
| config.json | 运行配置文件 | | config.json | 运行配置文件 |
| device.json | 虚拟设备配置文件 | | device.json | 虚拟设备配置文件 |
| servers.bin | 储存QQ服务器地址 |
| logs | 日志存放目录 | | logs | 日志存放目录 |
| data | 数据目录 | | data | 数据目录 |
| data/images | 图片缓存目录 | | data/images | 图片缓存目录 |

View File

@ -1,3 +1,123 @@
# 开始 # 开始
欢迎来到 go-cqhttp 文档 欢迎来到 go-cqhttp 文档 目前还在咕
# 基础教程
## 下载
从[release](https://github.com/Mrs4s/go-cqhttp/releases)界面下载最新版本的go-cqhttp
- Windows下32位文件为 `go-cqhttp-v*-windows-386.zip`
- Windows下64位文件为 `go-cqhttp-v*-windows-amd64.zip`
- Windows下arm用(如使用高通CPU的笔记本)文件为 `go-cqhttp-v*-windows-arm.zip`
- Linux下32位文件为 `go-cqhttp-v*-linux-386.tar.gz`
- Linux下64位文件为 `go-cqhttp-v*-linux-amd64.tar.gz`
- Linux下arm用(如树莓派)文件为 `go-cqhttp-v*-linux-arm.tar.gz`
- MD5文件为 `*.md5` ,用于校验文件完整性
- 如果没有你所使用的系统版本或者希望自己构建,请移步[进阶指南-如何自己构建](#如何自己构建)
## 解压
- Windows下请使用自己熟悉的解压软件自行解压
- Linux下在命令行中输入 `tar -xzvf [文件名]`
## 使用
### Windows
#### 标准方法
1. 双击`go-cqhttp.exe`此时将提示
```
[WARNING]: 尝试加载配置文件 config.json 失败: 文件不存在
[INFO]: 默认配置文件已生成,请编辑 config.json 后重启程序.
```
2. 参照[config.md](https://github.com/Mrs4s/go-cqhttp/blob/master/docs/config.md)和你所用到的插件的 `README` 填入参数
3. 再次双击`go-cqhttp.exe`
```
[INFO]: 登录成功 欢迎使用: balabala
```
如出现需要认证的信息,请自行认证设备。
此时,基础配置完成
#### 懒人法
1. [下载包含Windows.bat的zip](https://github.com/fkx4-p/go-cqhttp-lazy/archive/master.zip)
2. 解压
3.`Windows.bat`复制/剪切到**go-cqhttp**文件夹
4. 双击运行
效果如下
```
QQ account:
[QQ账号]
QQ password:
[QQ密码]
enable http?(Y/n)
[是否开启http(y/n),默认开启]
enable ws?(Y/n)
[是否开启websocket(y/n),默认开启]
请按任意键继续. . .
```
5. 双击`go-cqhttp.exe`
```
[INFO]: 登录成功 欢迎使用: balabala
```
如出现需要认证的信息,请自行认证设备。
此时,基础配置完成
### Linux
#### 标准方法
1. 打开一个命令行/ssh
2. `cd`到解压目录
3. 输入 `./go-cqhttp``Enter`运行 ,此时将提示
```
[WARNING]: 尝试加载配置文件 config.json 失败: 文件不存在
[INFO]: 默认配置文件已生成,请编辑 config.json 后重启程序.
```
4. 参照[config.md](https://github.com/Mrs4s/go-cqhttp/blob/master/docs/config.md)和你所用到的插件的 `README` 填入参数
5. 再次输入 `./go-cqhttp``Enter`运行
```
[INFO]: 登录成功 欢迎使用: balabala
```
如出现需要认证的信息,请自行认证设备。
此时,基础配置完成
#### 懒人法
暂时咕咕咕了
## 验证http是否成功配置
此时,如果在本地开启的服务器,可以在浏览器输入`http://127.0.0.1:5700/send_private_msg?user_id=[接收者qq号]&message=[发送的信息]`来发送一条测试信息
如果出现`{"data":{"message_id":balabala},"retcode":0,"status":"ok"}`则证明已经成功配置HTTP
# 进阶指南
## 如何自己构建
1. [下载源码](https://github.com/Mrs4s/go-cqhttp/archive/master.zip)并解压 || 使用`git clone https://github.com/Mrs4s/go-cqhttp.git`来拉取
2. [下载golang binary release](https://golang.google.cn/dl/)并安装或者[自己构建golang](https://golang.google.cn/doc/install/source)
3.`cmd`或Linux命令行中`cd`到目录中
4. 输入`go build -ldflags "-s -w -extldflags '-static'"``Enter`运行
*注:可以使用*`go env -w GOPROXY=https://goproxy.cn,direct`*来加速国内依赖安装速度*
*注:此时构建后的文件名为*`main`(Linux)或`main.exe`(Windows)

44
global/codec.go Normal file
View File

@ -0,0 +1,44 @@
package global
import (
"crypto/md5"
"errors"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/wdvxdr1123/go-silk/silk"
"io/ioutil"
"path"
"sync"
)
var codec silk.Encoder
var useCodec = true
var once sync.Once
func InitCodec() {
once.Do(func() {
log.Info("正在加载silk编码器...")
err := codec.Init("data/cache", "codec")
if err != nil {
log.Error(err)
useCodec = false
}
})
}
func Encoder(data []byte) ([]byte, error) {
if useCodec == false {
return nil, errors.New("no silk encoder")
}
h := md5.New()
h.Write(data)
tempName := fmt.Sprintf("%x", h.Sum(nil))
if silkPath := path.Join("data/cache", tempName+".silk"); PathExists(silkPath) {
return ioutil.ReadFile(silkPath)
}
slk, err := codec.EncodeToSilk(data, tempName, true)
if err != nil {
return nil, err
}
return slk, nil
}

View File

@ -35,6 +35,7 @@ type JsonConfig struct {
PostMessageFormat string `json:"post_message_format"` PostMessageFormat string `json:"post_message_format"`
Debug bool `json:"debug"` Debug bool `json:"debug"`
LogLevel string `json:"log_level"` LogLevel string `json:"log_level"`
WebUi *GoCqWebUi `json:"web_ui"`
} }
type CQHttpApiConfig struct { type CQHttpApiConfig struct {
@ -78,6 +79,13 @@ type GoCQReverseWebsocketConfig struct {
ReverseReconnectInterval uint16 `json:"reverse_reconnect_interval"` ReverseReconnectInterval uint16 `json:"reverse_reconnect_interval"`
} }
type GoCqWebUi struct {
Enabled bool `json:"enabled"`
Host string `json:"host"`
WebUiPort uint64 `json:"web_ui_port"`
WebInput bool `json:"web_input"`
}
func DefaultConfig() *JsonConfig { func DefaultConfig() *JsonConfig {
return &JsonConfig{ return &JsonConfig{
EnableDB: true, EnableDB: true,
@ -100,7 +108,7 @@ func DefaultConfig() *JsonConfig {
BucketSize: 1, BucketSize: 1,
}, },
PostMessageFormat: "string", PostMessageFormat: "string",
ForceFragmented: true, ForceFragmented: false,
HttpConfig: &GoCQHttpConfig{ HttpConfig: &GoCQHttpConfig{
Enabled: true, Enabled: true,
Host: "0.0.0.0", Host: "0.0.0.0",
@ -121,6 +129,12 @@ func DefaultConfig() *JsonConfig {
ReverseReconnectInterval: 3000, ReverseReconnectInterval: 3000,
}, },
}, },
WebUi: &GoCqWebUi{
Enabled: true,
Host: "0.0.0.0",
WebInput: false,
WebUiPort: 9999,
},
} }
} }

View File

@ -2,11 +2,17 @@ package global
import ( import (
"bytes" "bytes"
"crypto/md5"
"encoding/base64"
"encoding/hex"
"errors"
log "github.com/sirupsen/logrus"
"io/ioutil" "io/ioutil"
"net/url"
"os" "os"
"path" "path"
"runtime"
log "github.com/sirupsen/logrus" "strings"
) )
var ( var (
@ -45,3 +51,59 @@ func Check(err error) {
func IsAMRorSILK(b []byte) bool { func IsAMRorSILK(b []byte) bool {
return bytes.HasPrefix(b, HEADER_AMR) || bytes.HasPrefix(b, HEADER_SILK) return bytes.HasPrefix(b, HEADER_AMR) || bytes.HasPrefix(b, HEADER_SILK)
} }
func FindFile(f, cache, PATH string) (data []byte, err error) {
data, err = nil, errors.New("syntax error")
if strings.HasPrefix(f, "http") || strings.HasPrefix(f, "https") {
if cache == "" {
cache = "1"
}
hash := md5.Sum([]byte(f))
cacheFile := path.Join(CACHE_PATH, hex.EncodeToString(hash[:])+".cache")
if PathExists(cacheFile) && cache == "1" {
return ioutil.ReadFile(cacheFile)
}
data, err = GetBytes(f)
_ = ioutil.WriteFile(cacheFile, data, 0644)
if err != nil {
return nil, err
}
} else if strings.HasPrefix(f, "base64") {
data, err = base64.StdEncoding.DecodeString(strings.ReplaceAll(f, "base64://", ""))
if err != nil {
return nil, err
}
} else if strings.HasPrefix(f, "file") {
var fu *url.URL
fu, err = url.Parse(f)
if err != nil {
return nil, err
}
if strings.HasPrefix(fu.Path, "/") && runtime.GOOS == `windows` {
fu.Path = fu.Path[1:]
}
data, err = ioutil.ReadFile(fu.Path)
if err != nil {
return nil, err
}
} else if PathExists(path.Join(PATH, f)) {
data, err = ioutil.ReadFile(path.Join(PATH, f))
if err != nil {
return nil, err
}
}
return
}
func DelFile(path string) bool {
err := os.Remove(path)
if err != nil {
// 删除失败
log.Error(err)
return false
} else {
// 删除成功
log.Info(path + "删除成功")
return true
}
}

View File

@ -50,4 +50,3 @@ func NeteaseMusicSongInfo(id string) (gjson.Result, error) {
} }
return gjson.ParseBytes(d).Get("songs.0"), nil return gjson.ParseBytes(d).Get("songs.0"), nil
} }

13
go.mod
View File

@ -3,10 +3,10 @@ module github.com/Mrs4s/go-cqhttp
go 1.14 go 1.14
require ( require (
github.com/Mrs4s/MiraiGo v0.0.0-20200919153352-249af274638d github.com/Mrs4s/MiraiGo v0.0.0-20201008134448-b53aaceaa1b4
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/gin-gonic/gin v1.6.3 github.com/gin-gonic/gin v1.6.3
github.com/go-playground/validator/v10 v10.3.0 // indirect github.com/go-playground/validator/v10 v10.4.0 // indirect
github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket v1.4.2
github.com/guonaihong/gout v0.1.2 github.com/guonaihong/gout v0.1.2
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
@ -18,14 +18,17 @@ require (
github.com/modern-go/reflect2 v1.0.1 // indirect github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
github.com/sirupsen/logrus v1.6.0 github.com/sirupsen/logrus v1.7.0
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
github.com/tebeka/strftime v0.1.5 // indirect github.com/tebeka/strftime v0.1.5 // indirect
github.com/tidwall/gjson v1.6.1 github.com/tidwall/gjson v1.6.1
github.com/ugorji/go v1.1.10 // indirect
github.com/wdvxdr1123/go-silk v0.0.0-20201007123416-b982fd3d91d6
github.com/xujiajun/nutsdb v0.5.0 github.com/xujiajun/nutsdb v0.5.0
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189 github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
golang.org/x/net v0.0.0-20200904194848-62affa334b73 // indirect golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 // indirect
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 // indirect golang.org/x/net v0.0.0-20201002202402-0a1ea396d57c // indirect
golang.org/x/sys v0.0.0-20201005172224-997123666555 // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
gopkg.in/yaml.v2 v2.3.0 // indirect gopkg.in/yaml.v2 v2.3.0 // indirect
) )

39
go.sum
View File

@ -1,9 +1,7 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Mrs4s/MiraiGo v0.0.0-20200919083021-4013c077186d h1:LZ1pjJJ7sD/AOL8tvkTB9bPc0DiOErCNN+wWXUMyvX0= github.com/Mrs4s/MiraiGo v0.0.0-20201008134448-b53aaceaa1b4 h1:vNDY7JAh+e7ac0Dft3GF+s4WZU55SZkwaAI7UmXfwHc=
github.com/Mrs4s/MiraiGo v0.0.0-20200919083021-4013c077186d/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo= github.com/Mrs4s/MiraiGo v0.0.0-20201008134448-b53aaceaa1b4/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20200919153352-249af274638d h1:nGJSE9xQBeDiugBKKX0vUOq51MqlUEm/y2FMfZFH/w4=
github.com/Mrs4s/MiraiGo v0.0.0-20200919153352-249af274638d/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0= github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE= github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@ -26,8 +24,8 @@ github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEK
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= 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/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-playground/validator/v10 v10.3.0 h1:nZU+7q+yJoFmwvNgv/LnPUkwPal62+b2xXj0AU1Es7o= github.com/go-playground/validator/v10 v10.4.0 h1:72qIR/m8ybvL8L5TIyfgrigqkrw7kVYAvjEvpT85l70=
github.com/go-playground/validator/v10 v10.3.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= github.com/go-playground/validator/v10 v10.4.0/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 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/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@ -58,8 +56,6 @@ github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 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.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= 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/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
@ -85,8 +81,8 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo= github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo=
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM= github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
@ -101,10 +97,16 @@ github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU= github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= github.com/ugorji/go v1.1.10 h1:Mh7W3N/hGJJ8fRQNHIgomNTa0CgZc0aKDFvbgHl+U7A=
github.com/ugorji/go v1.1.10/go.mod h1:/tC+H0R6N4Lcv4DoSdphIa9y/RAs4QFHDtN9W2oQcHw=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/ugorji/go/codec v1.1.10 h1:otofY/FAoRTMVqlVeDv/Kpm04D13lfJdrDqPbc3axg4=
github.com/ugorji/go/codec v1.1.10/go.mod h1:jdPQoxvTq1mb8XV6RmofOz5UgNKV2czR6xvxXGwy1Bo=
github.com/wdvxdr1123/go-silk v0.0.0-20201006020916-0398076200ea h1:OqkIV1VL5xm88jhXLaPHRJroeRknxN3EApcAVlNIIOw=
github.com/wdvxdr1123/go-silk v0.0.0-20201006020916-0398076200ea/go.mod h1:5q9LFlBr+yX/J8Jd/9wHdXwkkjFkNyQIS7kX2Lgx/Zs=
github.com/wdvxdr1123/go-silk v0.0.0-20201007123416-b982fd3d91d6 h1:lX18MCdNzT2zIi7K02x4C5cPkDXpL+wCb1YTAMXjLWQ=
github.com/wdvxdr1123/go-silk v0.0.0-20201007123416-b982fd3d91d6/go.mod h1:5q9LFlBr+yX/J8Jd/9wHdXwkkjFkNyQIS7kX2Lgx/Zs=
github.com/xujiajun/gorouter v1.2.0/go.mod h1:yJrIta+bTNpBM/2UT8hLOaEAFckO+m/qmR3luMIQygM= github.com/xujiajun/gorouter v1.2.0/go.mod h1:yJrIta+bTNpBM/2UT8hLOaEAFckO+m/qmR3luMIQygM=
github.com/xujiajun/mmap-go v1.0.1 h1:7Se7ss1fLPPRW+ePgqGpCkfGIZzJV6JPq9Wq9iv/WHc= github.com/xujiajun/mmap-go v1.0.1 h1:7Se7ss1fLPPRW+ePgqGpCkfGIZzJV6JPq9Wq9iv/WHc=
github.com/xujiajun/mmap-go v1.0.1/go.mod h1:CNN6Sw4SL69Sui00p0zEzcZKbt+5HtEnYUsc6BKKRMg= github.com/xujiajun/mmap-go v1.0.1/go.mod h1:CNN6Sw4SL69Sui00p0zEzcZKbt+5HtEnYUsc6BKKRMg=
@ -116,6 +118,8 @@ github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189 h1:4UJw9if5
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189/go.mod h1:rIrm5geMiBhPQkdfUm8gDFi/WiHneOp1i9KjmJqc+9I= github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189/go.mod h1:rIrm5geMiBhPQkdfUm8gDFi/WiHneOp1i9KjmJqc+9I=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 h1:hb9wdF1z5waM+dSIICn1l0DkLVDT3hqhhQsDNUmHPRE=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
@ -126,8 +130,8 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 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-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-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200904194848-62affa334b73 h1:MXfv8rhZWmFeqX3GNZRsd6vOLoaCHjYEX3qkRo3YBUA= golang.org/x/net v0.0.0-20201002202402-0a1ea396d57c h1:dk0ukUIHmGHqASjP0iue2261isepFCC6XRCSd1nHgDw=
golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201002202402-0a1ea396d57c/go.mod h1:iQL9McJNjoIa5mjH6nYTCTZXUN6RP+XW3eib7Ya3XcI=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -138,10 +142,11 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/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-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 h1:W0lCpv29Hv0UaM1LXb9QlBHLNP8UFfcKjblhVCWftOM= golang.org/x/sys v0.0.0-20201005172224-997123666555 h1:fihtqzYxy4E31W1yUlyRGveTZT1JIP0bmKaDZ2ceKAw=
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201005172224-997123666555/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s= golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s=

162
main.go
View File

@ -2,33 +2,27 @@ package main
import ( import (
"bufio" "bufio"
"bytes"
"crypto/md5" "crypto/md5"
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"image" "github.com/Mrs4s/go-cqhttp/server"
"io" "io"
"io/ioutil" "io/ioutil"
"net"
"os" "os"
"os/signal" "os/signal"
"path" "path"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/Mrs4s/MiraiGo/binary" "github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client" "github.com/Mrs4s/MiraiGo/client"
"github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/coolq"
"github.com/Mrs4s/go-cqhttp/global" "github.com/Mrs4s/go-cqhttp/global"
"github.com/Mrs4s/go-cqhttp/server" "github.com/lestrrat-go/file-rotatelogs"
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
"github.com/rifflock/lfshook" "github.com/rifflock/lfshook"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
easy "github.com/t-tomalak/logrus-easy-formatter" "github.com/t-tomalak/logrus-easy-formatter"
asciiart "github.com/yinghau76/go-ascii-art"
) )
func init() { func init() {
@ -237,146 +231,28 @@ func main() {
} }
}) })
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) { cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) {
log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. 地址信息已储存到 servers.bin 文件") log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. ")
_ = ioutil.WriteFile("servers.bin", binary.NewWriterF(func(w *binary.Writer) {
w.WriteUInt16(func() (c uint16) {
for _, s := range e.Servers {
if !strings.Contains(s.Server, "com") {
c++
}
}
return
}())
for _, s := range e.Servers {
if !strings.Contains(s.Server, "com") {
w.WriteString(s.Server)
w.WriteUInt16(uint16(s.Port))
}
}
}), 0644)
}) })
if global.PathExists("servers.bin") { if conf.WebUi == nil {
if data, err := ioutil.ReadFile("servers.bin"); err == nil { conf.WebUi = &global.GoCqWebUi{
func() { Enabled: true,
defer func() { WebInput: false,
if pan := recover(); pan != nil { Host: "0.0.0.0",
log.Error("读取服务器地址时出现错误: %v", pan) WebUiPort: 9999,
}
}()
r := binary.NewReader(data)
var addr []*net.TCPAddr
l := r.ReadUInt16()
for i := 0; i < int(l); i++ {
addr = append(addr, &net.TCPAddr{
IP: net.ParseIP(r.ReadString()),
Port: int(r.ReadUInt16()),
})
}
if len(addr) > 0 {
cli.SetCustomServer(addr)
}
}()
} }
} }
rsp, err := cli.Login() if conf.WebUi.WebUiPort <= 0 {
for { conf.WebUi.WebUiPort = 9999
global.Check(err)
if !rsp.Success {
switch rsp.Error {
case client.NeedCaptcha:
_ = ioutil.WriteFile("captcha.jpg", rsp.CaptchaImage, 0644)
img, _, _ := image.Decode(bytes.NewReader(rsp.CaptchaImage))
fmt.Println(asciiart.New("image", img).Art)
log.Warn("请输入验证码 (captcha.jpg) (Enter 提交)")
text, _ := console.ReadString('\n')
rsp, err = cli.SubmitCaptcha(strings.ReplaceAll(text, "\n", ""), rsp.CaptchaSign)
continue
case client.UnsafeDeviceError:
log.Warnf("账号已开启设备锁,请前往 -> %v <- 验证并重启Bot.", rsp.VerifyUrl)
log.Infof(" 按 Enter 继续....")
_, _ = console.ReadString('\n')
return
case client.OtherLoginError, client.UnknownLoginError:
log.Fatalf("登录失败: %v", rsp.ErrorMessage)
}
}
break
} }
log.Infof("登录成功 欢迎使用: %v", cli.Nickname) if conf.WebUi.Host == "" {
time.Sleep(time.Second) conf.WebUi.Host = "0.0.0.0"
log.Info("开始加载好友列表...")
global.Check(cli.ReloadFriendList())
log.Infof("共加载 %v 个好友.", len(cli.FriendList))
log.Infof("开始加载群列表...")
global.Check(cli.ReloadGroupList())
log.Infof("共加载 %v 个群.", len(cli.GroupList))
b := coolq.NewQQBot(cli, conf)
if conf.PostMessageFormat != "string" && conf.PostMessageFormat != "array" {
log.Warnf("post_message_format 配置错误, 将自动使用 string")
coolq.SetMessageFormat("string")
} else {
coolq.SetMessageFormat(conf.PostMessageFormat)
} }
if conf.RateLimit.Enabled { confErr := conf.Save("config.json")
global.InitLimiter(conf.RateLimit.Frequency, conf.RateLimit.BucketSize) if confErr != nil {
log.Error("保存配置文件失败")
} }
log.Info("正在加载事件过滤器.") b := server.WebServer.Run(fmt.Sprintf("%s:%d", conf.WebUi.Host, conf.WebUi.WebUiPort), cli)
global.BootFilter() c := server.Console
coolq.IgnoreInvalidCQCode = conf.IgnoreInvalidCQCode
coolq.ForceFragmented = conf.ForceFragmented
if conf.HttpConfig != nil && conf.HttpConfig.Enabled {
server.HttpServer.Run(fmt.Sprintf("%s:%d", conf.HttpConfig.Host, conf.HttpConfig.Port), conf.AccessToken, b)
for k, v := range conf.HttpConfig.PostUrls {
server.NewHttpClient().Run(k, v, conf.HttpConfig.Timeout, b)
}
}
if conf.WSConfig != nil && conf.WSConfig.Enabled {
server.WebsocketServer.Run(fmt.Sprintf("%s:%d", conf.WSConfig.Host, conf.WSConfig.Port), conf.AccessToken, b)
}
for _, rc := range conf.ReverseServers {
server.NewWebsocketClient(rc, conf.AccessToken, b).Run()
}
log.Info("资源初始化完成, 开始处理信息.")
log.Info("アトリは、高性能ですから!")
cli.OnDisconnected(func(bot *client.QQClient, e *client.ClientDisconnectedEvent) {
if conf.ReLogin.Enabled {
var times uint = 1
for {
if conf.ReLogin.MaxReloginTimes == 0 {
} else if times > conf.ReLogin.MaxReloginTimes {
break
}
log.Warnf("Bot已离线 (%v),将在 %v 秒后尝试重连. 重连次数:%v",
e.Message, conf.ReLogin.ReLoginDelay, times)
times++
time.Sleep(time.Second * time.Duration(conf.ReLogin.ReLoginDelay))
rsp, err := cli.Login()
if err != nil {
log.Errorf("重连失败: %v", err)
continue
}
if !rsp.Success {
switch rsp.Error {
case client.NeedCaptcha:
log.Fatalf("重连失败: 需要验证码. (验证码处理正在开发中)")
case client.UnsafeDeviceError:
log.Fatalf("重连失败: 设备锁")
default:
log.Errorf("重连失败: %v", rsp.ErrorMessage)
continue
}
}
log.Info("重连成功")
return
}
log.Fatal("重连失败: 重连次数达到设置的上限值")
}
b.Release()
log.Fatalf("Bot已离线%v", e.Message)
})
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill) signal.Notify(c, os.Interrupt, os.Kill)
<-c <-c
b.Release() b.Release()

549
server/apiAdmin.go Normal file
View File

@ -0,0 +1,549 @@
package server
import (
"bufio"
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"github.com/Mrs4s/MiraiGo/client"
"github.com/Mrs4s/go-cqhttp/coolq"
"github.com/Mrs4s/go-cqhttp/global"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
"github.com/yinghau76/go-ascii-art"
"image"
"io/ioutil"
"net/http"
"os"
"os/signal"
"strconv"
"strings"
"time"
)
var WebInput = make(chan string, 1) //长度1用于阻塞
var Console = make(chan os.Signal, 1)
var JsonConfig *global.JsonConfig
type webServer struct {
engine *gin.Engine
bot *coolq.CQBot
Cli *client.QQClient
Conf *global.JsonConfig //old config
Console *bufio.Reader
}
var WebServer = &webServer{}
// admin 子站的 路由映射
var HttpuriAdmin = map[string]func(s *webServer, c *gin.Context){
"do_restart": AdminDoRestart, //热重启
"get_web_write": AdminWebWrite, //获取是否验证码输入
"do_web_write": AdminDoWebWrite, //web上进行输入操作
"do_restart_docker": AdminDoRestartDocker, //直接停止依赖supervisord/docker重新拉起
"do_config_base": AdminDoConfigBase, //修改config.json中的基础部分
"do_config_http": AdminDoConfigHttp, //修改config.json的http部分
"do_config_ws": AdminDoConfigWs, //修改config.json的正向ws部分
"do_config_reverse": AdminDoConfigReverse, //修改config.json 中的反向ws部分
"do_config_json": AdminDoConfigJson, //直接修改 config.json配置
"get_config_json": AdminGetConfigJson, //拉取 当前的config.json配置
}
func Failed(code int, msg string) coolq.MSG {
return coolq.MSG{"data": nil, "retcode": code, "status": "failed", "msg": msg}
}
func (s *webServer) Run(addr string, cli *client.QQClient) *coolq.CQBot {
s.Cli = cli
s.Conf = GetConf()
JsonConfig = s.Conf
gin.SetMode(gin.ReleaseMode)
s.engine = gin.New()
s.engine.Use(AuthMiddleWare())
//通用路由
s.engine.Any("/admin/:action", s.admin)
go func() {
//开启端口监听
if s.Conf.WebUi.Enabled {
log.Infof("Admin API 服务器已启动: %v", addr)
err := s.engine.Run(addr)
if err != nil {
log.Error(err)
log.Infof("请检查端口是否被占用.")
time.Sleep(time.Second * 5)
os.Exit(1)
}
} else {
//关闭端口监听
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
<-c
os.Exit(1)
}
}()
s.Dologin()
s.UpServer()
b := s.bot //外部引入 bot对象用于操作bot
return b
}
func (s *webServer) Dologin() {
s.Console = bufio.NewReader(os.Stdin)
conf := GetConf()
cli := s.Cli
cli.AllowSlider = true
rsp, err := cli.Login()
for {
global.Check(err)
var text string
if !rsp.Success {
switch rsp.Error {
case client.SliderNeededError:
if client.SystemDeviceInfo.Protocol == client.AndroidPhone {
log.Warnf("警告: Android Phone 强制要求暂不支持的滑条验证码, 请开启设备锁或切换到Watch协议验证通过后再使用.")
log.Infof("按 Enter 继续....")
_, _ = s.Console.ReadString('\n')
os.Exit(0)
}
cli.AllowSlider = false
cli.Disconnect()
rsp, err = cli.Login()
continue
case client.NeedCaptcha:
_ = ioutil.WriteFile("captcha.jpg", rsp.CaptchaImage, 0644)
img, _, _ := image.Decode(bytes.NewReader(rsp.CaptchaImage))
fmt.Println(asciiart.New("image", img).Art)
if conf.WebUi.WebInput {
log.Warnf("请输入验证码 (captcha.jpg) (http://%s:%d/admin/do_web_write 输入)", conf.WebUi.Host, conf.WebUi.WebUiPort)
text = <-WebInput
} else {
log.Warn("请输入验证码 (captcha.jpg) (Enter 提交)")
text, _ = s.Console.ReadString('\n')
}
rsp, err = cli.SubmitCaptcha(strings.ReplaceAll(text, "\n", ""), rsp.CaptchaSign)
global.DelFile("captcha.jpg")
continue
case client.SMSNeededError:
log.Warnf("账号已开启设备锁, 按下 Enter 向手机 %v 发送短信验证码.", rsp.SMSPhone)
_, _ = s.Console.ReadString('\n')
if !cli.RequestSMS() {
log.Warnf("发送验证码失败,可能是请求过于频繁.")
time.Sleep(time.Second * 5)
os.Exit(0)
}
log.Warn("请输入短信验证码: (Enter 提交)")
text, _ = s.Console.ReadString('\n')
rsp, err = cli.SubmitSMS(strings.ReplaceAll(strings.ReplaceAll(text, "\n", ""), "\r", ""))
continue
case client.SMSOrVerifyNeededError:
log.Warnf("账号已开启设备锁,请选择验证方式:")
log.Warnf("1. 向手机 %v 发送短信验证码", rsp.SMSPhone)
log.Warnf("2. 使用手机QQ扫码验证.")
log.Warn("请输入(1 - 2): ")
text, _ = s.Console.ReadString('\n')
if strings.Contains(text, "1") {
if !cli.RequestSMS() {
log.Warnf("发送验证码失败,可能是请求过于频繁.")
time.Sleep(time.Second * 5)
os.Exit(0)
}
log.Warn("请输入短信验证码: (Enter 提交)")
text, _ = s.Console.ReadString('\n')
rsp, err = cli.SubmitSMS(strings.ReplaceAll(strings.ReplaceAll(text, "\n", ""), "\r", ""))
continue
}
log.Warnf("请前往 -> %v <- 验证并重启Bot.", rsp.VerifyUrl)
log.Infof("按 Enter 继续....")
_, _ = s.Console.ReadString('\n')
os.Exit(0)
return
case client.UnsafeDeviceError:
log.Warnf("账号已开启设备锁,请前往 -> %v <- 验证并重启Bot.", rsp.VerifyUrl)
if conf.WebUi.WebInput {
log.Infof(" (http://%s:%d/admin/do_web_write 确认后继续)....", conf.WebUi.Host, conf.WebUi.WebUiPort)
text = <-WebInput
} else {
log.Infof("按 Enter 继续....")
_, _ = s.Console.ReadString('\n')
}
log.Info(text)
os.Exit(0)
return
case client.OtherLoginError, client.UnknownLoginError:
log.Warnf("登录失败: %v", rsp.ErrorMessage)
log.Infof("按 Enter 继续....")
_, _ = s.Console.ReadString('\n')
os.Exit(0)
return
}
}
break
}
log.Infof("登录成功 欢迎使用: %v", cli.Nickname)
time.Sleep(time.Second)
log.Info("开始加载好友列表...")
global.Check(cli.ReloadFriendList())
log.Infof("共加载 %v 个好友.", len(cli.FriendList))
log.Infof("开始加载群列表...")
global.Check(cli.ReloadGroupList())
log.Infof("共加载 %v 个群.", len(cli.GroupList))
s.bot = coolq.NewQQBot(cli, conf)
if conf.PostMessageFormat != "string" && conf.PostMessageFormat != "array" {
log.Warnf("post_message_format 配置错误, 将自动使用 string")
coolq.SetMessageFormat("string")
} else {
coolq.SetMessageFormat(conf.PostMessageFormat)
}
if conf.RateLimit.Enabled {
global.InitLimiter(conf.RateLimit.Frequency, conf.RateLimit.BucketSize)
}
log.Info("正在加载事件过滤器.")
global.BootFilter()
global.InitCodec()
coolq.IgnoreInvalidCQCode = conf.IgnoreInvalidCQCode
coolq.ForceFragmented = conf.ForceFragmented
log.Info("资源初始化完成, 开始处理信息.")
log.Info("アトリは、高性能ですから!")
cli.OnDisconnected(func(bot *client.QQClient, e *client.ClientDisconnectedEvent) {
if conf.ReLogin.Enabled {
var times uint = 1
for {
if cli.Online {
log.Warn("Bot已登录")
return
}
if conf.ReLogin.MaxReloginTimes == 0 {
} else if times > conf.ReLogin.MaxReloginTimes {
break
}
log.Warnf("Bot已离线 (%v),将在 %v 秒后尝试重连. 重连次数:%v",
e.Message, conf.ReLogin.ReLoginDelay, times)
times++
time.Sleep(time.Second * time.Duration(conf.ReLogin.ReLoginDelay))
rsp, err := cli.Login()
if err != nil {
log.Errorf("重连失败: %v", err)
continue
}
if !rsp.Success {
switch rsp.Error {
case client.NeedCaptcha:
log.Fatalf("重连失败: 需要验证码. (验证码处理正在开发中)")
case client.UnsafeDeviceError:
log.Fatalf("重连失败: 设备锁")
default:
log.Errorf("重连失败: %v", rsp.ErrorMessage)
continue
}
}
log.Info("重连成功")
return
}
log.Fatal("重连失败: 重连次数达到设置的上限值")
}
s.bot.Release()
log.Fatalf("Bot已离线%v", e.Message)
})
}
func (s *webServer) admin(c *gin.Context) {
action := c.Param("action")
log.Debugf("WebServer接收到cgi调用: %v", action)
if f, ok := HttpuriAdmin[action]; ok {
f(s, c)
} else {
c.JSON(200, coolq.Failed(404))
}
}
// 获取当前配置文件信息
func GetConf() *global.JsonConfig {
if JsonConfig != nil {
return JsonConfig
}
conf := global.Load("config.json")
return conf
}
// admin 控制器 登录验证
func AuthMiddleWare() gin.HandlerFunc {
return func(c *gin.Context) {
conf := GetConf()
//处理跨域问题
c.Header("Access-Control-Allow-Origin", "*")
c.Header("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization, Token")
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, PATCH, DELETE")
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
c.Header("Access-Control-Allow-Credentials", "true")
// 放行所有OPTIONS方法因为有的模板是要请求两次的
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(http.StatusNoContent)
}
// 处理请求
if c.Request.Method != "GET" && c.Request.Method != "POST" {
log.Warnf("已拒绝客户端 %v 的请求: 方法错误", c.Request.RemoteAddr)
c.Status(404)
c.Abort()
}
if c.Request.Method == "POST" && strings.Contains(c.Request.Header.Get("Content-Type"), "application/json") {
d, err := c.GetRawData()
if err != nil {
log.Warnf("获取请求 %v 的Body时出现错误: %v", c.Request.RequestURI, err)
c.Status(400)
c.Abort()
}
if !gjson.ValidBytes(d) {
log.Warnf("已拒绝客户端 %v 的请求: 非法Json", c.Request.RemoteAddr)
c.Status(400)
c.Abort()
}
c.Set("json_body", gjson.ParseBytes(d))
}
authToken := conf.AccessToken
if auth := c.Request.Header.Get("Authorization"); auth != "" {
if strings.SplitN(auth, " ", 2)[1] != authToken {
c.AbortWithStatus(401)
return
}
} else if c.Query("access_token") != authToken {
c.AbortWithStatus(401)
return
} else {
c.Next()
}
}
}
func (s *webServer) DoReLogin() { // TODO: 协议层的 ReLogin
JsonConfig = nil
conf := GetConf()
OldConf := s.Conf
cli := client.NewClient(conf.Uin, conf.Password)
log.Info("开始尝试登录并同步消息...")
log.Infof("使用协议: %v", func() string {
switch client.SystemDeviceInfo.Protocol {
case client.AndroidPad:
return "Android Pad"
case client.AndroidPhone:
return "Android Phone"
case client.AndroidWatch:
return "Android Watch"
}
return "未知"
}())
cli.OnLog(func(c *client.QQClient, e *client.LogEvent) {
switch e.Type {
case "INFO":
log.Info("Protocol -> " + e.Message)
case "ERROR":
log.Error("Protocol -> " + e.Message)
case "DEBUG":
log.Debug("Protocol -> " + e.Message)
}
})
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) {
log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. ")
})
s.Cli = cli
s.Dologin()
//关闭之前的 server
if OldConf.HttpConfig != nil && OldConf.HttpConfig.Enabled {
HttpServer.ShutDown()
}
//if OldConf.WSConfig != nil && OldConf.WSConfig.Enabled {
// server.WsShutdown()
//}
//s.UpServer()
s.ReloadServer()
s.Conf = conf
}
func (s *webServer) UpServer() {
conf := GetConf()
if conf.HttpConfig != nil && conf.HttpConfig.Enabled {
go HttpServer.Run(fmt.Sprintf("%s:%d", conf.HttpConfig.Host, conf.HttpConfig.Port), conf.AccessToken, s.bot)
for k, v := range conf.HttpConfig.PostUrls {
NewHttpClient().Run(k, v, conf.HttpConfig.Timeout, s.bot)
}
}
if conf.WSConfig != nil && conf.WSConfig.Enabled {
go WebsocketServer.Run(fmt.Sprintf("%s:%d", conf.WSConfig.Host, conf.WSConfig.Port), conf.AccessToken, s.bot)
}
for _, rc := range conf.ReverseServers {
go NewWebsocketClient(rc, conf.AccessToken, s.bot).Run()
}
}
// 暂不支持ws服务的重启
func (s *webServer) ReloadServer() {
conf := GetConf()
if conf.HttpConfig != nil && conf.HttpConfig.Enabled {
go HttpServer.Run(fmt.Sprintf("%s:%d", conf.HttpConfig.Host, conf.HttpConfig.Port), conf.AccessToken, s.bot)
for k, v := range conf.HttpConfig.PostUrls {
NewHttpClient().Run(k, v, conf.HttpConfig.Timeout, s.bot)
}
}
for _, rc := range conf.ReverseServers {
go NewWebsocketClient(rc, conf.AccessToken, s.bot).Run()
}
}
// 热重启
func AdminDoRestart(s *webServer, c *gin.Context) {
s.bot = nil
s.Cli = nil
s.DoReLogin()
c.JSON(200, coolq.OK(coolq.MSG{}))
return
}
// 冷重启
func AdminDoRestartDocker(s *webServer, c *gin.Context) {
Console <- os.Kill
c.JSON(200, coolq.OK(coolq.MSG{}))
return
}
// web输入 html 页面
func AdminWebWrite(s *webServer, c *gin.Context) {
pic := global.ReadAllText("captcha.jpg")
var picbase64 string
var ispic = false
if pic != "" {
input := []byte(pic)
// base64编码
picbase64 = base64.StdEncoding.EncodeToString(input)
ispic = true
}
c.JSON(200, coolq.OK(coolq.MSG{
"ispic": ispic, //为空则为 设备锁 或者没有需要输入
"picbase64": picbase64, //web上显示图片
}))
}
// web输入 处理
func AdminDoWebWrite(s *webServer, c *gin.Context) {
input := c.PostForm("input")
WebInput <- input
c.JSON(200, coolq.OK(coolq.MSG{}))
}
// 普通配置修改
func AdminDoConfigBase(s *webServer, c *gin.Context) {
conf := GetConf()
conf.Uin, _ = strconv.ParseInt(c.PostForm("uin"), 10, 64)
conf.Password = c.PostForm("password")
if c.PostForm("enable_db") == "true" {
conf.EnableDB = true
} else {
conf.EnableDB = false
}
conf.AccessToken = c.PostForm("access_token")
if err := conf.Save("config.json"); err != nil {
log.Fatalf("保存 config.json 时出现错误: %v", err)
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
} else {
JsonConfig = nil
c.JSON(200, coolq.OK(coolq.MSG{}))
}
}
// http配置修改
func AdminDoConfigHttp(s *webServer, c *gin.Context) {
conf := GetConf()
p, _ := strconv.ParseUint(c.PostForm("port"), 10, 16)
conf.HttpConfig.Port = uint16(p)
conf.HttpConfig.Host = c.PostForm("host")
if c.PostForm("enable") == "true" {
conf.HttpConfig.Enabled = true
} else {
conf.HttpConfig.Enabled = false
}
t, _ := strconv.ParseInt(c.PostForm("timeout"), 10, 32)
conf.HttpConfig.Timeout = int32(t)
if c.PostForm("post_url") != "" {
conf.HttpConfig.PostUrls[c.PostForm("post_url")] = c.PostForm("post_secret")
}
if err := conf.Save("config.json"); err != nil {
log.Fatalf("保存 config.json 时出现错误: %v", err)
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
} else {
JsonConfig = nil
c.JSON(200, coolq.OK(coolq.MSG{}))
}
}
// ws配置修改
func AdminDoConfigWs(s *webServer, c *gin.Context) {
conf := GetConf()
p, _ := strconv.ParseUint(c.PostForm("port"), 10, 16)
conf.WSConfig.Port = uint16(p)
conf.WSConfig.Host = c.PostForm("host")
if c.PostForm("enable") == "true" {
conf.WSConfig.Enabled = true
} else {
conf.WSConfig.Enabled = false
}
if err := conf.Save("config.json"); err != nil {
log.Fatalf("保存 config.json 时出现错误: %v", err)
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
} else {
JsonConfig = nil
c.JSON(200, coolq.OK(coolq.MSG{}))
}
}
// 反向ws配置修改
func AdminDoConfigReverse(s *webServer, c *gin.Context) {
conf := GetConf()
conf.ReverseServers[0].ReverseApiUrl = c.PostForm("reverse_api_url")
conf.ReverseServers[0].ReverseUrl = c.PostForm("reverse_url")
conf.ReverseServers[0].ReverseEventUrl = c.PostForm("reverse_event_url")
t, _ := strconv.ParseUint(c.PostForm("reverse_reconnect_interval"), 10, 16)
conf.ReverseServers[0].ReverseReconnectInterval = uint16(t)
if c.PostForm("enable") == "true" {
conf.ReverseServers[0].Enabled = true
} else {
conf.ReverseServers[0].Enabled = false
}
if err := conf.Save("config.json"); err != nil {
log.Fatalf("保存 config.json 时出现错误: %v", err)
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
} else {
JsonConfig = nil
c.JSON(200, coolq.OK(coolq.MSG{}))
}
}
// config.json配置修改
func AdminDoConfigJson(s *webServer, c *gin.Context) {
conf := GetConf()
Json := c.PostForm("json")
err := json.Unmarshal([]byte(Json), &conf)
if err != nil {
log.Warnf("尝试加载配置文件 %v 时出现错误: %v", "config.json", err)
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
return
}
if err := conf.Save("config.json"); err != nil {
log.Fatalf("保存 config.json 时出现错误: %v", err)
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
} else {
JsonConfig = nil
c.JSON(200, coolq.OK(coolq.MSG{}))
}
}
// 拉取config.json配置
func AdminGetConfigJson(s *webServer, c *gin.Context) {
conf := GetConf()
c.JSON(200, coolq.OK(coolq.MSG{"config": conf}))
}

View File

@ -5,6 +5,7 @@ import (
"crypto/hmac" "crypto/hmac"
"crypto/sha1" "crypto/sha1"
"encoding/hex" "encoding/hex"
"net/http"
"os" "os"
"strconv" "strconv"
"strings" "strings"
@ -21,6 +22,7 @@ import (
type httpServer struct { type httpServer struct {
engine *gin.Engine engine *gin.Engine
bot *coolq.CQBot bot *coolq.CQBot
Http *http.Server
} }
type httpClient struct { type httpClient struct {
@ -79,13 +81,23 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
go func() { go func() {
log.Infof("CQ HTTP 服务器已启动: %v", addr) log.Infof("CQ HTTP 服务器已启动: %v", addr)
err := s.engine.Run(addr) s.Http = &http.Server{
if err != nil { Addr: addr,
Handler: s.engine,
}
if err := s.Http.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Error(err) log.Error(err)
log.Infof("请检查端口是否被占用.") log.Infof("请检查端口是否被占用.")
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
os.Exit(1) os.Exit(1)
} }
//err := s.engine.Run(addr)
//if err != nil {
// log.Error(err)
// log.Infof("请检查端口是否被占用.")
// time.Sleep(time.Second * 5)
// os.Exit(1)
//}
}() }()
} }
@ -118,7 +130,9 @@ func (c *httpClient) onBotPushEvent(m coolq.MSG) {
h["X-Signature"] = "sha1=" + hex.EncodeToString(mac.Sum(nil)) h["X-Signature"] = "sha1=" + hex.EncodeToString(mac.Sum(nil))
} }
return h return h
}()).SetTimeout(time.Second * time.Duration(c.timeout)).Do() }()).SetTimeout(time.Second * time.Duration(c.timeout)).F().Retry().Attempt(5).
WaitTime(time.Millisecond * 500).MaxWaitTime(time.Second * 5).
Do()
if err != nil { if err != nil {
log.Warnf("上报Event数据 %v 到 %v 失败: %v", m.ToJson(), c.addr, err) log.Warnf("上报Event数据 %v 到 %v 失败: %v", m.ToJson(), c.addr, err)
return return
@ -349,6 +363,23 @@ func (s *httpServer) HandleQuickOperation(c *gin.Context) {
} }
} }
func (s *httpServer) OcrImage(c *gin.Context) {
img := getParam(c, "image")
c.JSON(200, s.bot.CQOcrImage(img))
}
func (s *httpServer) GetWordSlices(c *gin.Context) {
content := getParam(c, "content")
c.JSON(200, s.bot.CQGetWordSlices(content))
}
func (s *httpServer) SetGroupPortrait(c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
file := getParam(c, "file")
cache := getParam(c, "cache")
c.JSON(200, s.bot.CQSetGroupPortrait(gid, file, cache))
}
func getParamOrDefault(c *gin.Context, k, def string) string { func getParamOrDefault(c *gin.Context, k, def string) string {
r := getParam(c, k) r := getParam(c, k)
if r != "" { if r != "" {
@ -497,7 +528,29 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
"reload_event_filter": func(s *httpServer, c *gin.Context) { "reload_event_filter": func(s *httpServer, c *gin.Context) {
s.ReloadEventFilter(c) s.ReloadEventFilter(c)
}, },
"set_group_portrait": func(s *httpServer, c *gin.Context) {
s.SetGroupPortrait(c)
},
".handle_quick_operation": func(s *httpServer, c *gin.Context) { ".handle_quick_operation": func(s *httpServer, c *gin.Context) {
s.HandleQuickOperation(c) s.HandleQuickOperation(c)
}, },
".ocr_image": func(s *httpServer, c *gin.Context) {
s.OcrImage(c)
},
".get_word_slices": func(s *httpServer, c *gin.Context) {
s.GetWordSlices(c)
},
}
func (s *httpServer) ShutDown() {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := s.Http.Shutdown(ctx); err != nil {
log.Fatal("http Server Shutdown:", err)
}
select {
case <-ctx.Done():
log.Println("timeout of 5 seconds.")
}
log.Println("http Server exiting")
} }

View File

@ -501,6 +501,15 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
"reload_event_filter": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { "reload_event_filter": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQReloadEventFilter() return bot.CQReloadEventFilter()
}, },
".ocr_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQOcrImage(p.Get("image").Str)
},
".get_word_slices": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetWordSlices(p.Get("content").Str)
},
"set_group_portrait": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQSetGroupPortrait(p.Get("group_id").Int(), p.Get("file").String(), p.Get("cache").String())
},
".handle_quick_operation": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { ".handle_quick_operation": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQHandleQuickOperation(p.Get("context"), p.Get("operation")) return bot.CQHandleQuickOperation(p.Get("context"), p.Get("operation"))
}, },