diff --git a/index.js b/index.js index b1d1aa3..2e24a11 100644 --- a/index.js +++ b/index.js @@ -205,7 +205,7 @@ function main() { discordQueue = setInterval(function() { if (dcmsg.queue!='') { - channel.send(dcmsg.queue.substring(0, 1997) + '\u200b'); + channel.send('```ansi\n' + dcmsg.queue.substring(0, 1997) + '\n```'); dcmsg.queue = ''; } }, 1000); @@ -297,8 +297,8 @@ function main() { if (parsedMessage.extra[0].text==='Command set: ') return; } - const cleanMessage = escapeMarkdown(message.toString()); - discordMsg = /* '_ _ ' + */cleanMessage.replaceAll('@', '@\u200B').replaceAll('http', 'http\u200B');// .replace(/[\r\n]/gm, '\n') + const cleanMessage = escapeMarkdown(message.toAnsi()); + discordMsg = /* '_ _ ' + */cleanMessage.replaceAll('@', '@\u200b\u200b\u200b\u200b\u200b').replaceAll('http', 'http\u200b\u200b\u200b\u200b\u200b');// .replace(/[\r\n]/gm, '\n') consoleQueue.push(message.toAnsi()); diff --git a/util/escapeMarkdown.js b/util/escapeMarkdown.js index 8875319..a7d8a6d 100644 --- a/util/escapeMarkdown.js +++ b/util/escapeMarkdown.js @@ -3,12 +3,13 @@ /** * escape markdown so on discord it will be \_ChipMC\_ instead of ChipMC in italic * @param {String} text + * @param {Boolean} zwsp * @return {String} */ -function escapeMarkdown(text) { +function escapeMarkdown(text, zwsp) { try { var unescaped = text.replace(/\\(\*|@|_|`|~|\\)/g, '$1'); - var escaped = unescaped.replace(/(\*|@|_|`|~|\\)/g, '\\$1'); + var escaped = unescaped.replace(/(\*|@|_|`|~|\\)/g, zwsp ? '\u200b\u200b\u200b\u200b\u200b$1' : '\\$1'); } catch (e) { return unescaped; }