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

Compare commits

...

7 Commits

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

View File

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

View File

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

View File

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

View File

@ -115,6 +115,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
| 0 | iPad | 无 | | 0 | iPad | 无 |
| 1 | Android Phone | 无 | | 1 | Android Phone | 无 |
| 2 | Android Watch | 无法接收 `group_notify` 事件、无法接收口令红包、无法接收撤回消息 | | 2 | Android Watch | 无法接收 `group_notify` 事件、无法接收口令红包、无法接收撤回消息 |
| 3 | MacOS | 无 |
> 注意, 根据协议的不同, 各类消息有所限制 > 注意, 根据协议的不同, 各类消息有所限制

View File

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

View File

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

View File

@ -121,7 +121,7 @@ func ReadAddrFile(path string) []*net.TCPAddr {
lines := strings.Split(str, "\n") lines := strings.Split(str, "\n")
var ret []*net.TCPAddr var ret []*net.TCPAddr
for _, l := range lines { for _, l := range lines {
ip := strings.Split(l, ":") ip := strings.Split(strings.TrimSpace(l), ":")
if len(ip) == 2 { if len(ip) == 2 {
port, _ := strconv.Atoi(ip[1]) port, _ := strconv.Atoi(ip[1])
ret = append(ret, &net.TCPAddr{IP: net.ParseIP(ip[0]), Port: port}) ret = append(ret, &net.TCPAddr{IP: net.ParseIP(ip[0]), Port: port})

2
go.mod
View File

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

8
go.sum
View File

@ -1,7 +1,11 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Mrs4s/MiraiGo v0.0.0-20201113113825-c1739dba15c9 h1:7mFBaoEz2HCIkUqfiW1EtpsZEhxfupEda8+EMeuNS+4= github.com/Mrs4s/MiraiGo v0.0.0-20201114105236-1ea9f982fee4 h1:0qoqKkSLTnWBS2rZm95ey9YYbCo4sujO4Kk2frw27yY=
github.com/Mrs4s/MiraiGo v0.0.0-20201113113825-c1739dba15c9/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs= github.com/Mrs4s/MiraiGo v0.0.0-20201114105236-1ea9f982fee4/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs=
github.com/Mrs4s/MiraiGo v0.0.0-20201114105600-231b2d89dbb9 h1:evnR9D9rXcBTUzioFf7XlXX4KbZBhc0/Urp09yV01dc=
github.com/Mrs4s/MiraiGo v0.0.0-20201114105600-231b2d89dbb9/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs=
github.com/Mrs4s/MiraiGo v0.0.0-20201114110437-3d349df7362e h1:cE3YcEtd9LWqtR4nyxciRg/qLaJ6jW9eO8I6ZW7oNDw=
github.com/Mrs4s/MiraiGo v0.0.0-20201114110437-3d349df7362e/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

View File

@ -232,6 +232,8 @@ func main() {
return "Android Phone" return "Android Phone"
case client.AndroidWatch: case client.AndroidWatch:
return "Android Watch" return "Android Watch"
case client.MacOS:
return "MacOS"
} }
return "未知" return "未知"
}()) }())

View File

@ -346,6 +346,8 @@ func (s *webServer) DoReLogin() { // TODO: 协议层的 ReLogin
return "Android Phone" return "Android Phone"
case client.AndroidWatch: case client.AndroidWatch:
return "Android Watch" return "Android Watch"
case client.MacOS:
return "MacOS"
} }
return "未知" return "未知"
}()) }())