Make the MOTDs a little nicer if possible

This removes the leading hyphens from MOTD lines (under the condition they all do) and trims empty lines around the MOTD (but not inside).
This commit is contained in:
Jérémie Astori 2018-07-09 01:30:51 -04:00
parent 6187b3bd0b
commit 3eca924a7c
No known key found for this signature in database
GPG Key ID: B9A4F245CD67BDE8

View File

@ -101,6 +101,20 @@ function buildChatMessage(msg) {
template = "msg_unhandled"; template = "msg_unhandled";
} }
// Make the MOTDs a little nicer if possible
if (msg.type === "motd") {
let lines = msg.text.split("\n");
// If all non-empty lines of the MOTD start with a hyphen (which is common
// across MOTDs), remove all the leading hyphens.
if (lines.every((line) => line === "" || line[0] === "-")) {
lines = lines.map((line) => line.substr(2));
}
// Remove empty lines around the MOTD (but not within it)
msg.text = lines.join("\n").trim();
}
const renderedMessage = $(templates[template](msg)); const renderedMessage = $(templates[template](msg));
const content = renderedMessage.find(".content"); const content = renderedMessage.find(".content");