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,9 +5,9 @@ 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) {
//todo figure out new way to buffer
function dSend(msg, options) {
if (arguments.length == 1) options = msg;
if (options.content?.length > 2000) {
options.attachments ||= [];
@ -18,26 +18,12 @@ global.createMPPbridge = async function createMPPbridge({room, channel, uri}) {
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 => {
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`));
});
}
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);
}
const gClient = new Client(uri);
if (uri == "wss://mppclone.com:8443") gClient.token = config.mpc_token; //todo hmm