Merge pull request #2633 from thelounge/astorije/nicer-motd

Make the MOTDs a little nicer if possible
This commit is contained in:
Pavel Djundik 2018-07-15 13:40:58 +03:00 committed by GitHub
commit 4b84adb834
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -101,6 +101,20 @@ function buildChatMessage(msg) {
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 content = renderedMessage.find(".content");