Clean up unneeded files
This commit is contained in:
parent
1a1d4ccb6b
commit
0f4ab267c8
2 changed files with 1 additions and 88 deletions
49
index.js
49
index.js
|
@ -7,13 +7,10 @@
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
|
|
||||||
// Add pm2 metrics - this should NEVER track ANYTHING identifiable. This is purely for basic metrics and bot performance tracking
|
|
||||||
const metrics = require('./utils/pm2-metrics.js');
|
|
||||||
|
|
||||||
// Use a custom logging script
|
// Use a custom logging script
|
||||||
const logger = require('./utils/logging.js');
|
const logger = require('./utils/logging.js');
|
||||||
|
|
||||||
// Listen for (Semi-)Permenant Interactions
|
// Listen for (Semi-)Permanent Interactions
|
||||||
const interactionListener = require('./utils/interaction-trigger.js');
|
const interactionListener = require('./utils/interaction-trigger.js');
|
||||||
|
|
||||||
// Require the necessary discord.js classes
|
// Require the necessary discord.js classes
|
||||||
|
@ -47,17 +44,6 @@ for (const file of commandFiles) {
|
||||||
client.once(Events.ClientReady, c => {
|
client.once(Events.ClientReady, c => {
|
||||||
logger.log(logger.logLevels.INFO, `${logger.colorText('Ready!', logger.textColor.Green)} Logged in as ${logger.colorText(c.user.tag, logger.textColor.Blue)}`);
|
logger.log(logger.logLevels.INFO, `${logger.colorText('Ready!', logger.textColor.Green)} Logged in as ${logger.colorText(c.user.tag, logger.textColor.Blue)}`);
|
||||||
client.user.setPresence({ activities: [{ name: activity }], status: status });
|
client.user.setPresence({ activities: [{ name: activity }], status: status });
|
||||||
|
|
||||||
// Track websocket heartbeat with PM2 Histogram
|
|
||||||
let latency = 0;
|
|
||||||
setInterval(function() {
|
|
||||||
latency = c.ws.ping;
|
|
||||||
metrics.websocketHeartbeatHist.update(latency);
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
// Report current server count with PM2 (Servers counted anonymously)
|
|
||||||
metrics.serverCount.set(c.guilds.cache.size);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Client "on" Events
|
// Client "on" Events
|
||||||
|
@ -71,14 +57,6 @@ client.on(Events.InteractionCreate, async interaction => {
|
||||||
logger.log(logger.logLevels.ERROR, `No command matching ${interaction.commandName} was found.`);
|
logger.log(logger.logLevels.ERROR, `No command matching ${interaction.commandName} was found.`);
|
||||||
await interaction.reply({ content: `This command no longer exists! Please contact ${botOwner} to report that this is happening!`, ephemeral: true });
|
await interaction.reply({ content: `This command no longer exists! Please contact ${botOwner} to report that this is happening!`, ephemeral: true });
|
||||||
|
|
||||||
// Report error to PM2 dashboard
|
|
||||||
metrics.interactionErrors.inc();
|
|
||||||
metrics.io.notifyError(new Error('Interaction doesn\'t exist'), {
|
|
||||||
custom: {
|
|
||||||
interactionCommand: interaction.commandName,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,20 +66,7 @@ client.on(Events.InteractionCreate, async interaction => {
|
||||||
catch (error) {
|
catch (error) {
|
||||||
logger.log(logger.logLevels.ERROR, error);
|
logger.log(logger.logLevels.ERROR, error);
|
||||||
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
|
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
|
||||||
|
|
||||||
// Report error to PM2 dashboard
|
|
||||||
metrics.interactionErrors.inc();
|
|
||||||
metrics.io.notifyError(new Error('Error executing interaction'), {
|
|
||||||
custom: {
|
|
||||||
interactionCommand: interaction.commandName,
|
|
||||||
error: error,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
// Successful Execution, report as a PM2 metric
|
|
||||||
// If the bot gets a lot of use, consider removing this for performance
|
|
||||||
metrics.interactionSuccess();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (interaction.isButton()) {
|
else if (interaction.isButton()) {
|
||||||
interactionListener.buttonInteraction(interaction);
|
interactionListener.buttonInteraction(interaction);
|
||||||
|
@ -111,17 +76,5 @@ client.on(Events.InteractionCreate, async interaction => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Joined a server
|
|
||||||
client.on(Events.GuildCreate, guild => {
|
|
||||||
// Report current server count with PM2 (Servers counted anonymously)
|
|
||||||
metrics.serverCount.set(guild.client.guilds.cache.size);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Removed from a server
|
|
||||||
client.on(Events.GuildDelete, guild => {
|
|
||||||
// Report current server count with PM2 (Servers counted anonymously)
|
|
||||||
metrics.serverCount.set(guild.client.guilds.cache.size);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Log in to Discord with your client's token
|
// Log in to Discord with your client's token
|
||||||
client.login(token);
|
client.login(token);
|
|
@ -1,40 +0,0 @@
|
||||||
/*
|
|
||||||
* Konpeki Discord Bot - Utility Definition File
|
|
||||||
* pm2-metrics.js - A place to keep all pm2 metrics and error definitions
|
|
||||||
*/
|
|
||||||
|
|
||||||
const io = require('@pm2/io');
|
|
||||||
|
|
||||||
const interactionErrors = io.counter({
|
|
||||||
name: 'Interaction Errors (Since last restart)',
|
|
||||||
});
|
|
||||||
|
|
||||||
const interactionSuccessCounter = io.counter({
|
|
||||||
name: 'Interaction Successful Runs (Since last restart)',
|
|
||||||
});
|
|
||||||
|
|
||||||
const interactionSuccessMeter = io.meter({
|
|
||||||
name: 'Successful Interactions per Second',
|
|
||||||
});
|
|
||||||
|
|
||||||
const websocketHeartbeatHist = io.histogram({
|
|
||||||
name: 'Avg. Websocket Heartbeat (ms) / 5 min.',
|
|
||||||
measurement: 'mean',
|
|
||||||
});
|
|
||||||
|
|
||||||
const serverCount = io.metric({
|
|
||||||
name : 'Server Count',
|
|
||||||
});
|
|
||||||
|
|
||||||
const interactionSuccess = function() {
|
|
||||||
interactionSuccessCounter.inc();
|
|
||||||
interactionSuccessMeter.mark();
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
io,
|
|
||||||
interactionErrors,
|
|
||||||
interactionSuccess,
|
|
||||||
websocketHeartbeatHist,
|
|
||||||
serverCount,
|
|
||||||
};
|
|
Loading…
Reference in a new issue