diff --git a/packages/adapter-discord/src/bot.ts b/packages/adapter-discord/src/bot.ts index a4a90bb969..c7de3e524b 100644 --- a/packages/adapter-discord/src/bot.ts +++ b/packages/adapter-discord/src/bot.ts @@ -240,7 +240,7 @@ export class DiscordBot extends Bot<'discord'> { result.author.nickname = msg.member?.nick if (msg.message_reference) { const quoteMsg = await this.$getMessage(msg.message_reference.channel_id, msg.message_reference.message_id) - result.quote = await adaptMessage(this, quoteMsg) + result.quote = adaptMessage(this, quoteMsg) } return result } @@ -260,6 +260,19 @@ export class DiscordBot extends Bot<'discord'> { return adaptChannel(data) } + async $createReaction(channelId: string, messageId: string, emoji: string) { + await this.request('PUT', `/channels/${channelId}/messages/${messageId}/reactions/${emoji}/@me`) + } + + async $deleteReaction(channelId: string, messageId: string, emoji: string, userId = '@me') { + await this.request('DELETE', `/channels/${channelId}/messages/${messageId}/reactions/${emoji}/${userId}`) + } + + async $deleteAllReactions(channelId: string, messageId: string, emoji?: string) { + const path = emoji ? '/' + emoji : '' + await this.request('DELETE', `/channels/${channelId}/messages/${messageId}/reactions${path}`) + } + async $executeWebhook(id: string, token: string, data: DC.ExecuteWebhookBody, wait = false): Promise { const chain = segment.parse(data.content) if (chain.filter(v => v.type === 'image').length > 10) { diff --git a/packages/adapter-discord/src/utils.ts b/packages/adapter-discord/src/utils.ts index cd75de0c92..a90abda689 100644 --- a/packages/adapter-discord/src/utils.ts +++ b/packages/adapter-discord/src/utils.ts @@ -1,5 +1,5 @@ /* eslint-disable camelcase */ -import { AuthorInfo, ChannelInfo, GroupInfo, segment, Session, UserInfo } from 'koishi-core' +import { AuthorInfo, ChannelInfo, GroupInfo, MessageInfo, segment, Session, UserInfo } from 'koishi-core' import { DiscordBot } from './bot' import * as DC from './types' @@ -103,7 +103,7 @@ export function adaptMessage(bot: DiscordBot, meta: DC.Message, session: Partial session.content += segment('video', { url: embed.video.url, proxy_url: embed.video.proxy_url }) } } - return session + return session as MessageInfo } function adaptMessageSession(bot: DiscordBot, meta: DC.Message, session: Partial = {}) { diff --git a/packages/adapter-kaiheila/src/bot.ts b/packages/adapter-kaiheila/src/bot.ts index 3d79b34907..7dd1384800 100644 --- a/packages/adapter-kaiheila/src/bot.ts +++ b/packages/adapter-kaiheila/src/bot.ts @@ -236,6 +236,22 @@ export class KaiheilaBot extends Bot { } } + async $createReaction(channelId: string, messageId: string, emoji: string) { + if (channelId.length > 30) { + await this.request('POST', '/direct-message/add-reaction', { msg_id: messageId, emoji }) + } else { + await this.request('POST', '/message/add-reaction', { msg_id: messageId, emoji }) + } + } + + async $deleteReaction(channelId: string, messageId: string, emoji: string, userId?: string) { + if (channelId.length > 30) { + await this.request('POST', '/direct-message/delete-reaction', { msg_id: messageId, emoji }) + } else { + await this.request('POST', '/message/delete-reaction', { msg_id: messageId, emoji, user_id: userId }) + } + } + async getSelf() { const data = adaptUser(await this.request('GET', '/user/me')) renameProperty(data, 'selfId' as never, 'userId')