xenforo-dl
Version:
XenForo Forum Downloader
45 lines (39 loc) • 2.02 kB
JavaScript
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _a, _MessageTemplate_getSeparator;
import { EOL } from 'os';
const MESSAGE_TEMPLATE_BASE = `{message.separator}
{message.index} - {message.publishedAt}
by {message.author}
{message.separator}
{message.body}`;
const MESSAGE_TEMPLATE_WITH_ATTACHMENTS = `${MESSAGE_TEMPLATE_BASE}
**Attachments**
{message.attachments}
`;
const MESSAGE_TEMPLATE_WITHOUT_ATTACHMENTS = `${MESSAGE_TEMPLATE_BASE}
`;
export default class MessageTemplate {
static format(message) {
const attachments = message.attachments
.map((attachment, i) => `${i}: ${attachment.filename}`)
.join(EOL);
const template = attachments ? MESSAGE_TEMPLATE_WITH_ATTACHMENTS : MESSAGE_TEMPLATE_WITHOUT_ATTACHMENTS;
return template
.replaceAll('{message.separator}', __classPrivateFieldGet(this, _a, "m", _MessageTemplate_getSeparator).call(this, message))
.replaceAll('{message.index}', String(message.index))
.replaceAll('{message.author}', message.author || '[unknown]')
.replaceAll('{message.publishedAt}', message.publishedAt || '')
.replaceAll('{message.body}', message.body || '')
.replaceAll('{message.attachments}', attachments);
}
}
_a = MessageTemplate, _MessageTemplate_getSeparator = function _MessageTemplate_getSeparator(message) {
const s1 = `${message.index} - ${message.publishedAt}`;
const s2 = `by ${message.author}`;
return '-'.repeat(Math.max(s1.length, s2.length));
};
//# sourceMappingURL=Message.js.map