From 92e5626632f004f09a7b9f5ca30d5e4e5fdf7f50 Mon Sep 17 00:00:00 2001 From: _LittleC_ <26459759+XxLittleCxX@users.noreply.github.com> Date: Tue, 2 Apr 2024 04:40:43 +0800 Subject: [PATCH] feat(qq): delete message (#252) --- adapters/qq/src/bot/index.ts | 9 +++++++++ adapters/qq/src/internal/group.ts | 8 ++++++++ adapters/qq/src/message.ts | 10 +++++----- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/adapters/qq/src/bot/index.ts b/adapters/qq/src/bot/index.ts index e616a7f6..c0342a83 100644 --- a/adapters/qq/src/bot/index.ts +++ b/adapters/qq/src/bot/index.ts @@ -111,6 +111,15 @@ export class QQBot extends Bot { async createDirectChannel(id: string) { return { id, type: Universal.Channel.Type.DIRECT } } + + async deleteMessage(channelId: string, messageId: string): Promise { + // @TODO: need `private:` + try { + await this.internal.deleteMessage(channelId, messageId) + } catch (e) { + await this.internal.deletePrivateMessage(channelId, messageId) + } + } } export namespace QQBot { diff --git a/adapters/qq/src/internal/group.ts b/adapters/qq/src/internal/group.ts index 7afd223d..1c911dd4 100644 --- a/adapters/qq/src/internal/group.ts +++ b/adapters/qq/src/internal/group.ts @@ -19,6 +19,8 @@ declare module './internal' { }): Promise getGateway(): Promise getGatewayBot(): Promise + deleteMessage(openid: string, message_id: string): Promise + deletePrivateMessage(userid: string, message_id: string): Promise } } @@ -26,9 +28,15 @@ GroupInternal.define(false, { '/v2/groups/{channel.id}/messages': { POST: 'sendMessage', }, + '/v2/groups/{channel.id}/messages/{message.id}': { + DELETE: 'deleteMessage', + }, '/v2/users/{user.id}/messages': { POST: 'sendPrivateMessage', }, + '/v2/users/{user.id}/messages/{message.id}': { + DELETE: 'deletePrivateMessage', + }, '/v2/users/{user.id}/files': { POST: 'sendFilePrivate', }, diff --git a/adapters/qq/src/message.ts b/adapters/qq/src/message.ts index f1734b0c..23fa60bf 100644 --- a/adapters/qq/src/message.ts +++ b/adapters/qq/src/message.ts @@ -88,11 +88,9 @@ export class QQGuildMessageEncoder extends MessageE const session = this.bot.session() session.type = 'send' // await decodeMessage(this.bot, r, session.event.message = {}, session.event) - if (isDirect) { - session.guildId = this.session.guildId - session.channelId = this.channelId - session.isDirect = true - } + session.guildId = this.session.guildId + session.channelId = this.channelId + session.isDirect = isDirect // https://bot.q.qq.com/wiki/develop/api/gateway/direct_message.html#%E6%B3%A8%E6%84%8F /** @@ -250,6 +248,8 @@ export class QQMessageEncoder extends MessageEncode if (resp.id) { session.messageId = resp.id session.timestamp = new Date(resp.timestamp).valueOf() + session.channelId = this.session.channelId + session.guildId = this.session.guildId session.app.emit(session, 'send', session) this.results.push(session.event.message) } else if (resp.code === 304023 && this.bot.config.intents & QQ.Intents.MESSAGE_AUDIT) {