try new thing (delete discord msg and show what mpp sees)

This commit is contained in:
Lamp 2022-01-03 21:44:30 -08:00
parent 78c9e1e3b5
commit fac15e380c
4 changed files with 17 additions and 23 deletions

View File

@ -30,7 +30,7 @@ var collectWsMessage = createWsMessageCollector(async function(data, startDate,
if (chatmsg.type == "message") { if (chatmsg.type == "message") {
//if (chatmsg.id != myId) //if (chatmsg.id != myId)
if (!chatmsg.content.startsWith('\u034f')) if (!chatmsg.content.startsWith('\u034f'))
send2discord(`**${sanitizeName(chatmsg.user.nick)}:** ${escapeDiscordMentions(chatmsg.content)}`); send2discord(`**${sanitizeName(chatmsg.user.nick)}:** ${chatmsg.content}`);
} else if (chatmsg.type == "join") { } else if (chatmsg.type == "join") {
send2discord(`__***${sanitizeName(chatmsg.nick || chatmsg.id)} joined.***__`); send2discord(`__***${sanitizeName(chatmsg.nick || chatmsg.id)} joined.***__`);
} else if (chatmsg.type == "leave") { } else if (chatmsg.type == "leave") {

View File

@ -97,34 +97,35 @@ global.createMPPbridge = async function createMPPbridge({room, channel, uri}) {
// MPP to Discord // MPP to Discord
gClient.on('a', async msg => { gClient.on('a', async msg => {
if (msg.p._id == gClient.getOwnParticipant()._id) return;
var id = msg.p._id.substr(0,6); var id = msg.p._id.substr(0,6);
var name = sanitizeName(msg.p.name); var name = sanitizeName(msg.p.name);
var content = escapeDiscordMentions(msg.a); var content = msg.a;
var str = `\`${id}\` **${name}:** ${content}`; var str = `\`${id}\` **${name}:** ${content}`;
dSend(str); dSend(str);
}); });
// Discord to MPP // Discord to MPP
{ {
let msgQueue = []; //let msgQueue = [];
dClient.on('message', async message => { dClient.on('message', async message => {
if (message.channel.id !== channel.id || message.author.id == dClient.user.id || !message.member /*|| message.content.startsWith('!')*/) return; if (message.channel.id !== channel.id || message.author.id == dClient.user.id || !message.member /*|| message.content.startsWith('!')*/) return;
var str = message.cleanContent; var str = message.cleanContent;
var aname = `${message.member.displayName}#${message.member.user.discriminator}`; var aname = message.user.tag;
if (str.startsWith('/') || str.startsWith('\\')) //if (str.startsWith('/') || str.startsWith('\\'))
msgQueue.push(`${aname}`); // msgQueue.push(`⤹ ${aname}`);
else //else
str = `${aname}: ${str}`; str = `${aname}: ${str}`;
if (str.startsWith('\\')) str = str.slice(1); //if (str.startsWith('\\')) str = str.slice(1);
if (message.attachments.first()) str += ' '+message.attachments.first().url; if (message.attachments.size > 0) str += ' ' + message.attachments.join(' ');
if (str.length > 512) str = str.substr(0,511) + '…'; if (str.length > 512) str = str.substr(0,511) + '…';
msgQueue.push(str); //msgQueue.push(str);
gClient.sendArray([{m:'a', message: str}]);
if (gClient.isConnected()) message.delete();
}); });
setInterval(()=>{ //setInterval(()=>{
let message = msgQueue.shift(); // let message = msgQueue.shift();
if (message) gClient.sendArray([{m:'a', message}]); // if (message) gClient.sendArray([{m:'a', message}]);
}, 1600); // just about fastest without exceeding quota; I figured quota is 4 messages per 6 seconds in lobbies //}, 1600); // just about fastest without exceeding quota; I figured quota is 4 messages per 6 seconds in lobbies
} }

View File

@ -31,7 +31,7 @@ async function messagehandle(data) {
if (id == client.socket.id) return; if (id == client.socket.id) return;
let c = dClient.channels.resolve("593943518351982603"); let c = dClient.channels.resolve("593943518351982603");
let msg; let msg;
(!name && (data.message.startsWith("[i]"))) ? msg = `*${escapeDiscordMentions(data.message.split("[i]")[1])}*` : msg = `**${sanitizeName(name)}:** ${escapeDiscordMentions(data.message)}`; (!name && (data.message.startsWith("[i]"))) ? msg = `*${data.message.split("[i]")[1]}*` : msg = `**${sanitizeName(name)}:** ${data.message}`;
if (c) c.send(msg); if (c) c.send(msg);
} }
break; break;

View File

@ -5,14 +5,7 @@ global.random = function (array) {
global.sanitizeName = function sanitizeName(str){ // for showing names in discord global.sanitizeName = function sanitizeName(str){ // for showing names in discord
str = str.replace(/[_~*\\]/g,"\\$&"); // formatting str = str.replace(/[_~*\\]/g,"\\$&"); // formatting
str = escapeDiscordMentions(str); // mentions
str = str.replace(/discord.gg\//g, 'discord.gg\\/'); // invites str = str.replace(/discord.gg\//g, 'discord.gg\\/'); // invites
str = str.replace(/(http|https):\/\//g, "$1\\://"); // urls str = str.replace(/(http|https):\/\//g, "$1\\://"); // urls
return str; 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;
}