Make escaping utils global and add to ddp bridge
This commit is contained in:
parent
7ece8e4416
commit
d12b882dfc
|
@ -21,11 +21,11 @@ var wasConnected = false;
|
|||
if (chatmsg.type == "message") {
|
||||
//if (chatmsg.id != myId)
|
||||
if (!chatmsg.content.startsWith('\u034f'))
|
||||
send2discord(`**${chatmsg.user.nick}:** ${chatmsg.content}`);
|
||||
send2discord(`**${sanitizeName(chatmsg.user.nick)}:** ${escapeDiscordMentions(chatmsg.content)}`);
|
||||
} else if (chatmsg.type == "join") {
|
||||
send2discord(`__***${chatmsg.nick || chatmsg.id} joined.***__`);
|
||||
send2discord(`__***${sanitizeName(chatmsg.nick || chatmsg.id)} joined.***__`);
|
||||
} else if (chatmsg.type == "leave") {
|
||||
send2discord(`__***${chatmsg.nick || chatmsg.id} left.***__`);
|
||||
send2discord(`__***${sanitizeName(chatmsg.nick || chatmsg.id)} left.***__`);
|
||||
}
|
||||
} /*else if (transmission.type == 'load') {
|
||||
myId = transmission.id;
|
||||
|
|
|
@ -130,9 +130,9 @@ global.createMPPbridge = function createMPPbridge(room, DiscordChannelID, site =
|
|||
gClient.on('a', async msg => {
|
||||
if (msg.p._id == gClient.getOwnParticipant()._id) return;
|
||||
var id = msg.p._id.substr(0,6);
|
||||
var name = msg.p.name
|
||||
var name = sanitizeName(msg.p.name);
|
||||
var str = `\`${id}\` **${name}:** ${msg.a.replace(/<@/g, "<\\@")}`;
|
||||
var content = escapeDiscordMentions(msg.a);
|
||||
var str = `\`${id}\` **${name}:** ${content}`;
|
||||
dSend(str);
|
||||
});
|
||||
|
||||
|
@ -143,7 +143,6 @@ global.createMPPbridge = function createMPPbridge(room, DiscordChannelID, site =
|
|||
if (message.channel.id !== DiscordChannelID || message.author.bot || message.content.startsWith('!')) return;
|
||||
var str = message.cleanContent;
|
||||
var aname = `${message.member.displayName}#${message.member.user.discriminator}`;
|
||||
var arr = [];
|
||||
if (str.startsWith('/') || str.startsWith('\\'))
|
||||
msgQueue.push(`⤹ ${aname}`);
|
||||
else
|
||||
|
@ -288,18 +287,3 @@ commands.chown = require('./commands/chown');
|
|||
commands.list = require('./commands/list');
|
||||
commands.ban = require('./commands/ban');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* util */
|
||||
|
||||
function sanitizeName(str){ // for showing mpp names in discord
|
||||
str = str.replace(/[_~*\\]/g,"\\$&"); // formatting
|
||||
str = str.replace(/<@/g, "<\\@"); // mentions
|
||||
str = str.replace(/discord.gg\//g, 'discord.gg\\/'); // invites
|
||||
//TODO escape channel mentions too? not necessary but for consistency
|
||||
return str;
|
||||
}
|
||||
|
|
15
src/util.js
15
src/util.js
|
@ -1,3 +1,18 @@
|
|||
|
||||
Array.prototype.random = function () {
|
||||
return this[Math.floor(Math.random() * this.length)]
|
||||
}
|
||||
|
||||
global.sanitizeName = function sanitizeName(str){ // for showing names in discord
|
||||
str = str.replace(/[_~*\\]/g,"\\$&"); // formatting
|
||||
str = escapeDiscordMentions(str); // mentions
|
||||
str = str.replace(/discord.gg\//g, 'discord.gg\\/'); // invites
|
||||
str = str.replace(/(http|https):\/\//g, "$1\\://"); // urls
|
||||
return str;
|
||||
}
|
||||
|
||||
global.escapeDiscordMentions = function escapeDiscordMentions(str) { // escape discord mentions from a string to be sent to discord
|
||||
str = str.replace(/<@/g, "<\\@"); // users & roles
|
||||
// escaping channel mentions is not necessary
|
||||
return str;
|
||||
}
|
Loading…
Reference in New Issue