index.js
// Function to process the message queue
Function to process the message queue
Function to process the message queue
function processQueue() {
  if (messages.length > 0) {
    sendToDiscord(bufferMessage());
  }
  if (messages.length > conf.queue_max) {
    if (!suppressed.isSuppressed) {
      suppressed.isSuppressed = true;
      suppressed.date = new Date().getTime();
      sendToDiscord({
          name: 'pm2-discord',
          event: 'suppressed',
          description: 'Messages are being suppressed due to rate limiting.'
      });
    }
    messages.splice(conf.queue_max, messages.length);
  }
  if (suppressed.isSuppressed && suppressed.date < (new Date().getTime() - 60000)) {
    suppressed.isSuppressed = false;
  }
  setTimeout(function() {
    processQueue();
  }, 500);
}
function processQueue ( ) { if ( messages . length > 0 ) { sendToDiscord ( bufferMessage ( ) ) ; } if ( messages . length > conf . queue_max ) { if ( ! suppressed . isSuppressed ) { suppressed . isSuppressed = true ; suppressed . date = new Date ( ) . getTime ( ) ; sendToDiscord ( { name : 'pm2-discord' , event : 'suppressed' , description : 'Messages are being suppressed due to rate limiting.' } ) ; } messages . splice ( conf . queue_max , messages . length ) ; } if ( suppressed . isSuppressed && suppressed . date < ( new Date ( ) . getTime ( ) - 60000 ) ) { suppressed . isSuppressed = false ; } setTimeout ( function ( ) { processQueue ( ) ; } , 500 ) ; }
Function to process the message queue
Function to process the message queue
// If we have a message in the message queue, removed it from the queue and send it to discord // If there are over conf.queue_max messages in the queue, send the suppression message if it has not been sent and delete all the messages in the queue after this amount (default: 100) // If the suppression message has been sent over 1 minute ago, we need to reset it back to false // Wait 0.5 seconds and then process the next message in the queue