try new thing (delete discord msg and show what mpp sees)
This commit is contained in:
parent
78c9e1e3b5
commit
fac15e380c
|
@ -30,7 +30,7 @@ var collectWsMessage = createWsMessageCollector(async function(data, startDate,
|
|||
if (chatmsg.type == "message") {
|
||||
//if (chatmsg.id != myId)
|
||||
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") {
|
||||
send2discord(`__***${sanitizeName(chatmsg.nick || chatmsg.id)} joined.***__`);
|
||||
} else if (chatmsg.type == "leave") {
|
||||
|
|
|
@ -97,34 +97,35 @@ global.createMPPbridge = async function createMPPbridge({room, channel, uri}) {
|
|||
|
||||
// MPP to Discord
|
||||
gClient.on('a', async msg => {
|
||||
if (msg.p._id == gClient.getOwnParticipant()._id) return;
|
||||
var id = msg.p._id.substr(0,6);
|
||||
var name = sanitizeName(msg.p.name);
|
||||
var content = escapeDiscordMentions(msg.a);
|
||||
var content = msg.a;
|
||||
var str = `\`${id}\` **${name}:** ${content}`;
|
||||
dSend(str);
|
||||
});
|
||||
|
||||
// Discord to MPP
|
||||
{
|
||||
let msgQueue = [];
|
||||
//let msgQueue = [];
|
||||
dClient.on('message', async message => {
|
||||
if (message.channel.id !== channel.id || message.author.id == dClient.user.id || !message.member /*|| message.content.startsWith('!')*/) return;
|
||||
var str = message.cleanContent;
|
||||
var aname = `${message.member.displayName}#${message.member.user.discriminator}`;
|
||||
if (str.startsWith('/') || str.startsWith('\\'))
|
||||
msgQueue.push(`⤹ ${aname}`);
|
||||
else
|
||||
var aname = message.user.tag;
|
||||
//if (str.startsWith('/') || str.startsWith('\\'))
|
||||
// msgQueue.push(`⤹ ${aname}`);
|
||||
//else
|
||||
str = `${aname}: ${str}`;
|
||||
if (str.startsWith('\\')) str = str.slice(1);
|
||||
if (message.attachments.first()) str += ' '+message.attachments.first().url;
|
||||
//if (str.startsWith('\\')) str = str.slice(1);
|
||||
if (message.attachments.size > 0) str += ' ' + message.attachments.join(' ');
|
||||
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(()=>{
|
||||
let message = msgQueue.shift();
|
||||
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
|
||||
//setInterval(()=>{
|
||||
// let message = msgQueue.shift();
|
||||
// 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
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ async function messagehandle(data) {
|
|||
if (id == client.socket.id) return;
|
||||
let c = dClient.channels.resolve("593943518351982603");
|
||||
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);
|
||||
}
|
||||
break;
|
||||
|
|
7
util.js
7
util.js
|
@ -5,14 +5,7 @@ global.random = function (array) {
|
|||
|
||||
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