swapped to a new db locally hosted

This commit is contained in:
2025-10-06 00:25:29 -04:00
parent 097583ca0a
commit ca23c0ab8c
40 changed files with 2244 additions and 556 deletions

View File

@@ -1,4 +1,4 @@
const { SlashCommandBuilder } = require('discord.js');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
module.exports = {
name: 'help',
@@ -6,20 +6,62 @@ module.exports = {
enabled: true,
builder: new SlashCommandBuilder()
.setName('help')
.setDescription('List available bot commands and what they do.'),
.setDescription('List available bot commands and what they do.')
.addStringOption(opt => opt.setName('command').setDescription('Get detailed help for a specific command').setRequired(false)),
async execute(interaction) {
const commands = Array.from(interaction.client.commands.values()).filter(cmd => !!cmd.builder);
let text = '**Available Commands:**\n\n';
const db = require('../../backend/db').readDb();
const guildSettings = db[interaction.guildId] || {};
const toggles = guildSettings.commandToggles || {};
const protectedCommands = ['manage-commands', 'help'];
try {
const api = require('../api');
// fetch authoritative commands list for this guild
const commands = await api.getCommands(interaction.guildId) || [];
for (const cmd of commands) {
const isEnabled = protectedCommands.includes(cmd.name) ? true : (toggles[cmd.name] !== false && cmd.enabled !== false);
text += `/${cmd.name}${cmd.description || 'No description.'}${isEnabled ? 'Enabled' : 'Disabled'}${protectedCommands.includes(cmd.name) ? ' (locked)' : ''}\n`;
const target = interaction.options.getString('command');
if (target) {
const found = commands.find(c => c.name.toLowerCase() === target.toLowerCase());
if (!found) {
return await interaction.reply({ content: `No command named "/${target}" found.`, flags: 64 });
}
const embed = new EmbedBuilder()
.setTitle(`/${found.name}${found.locked ? 'Locked' : (found.enabled ? 'Enabled' : 'Disabled')}`)
.setDescription(found.description || 'No description available.')
.setColor(found.enabled ? 0x22c55e : 0xe11d48)
.addFields(
{ name: 'Usage', value: `/${found.name} ${(found.usage || '').trim() || ''}` },
{ name: 'Status', value: found.locked ? 'Locked (cannot be toggled)' : (found.enabled ? 'Enabled' : 'Disabled'), inline: true },
{ name: 'Has Slash Builder', value: found.hasSlashBuilder ? 'Yes' : 'No', inline: true }
)
.setFooter({ text: 'Use /help <command> to view detailed info about a command.' });
return await interaction.reply({ embeds: [embed], flags: 64 });
}
// Build a neat embed listing commands grouped by status
const embed = new EmbedBuilder()
.setTitle('Available Commands')
.setDescription('Use `/help <command>` to get detailed info on a specific command.')
.setColor(0x5865f2);
// Sort commands: enabled first, then disabled, locked last
const sorted = commands.slice().sort((a, b) => {
const ka = a.locked ? 2 : (a.enabled ? 0 : 1);
const kb = b.locked ? 2 : (b.enabled ? 0 : 1);
if (ka !== kb) return ka - kb;
return a.name.localeCompare(b.name);
});
// Build a concise field list (max 25 fields in Discord embed)
const fields = [];
for (const cmd of sorted) {
const status = cmd.locked ? '🔒 Locked' : (cmd.enabled ? '✅ Enabled' : '⛔ Disabled');
fields.push({ name: `/${cmd.name}`, value: `${cmd.description || 'No description.'}\n${status}`, inline: false });
if (fields.length >= 24) break;
}
if (fields.length > 0) embed.addFields(fields);
else embed.setDescription('No commands available.');
return await interaction.reply({ embeds: [embed], flags: 64 });
} catch (e) {
console.error('Error in help command:', e && e.message ? e.message : e);
return await interaction.reply({ content: 'Failed to retrieve commands. Try again later.', flags: 64 });
}
await interaction.reply({ content: text, flags: 64 });
},
};