From 61265eb5b19d8493ecfcf0ad006660d99a5e5fed Mon Sep 17 00:00:00 2001 From: LittleC <26459759+XxLittleCxX@users.noreply.github.com> Date: Mon, 21 Aug 2023 22:06:28 +0800 Subject: [PATCH] feat(zulip): sharp --- adapters/zulip/src/message.ts | 21 +++++++++++++++++---- adapters/zulip/src/utils.ts | 10 +++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/adapters/zulip/src/message.ts b/adapters/zulip/src/message.ts index 26bf691d..adc77181 100644 --- a/adapters/zulip/src/message.ts +++ b/adapters/zulip/src/message.ts @@ -24,9 +24,18 @@ export class ZulipMessageEncoder extends MessageEncoder { form.append('content', this.buffer) if (!this.session.isDirect) form.append('topic', this.session.channelId) - await this.bot.http.post('/messages', form, { + const { id } = await this.bot.http.post('/messages', form, { headers: form.getHeaders(), }) + const session = this.bot.session() + session.messageId = id.toString() + session.userId = this.bot.selfId + session.channelId = this.session.channelId + session.guildId = this.session.guildId + session.isDirect = this.session.isDirect + session.author = this.bot + session.app.emit(session, 'send', session) + this.results.push(session) } async uploadMedia(element: h) { @@ -81,9 +90,13 @@ export class ZulipMessageEncoder extends MessageEncoder { this.buffer = `@_**${quoteMsg.message.sender_full_name}|${quoteMsg.message.sender_id}** [Said](${path}):\n` + '```quote\n' + quoteMsg.raw_content + '\n```\n\n' + this.buffer - } else if (type === 'sharp') { - // @TODO - // this.buffer += `#**${attrs.name}** ` + } else if (type === 'sharp' && attrs.guild) { + const { stream } = await this.bot.internal.getStreamById(attrs.guild) + if (!attrs.id) { + this.buffer += ` #**${stream.name}** ` + } else { + this.buffer += ` #**${stream.name}>${attrs.id}** ` + } } else if (type === 'at' && attrs.id) { try { const u = await this.getUser(attrs.id) diff --git a/adapters/zulip/src/utils.ts b/adapters/zulip/src/utils.ts index e938efac..72675676 100644 --- a/adapters/zulip/src/utils.ts +++ b/adapters/zulip/src/utils.ts @@ -141,6 +141,10 @@ export function setupMessage(session: Partial, data: Zulip.MessagesBase session.channelId = data.subject } session.userId = data.sender_id.toString() + session.author = { + userId: session.userId, + username: data.sender_full_name, + } } export async function decodeMessage(bot: ZulipBot, message: Zulip.MessagesBase, session: Partial = {}) { @@ -181,8 +185,12 @@ export async function decodeMessage(bot: ZulipBot, message: Zulip.MessagesBase, async sharp(attrs: Dict) { const raw = attrs.raw as string if (raw.includes('>')) { + const guildName = raw.slice(0, raw.indexOf('>')) + const { stream_id } = await bot.internal.getStreamId({ + stream: guildName, + }) const channel = raw.slice(raw.indexOf('>') + 1) - return h('sharp', { id: channel, guild: raw.slice(0, raw.indexOf('>')) }) + return h('sharp', { id: channel, guild: stream_id.toString() }) } return h('sharp', { guild: raw }) },