1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-04 19:17:37 +08:00

coolq: adapt generic event handle & update MiraiGo

This commit is contained in:
wdvxdr 2022-03-01 16:30:23 +08:00
parent 8d26e3aec4
commit c00e07dec9
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6
6 changed files with 35 additions and 33 deletions

View File

@ -28,7 +28,8 @@ jobs:
- name: Setup Go environment
uses: actions/setup-go@v2.1.3
with:
go-version: 1.17
stable: false
go-version: 1.18.0-rc1
- name: Cache downloaded module
uses: actions/cache@v2
with:

View File

@ -259,7 +259,7 @@ func Main() {
}
var times uint = 1 // 重试次数
var reLoginLock sync.Mutex
cli.OnDisconnected(func(q *client.QQClient, e *client.ClientDisconnectedEvent) {
cli.DisconnectedEvent.Subscribe(func(q *client.QQClient, e *client.ClientDisconnectedEvent) {
reLoginLock.Lock()
defer reLoginLock.Unlock()
times = 1

View File

@ -156,7 +156,7 @@ func (bot *CQBot) CQGetGuildMembers(guildID uint64, nextToken string) global.MSG
if !exists {
return Failed(100, "NEXT_TOKEN_NOT_EXISTS")
}
token = i.(*guildMemberPageToken)
token = i
if token.guildID != guildID {
return Failed(100, "GUILD_NOT_MATCH")
}

View File

@ -32,7 +32,7 @@ type CQBot struct {
friendReqCache sync.Map
tempSessionCache sync.Map
nextTokenCache *utils.Cache
nextTokenCache *utils.Cache[*guildMemberPageToken]
}
// Event 事件
@ -67,40 +67,40 @@ func (e *Event) JSONString() string {
func NewQQBot(cli *client.QQClient) *CQBot {
bot := &CQBot{
Client: cli,
nextTokenCache: utils.NewCache(time.Second * 10),
nextTokenCache: utils.NewCache[*guildMemberPageToken](time.Second * 10),
}
bot.Client.OnPrivateMessage(bot.privateMessageEvent)
bot.Client.OnGroupMessage(bot.groupMessageEvent)
bot.Client.PrivateMessageEvent.Subscribe(bot.privateMessageEvent)
bot.Client.GroupMessageEvent.Subscribe(bot.groupMessageEvent)
if base.ReportSelfMessage {
bot.Client.OnSelfPrivateMessage(bot.privateMessageEvent)
bot.Client.OnSelfGroupMessage(bot.groupMessageEvent)
bot.Client.SelfPrivateMessageEvent.Subscribe(bot.privateMessageEvent)
bot.Client.SelfGroupMessageEvent.Subscribe(bot.groupMessageEvent)
}
bot.Client.OnTempMessage(bot.tempMessageEvent)
bot.Client.TempMessageEvent.Subscribe(bot.tempMessageEvent)
bot.Client.GuildService.OnGuildChannelMessage(bot.guildChannelMessageEvent)
bot.Client.GuildService.OnGuildMessageReactionsUpdated(bot.guildMessageReactionsUpdatedEvent)
bot.Client.GuildService.OnGuildMessageRecalled(bot.guildChannelMessageRecalledEvent)
bot.Client.GuildService.OnGuildChannelUpdated(bot.guildChannelUpdatedEvent)
bot.Client.GuildService.OnGuildChannelCreated(bot.guildChannelCreatedEvent)
bot.Client.GuildService.OnGuildChannelDestroyed(bot.guildChannelDestroyedEvent)
bot.Client.OnGroupMuted(bot.groupMutedEvent)
bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent)
bot.Client.OnGroupNotify(bot.groupNotifyEvent)
bot.Client.OnFriendNotify(bot.friendNotifyEvent)
bot.Client.OnMemberSpecialTitleUpdated(bot.memberTitleUpdatedEvent)
bot.Client.OnFriendMessageRecalled(bot.friendRecallEvent)
bot.Client.OnReceivedOfflineFile(bot.offlineFileEvent)
bot.Client.OnJoinGroup(bot.joinGroupEvent)
bot.Client.OnLeaveGroup(bot.leaveGroupEvent)
bot.Client.OnGroupMemberJoined(bot.memberJoinEvent)
bot.Client.OnGroupMemberLeaved(bot.memberLeaveEvent)
bot.Client.OnGroupMemberPermissionChanged(bot.memberPermissionChangedEvent)
bot.Client.OnGroupMemberCardUpdated(bot.memberCardUpdatedEvent)
bot.Client.OnNewFriendRequest(bot.friendRequestEvent)
bot.Client.OnNewFriendAdded(bot.friendAddedEvent)
bot.Client.OnGroupInvited(bot.groupInvitedEvent)
bot.Client.OnUserWantJoinGroup(bot.groupJoinReqEvent)
bot.Client.OnOtherClientStatusChanged(bot.otherClientStatusChangedEvent)
bot.Client.OnGroupDigest(bot.groupEssenceMsg)
bot.Client.GroupMuteEvent.Subscribe(bot.groupMutedEvent)
bot.Client.GroupMessageRecalledEvent.Subscribe(bot.groupRecallEvent)
bot.Client.GroupNotifyEvent.Subscribe(bot.groupNotifyEvent)
bot.Client.FriendNotifyEvent.Subscribe(bot.friendNotifyEvent)
bot.Client.MemberSpecialTitleUpdatedEvent.Subscribe(bot.memberTitleUpdatedEvent)
bot.Client.FriendMessageRecalledEvent.Subscribe(bot.friendRecallEvent)
bot.Client.OfflineFileEvent.Subscribe(bot.offlineFileEvent)
bot.Client.GroupJoinEvent.Subscribe(bot.joinGroupEvent)
bot.Client.GroupLeaveEvent.Subscribe(bot.leaveGroupEvent)
bot.Client.GroupMemberJoinEvent.Subscribe(bot.memberJoinEvent)
bot.Client.GroupMemberLeaveEvent.Subscribe(bot.memberLeaveEvent)
bot.Client.GroupMemberPermissionChangedEvent.Subscribe(bot.memberPermissionChangedEvent)
bot.Client.MemberCardUpdatedEvent.Subscribe(bot.memberCardUpdatedEvent)
bot.Client.NewFriendRequestEvent.Subscribe(bot.friendRequestEvent)
bot.Client.NewFriendEvent.Subscribe(bot.friendAddedEvent)
bot.Client.GroupInvitedEvent.Subscribe(bot.groupInvitedEvent)
bot.Client.UserWantJoinGroupEvent.Subscribe(bot.groupJoinReqEvent)
bot.Client.OtherClientStatusChangedEvent.Subscribe(bot.otherClientStatusChangedEvent)
bot.Client.GroupDigestEvent.Subscribe(bot.groupEssenceMsg)
go func() {
if base.HeartbeatInterval == 0 {
log.Warn("警告: 心跳功能已关闭,若非预期,请检查配置文件。")
@ -158,6 +158,7 @@ func (bot *CQBot) uploadLocalImage(target message.Source, img *LocalImageElement
if lawful, mime := base.IsLawfulImage(img.Stream); !lawful {
return nil, errors.New("image type error: " + mime)
}
// todo: enable multi-thread upload, now got error code 81
i, err := bot.Client.UploadImage(target, img.Stream, 4)
if err != nil {
return nil, err

4
go.mod
View File

@ -1,10 +1,10 @@
module github.com/Mrs4s/go-cqhttp
go 1.17
go 1.18
require (
github.com/Microsoft/go-winio v0.5.1
github.com/Mrs4s/MiraiGo v0.0.0-20220227135520-9884d9b0de20
github.com/Mrs4s/MiraiGo v0.0.0-20220301082018-d9f803837f49
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc
github.com/fumiama/go-hide-param v0.1.4
github.com/gabriel-vasile/mimetype v1.4.0

4
go.sum
View File

@ -1,7 +1,7 @@
github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY=
github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/Mrs4s/MiraiGo v0.0.0-20220227135520-9884d9b0de20 h1:ZbJOWQRQB64npjqGMc031/Ry3bKhtMvx7Rf4bx0t9xI=
github.com/Mrs4s/MiraiGo v0.0.0-20220227135520-9884d9b0de20/go.mod h1:23f5g1I7XT7mB3zq02B3rfuiDnE7PJYSfvb/skzDVhI=
github.com/Mrs4s/MiraiGo v0.0.0-20220301082018-d9f803837f49 h1:IIEX0ue2VBA7kGOR1RpdQfPPKfeB4gWine47QXUyzTY=
github.com/Mrs4s/MiraiGo v0.0.0-20220301082018-d9f803837f49/go.mod h1:qJWkRO5vry/sUHthX5kh6go2llYIVAJ+Mq8p+N/FW+8=
github.com/RomiChan/protobuf v0.0.0-20220227114948-643565fff248 h1:1jRB6xuBKwfgZrg0bA7XJin0VeNwG9iJKx9RXwDobt4=
github.com/RomiChan/protobuf v0.0.0-20220227114948-643565fff248/go.mod h1:CKKOWC7mBxd36zxsCB1V8DTrwlTNRQvkSVbYqyUiGEE=
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc h1:AAx50/fb/xS4lvsdQg+bFbGvqSDhyV1MF+p2PLCamZ0=