Mutiple Changes

- Added events loader and directory
This commit is contained in:
Logan Cusano
2023-02-25 03:25:54 -05:00
parent 02bf0ebda2
commit 6b96f048fd
4 changed files with 45 additions and 39 deletions

View File

@@ -1,11 +0,0 @@
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
//const { clientId, guildId, token } = require('./config.json');
const commands = [];
const rest = new REST({ version: '9' }).setToken(token);
rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })
.then(() => console.log('Successfully registered application commands.'))
.catch(console.error);

View File

@@ -0,0 +1,28 @@
const { Events } = require('discord.js');
module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
log.DEBUG(`${interaction.member.user} is running '${interaction.commandName}'`);
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
},
};

View File

@@ -91,7 +91,7 @@ function runHTTPServer() {
server.on('error', libUtils.onError);
server.on('listening', () => {
log.INFO("Local HTTP Server Running");
log.INFO("HTTP server started!");
try {
libCore.feedArray = libCore.getFeeds();
} catch (error) {
@@ -115,43 +115,32 @@ for (const file of commandFiles) {
client.commands.set(command.data.name, command);
}
// Run when the bot is ready
client.on('ready', () => {
log.DEBUG(`Discord server up and running with client: ${client.user.tag}`);
log.INFO(`Logged in as ${client.user.tag}!`);
// Deploy commands
log.DEBUG("Deploying commands");
// Deploy slash commands
log.DEBUG("Deploying slash commands");
deployCommands.deploy(client.guilds.cache.map(guild => guild.id));
log.DEBUG(`Starting HTTP Server`);
runHTTPServer();
log.INFO(`Logged in as ${client.user.tag}!`);
log.INFO("HTTP server started!");
});
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
// Setup any additional event handlers
const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
log.DEBUG(`${interaction.member.user} is running '${command}'`);
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
client.on(event.name, (...args) => event.execute(...args));
}
}
});
}
client.login(discordToken); //Load Client Discord Token
try {

View File

@@ -103,7 +103,7 @@ exports.deleteSource = function (title, callback) {
*/
exports.getFeeds = function (feedType) {
var linkFlayerFilteredMap = [];
if (feedType == null || feedType == undefined || feedType == "") {
if (feedType == null || feedType == undefined || feedType == "" || feedType.toLowerCase() == "all") {
return rssFeedMap;
} else {