Skip to content

Commit

Permalink
Create export-commands & fix giveaway errors
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMonDon committed Aug 3, 2024
1 parent 1b90d85 commit f63dae0
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 19 deletions.
2 changes: 1 addition & 1 deletion commands/Administrator/auto-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AutoRole extends Command {
constructor(client) {
super(client, {
name: 'auto-role',
category: 'Moderation',
category: 'Administrator',
description: 'Manage auto-roles in the server.',
usage: 'auto-role <add | remove | list> [role or page]',
aliases: ['autorole', 'autoroles'],
Expand Down
11 changes: 5 additions & 6 deletions commands/Giveaways/delete-giveaway.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ class DeleteGiveaway extends Command {
return this.client.util.errorEmbed(msg, 'You need to have the Manage Messages permission to delete giveaways');
const query = args.join(' ');

const ErrorEmbed = new EmbedBuilder()
.setAuthor({ name: msg.author.tag, iconURL: msg.author.displayAvatarURL() })
.setColor(msg.settings.embedErrorColor);

if (isNaN(query))
return this.client.util.errorEmbed(msg, msg.settings.prefix + this.help.usage, 'Invalid Message ID');

Expand All @@ -41,8 +37,11 @@ class DeleteGiveaway extends Command {
msg.channel.send('Giveaway deleted!');
})
.catch((e) => {
ErrorEmbed.setTitle(e);
return msg.channel.send(ErrorEmbed);
const ErrorEmbed = new EmbedBuilder()
.setAuthor({ name: msg.author.tag, iconURL: msg.author.displayAvatarURL() })
.setColor(msg.settings.embedErrorColor)
.setDescription(e);
return msg.channel.send({ embeds: [ErrorEmbed] });
});
}
}
Expand Down
13 changes: 6 additions & 7 deletions commands/Giveaways/end-giveaway.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ class EndGiveaway extends Command {

const query = args.join(' ');

const ErrorEmbed = new EmbedBuilder()
.setAuthor({ name: msg.author.tag, iconURL: msg.author.displayAvatarURL() })
.setColor(msg.settings.embedErrorColor);

if (isNaN(query)) return this.client.util.errorEmbed(msg, msg.settings.prefix + this.help.usage, 'Incorrect Usage');

const giveaway = this.client.giveawaysManager.giveaways.find(
Expand All @@ -40,9 +36,12 @@ class EndGiveaway extends Command {
// Success message
msg.channel.send('Giveaway ended!');
})
.catch((e) => {
ErrorEmbed.setTitle(e);
return msg.channel.send(ErrorEmbed);
.catch((error) => {
const ErrorEmbed = new EmbedBuilder()
.setAuthor({ name: msg.author.tag, iconURL: msg.author.displayAvatarURL() })
.setColor(msg.settings.embedErrorColor)
.setDescription(error);
return msg.channel.send({ embeds: [ErrorEmbed] });
});
}
}
Expand Down
9 changes: 4 additions & 5 deletions commands/Giveaways/reroll-giveaway.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ class RerollGiveaway extends Command {
return this.client.util.errorEmbed(msg, 'You need to have the Manage Messages permission to reroll giveaways');
const query = args.join('');

const ErrorEmbed = new EmbedBuilder()
.setAuthor({ name: msg.author.tag, iconURL: msg.author.displayAvatarURL() })
.setColor(msg.settings.embedErrorColor);

if (isNaN(query)) return this.client.util.errorEmbed(msg, msg.settings.prefix + this.help.usage, 'Incorrect Usage');

const giveaway = this.client.giveawaysManager.giveaways.find(
Expand All @@ -40,7 +36,10 @@ class RerollGiveaway extends Command {
msg.channel.send('Giveaway rerolled!');
})
.catch((e) => {
ErrorEmbed.setTitle(e);
const ErrorEmbed = new EmbedBuilder()
.setAuthor({ name: msg.author.tag, iconURL: msg.author.displayAvatarURL() })
.setColor(msg.settings.embedErrorColor)
.setDescription(e);
return msg.channel.send(ErrorEmbed);
});
}
Expand Down
54 changes: 54 additions & 0 deletions commands/Owner/export-commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const Command = require('../../base/Command.js');
const { QuickDB } = require('quick.db');

Check failure on line 2 in commands/Owner/export-commands.js

View workflow job for this annotation

GitHub Actions / eslint

'QuickDB' is assigned a value but never used
const { EmbedBuilder } = require('discord.js');
const fs = require('fs');

class ExportCommands extends Command {
constructor(client) {
super(client, {
name: 'export-commands',
description: 'Exports all commands to a JSON file.',
category: 'General',
usage: 'export-commands',
examples: ['exportcommands'],
aliases: ['exportcmds', 'exportjson'],
});
}

async run(msg, args, level) {
const allCommands = this.client.commands;
const commandData = {};

allCommands.forEach((cmd) => {
const category = cmd.help.category || 'Unknown';
const cmdName = cmd.help.name;

if (!commandData[category]) {
commandData[category] = {};
}

commandData[category][cmdName] = {
description: cmd.help.description,
usage: cmd.help.usage,
examples: cmd.help.examples,
aliases: cmd.conf.aliases,
permissionLevel: cmd.conf.permLevel,
guildOnly: cmd.conf.guildOnly,
nsfw: cmd.conf.nsfw,
longDescription: cmd.help.longDescription || 'None',
};
});

const jsonFilePath = './commands.json';
fs.writeFileSync(jsonFilePath, JSON.stringify(commandData, null, 2), 'utf-8');

const embed = new EmbedBuilder()
.setTitle('Commands Exported')
.setDescription(`All commands have been exported to \`${jsonFilePath}\``)
.setColor('#00FF00');

msg.channel.send({ embeds: [embed] });
}
}

module.exports = ExportCommands;

0 comments on commit f63dae0

Please sign in to comment.