diff --git a/example_config/carriers.json b/example_config/carriers.json index 588e1b3..8181949 100644 --- a/example_config/carriers.json +++ b/example_config/carriers.json @@ -1,5 +1,6 @@ { "timeout": 15, + "waitmessage": 30, "baseurl": "https://", "list": [ { diff --git a/luna.js b/luna.js index 2f8c8d2..7450426 100644 --- a/luna.js +++ b/luna.js @@ -8240,77 +8240,79 @@ function loopCorona() { function loopCarriers() { setTimeout(loopCarriers, carriers.timeout * 60 * 1000); - carriers.list.forEach(function (c) { - exec("curl GET " + c.url, (error, stdout, stderr) => { - if (error) { - console.log(util.format( - strings.debug.carriers.errorA, - c.name, - error - )); - return; - } - //console.log("Execution result: " + stdout); + carriers.list.forEach(function (c, i) { + setTimeout(function() { + exec("curl GET " + c.url, (error, stdout, stderr) => { + if (error) { + console.log(util.format( + strings.debug.carriers.errorA, + c.name, + error + )); + return; + } + //console.log("Execution result: " + stdout); - try { - const $ = cheerio.load(stdout); - - const ownerElement = $('.itempairlabel:contains("Owner")').next().children('a'); - const ownerUrl = carriers.baseurl + ownerElement.attr('href'); - - const starSystemElement = $('.itempairlabel:contains("Star system")').next().find('a'); - const starSystemName = starSystemElement.text().trim(); - const starSystemUrl = carriers.baseurl + starSystemElement.attr('href'); - - const updateElement = $('.itempairlabel:contains("Location update")').next() - const updateValue = updateElement.text().trim(); - - const distanceElement = $('.itempairlabel:contains("Station distance")').next() - const distanceValue = distanceElement.text().trim(); - - const accessElement = $('.itempairlabel:contains("Docking access")').next() - const accessValue = accessElement.text().trim(); - - var message = {}; - message.channelID = channelNameToID(c.channel); - message.messageID = c.messageid; - - bot.getMessage(message, function(err, msg) { - if (msg != undefined) { - var now = new Date(); - var text = util.format( - strings.announcements.carriers.message, - c.name, - c.url, - c.callsign, - c.owner, - ownerUrl, - starSystemName, - starSystemUrl, - updateValue, - distanceValue, - accessValue, - getDiscordTimestamp(now, "R") - ); + try { + const $ = cheerio.load(stdout); + + const ownerElement = $('.itempairlabel:contains("Owner")').next().children('a'); + const ownerUrl = carriers.baseurl + ownerElement.attr('href'); + + const starSystemElement = $('.itempairlabel:contains("Star system")').next().find('a'); + const starSystemName = starSystemElement.text().trim(); + const starSystemUrl = carriers.baseurl + starSystemElement.attr('href'); + + const updateElement = $('.itempairlabel:contains("Location update")').next() + const updateValue = updateElement.text().trim(); + + const distanceElement = $('.itempairlabel:contains("Station distance")').next() + const distanceValue = distanceElement.text().trim(); + + const accessElement = $('.itempairlabel:contains("Docking access")').next() + const accessValue = accessElement.text().trim(); + + var message = {}; + message.channelID = channelNameToID(c.channel); + message.messageID = c.messageid; + + bot.getMessage(message, function(err, msg) { + if (msg != undefined) { + var now = new Date(); + var text = util.format( + strings.announcements.carriers.message, + c.name, + c.url, + c.callsign, + c.owner, + ownerUrl, + starSystemName, + starSystemUrl, + updateValue, + distanceValue, + accessValue, + getDiscordTimestamp(now, "R") + ); - edit(channelNameToID(c.channel), c.messageid, text, false); - } - else { - send(channelNameToID(c.channel), util.format( - strings.announcements.carriers.inital, - c.name - ), false); - } - }); - } - catch (error) { - console.log(util.format( - strings.debug.carriers.errorB, - c.name, - error - )); - } - }); + edit(channelNameToID(c.channel), c.messageid, text, false); + } + else { + send(channelNameToID(c.channel), util.format( + strings.announcements.carriers.inital, + c.name + ), false); + } + }); + } + catch (error) { + console.log(util.format( + strings.debug.carriers.errorB, + c.name, + error + )); + } + }); + }, i * carriers.waitmessage * 1000); }); } diff --git a/package.json b/package.json index 6c02250..d9af5ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "PrincessLuna", - "version": "2.30.0", + "version": "2.30.1", "description": "Princess Luna is a Discord bot designed for Thorinair's official Glory of The Night Discord server.", "main": "luna.js", "repository": {