Skip to content

Commit

Permalink
Fix a rate limit issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorinair committed Oct 20, 2024
1 parent a57e61f commit be89c30
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 70 deletions.
1 change: 1 addition & 0 deletions example_config/carriers.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"timeout": 15,
"waitmessage": 30,
"baseurl": "https://",
"list": [
{
Expand Down
140 changes: 71 additions & 69 deletions luna.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit be89c30

Please sign in to comment.