Skip to content

Commit

Permalink
feat(zulip): sharp
Browse files Browse the repository at this point in the history
  • Loading branch information
XxLittleCxX committed Aug 21, 2023
1 parent 63d83f0 commit 61265eb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
21 changes: 17 additions & 4 deletions adapters/zulip/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ export class ZulipMessageEncoder extends MessageEncoder<ZulipBot> {
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) {
Expand Down Expand Up @@ -81,9 +90,13 @@ export class ZulipMessageEncoder extends MessageEncoder<ZulipBot> {

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)
Expand Down
10 changes: 9 additions & 1 deletion adapters/zulip/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ export function setupMessage(session: Partial<Session>, 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<Session> = {}) {
Expand Down Expand Up @@ -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 })
},
Expand Down

0 comments on commit 61265eb

Please sign in to comment.