diff --git a/mppbridger.js b/mppbridger.js index b7b0e37..6fa3709 100644 --- a/mppbridger.js +++ b/mppbridger.js @@ -5,38 +5,24 @@ global.createMPPbridge = async function createMPPbridge({room, channel, uri}) { var webhooks = await channel.fetchWebhooks(); var webhook = webhooks.filter(w => w.token).first() || await channel.createWebhook("sdfadffg"); - { // discord message sending - let msgBuffer = []; - function _dSend(options) { - - if (options.content?.length > 2000) { - options.attachments ||= []; - options.attachments.push(new Discord.MessageAttachment(Buffer.from(options.content), "message.txt")); - delete options.content; - } - - let username = gClient.channel && gClient.channel._id || room; - if (username.length > 80) username = username.substr(0,79) + '…'; - - webhook.send(Object.assign(options, {username})).catch(error => { - handleError(error, `webhook fail in ${channel.id}`); - channel.send(options).catch(error => handleError(error, `send fail in ${channel.id} after webhook send fail`)); - }); - + //todo figure out new way to buffer + function dSend(msg, options) { + if (arguments.length == 1) options = msg; + + if (options.content?.length > 2000) { + options.attachments ||= []; + options.attachments.push(new Discord.MessageAttachment(Buffer.from(options.content), "message.txt")); + delete options.content; } - function dSend(msg, options) { - if (arguments.length == 1) options = msg; - else { - options ||= {}; - options.content = msg; - } - msgBuffer.push(options); - } - setInterval(()=>{ - if (msgBuffer.length == 0) return; - _dSend(msgBuffer.join('\n')); - msgBuffer = []; - }, 3000); + + let username = gClient.channel && gClient.channel._id || room; + if (username.length > 80) username = username.substr(0,79) + '…'; + + webhook.send(options).catch(error => { + handleError(error, `webhook fail in ${channel.id}`); + channel.send(options).catch(error => handleError(error, `send fail in ${channel.id} after webhook send fail`)); + }); + } const gClient = new Client(uri);