PAEforever

Bot Message at Certain Uptime

May 27th, 2022 (edited)
451
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const messages = {
  2.     '0000': 'Message at 0 minute of stream time',
  3.     '0520': 'eillax is live 0520',
  4.     '0523': 'eillax is live 0523',
  5.     '0535': 'eillax is live 0535',
  6.     '0540': 'eillax is live 0540'
  7.  
  8. };
  9.  
  10. const messagesTimestamps = Object.keys(messages);
  11.  
  12. const findData = (string, regex) => string.match(regex) || '0';
  13. const keepAmount = string => string.split(' ').filter(e => isNaN(e) === false);
  14. const normalizeAmount = string => string.padStart(2, '0');
  15. const arrayToString = array => Array.isArray(array) ? array.join('') : array;
  16.  
  17. const hourRegex = /\d+\s\bhour/;
  18. const minuteRegex = /\d+\s\bminute/;
  19.  
  20. const hourData = arrayToString(findData(uptime, hourRegex));
  21. const minuteData = arrayToString(findData(uptime, minuteRegex));
  22.  
  23. const hourAmount = arrayToString(keepAmount(hourData));
  24. const minuteAmount = arrayToString(keepAmount(minuteData));
  25.  
  26. const normalizedHourAmount = normalizeAmount(hourAmount);
  27. const normalizedMinuteAmount = normalizeAmount(minuteAmount);
  28.  
  29. const currentTime = normalizedHourAmount.concat(normalizedMinuteAmount);
  30.  
  31. let timestamp = [];
  32. messagesTimestamps.forEach(e => {
  33.     if (Math.abs(parseInt(e) - parseInt(currentTime)) <= 5) {
  34.         timestamp.push(e);
  35.     }
  36. });
  37.  
  38. messages[timestamp[0]] || ' ';
RAW Paste Data Copied