Skip to content

Commit

Permalink
fix(qq): avatar, filter events
Browse files Browse the repository at this point in the history
  • Loading branch information
XxLittleCxX committed Oct 5, 2023
1 parent 3c5dc1b commit 2400025
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
17 changes: 11 additions & 6 deletions adapters/qq/src/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,21 @@ export class QQBot extends Bot<QQBot.Config> {
'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() {
Expand Down
4 changes: 2 additions & 2 deletions adapters/qq/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions adapters/qq/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class WsClient extends Adapter.WsClient<QQBot> {
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') {
Expand Down

0 comments on commit 2400025

Please sign in to comment.