From 2400025224d96f6aac89aebf3efb6dbe0f05122f Mon Sep 17 00:00:00 2001 From: LittleC <26459759+XxLittleCxX@users.noreply.github.com> Date: Thu, 5 Oct 2023 19:58:30 +0800 Subject: [PATCH] fix(qq): avatar, filter events --- adapters/qq/src/bot/index.ts | 17 +++++++++++------ adapters/qq/src/utils.ts | 4 ++-- adapters/qq/src/ws.ts | 1 + 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/adapters/qq/src/bot/index.ts b/adapters/qq/src/bot/index.ts index 8e4117c6..ba9b2553 100644 --- a/adapters/qq/src/bot/index.ts +++ b/adapters/qq/src/bot/index.ts @@ -34,16 +34,21 @@ export class QQBot extends Bot { 'Authorization': `Bot ${this.config.id}.${this.config.token}`, }, }) - this.getAccessToken() - this.initialize() - this.internal = new GroupInternal(() => this.groupHttp) - ctx.plugin(WsClient, this) - } - initialize() { this.ctx.plugin(QQGuildBot, { parent: this, }) + this.internal = new GroupInternal(() => this.groupHttp) + this.ctx.plugin(WsClient, this) + } + + async initialize() { + try { + const user = await this.guildBot.internal.getMe() + Object.assign(this.user, user) + } catch (e) { + this.ctx.logger('qq').error(e) + } } async stop() { diff --git a/adapters/qq/src/utils.ts b/adapters/qq/src/utils.ts index 1aabaff5..9ccc4f99 100644 --- a/adapters/qq/src/utils.ts +++ b/adapters/qq/src/utils.ts @@ -116,7 +116,7 @@ export async function adaptSession(bot: QQBot, input: QQ.DispatchPayload) { session.setInternal('qq', input) if (input.t === 'MESSAGE_CREATE' || input.t === 'AT_MESSAGE_CREATE' || input.t === 'DIRECT_MESSAGE_CREATE') { - if (bot.config.type === 'private' && input.t === 'AT_MESSAGE_CREATE') return + if (bot.config.type === 'private' && input.t === 'AT_MESSAGE_CREATE' && bot.config.intents & QQ.Intents.GUILD_MESSAGES) return session.type = 'message' await decodeMessage(bot, input.d, session.event.message = {}, session.event) } else if (input.t === 'MESSAGE_REACTION_ADD') { @@ -143,7 +143,7 @@ export async function adaptSession(bot: QQBot, input: QQ.DispatchPayload) { }[input.t] session.event.guild = decodeGuild(input.d) } else if (input.t === 'DIRECT_MESSAGE_DELETE' || input.t === 'MESSAGE_DELETE' || input.t === 'PUBLIC_MESSAGE_DELETE') { - if (bot.config.type === 'private' && input.t === 'PUBLIC_MESSAGE_DELETE') return + if (bot.config.type === 'private' && input.t === 'PUBLIC_MESSAGE_DELETE' && bot.config.intents & QQ.Intents.GUILD_MESSAGES) return session.type = 'message-deleted' session.userId = input.d.message.author.id session.operatorId = input.d.op_user.id diff --git a/adapters/qq/src/ws.ts b/adapters/qq/src/ws.ts index 757590d8..100683c2 100644 --- a/adapters/qq/src/ws.ts +++ b/adapters/qq/src/ws.ts @@ -71,6 +71,7 @@ export class WsClient extends Adapter.WsClient { this._sessionId = parsed.d.session_id this.bot.user = decodeUser(parsed.d.user) this.bot.guildBot.user = this.bot.user + await this.bot.initialize() return this.bot.online() } if (parsed.t === 'RESUMED') {