Skip to content

Commit

Permalink
feat(qq): delete message (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
XxLittleCxX authored Apr 1, 2024
1 parent 214b4f6 commit 92e5626
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
9 changes: 9 additions & 0 deletions adapters/qq/src/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ export class QQBot<C extends Context = Context> extends Bot<C, QQBot.Config> {
async createDirectChannel(id: string) {
return { id, type: Universal.Channel.Type.DIRECT }
}

async deleteMessage(channelId: string, messageId: string): Promise<void> {
// @TODO: need `private:`
try {
await this.internal.deleteMessage(channelId, messageId)
} catch (e) {
await this.internal.deletePrivateMessage(channelId, messageId)
}
}
}

export namespace QQBot {
Expand Down
8 changes: 8 additions & 0 deletions adapters/qq/src/internal/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,24 @@ declare module './internal' {
}): Promise<any>
getGateway(): Promise<QQ.GetGatewayResponse>
getGatewayBot(): Promise<QQ.GetGatewayBotResponse>
deleteMessage(openid: string, message_id: string): Promise<any>
deletePrivateMessage(userid: string, message_id: string): Promise<any>
}
}

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',
},
Expand Down
10 changes: 5 additions & 5 deletions adapters/qq/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ export class QQGuildMessageEncoder<C extends Context = Context> 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
/**
Expand Down Expand Up @@ -250,6 +248,8 @@ export class QQMessageEncoder<C extends Context = Context> 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) {
Expand Down

0 comments on commit 92e5626

Please sign in to comment.