2023-07-02 13:06:05 +00:00
|
|
|
// @ts-check
|
|
|
|
|
2023-07-04 05:19:17 +00:00
|
|
|
const Ty = require("../../types")
|
2023-07-02 13:06:05 +00:00
|
|
|
const DiscordTypes = require("discord-api-types/v10")
|
|
|
|
const markdown = require("discord-markdown")
|
|
|
|
|
|
|
|
const passthrough = require("../../passthrough")
|
|
|
|
const { sync, db, discord } = passthrough
|
|
|
|
/** @type {import("../../matrix/file")} */
|
|
|
|
const file = sync.require("../../matrix/file")
|
|
|
|
|
|
|
|
/**
|
2023-07-04 05:19:17 +00:00
|
|
|
* @param {Ty.Event.Outer<Ty.Event.M_Room_Message>} event
|
2023-07-02 13:06:05 +00:00
|
|
|
*/
|
|
|
|
function eventToMessage(event) {
|
|
|
|
/** @type {(DiscordTypes.RESTPostAPIWebhookWithTokenJSONBody & {files?: {name: string, file: Buffer}[]})[]} */
|
|
|
|
const messages = []
|
|
|
|
|
2023-08-19 06:37:34 +00:00
|
|
|
let displayName = event.sender
|
|
|
|
let avatarURL = undefined
|
|
|
|
const match = event.sender.match(/^@(.*?):/)
|
|
|
|
if (match) {
|
|
|
|
displayName = match[1]
|
|
|
|
// TODO: get the media repo domain and the avatar url from the matrix member event
|
|
|
|
}
|
|
|
|
|
2023-07-02 13:06:05 +00:00
|
|
|
if (event.content.msgtype === "m.text") {
|
|
|
|
messages.push({
|
|
|
|
content: event.content.body,
|
2023-08-19 06:37:34 +00:00
|
|
|
username: displayName,
|
|
|
|
avatar_url: avatarURL
|
2023-07-02 13:06:05 +00:00
|
|
|
})
|
2023-08-19 10:54:23 +00:00
|
|
|
} else if (event.content.msgtype === "m.emote") {
|
|
|
|
messages.push({
|
|
|
|
content: `*${displayName} ${event.content.body}*`,
|
|
|
|
username: displayName,
|
|
|
|
avatar_url: avatarURL
|
|
|
|
})
|
2023-07-02 13:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return messages
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.eventToMessage = eventToMessage
|