out-of-your-element/m2d/converters/event-to-message.js

31 lines
877 B
JavaScript
Raw Normal View History

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 = []
if (event.content.msgtype === "m.text") {
messages.push({
content: event.content.body,
username: event.sender.replace(/^@/, ""),
avatar_url: undefined, // TODO: provide the URL to the avatar from the homeserver's content repo
})
}
return messages
}
module.exports.eventToMessage = eventToMessage