This commit is contained in:
Lamp 2022-01-03 21:02:27 -08:00
parent 006b2f2d77
commit 1b01804230
1 changed files with 17 additions and 31 deletions

View File

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