Render MOTD with a single message

This commit is contained in:
Pavel Djundik 2018-02-13 13:05:49 +02:00
parent 116a73c8d0
commit d1e5a8f492
3 changed files with 9 additions and 10 deletions

View File

@ -19,7 +19,8 @@ const colorRx = /^(\d{1,2})(?:,(\d{1,2}))?/;
const hexColorRx = /^([0-9a-f]{6})(?:,([0-9a-f]{6}))?/i; const hexColorRx = /^([0-9a-f]{6})(?:,([0-9a-f]{6}))?/i;
// Represents all other control codes that to be ignored/filtered from the text // Represents all other control codes that to be ignored/filtered from the text
const controlCodesRx = /[\u0000-\u001F]/g; // This regex allows line feed character
const controlCodesRx = /[\u0000-\u0009\u000B-\u001F]/g;
// Converts a given text into an array of objects, each of them representing a // Converts a given text into an array of objects, each of them representing a
// similarly styled section of the text. Each object carries the `text`, style // similarly styled section of the text. Each object carries the `text`, style

View File

@ -9,13 +9,11 @@ module.exports = function(irc, network) {
const lobby = network.channels[0]; const lobby = network.channels[0];
if (data.motd) { if (data.motd) {
data.motd.trim().split("\n").forEach((text) => {
const msg = new Msg({ const msg = new Msg({
type: Msg.Type.MOTD, type: Msg.Type.MOTD,
text: text, text: data.motd,
}); });
lobby.pushMessage(client, msg); lobby.pushMessage(client, msg);
});
} }
if (data.error) { if (data.error) {

View File

@ -19,10 +19,10 @@ describe("parse Handlebars helper", () => {
expect(actual).to.deep.equal(expected); expect(actual).to.deep.equal(expected);
}); });
it("should skip control codes", () => { it("should skip all <32 ASCII codes except linefeed", () => {
const testCases = [{ const testCases = [{
input: "text\x01with\x04control\x05codes", input: "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1B\x1D\x1D\x1E\x1Ftext\x0Awithcontrolcodestest",
expected: "textwithcontrolcodes", expected: '<span class="irc-underline irc-strikethrough irc-monospace">text\nwithcontrolcodestest</span>',
}]; }];
const actual = testCases.map((testCase) => parse(testCase.input)); const actual = testCases.map((testCase) => parse(testCase.input));