better logging
This commit is contained in:
7
index.js
7
index.js
@@ -42,10 +42,10 @@ fs.readdir('./tasks/', (err, files) => {
|
||||
const taskName = file.split('.')[0];
|
||||
task[taskName] = taskFile;
|
||||
if (taskFile.schedule) {
|
||||
console.log(`Tasks: Scheduling "${taskName}" for ${taskFile.schedule}`);
|
||||
console.debug(`Tasks: Scheduling "${taskName}" for ${taskFile.schedule}`);
|
||||
cron.schedule(taskFile.schedule, () => { taskFile(client, torn, config, state); });
|
||||
} else {
|
||||
console.log(`Tasks: Registered "${taskName}"`);
|
||||
console.debug(`Tasks: Registered "${taskName}"`);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -61,7 +61,7 @@ const commandFolders = fs.readdirSync(foldersPath);
|
||||
const command = require(filePath);
|
||||
if ('data' in command && 'execute' in command) {
|
||||
client.commands.set(command.data.name, command);
|
||||
console.log(`Commands: Registered "${command.data.name}"`);
|
||||
console.debug(`Commands: Registered "${command.data.name}"`);
|
||||
} else {
|
||||
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
|
||||
}
|
||||
@@ -75,6 +75,7 @@ client.on(Events.InteractionCreate, async interaction => {
|
||||
console.error(`No command matching ${interaction.commandName} was found.`);
|
||||
return;
|
||||
} try {
|
||||
console.debug(`Command: Executing ${interaction.commandName}`);
|
||||
await command.execute(interaction);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
module.exports = async (client, torn, config, state) => {
|
||||
console.debug("Task: Executing unavailableOC");
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const channel = client.channels.resolve(config.channels.ocAlert);
|
||||
@@ -31,6 +32,7 @@ module.exports = async (client, torn, config, state) => {
|
||||
});
|
||||
let isSomethingZero = false;
|
||||
crimes.difficulty.forEach(difficulty => {
|
||||
console.debug(`unavailableOC: ${difficulty.name}: ${difficulty.count}`);
|
||||
if (difficulty.count === 0) {
|
||||
isSomethingZero = true;
|
||||
embed.addFields({
|
||||
@@ -49,11 +51,13 @@ module.exports = async (client, torn, config, state) => {
|
||||
const then = new Date(state.ocAlertLast);
|
||||
const twelveHours = 12 * 60 * 60 * 1000;
|
||||
if (now.getTime() - then.getTime() > twelveHours) {
|
||||
console.debug(`unavailableOC: Sending alert`);
|
||||
channel.send({ embeds: [embed] });
|
||||
state.ocAlertLast = now.toISOString();
|
||||
fs.writeFile('./state.json', JSON.stringify(state, null, 4), err => {if (err) {console.error(err)}});
|
||||
}
|
||||
} else { console.debug(`unavailableOC: Would send alert, but one was sent recently`); }
|
||||
} else {
|
||||
console.debug(`unavailableOC: All crimes available, not sending alert`);
|
||||
const now = new Date();
|
||||
const twentyFourHoursAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);
|
||||
state.ocAlertLast = twentyFourHoursAgo.toISOString();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
module.exports = async (client, torn, config, state) => {
|
||||
console.debug("Task: Executing unpaidOC");
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const channel = client.channels.resolve(config.channels.ocAlert);
|
||||
@@ -8,6 +9,7 @@ module.exports = async (client, torn, config, state) => {
|
||||
const data = await torn.api(`https://api.torn.com/v2/faction/crimes?cat=successful&from=${now.getTime() / 1000 - 7 * 24 * 60 * 60}&sort=DESC`);
|
||||
for (const crime of data.crimes) {
|
||||
if (!crime.rewards.payout) {
|
||||
console.debug(`unpaidOC: Found unpaid crime: ${crime.name}:${crime.id}`);
|
||||
const execDate = new Date(crime.executed_at * 1000);
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(crime.name)
|
||||
@@ -41,16 +43,17 @@ module.exports = async (client, torn, config, state) => {
|
||||
embeds.push(embed);
|
||||
}
|
||||
}
|
||||
console.log(embeds)
|
||||
if (embeds.length > 0) {
|
||||
const then = new Date(state.payoutAlertLast);
|
||||
const twelveHours = 12 * 60 * 60 * 1000;
|
||||
if (now.getTime() - then.getTime() > twelveHours) {
|
||||
console.debug(`unpaidOC: Sending alert`);
|
||||
channel.send({content: "# Unpaid Faction Crimes:", embeds: embeds });
|
||||
state.payoutAlertLast = now.toISOString();
|
||||
fs.writeFile('./state.json', JSON.stringify(state, null, 4), err => {if (err) {console.error(err)}});
|
||||
}
|
||||
} else { console.debug(`unpaidOC: Would send alert, but one was sent recently`); }
|
||||
} else {
|
||||
console.debug(`unpaidOC: All crimes are paid, not sending alert`);
|
||||
const twentyFourHoursAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);
|
||||
state.payoutAlertLast = twentyFourHoursAgo.toISOString();
|
||||
fs.writeFile('./state.json', JSON.stringify(state, null, 4), err => {if (err) {console.error(err)}});
|
||||
|
||||
Reference in New Issue
Block a user