ansi colors like luftwaffe

This commit is contained in:
ChomeNS 2022-10-16 13:19:14 +07:00
parent 0881a57544
commit ad3604af04
2 changed files with 6 additions and 5 deletions

View file

@ -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());

View file

@ -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;
}