mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-06-30 20:03:24 +00:00
Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
e754bd36ed | |||
fb47a66931 | |||
4be73b2834 | |||
e2227d582a | |||
06fccbd9ef | |||
81d2ad3e79 | |||
977337914d | |||
6780615d45 | |||
2670c84c8e | |||
e2b6c3d607 | |||
58a3f81142 | |||
64cb539c0d |
16
README.md
16
README.md
@ -23,6 +23,19 @@
|
|||||||
- [ ] 使用代理请求网络图片
|
- [ ] 使用代理请求网络图片
|
||||||
|
|
||||||
#### 实现
|
#### 实现
|
||||||
|
<details>
|
||||||
|
<summary>已实现CQ码</summary>
|
||||||
|
|
||||||
|
- [CQ:image]
|
||||||
|
- [CQ:face]
|
||||||
|
- [CQ:at]
|
||||||
|
- [CQ:share]
|
||||||
|
- [CQ:reply]
|
||||||
|
- [CQ:forward]
|
||||||
|
- [CQ:node]
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>已实现API</summary>
|
<summary>已实现API</summary>
|
||||||
|
|
||||||
@ -65,7 +78,8 @@
|
|||||||
| ------------------------------------------------------------ |
|
| ------------------------------------------------------------ |
|
||||||
| [私聊信息](https://cqhttp.cc/docs/4.15/#/Post?id=私聊消息) |
|
| [私聊信息](https://cqhttp.cc/docs/4.15/#/Post?id=私聊消息) |
|
||||||
| [群消息](https://cqhttp.cc/docs/4.15/#/Post?id=群消息) |
|
| [群消息](https://cqhttp.cc/docs/4.15/#/Post?id=群消息) |
|
||||||
| [群消息撤回(拓展Event)](docs/cqhttp.md#群消息撤回) |
|
| [群消息撤回(拓展Event)](docs/cqhttp.md#群消息撤回) |
|
||||||
|
| [好友消息撤回(拓展Event)](docs/cqhttp.md#好友消息撤回) |
|
||||||
| [群管理员变动](https://cqhttp.cc/docs/4.15/#/Post?id=群管理员变动) |
|
| [群管理员变动](https://cqhttp.cc/docs/4.15/#/Post?id=群管理员变动) |
|
||||||
| [群成员减少](https://cqhttp.cc/docs/4.15/#/Post?id=群成员减少) |
|
| [群成员减少](https://cqhttp.cc/docs/4.15/#/Post?id=群成员减少) |
|
||||||
| [群成员增加](https://cqhttp.cc/docs/4.15/#/Post?id=群成员增加) |
|
| [群成员增加](https://cqhttp.cc/docs/4.15/#/Post?id=群成员增加) |
|
||||||
|
101
coolq/api.go
101
coolq/api.go
@ -96,28 +96,36 @@ func (bot *CQBot) CQGetGroupMemberInfo(groupId, userId int64, noCache bool) MSG
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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, m gjson.Result) MSG {
|
func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}) MSG {
|
||||||
if m.Type == gjson.String {
|
var str string
|
||||||
str := m.Str
|
if m, ok := i.(gjson.Result); ok {
|
||||||
if str == "" {
|
if m.Type == gjson.JSON {
|
||||||
return Failed(100)
|
elem := bot.ConvertObjectMessage(m, true)
|
||||||
|
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
||||||
|
if mid == -1 {
|
||||||
|
return Failed(100)
|
||||||
|
}
|
||||||
|
return OK(MSG{"message_id": mid})
|
||||||
}
|
}
|
||||||
elem := bot.ConvertStringMessage(str, true)
|
str = func() string {
|
||||||
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
if m.Str != "" {
|
||||||
if mid == -1 {
|
return m.Str
|
||||||
return Failed(100)
|
}
|
||||||
}
|
return m.Raw
|
||||||
return OK(MSG{"message_id": mid})
|
}()
|
||||||
}
|
}
|
||||||
if m.Type == gjson.JSON {
|
if s, ok := i.(string); ok {
|
||||||
elem := bot.ConvertObjectMessage(m, true)
|
str = s
|
||||||
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
|
||||||
if mid == -1 {
|
|
||||||
return Failed(100)
|
|
||||||
}
|
|
||||||
return OK(MSG{"message_id": mid})
|
|
||||||
}
|
}
|
||||||
return Failed(100)
|
if str == "" {
|
||||||
|
return Failed(100)
|
||||||
|
}
|
||||||
|
elem := bot.ConvertStringMessage(str, true)
|
||||||
|
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
||||||
|
if mid == -1 {
|
||||||
|
return Failed(100)
|
||||||
|
}
|
||||||
|
return OK(MSG{"message_id": mid})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
||||||
@ -191,25 +199,36 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=send_private_msg-%E5%8F%91%E9%80%81%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF
|
// https://cqhttp.cc/docs/4.15/#/API?id=send_private_msg-%E5%8F%91%E9%80%81%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF
|
||||||
func (bot *CQBot) CQSendPrivateMessage(userId int64, m gjson.Result) MSG {
|
func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}) MSG {
|
||||||
if m.Type == gjson.String {
|
var str string
|
||||||
str := m.Str
|
if m, ok := i.(gjson.Result); ok {
|
||||||
elem := bot.ConvertStringMessage(str, false)
|
if m.Type == gjson.JSON {
|
||||||
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
elem := bot.ConvertObjectMessage(m, true)
|
||||||
if mid == -1 {
|
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
||||||
return Failed(100)
|
if mid == -1 {
|
||||||
|
return Failed(100)
|
||||||
|
}
|
||||||
|
return OK(MSG{"message_id": mid})
|
||||||
}
|
}
|
||||||
return OK(MSG{"message_id": mid})
|
str = func() string {
|
||||||
|
if m.Str != "" {
|
||||||
|
return m.Str
|
||||||
|
}
|
||||||
|
return m.Raw
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
if m.Type == gjson.JSON {
|
if s, ok := i.(string); ok {
|
||||||
elem := bot.ConvertObjectMessage(m, true)
|
str = s
|
||||||
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
|
||||||
if mid == -1 {
|
|
||||||
return Failed(100)
|
|
||||||
}
|
|
||||||
return OK(MSG{"message_id": mid})
|
|
||||||
}
|
}
|
||||||
return Failed(100)
|
if str == "" {
|
||||||
|
return Failed(100)
|
||||||
|
}
|
||||||
|
elem := bot.ConvertStringMessage(str, false)
|
||||||
|
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
||||||
|
if mid == -1 {
|
||||||
|
return Failed(100)
|
||||||
|
}
|
||||||
|
return OK(MSG{"message_id": mid})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_card-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%90%8D%E7%89%87%EF%BC%88%E7%BE%A4%E5%A4%87%E6%B3%A8%EF%BC%89
|
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_card-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%90%8D%E7%89%87%EF%BC%88%E7%BE%A4%E5%A4%87%E6%B3%A8%EF%BC%89
|
||||||
@ -343,12 +362,14 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
|||||||
msgType := context.Get("message_type").Str
|
msgType := context.Get("message_type").Str
|
||||||
reply := operation.Get("reply")
|
reply := operation.Get("reply")
|
||||||
if reply.Exists() {
|
if reply.Exists() {
|
||||||
at := true
|
/*
|
||||||
if operation.Get("at_sender").Exists() {
|
at := true
|
||||||
at = operation.Get("at_sender").Bool()
|
if operation.Get("at_sender").Exists() {
|
||||||
}
|
at = operation.Get("at_sender").Bool()
|
||||||
|
}
|
||||||
|
*/
|
||||||
// TODO: 处理at字段
|
// TODO: 处理at字段
|
||||||
if msgType == "group" && at {
|
if msgType == "group" {
|
||||||
bot.CQSendGroupMessage(context.Get("group_id").Int(), reply)
|
bot.CQSendGroupMessage(context.Get("group_id").Int(), reply)
|
||||||
}
|
}
|
||||||
if msgType == "private" {
|
if msgType == "private" {
|
||||||
|
@ -51,6 +51,7 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
|
|||||||
bot.Client.OnTempMessage(bot.tempMessageEvent)
|
bot.Client.OnTempMessage(bot.tempMessageEvent)
|
||||||
bot.Client.OnGroupMuted(bot.groupMutedEvent)
|
bot.Client.OnGroupMuted(bot.groupMutedEvent)
|
||||||
bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent)
|
bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent)
|
||||||
|
bot.Client.OnFriendMessageRecalled(bot.friendRecallEvent)
|
||||||
bot.Client.OnJoinGroup(bot.joinGroupEvent)
|
bot.Client.OnJoinGroup(bot.joinGroupEvent)
|
||||||
bot.Client.OnLeaveGroup(bot.leaveGroupEvent)
|
bot.Client.OnLeaveGroup(bot.leaveGroupEvent)
|
||||||
bot.Client.OnGroupMemberJoined(bot.memberJoinEvent)
|
bot.Client.OnGroupMemberJoined(bot.memberJoinEvent)
|
||||||
@ -92,7 +93,7 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
|
|||||||
if i, ok := elem.(*message.ImageElement); ok {
|
if i, ok := elem.(*message.ImageElement); ok {
|
||||||
gm, err := bot.Client.UploadGroupImage(groupId, i.Data)
|
gm, err := bot.Client.UploadGroupImage(groupId, i.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("警告: 群 %v 消息图片上传失败.", groupId)
|
log.Warnf("警告: 群 %v 消息图片上传失败: %v", groupId, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
newElem = append(newElem, gm)
|
newElem = append(newElem, gm)
|
||||||
|
@ -10,8 +10,10 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -176,6 +178,20 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
|
|||||||
}
|
}
|
||||||
return message.NewImage(b), nil
|
return message.NewImage(b), nil
|
||||||
}
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
return message.NewImage(b), nil
|
||||||
|
}
|
||||||
if global.PathExists(path.Join(global.IMAGE_PATH, f)) {
|
if global.PathExists(path.Join(global.IMAGE_PATH, f)) {
|
||||||
b, err := ioutil.ReadFile(path.Join(global.IMAGE_PATH, f))
|
b, err := ioutil.ReadFile(path.Join(global.IMAGE_PATH, f))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -21,7 +21,7 @@ func (bot *CQBot) privateMessageEvent(c *client.QQClient, m *message.PrivateMess
|
|||||||
"post_type": "message",
|
"post_type": "message",
|
||||||
"message_type": "private",
|
"message_type": "private",
|
||||||
"sub_type": "friend",
|
"sub_type": "friend",
|
||||||
"message_id": m.Id,
|
"message_id": ToGlobalId(m.Sender.Uin, m.Id),
|
||||||
"user_id": m.Sender.Uin,
|
"user_id": m.Sender.Uin,
|
||||||
"message": ToStringMessage(m.Elements, 0, false),
|
"message": ToStringMessage(m.Elements, 0, false),
|
||||||
"raw_message": cqm,
|
"raw_message": cqm,
|
||||||
@ -53,6 +53,7 @@ func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage)
|
|||||||
"name": file.Name,
|
"name": file.Name,
|
||||||
"size": file.Size,
|
"size": file.Size,
|
||||||
"busid": file.Busid,
|
"busid": file.Busid,
|
||||||
|
"url": c.GetGroupFileUrl(m.GroupCode, file.Path, file.Busid),
|
||||||
},
|
},
|
||||||
"self_id": c.Uin,
|
"self_id": c.Uin,
|
||||||
"time": time.Now().Unix(),
|
"time": time.Now().Unix(),
|
||||||
@ -184,6 +185,20 @@ func (bot *CQBot) groupRecallEvent(c *client.QQClient, e *client.GroupMessageRec
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bot *CQBot) friendRecallEvent(c *client.QQClient, e *client.FriendMessageRecalledEvent) {
|
||||||
|
f := c.FindFriend(e.FriendUin)
|
||||||
|
gid := ToGlobalId(e.FriendUin, e.MessageId)
|
||||||
|
log.Infof("好友 %v(%v) 撤回了消息: %v", f.Nickname, f.Uin, gid)
|
||||||
|
bot.dispatchEventMessage(MSG{
|
||||||
|
"post_type": "notice",
|
||||||
|
"notice_type": "friend_recall",
|
||||||
|
"self_id": c.Uin,
|
||||||
|
"user_id": f.Uin,
|
||||||
|
"time": e.Time,
|
||||||
|
"message_id": gid,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (bot *CQBot) joinGroupEvent(c *client.QQClient, group *client.GroupInfo) {
|
func (bot *CQBot) joinGroupEvent(c *client.QQClient, group *client.GroupInfo) {
|
||||||
log.Infof("Bot进入了群 %v.", formatGroupName(group))
|
log.Infof("Bot进入了群 %v.", formatGroupName(group))
|
||||||
bot.dispatchEventMessage(bot.groupIncrease(group.Code, 0, c.Uin))
|
bot.dispatchEventMessage(bot.groupIncrease(group.Code, 0, c.Uin))
|
||||||
|
@ -247,3 +247,14 @@ Type: `node`
|
|||||||
| `operator_id` | int64 | | 操作者id |
|
| `operator_id` | int64 | | 操作者id |
|
||||||
| `message_id` | int64 | | 被撤回的消息id |
|
| `message_id` | int64 | | 被撤回的消息id |
|
||||||
|
|
||||||
|
#### 好友消息撤回
|
||||||
|
|
||||||
|
**上报数据**
|
||||||
|
|
||||||
|
| 字段 | 类型 | 可能的值 | 说明 |
|
||||||
|
| ------------- | ------ | -------------- | -------------- |
|
||||||
|
| `post_type` | string | `notice` | 上报类型 |
|
||||||
|
| `notice_type` | string | `friend_recall`| 消息类型 |
|
||||||
|
| `user_id` | int64 | | 好友id |
|
||||||
|
| `message_id` | int64 | | 被撤回的消息id |
|
||||||
|
|
||||||
|
101
global/art.go
101
global/art.go
@ -1,101 +0,0 @@
|
|||||||
package global
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"golang.org/x/image/font"
|
|
||||||
"golang.org/x/image/font/basicfont"
|
|
||||||
"golang.org/x/image/math/fixed"
|
|
||||||
"image"
|
|
||||||
"image/color"
|
|
||||||
_ "image/jpeg"
|
|
||||||
_ "image/png"
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
// https://github.com/xrlin/AsciiArt
|
|
||||||
|
|
||||||
func Convert(f io.Reader, chars []string, subWidth, subHeight int, imageSwitch bool, bgColor, penColor color.RGBA) (string, *image.NRGBA, error) {
|
|
||||||
var charsLength = len(chars)
|
|
||||||
if charsLength == 0 {
|
|
||||||
return "", nil, fmt.Errorf("no chars provided")
|
|
||||||
}
|
|
||||||
if subWidth == 0 || subHeight == 0 {
|
|
||||||
return "", nil, fmt.Errorf("subWidth and subHeight params is required")
|
|
||||||
}
|
|
||||||
m, _, err := image.Decode(f)
|
|
||||||
if err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
imageWidth, imageHeight := m.Bounds().Max.X, m.Bounds().Max.Y
|
|
||||||
var img *image.NRGBA
|
|
||||||
if imageSwitch {
|
|
||||||
img = initImage(imageWidth, imageHeight, bgColor)
|
|
||||||
}
|
|
||||||
piecesX, piecesY := imageWidth/subWidth, imageHeight/subHeight
|
|
||||||
var buff bytes.Buffer
|
|
||||||
for y := 0; y < piecesY; y++ {
|
|
||||||
offsetY := y * subHeight
|
|
||||||
for x := 0; x < piecesX; x++ {
|
|
||||||
offsetX := x * subWidth
|
|
||||||
averageBrightness := calculateAverageBrightness(m, image.Rect(offsetX, offsetY, offsetX+subWidth, offsetY+subHeight))
|
|
||||||
char := getCharByBrightness(chars, averageBrightness)
|
|
||||||
buff.WriteString(char)
|
|
||||||
if img != nil {
|
|
||||||
addCharToImage(img, char, x*subWidth, y*subHeight, penColor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buff.WriteString("\n")
|
|
||||||
}
|
|
||||||
return buff.String(), img, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func initImage(width, height int, bgColor color.RGBA) *image.NRGBA {
|
|
||||||
img := image.NewNRGBA(image.Rect(0, 0, width, height))
|
|
||||||
for x := 0; x < width; x++ {
|
|
||||||
for y := 0; y < height; y++ {
|
|
||||||
img.Set(x, y, bgColor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return img
|
|
||||||
}
|
|
||||||
func calculateAverageBrightness(img image.Image, rect image.Rectangle) float64 {
|
|
||||||
var averageBrightness float64
|
|
||||||
width, height := rect.Max.X-rect.Min.X, rect.Max.Y-rect.Min.Y
|
|
||||||
var brightness float64
|
|
||||||
for x := rect.Min.X; x < rect.Max.X; x++ {
|
|
||||||
for y := rect.Min.Y; y < rect.Max.Y; y++ {
|
|
||||||
r, g, b, _ := img.At(x, y).RGBA()
|
|
||||||
brightness = float64(r>>8+g>>8+b>>8) / 3
|
|
||||||
averageBrightness += brightness
|
|
||||||
}
|
|
||||||
}
|
|
||||||
averageBrightness /= float64(width * height)
|
|
||||||
return averageBrightness
|
|
||||||
}
|
|
||||||
|
|
||||||
func getCharByBrightness(chars []string, brightness float64) string {
|
|
||||||
index := int(brightness*float64(len(chars))) >> 8
|
|
||||||
if index == len(chars) {
|
|
||||||
index--
|
|
||||||
}
|
|
||||||
return chars[len(chars)-index-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
func addCharToImage(img *image.NRGBA, char string, x, y int, penColor color.RGBA) {
|
|
||||||
face := basicfont.Face7x13
|
|
||||||
point := fixed.Point26_6{X: fixed.Int26_6(x * 64), Y: fixed.Int26_6(y * 64)}
|
|
||||||
d := &font.Drawer{
|
|
||||||
Dst: img,
|
|
||||||
Src: image.NewUniform(penColor),
|
|
||||||
Face: face,
|
|
||||||
Dot: point,
|
|
||||||
}
|
|
||||||
d.DrawString(char)
|
|
||||||
}
|
|
||||||
|
|
||||||
var Colors = map[string]color.RGBA{"black": {0, 0, 0, 255},
|
|
||||||
"gray": {140, 140, 140, 255},
|
|
||||||
"red": {255, 0, 0, 255},
|
|
||||||
"green": {0, 128, 0, 255},
|
|
||||||
"blue": {0, 0, 255, 255}}
|
|
@ -15,7 +15,6 @@ type JsonConfig struct {
|
|||||||
HttpConfig *GoCQHttpConfig `json:"http_config"`
|
HttpConfig *GoCQHttpConfig `json:"http_config"`
|
||||||
WSConfig *GoCQWebsocketConfig `json:"ws_config"`
|
WSConfig *GoCQWebsocketConfig `json:"ws_config"`
|
||||||
ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"`
|
ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"`
|
||||||
Proxy string `json:"proxy"`
|
|
||||||
Debug bool `json:"debug"`
|
Debug bool `json:"debug"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
go.mod
4
go.mod
@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
|
|||||||
go 1.14
|
go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200731043935-dbb4073480bb
|
github.com/Mrs4s/MiraiGo v0.0.0-20200803034534-d8ed1a49ff8b
|
||||||
github.com/gin-gonic/gin v1.6.3
|
github.com/gin-gonic/gin v1.6.3
|
||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.4.2
|
||||||
github.com/guonaihong/gout v0.1.1
|
github.com/guonaihong/gout v0.1.1
|
||||||
@ -14,7 +14,7 @@ require (
|
|||||||
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/tidwall/gjson v1.6.0
|
github.com/tidwall/gjson v1.6.0
|
||||||
github.com/xujiajun/nutsdb v0.5.0
|
github.com/xujiajun/nutsdb v0.5.0
|
||||||
golang.org/x/image v0.0.0-20200618115811-c13761719519
|
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
|
||||||
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa
|
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa
|
||||||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
|
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
|
||||||
)
|
)
|
||||||
|
18
go.sum
18
go.sum
@ -1,11 +1,11 @@
|
|||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200730113850-298c1bb9119f h1:+MW9qbGu9uWJc9vs6m8+8oQLh9nK6RCW2wk3BX7Z14c=
|
github.com/Mrs4s/MiraiGo v0.0.0-20200802150153-a7761bfb7571 h1:OQQhH7IVRX5BqjUwrlg6mKVUlxKoBzOPUNwZEToGQ00=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200730113850-298c1bb9119f/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
|
github.com/Mrs4s/MiraiGo v0.0.0-20200802150153-a7761bfb7571/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200730171208-f076f2a45730 h1:ZQoh1RyCacWyyJV9+MO9S+kJ5HOQOaA9PLBEGBbL3oA=
|
github.com/Mrs4s/MiraiGo v0.0.0-20200802165028-683ad4b6cbb5 h1:NF3YM6Bv2/sA6yc1wxuBuHRfVBhQws02INRpqrkqmh4=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200730171208-f076f2a45730/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
|
github.com/Mrs4s/MiraiGo v0.0.0-20200802165028-683ad4b6cbb5/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200731043935-dbb4073480bb h1:L40i56EyeItfy5SN/TRtZL/aLtMDoFIjTTefJBhgU6E=
|
github.com/Mrs4s/MiraiGo v0.0.0-20200803034534-d8ed1a49ff8b h1:XQEeWyot+xvUDV9btSbI+fAJdWXxRLBWE8wRyzpgmfA=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200731043935-dbb4073480bb/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
|
github.com/Mrs4s/MiraiGo v0.0.0-20200803034534-d8ed1a49ff8b/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
|
||||||
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=
|
||||||
@ -69,6 +69,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/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||||
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
@ -101,10 +103,10 @@ github.com/xujiajun/nutsdb v0.5.0 h1:j/jM3Zw7Chg8WK7bAcKR0Xr7Mal47U1oJAMgySfDn9E
|
|||||||
github.com/xujiajun/nutsdb v0.5.0/go.mod h1:owdwN0tW084RxEodABLbO7h4Z2s9WiAjZGZFhRh0/1Q=
|
github.com/xujiajun/nutsdb v0.5.0/go.mod h1:owdwN0tW084RxEodABLbO7h4Z2s9WiAjZGZFhRh0/1Q=
|
||||||
github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b h1:jKG9OiL4T4xQN3IUrhUpc1tG+HfDXppkgVcrAiiaI/0=
|
github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b h1:jKG9OiL4T4xQN3IUrhUpc1tG+HfDXppkgVcrAiiaI/0=
|
||||||
github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b/go.mod h1:AZd87GYJlUzl82Yab2kTjx1EyXSQCAfZDhpTo1SQC4k=
|
github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b/go.mod h1:AZd87GYJlUzl82Yab2kTjx1EyXSQCAfZDhpTo1SQC4k=
|
||||||
|
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189 h1:4UJw9if55Fu3HOwbfcaQlJ27p3oeJU2JZqoeT3ITJQk=
|
||||||
|
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/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/image v0.0.0-20200618115811-c13761719519 h1:1e2ufUJNM3lCHEY5jIgac/7UTjd6cgJNdatjPdFWf34=
|
|
||||||
golang.org/x/image v0.0.0-20200618115811-c13761719519/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
|
||||||
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=
|
||||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
|
48
main.go
48
main.go
@ -12,12 +12,14 @@ import (
|
|||||||
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
easy "github.com/t-tomalak/logrus-easy-formatter"
|
easy "github.com/t-tomalak/logrus-easy-formatter"
|
||||||
"image/color"
|
asciiart "github.com/yinghau76/go-ascii-art"
|
||||||
|
"image"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -72,7 +74,34 @@ func init() {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
console := bufio.NewReader(os.Stdin)
|
console := bufio.NewReader(os.Stdin)
|
||||||
conf := global.Load("config.json")
|
var conf *global.JsonConfig
|
||||||
|
if global.PathExists("config.json") || os.Getenv("UIN") == "" {
|
||||||
|
conf = global.Load("config.json")
|
||||||
|
} else if os.Getenv("UIN") != "" {
|
||||||
|
log.Infof("将从环境变量加载配置.")
|
||||||
|
uin, _ := strconv.ParseInt(os.Getenv("UIN"), 10, 64)
|
||||||
|
pwd := os.Getenv("PASS")
|
||||||
|
post := os.Getenv("HTTP_POST")
|
||||||
|
conf = &global.JsonConfig{
|
||||||
|
Uin: uin,
|
||||||
|
Password: pwd,
|
||||||
|
HttpConfig: &global.GoCQHttpConfig{
|
||||||
|
Enabled: true,
|
||||||
|
Host: "0.0.0.0",
|
||||||
|
Port: 5700,
|
||||||
|
PostUrls: map[string]string{},
|
||||||
|
},
|
||||||
|
WSConfig: &global.GoCQWebsocketConfig{
|
||||||
|
Enabled: true,
|
||||||
|
Host: "0.0.0.0",
|
||||||
|
Port: 6700,
|
||||||
|
},
|
||||||
|
Debug: os.Getenv("DEBUG") == "true",
|
||||||
|
}
|
||||||
|
if post != "" {
|
||||||
|
conf.HttpConfig.PostUrls[post] = os.Getenv("HTTP_SECRET")
|
||||||
|
}
|
||||||
|
}
|
||||||
if conf == nil {
|
if conf == nil {
|
||||||
err := global.DefaultConfig().Save("config.json")
|
err := global.DefaultConfig().Save("config.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -80,18 +109,20 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infof("默认配置文件已生成, 请编辑 config.json 后重启程序.")
|
log.Infof("默认配置文件已生成, 请编辑 config.json 后重启程序.")
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if conf.Uin == 0 || conf.Password == "" {
|
if conf.Uin == 0 || conf.Password == "" {
|
||||||
log.Fatal("请修改 config.json 以添加账号密码.")
|
log.Warnf("请修改 config.json 以添加账号密码.")
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if conf.Debug {
|
if conf.Debug {
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
log.Warnf("已开启Debug模式.")
|
log.Warnf("已开启Debug模式.")
|
||||||
}
|
}
|
||||||
if !global.PathExists("device.json") {
|
if !global.PathExists("device.json") {
|
||||||
log.Warn("虚拟设备信息不存在, 将自动生成随机设备,按 Enter 继续.")
|
log.Warn("虚拟设备信息不存在, 将自动生成随机设备.")
|
||||||
_, _ = console.ReadString('\n')
|
|
||||||
client.GenRandomDevice()
|
client.GenRandomDevice()
|
||||||
_ = ioutil.WriteFile("device.json", client.SystemDeviceInfo.ToJson(), 0777)
|
_ = ioutil.WriteFile("device.json", client.SystemDeviceInfo.ToJson(), 0777)
|
||||||
log.Info("已生成设备信息并保存到 device.json 文件.")
|
log.Info("已生成设备信息并保存到 device.json 文件.")
|
||||||
@ -111,10 +142,9 @@ func main() {
|
|||||||
if !rsp.Success {
|
if !rsp.Success {
|
||||||
switch rsp.Error {
|
switch rsp.Error {
|
||||||
case client.NeedCaptcha:
|
case client.NeedCaptcha:
|
||||||
art, _, err := global.Convert(bytes.NewReader(rsp.CaptchaImage), []string{" ", "1", "i", ":", "*", "|", "."}, 1, 1, false, global.Colors["gray"], color.RGBA{})
|
img, _, _ := image.Decode(bytes.NewReader(rsp.CaptchaImage))
|
||||||
global.Check(err)
|
fmt.Println(asciiart.New("image", img).Art)
|
||||||
fmt.Println(art)
|
log.Warn("请输入验证码: (回车提交)")
|
||||||
log.Warn("请输入验证码.")
|
|
||||||
text, _ := console.ReadString('\n')
|
text, _ := console.ReadString('\n')
|
||||||
rsp, err = cli.SubmitCaptcha(strings.ReplaceAll(text, "\n", ""), rsp.CaptchaSign)
|
rsp, err = cli.SubmitCaptcha(strings.ReplaceAll(text, "\n", ""), rsp.CaptchaSign)
|
||||||
continue
|
continue
|
||||||
|
@ -239,7 +239,7 @@ func (s *httpServer) SendPrivateMessage(c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQSendPrivateMessage(uid, gjson.Parse(msg)))
|
c.JSON(200, s.bot.CQSendPrivateMessage(uid, gjson.Parse(msg)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(200, s.bot.CQSendPrivateMessage(uid, gjson.Result{Type: gjson.String, Str: msg}))
|
c.JSON(200, s.bot.CQSendPrivateMessage(uid, msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SendGroupMessage(c *gin.Context) {
|
func (s *httpServer) SendGroupMessage(c *gin.Context) {
|
||||||
@ -249,7 +249,7 @@ func (s *httpServer) SendGroupMessage(c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQSendGroupMessage(gid, gjson.Parse(msg)))
|
c.JSON(200, s.bot.CQSendGroupMessage(gid, gjson.Parse(msg)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(200, s.bot.CQSendGroupMessage(gid, gjson.Result{Type: gjson.String, Str: msg}))
|
c.JSON(200, s.bot.CQSendGroupMessage(gid, msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SendGroupForwardMessage(c *gin.Context) {
|
func (s *httpServer) SendGroupForwardMessage(c *gin.Context) {
|
||||||
|
@ -157,12 +157,12 @@ func (c *websocketClient) connectUniversal() {
|
|||||||
func (c *websocketClient) listenApi(conn *wsc.Conn, u bool) {
|
func (c *websocketClient) listenApi(conn *wsc.Conn, u bool) {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
for {
|
for {
|
||||||
buf := make([]byte, 10240)
|
var buf []byte
|
||||||
l, err := conn.Read(buf)
|
err := wsc.Message.Receive(conn, &buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
j := gjson.ParseBytes(buf[:l])
|
j := gjson.ParseBytes(buf)
|
||||||
t := strings.ReplaceAll(j.Get("action").Str, "_async", "")
|
t := strings.ReplaceAll(j.Get("action").Str, "_async", "")
|
||||||
log.Debugf("反向WS接收到API调用: %v 参数: %v", t, j.Get("params").Raw)
|
log.Debugf("反向WS接收到API调用: %v 参数: %v", t, j.Get("params").Raw)
|
||||||
if f, ok := wsApi[t]; ok {
|
if f, ok := wsApi[t]; ok {
|
||||||
|
Reference in New Issue
Block a user