Advertisement
Everlike

unusedChannelDeleter.js

Jan 1st, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. registerPlugin({
  2.     name: 'unusedChannelDeleter',
  3.     version: '0.2.2',
  4.     backends: ['ts3'],
  5.     description: 'Deletes Channels, unused for a specific amount of time.',
  6.     author: 'Everlike <everlikezz@gmail.com>',
  7.     vars: [
  8.     //0 = all channels | 1 = specific channels | 2 = all channels with the same parentchannel
  9. {
  10.         name: 'listenType',
  11.         title: 'Channels to check',
  12.         type: 'select',
  13.         options: [
  14.           "All Channels",
  15.           "Specific Channels",
  16.           "All subchannels with the same parentchannel"
  17.         ]
  18.       },
  19.       //channels to ignore
  20. {
  21.         name: 'ignoreChannels',
  22.         title: 'Ignore channels',
  23.         type: 'array',
  24.         vars: [
  25.         {
  26.             name: 'channel',
  27.             title: 'channel',
  28.             type: 'channel'
  29.         }
  30.         ],
  31.         conditions: [
  32.                         {field: 'listenType', value: 0,}
  33.                 ]
  34.       },
  35.      
  36.       //choose channels to check, only shown when listentype is 1 (specific channels)
  37.       {
  38.         name: 'chooseChannels',
  39.         title: 'choose Channels',
  40.         type: 'array',
  41.         vars: [
  42.         {
  43.             name: 'channel',
  44.             title: 'channel',
  45.             type: 'channel'
  46.         }
  47.         ],
  48.         conditions: [
  49.                         { field: 'listenType', value: 1}
  50.                 ]
  51.       },
  52.       //parentchannel, only shown when listentype is 2 (all channels with the same parentchannel)
  53.       {
  54.         name: 'parentChannels',
  55.         title: 'Parent Channel',
  56.         type: 'array',
  57.         vars: [
  58.         {
  59.             name: 'channel',
  60.             title: 'channel',
  61.             type: 'channel'
  62.         }
  63.         ],
  64.         conditions: [
  65.                         { field: 'listenType', value: 2}
  66.                 ]
  67.       },
  68.       //time, a channel can be unused until it will be deleted.
  69.       {
  70.         name: 'timeTillDeletion',
  71.         title: 'Time, how long a channel can stay unused till it will be deleted. (in minutes)',
  72.         type: 'number',
  73.         placeholder: 20160
  74.       },
  75.       //Descriptionsettings
  76.         //check if user want to set a description
  77.       {
  78.         name: 'enableDescription',
  79.         title: 'Do you want to set a list of channels and their time until deletion as description of a channel?',
  80.         type: 'select',
  81.         options: [
  82.           "no",
  83.           "yes"
  84.         ]
  85.       },
  86.       //channel, the user want to set the description to
  87.       {
  88.         name: 'descriptionChannel',
  89.         title: 'Set a list of channels and their time until deletion as description of this channel.',
  90.         type: 'channel',
  91.         conditions: [
  92.                         { field: 'enableDescription', value: 1}
  93.                 ]
  94.       },
  95.       //how often the description should be updated
  96.       {
  97.         name: 'descriptionUpdateTime',
  98.         title: 'Update the description every ... minutes',
  99.         type: 'number',
  100.         conditions: [
  101.                         { field: 'enableDescription', value: 1}
  102.                 ]
  103.       },
  104.       {
  105.         name: 'descriptionRaw',
  106.         title: 'Enter the description. %channelList% will be replaced with a list of all channels and their time until deletetion.',
  107.         type: 'multiline',
  108.         conditions: [
  109.                         { field: 'enableDescription', value: 1}
  110.                 ]
  111.       },
  112. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  113.          {
  114.         name: 'enableWarning',
  115.         title: 'Do you want the bot to warn the users before the channel will be deleted, by adding text to the channelname?',
  116.         type: 'select',
  117.         options: [
  118.           "no",
  119.           "yes"
  120.         ]
  121.       },
  122.       {
  123.         name: 'minutesBeforeWarning',
  124.         title: 'How many minutes before channel-deletion do you want the bot to edit the channel?',
  125.         type: 'number',
  126.         conditions: [
  127.                         { field: 'enableWarning', value: 1}
  128.                 ]
  129.       },
  130.       {
  131.         name: 'warningString',
  132.         title: 'What should the bot add to the channelname?',
  133.         type: 'string',
  134.         conditions: [
  135.                         { field: 'enableWarning', value: 1}
  136.                 ]
  137.       },             
  138. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  139.       {
  140.         name: 'logStatus',
  141.         title: 'enable logging?',
  142.         type: 'checkbox'
  143.       },
  144. ],
  145. },
  146. function (sinusbot, config) {
  147.    
  148.     var engine = require ('engine');
  149.     var backend = require ('backend');
  150.     var event = require ('event');
  151.     var store = require('store');
  152.  
  153. /* setting variables */
  154. var listenType = config.listenType;             //0 = all channels | 1 = specific channels | 2 = all channels with the same parentchannel
  155. var channelsToIgnore = config.ignoreChannels;   //array of channels to ignore
  156. var timeTillDeletion = config.timeTillDeletion; //time, a channel can stay unused until it will be deleted (in minutes)
  157. var setDescription = config.setDescription;     //0 = no | 1 = yes
  158. var specificChannels = config.chooseChannels;   //array of channels to check if user only wants specific channels to check
  159. var parentChannels = config.parentChannels;     //parent-channel, which subchannels should be checked
  160. var enableWarning = config.enableWarning;       //0 = dont want | 1 = enable warning
  161.     var minutesBeforeWarning = config.minutesBeforeWarning;     //minutes before a channel will be deleted, the bot should warn
  162.     var warningString = config.warningString;   //string of what the bot should add to the channelname when warning
  163. var enableDescription = config.enableDescription;//0 =disable | 1 = enable
  164.     var descriptionChannel = config.descriptionChannel;     //channel, the users want to set the description at
  165.     var descriptionUpdateTime = config.descriptionUpdateTime;   //time in minutes, how often a user want to refresh the description
  166.     var descriptionRaw = config.descriptionRaw; //Is the text the user want to have as description...
  167. var logStatus = config.logStatus;               //true if user want to logs, false if not.
  168. var allparentchannels = allParentChannels(parentChannels);
  169. /* end setting variables */
  170.  
  171.  
  172. /* main */
  173.  
  174.         /* Debug Area*/
  175.         event.on('chat', function(ev) {
  176.         if (ev.text.indexOf("!printDebug") >= 0)    {
  177.             var AllChannelIdsToCheck = listOfAllChannelsToCheck();
  178.             engine.log(allParentChannels(parentChannels));
  179.         }
  180.         else if (ev.text.indexOf("!deleteChannelDB") >= 0) {
  181.             store.set('unusedChannelsDB', [{ channelID: "-1", channelName: "nothing", timeStamp: 100}]);
  182.             engine.log("Main-/Channel-Datebase has been reset successfully!");
  183.         }
  184.         else if (ev.text.indexOf("!deleteChannelNamesDB") >= 0) {
  185.             store.set('channelNames', [{ channelID: "-1", channelName: "nothing", timeStamp: 100}]);
  186.             engine.log("Channel-Name-Datebase has been reset successfully!");
  187.         }
  188.         else if (ev.text.indexOf("!channelNameDB") >= 0) {
  189.             var channelNames = store.get('channelNames');
  190.             engine.log(channelNames);
  191.         }
  192.         else if (ev.text.indexOf("!printMainDB") >= 0) {
  193.             //defining datebase
  194.             var unusedChannelsDB = definingDatebase();
  195.             engine.log('There are ' + unusedChannelsDB.length + ' channels in the datebase.');
  196.             engine.log(unusedChannelsDB);
  197.         }
  198.         else if (ev.text.indexOf("!recheckAllChannels") >= 0) {
  199.             getAllChannelsToCheck();
  200.             engine.log("rechecked all channels (function getAllChannelsToCheck()");
  201.         }
  202.         });
  203.         /* End Debug Area */
  204. /////////////////////////Unused-Channel-Warning/////////////////////////
  205.         setInterval(function() {
  206.             if (logStatus) {engine.log("running function: 'warningSystem()'");}
  207.             warningSystem();
  208.         }, 300000); //5 min.
  209.  
  210. /////////////////////////Unused-Channel-Deletion/////////////////////////
  211.         setInterval(function() {
  212.             if (logStatus) {engine.log("running function: 'checkForChannelToDelete()'");}
  213.             checkForChannelToDelete();         
  214.         }, 300000); //5 min.
  215.        
  216. /////////////////////////Synchronizing Main-Datebase/////////////////////////
  217.         setInterval(function() {
  218.             if (logStatus) {engine.log("running function: 'syncUnusedChannelDatebase()'");}
  219.             if (backend.isConnected()) {
  220.             syncUnusedChannelDatebase();       
  221.             }
  222.         }, 600000); //10 min.
  223.        
  224. /////////////////////////Updating Description/////////////////////////
  225.         setInterval(function() {
  226.         if (logStatus) {engine.log("running function: 'updateDescription()'");}
  227.         updateDescription();
  228.         }, descriptionUpdateTime*60000);
  229.        
  230.         event.on('clientMove', function (ev) {
  231.             if (ev.toChannel != undefined) {
  232.                 if (channelIsToCheck(ev.toChannel.id())) {
  233. /////////////////////////Updating Main-Datebase/////////////////////////
  234.             if (logStatus) {engine.log("running function: 'updateDatebase()'");}
  235.             updateDatebase(ev.toChannel.id());
  236.                 }
  237.             }
  238. /////////////////////////Revoke-Warning/////////////////////////
  239.         if (ev.toChannel != undefined) {
  240.             if (logStatus) {engine.log("running function: 'reviewWarningStatus()'");}
  241.             reviewWarningStatus(ev.toChannel.id());
  242.         }
  243.         });
  244. /* end main */
  245.  
  246.  
  247.  
  248. /* main functions */
  249. //returns an array containing all channel ids to check
  250. function listOfAllChannelsToCheck() {
  251.     var listOfAllChannelsToCheck = [];
  252.         //all channels
  253.         if (listenType == 0) {                 
  254.             if(channelsToIgnore == undefined) {
  255.                 var listOfAllChannelsToCheck = allChannelIds();
  256.             }
  257.             else {
  258.                 allChannelIds().forEach(function(channel) {
  259.                 if(channelBlacklist().indexOf(channel) < 0) {
  260.                 listOfAllChannelsToCheck.push(channel);
  261.                 }              
  262.                 })
  263.             }
  264.         }
  265.        
  266.         //specific channels
  267.         if (listenType == 1) {
  268.             for (i = 0; i < specificChannels.length; i++) {
  269.                 listOfAllChannelsToCheck.push(backend.getChannelByID(specificChannels[i].channel).id());
  270.             }
  271.         }
  272.        
  273.         //channels with the same parent-channel
  274.         if (listenType == 2) {
  275.             var allChannelIDs = allChannelIds();
  276.             var allparentchannels = allParentChannels(parentChannels);
  277.             for  (i = 0; i < allChannelIDs.length; i++) {
  278.                 if (backend.getChannelByID(allChannelIDs[i]).parent() != undefined && allparentchannels.indexOf(backend.getChannelByID(allChannelIDs[i]).parent())) {
  279.                     listOfAllChannelsToCheck.push(allChannelIDs[i]);
  280.                 }
  281.                 else {
  282.                    
  283.                 }
  284.             }
  285.         }
  286.         return listOfAllChannelsToCheck;
  287.         };
  288.        
  289. //updating the datebase
  290. function updateDatebase(channelID) {
  291.     /* defining the datebase */
  292.         //defining datebase
  293.         var unusedChannelsDB = definingDatebase();
  294.    
  295.     /* Defining parameters of the channel currently worked on */
  296.     var currChannelID = channelID;
  297.     if (logStatus) {engine.log("Incoming ChannelID: " + currChannelID);}
  298.    
  299.     var currChannelName = backend.getChannelByID(currChannelID).name();
  300.     if (logStatus) {engine.log("name of the channel: " + currChannelName);}
  301.     var currTime = Math.floor(Date.now() / 1000);
  302.    
  303.     //If channel is already in the datebase
  304.     if (allSafedChannelIDs().indexOf(channelID) >= 0) {
  305.         for (i = 0; i < unusedChannelsDB.length; i++) {
  306.             if (unusedChannelsDB[i].channelID == currChannelID) {
  307.                 unusedChannelsDB[i].channelName = currChannelName;
  308.                 unusedChannelsDB[i].timeStamp = currTime;
  309.             }
  310.         }
  311.         store.set('unusedChannelsDB', unusedChannelsDB);
  312.     }
  313.     //Add channel to the datebase
  314.     else {
  315.         unusedChannelsDB.push({ channelID: currChannelID, channelName: currChannelName, timeStamp: currTime});
  316.         store.set('unusedChannelsDB', unusedChannelsDB);
  317.     }  
  318. };
  319.  
  320. //whole process of warning by editing channel-names & icons
  321. function warningSystem() {
  322.     //check if the warningsystem is enabled
  323.     if (enableWarning == 1) {
  324.         //log common errors
  325.         if (minutesBeforeWarning == undefined) {
  326.             engine.log("you need to set a time, the bot should warn the users before deletion in your webinterface! | contact <admin@everlike.de>");
  327.         }
  328.         else if (warningString == undefined && warningIcon == undefined) {
  329.             engine.log("You need to define at least a text the bot should add to the channelname before deletion or enter a iconID, if you dont want to enable the warning system, just disable it in the webinterface. | contact <admin@everlike.de>");
  330.         }
  331.         else if (warningString != undefined && warningString.length > 40) {
  332.             engine.log ("A channelname can´t be longer than 40 characters, please change the warning text in your webinterface. | contact <admin@everlike.de>");
  333.         }
  334.        
  335.         //defining datebase
  336.         var unusedChannelsDB = definingDatebase();
  337.         //get actual time
  338.         var now = Math.floor(Date.now() / 1000);
  339.         if (warningString != undefined) {
  340.             for (i = 0; i < unusedChannelsDB.length; i++) {
  341.                                 //checking if its time to warn and or if the warning message has already been set
  342.                 if ((backend.getChannelByID(unusedChannelsDB[i].channelID) != undefined) && (timeTillDeletion - ((now - unusedChannelsDB[i].timeStamp) /60)) <= minutesBeforeWarning && backend.getChannelByID(unusedChannelsDB[i].channelID).name().indexOf(warningString) < 0) {
  343.                     //safe original channelname
  344.                     safeChannelname(unusedChannelsDB[i].channelID);
  345.                     //set warning-name
  346.                     backend.getChannelByID(unusedChannelsDB[i].channelID).setName(defineWarnChannelname(unusedChannelsDB[i].channelID));
  347.                 }
  348.                 else {
  349.                 }
  350.             }
  351.         }
  352.     }
  353. };
  354.  
  355. //changes back the channelname to the original one (Only use when a user joins the specific channel)
  356. function reviewWarningStatus(channelID) {
  357.     if (backend.getChannelByID(channelID) != undefined && backend.getChannelByID(channelID).name().indexOf(warningString) >= 0) {
  358.         setOriginalChannelname(channelID);
  359.     }
  360. };
  361.  
  362. //checks if channel is unused and propably deletes it
  363. function checkForChannelToDelete() {
  364.     //defining datebase
  365.     var unusedChannelsDB = definingDatebase();
  366.     //get actual time
  367.     var now = Math.floor(Date.now() / 1000);
  368.     //in case this channeldata is incorrect or the channel does not exist anymore
  369.     for (i = 0; i < unusedChannelsDB.length; i++) {
  370.     if (backend.getChannelByID(unusedChannelsDB[i].channelID) == undefined) {
  371.         engine.log("Seems like the channel: " + unusedChannelsDB[i].channelName + " with the channel-id: " + unusedChannelsDB[i].channelID + " does not exist anymore");
  372.         }
  373.         //if channel is inactive for too long - delete it
  374.     else if ((backend.getChannelByID(unusedChannelsDB[i].channelID) != undefined) && (now - unusedChannelsDB[i].timeStamp) /60 >= timeTillDeletion) {
  375.         //delete channel
  376.         backend.getChannelByID(unusedChannelsDB[i].channelID).delete();
  377.         //remove server from the datebase
  378.         unusedChannelsDB.splice(i, 1);
  379.         i--;
  380.     }
  381.     }
  382.         //safe the datebase
  383.         store.set('unusedChannelsDB', unusedChannelsDB);
  384. };
  385.  
  386. //checks each datebase entry if channel is still active, if not, deletes it from the db.
  387. function syncUnusedChannelDatebase() {
  388.     //defining datebase
  389.     var unusedChannelsDB = definingDatebase();
  390.     //get all channelids
  391.     var allChannelIDs = allChannelIds();
  392.     //get all channelids to check
  393.     var AllChannelIdsToCheck = listOfAllChannelsToCheck();
  394.     for (i = 0; i < unusedChannelsDB.length; i++) {
  395.         if (allChannelIDs.indexOf(unusedChannelsDB[i].channelID) < 0 || AllChannelIdsToCheck.indexOf(unusedChannelsDB[i].channelID) < 0) {
  396.             unusedChannelsDB.splice(i, 1);
  397.             i--;
  398.         }
  399.     }
  400.         store.set('unusedChannelsDB', unusedChannelsDB);
  401. };
  402.  
  403. //sets/updates all channels and their time until deletion as description of a specific channel
  404. function updateDescription() {
  405.     if (enableDescription == 1) {
  406.     if (descriptionChannel == undefined ||  descriptionUpdateTime == undefined) {
  407.         engine.log("Seems like you want the bot to set the channels and their time until deletion as description of a channel, but you haven´t entered the channel or update-time right...");
  408.     }
  409.     //generating the description-string
  410.     var descriptionString = definingDescription(); 
  411.     //set the description
  412.     backend.getChannelByID(descriptionChannel).setDescription(descriptionString);
  413.     }
  414. };
  415.  
  416. //return true if channel has to be checked, false if not. (Made to safe ressourcces)
  417. function channelIsToCheck(channelID) {
  418.     if (listenType == 0) {
  419.         if(listOfAllChannelsToCheck().indexOf(channelID) >= 0) {
  420.             return true;
  421.         }
  422.         else {
  423.         return false;  
  424.         }
  425.     }
  426.    
  427.     else if (listenType == 1) {
  428.         if (listOfAllChannelsToCheck().indexOf(channelID) >= 0) {
  429.             return true;
  430.         }
  431.         else {
  432.             return false;
  433.         }
  434.     }
  435.    
  436.     else if (listenType == 2) {
  437.         if (backend.getChannelByID(channelID).parent() != undefined) {
  438.         if (allParentChannels(parentChannels).indexOf(backend.getChannelByID(channelID).parent().id()) >= 0) {
  439.             return true;
  440.         }
  441.         else {
  442.         return false;
  443.         }
  444.         }
  445.     }
  446. };
  447.     //get and set all channels to check
  448. function getAllChannelsToCheck() {
  449.     //defining datebase
  450.     var unusedChannelsDB = definingDatebase();
  451.     //getting all channel ids already safed in the main db
  452.     var allCurrentSafedChannelIDs = allSafedChannelIDs()
  453.     //getting all channel ids
  454.     var allCurrExistingChannelIDs = allChannelIds();
  455.    
  456.     allCurrExistingChannelIDs.forEach(function(channelid) {
  457.         if (channelIsToCheck(channelid)) {
  458.             updateDatebase(channelid);
  459.         }
  460.     });
  461.    
  462.    
  463. };
  464. /* end main functions */
  465.  
  466.    
  467. /* helper functions */
  468. //returns an array of ids of blacklisted channels
  469. function channelBlacklist() {
  470.     var channelBlacklist = [];
  471.     if (channelsToIgnore != undefined) {
  472.         for (i = 0; i < channelsToIgnore.length; i++) {
  473.             channelBlacklist.push(backend.getChannelByID(channelsToIgnore[i].channel).id());
  474.         }
  475.     }
  476.     return channelBlacklist;
  477. };
  478.  
  479. //returns an array of all channel ids
  480. function allChannelIds() {
  481.         if(logStatus) {engine.log("now executing funcion 'allChannelIds()'");}
  482.     var allChannelIds = [];
  483.     var allChannels = backend.getChannels();
  484.         if(logStatus) {engine.log("backend.getChannels returned: " + allChannels.length + " channels");}
  485.     for (i = 0; i < allChannels.length; i++) {
  486.         allChannelIds.push(allChannels[i].id());
  487.     }
  488.     return allChannelIds;
  489. };
  490.  
  491. //returns an array of ids of channels existing in the datebase
  492. function allSafedChannelIDs() {
  493.         var unusedChannelsDB = store.get('unusedChannelsDB');
  494.         var allSafedChannelIDs = new Array;
  495.         for (i = 0; i < unusedChannelsDB.length; i++) {
  496.             allSafedChannelIDs.push(unusedChannelsDB[i].channelID);
  497.         }
  498.         return allSafedChannelIDs
  499.     };
  500.  
  501. //adds something to a channelname to warn users that their channel will be deleted soon.
  502. function warnChannelName(channelID) {
  503.     var channelName = backend.getChannelByID(channelID).name();
  504.    
  505. };
  506.  
  507. function definingDatebase() {
  508.     //defining datebase
  509.         if (logStatus) {engine.log("fired 'definingDatebase()' function");}
  510.        
  511.         if(backend.isConnected()) {
  512.             if (logStatus) {engine.log("backend is connected.");}
  513.             var currentuucdb = store.get('unusedChannelsDB');  
  514.             if (logStatus) {engine.log("store.get('unusedChannelsDB') returned: " + currentuucdb);}
  515.             if ((currentuucdb == undefined) || (currentuucdb == "") || (currentuucdb == [])) {
  516.             if (logStatus) {engine.log("store.get('unusedChannelsDB') is undefined, an empty string or an empty array.");}
  517.             var unusedChannelsDB = [{ channelID: "-1", channelName: "nothing", timeStamp: 100}];
  518.             if (logStatus) {engine.log("created a new Datebase");}
  519.             store.set('unusedChannelsDB', unusedChannelsDB);
  520.                 }
  521.         //get the datebase
  522.         var unusedChannelsDB = store.get('unusedChannelsDB');
  523.             if (logStatus) {engine.log("getting datebase in function definingDatebase() returns: " + unusedChannelsDB.length + " channels");}
  524.         return unusedChannelsDB;
  525.             }
  526.             else {
  527.             if (logStatus) {engine.log("backend is not connected");}   
  528.             }
  529. };
  530.  
  531. function safeChannelname(channelID) {
  532.     //defining datebase
  533.     if (store.get('channelNames') == undefined) {
  534.     var channelNames = [];
  535.     store.set('channelNames', channelNames);
  536.     }
  537.     //get the datebase
  538.     var channelNames = store.get('channelNames');
  539.     if (backend.getChannelByID(channelID) != undefined) {
  540.         var channelName = backend.getChannelByID(channelID).name();
  541.     //add channelinformation to the datebase
  542.     channelNames.push({ channelID: channelID, channelName: channelName});
  543.     }
  544.     //store the updated datebase
  545.     store.set('channelNames', channelNames);
  546. };
  547.  
  548. //generating the new channelname including the warningmessage
  549. function defineWarnChannelname(channelID) {
  550.     var channelName = backend.getChannelByID(channelID).name();
  551.     if ((channelName.length + warningString.length) > 40) {
  552.         var charsTooMuch = (channelName.length + warningString.length) - 40;
  553.         var updatedChannelName = channelName.substring(0,channelName.length-charsTooMuch) + config.warningString;
  554.     }
  555.     else {
  556.         var updatedChannelName = channelName + warningString;
  557.     }
  558.     return updatedChannelName;
  559. };
  560.  
  561. function setOriginalChannelname (channelID) {
  562.     //defining datebase
  563.     if (store.get('channelNames') == undefined) {
  564.     var channelNames = [];
  565.     store.set('channelNames', channelNames);
  566.     }
  567.     //get the datebase
  568.     var channelNames = store.get('channelNames');
  569.     //get original channel name
  570.     for (i = 0; i < channelNames.length; i++) {
  571.     if (channelNames[i].channelID == channelID) {
  572.         //set channelname back to the original one
  573.         backend.getChannelByID(channelID).setName(channelNames[i].channelName);
  574.         //remove original name entry from datebase
  575.         channelNames.splice(i, 1);
  576.         i--;
  577.     }
  578.     }
  579.             //safe datebase
  580.         store.set('channelNames', channelNames);
  581. };
  582.  
  583. //defines a string, containing the updated description of a channel that shows all channels in the db and their time until deletion.
  584. function definingDescription() {
  585.     //defining Datebase
  586.     var unusedChannelsDB = definingDatebase();
  587.     //defining now
  588.     var now = Math.floor(Date.now() / 1000);
  589.     //create var for the list of channels and their time until deleteion
  590.     var listOfChannelsDeletionTime = [];
  591.     for (i = 0; i < unusedChannelsDB.length; i++) {
  592.     listOfChannelsDeletionTime.push("\n" + 'Channel "' + "[b]" + unusedChannelsDB[i].channelName + "[/b]"+ '"' + " will be deleted in " + convertTime((timeTillDeletion*60) - (now - unusedChannelsDB[i].timeStamp)));
  593.     };
  594.     var description = (descriptionRaw.replace("%channelList%", listOfChannelsDeletionTime)) + "[center][size=7]made by Everlike <[url]everlike.de[/url]>[/size][/center]";
  595.     //checking if description is too long
  596.     if (description.length > 8192) {
  597.         var varsTooMuch = (description + "not all channels are shown due to less charspace" + "[center][size=7]made by Everlike <[url]everlike.de[/url]>[/size][/center]").length - 8192;
  598.         var description = description.substring(0,description.length-varsTooMuch) + "not all channels are shown due to less charspace" + "[center][size=7]made by Everlike <[url]everlike.de[/url]>[/size][/center]";
  599.     }
  600.     //descriptionRaw
  601.    
  602.     return description;
  603. };
  604.  
  605. function convertTime(seconds) {
  606.         var days = Math.floor(seconds / (3600*24));
  607.         seconds  -= days*3600*24;
  608.         var hrs   = Math.floor(seconds / 3600);
  609.         seconds  -= hrs*3600;
  610.         var mnts = Math.floor(seconds / 60);
  611.         seconds  -= mnts*60;       
  612.         return days+" days, "+hrs+" Hrs, "+mnts+" Minutes, "+seconds+" Seconds";
  613.     };
  614.    
  615. function allParentChannels(parentChannelsToCheck) {
  616.     allParentChannelIDs = [];
  617.     for (i = 0; i < parentChannelsToCheck.length; i++) {
  618.         allParentChannelIDs.push(parentChannelsToCheck[i].channel);
  619.     }
  620.     return allParentChannelIDs;
  621. };
  622.  
  623. /* end helper functions */
  624.  
  625. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement