xmppjs-chat-bot
Version:
Server-side XMPP chat bot
55 lines • 1.67 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReferenceMention = exports.Reference = void 0;
const xml_1 = __importDefault(require("@xmpp/xml"));
class Reference {
}
exports.Reference = Reference;
class ReferenceMention extends Reference {
constructor(jid, begin, end) {
super();
this.jid = jid;
this.begin = begin;
this.end = end;
this.type = 'mention';
}
toXml() {
return (0, xml_1.default)('reference', {
xmlns: 'urn:xmpp:reference:0',
begin: this.begin.toString(),
end: this.end.toString(),
type: this.type,
uri: 'xmpp:' + this.jid.toString()
});
}
static mention(txt, jid, placeholder = '{{NICK}}') {
const references = [];
const nick = jid.getResource();
if (!placeholder.length) {
return {
txt,
references
};
}
const parts = txt.split(placeholder);
txt = '';
while (parts.length) {
txt += parts.shift() ?? '';
if (parts.length > 0) {
const begin = txt.length;
const end = begin + nick.length;
txt += nick;
references.push(new ReferenceMention(jid, begin, end));
}
}
return {
txt,
references
};
}
}
exports.ReferenceMention = ReferenceMention;
//# sourceMappingURL=reference.js.map