NotParcel/commands/settings.js
2025-09-15 06:53:37 -06:00

62 lines
3.1 KiB
JavaScript

const client = global.discord_client
const pool = global.db_pool;
const hubSettingsHandler = require('../messageHandlers/hub_settings.js');
if (!global.hubSettingsHandlers) global.hubSettingsHandlers = {};
const execute = async (interaction) => {
if (!interaction.guildId) return interaction.reply({ content: "This command can only be used in a server", ephemeral: true });
if (global.hubSettingsHandlers[interaction.user.id]) return interaction.reply({ content: "See DMs!", ephemeral: true });
try {
const guildId = interaction.guildId;
const hubResult = await pool.query(`SELECT * FROM hubs WHERE discordGuild = ?`, [guildId]);
if (hubResult.length === 0) {
delete global.hubSettingsHandlers[interaction.user.id];
return interaction.reply({ content: "This guild does not have a hub set up!", ephemeral: true });
}
// Proceed with settings menu
await interaction.reply({ ephemeral: true, content: "Getting things ready..." });
await interaction.user.send({ embeds: [{
title: 'Welcome to Hub Settings!',
description: 'Below are your current hub settings.',
color: 0x00AE86,
fields: [
{ name: "Hub ID", value: hubResult[0].id },
{ name: "Hub Name", value: hubResult[0].name },
{ name: "Owner Discord ID", value: hubResult[0].ownerId.toString() },
{ name: "Discord Guild ID", value: hubResult[0].discordGuild.toString() },
{ name: "Short Description", value: hubResult[0].shortDescription },
{ name: "Long Description", value: hubResult[0].longDescription },
{ name: "Allow Gift Purchase", value: hubResult[0].allowGiftPurchase ? "Yes" : "No" },
{ name: "Terms of Service", value: hubResult[0].tos },
{ name: "Background Music ID", value: hubResult[0].bgmId ? hubResult[0].bgmId.toString() : "None" },
{ name: "Secret Key", value: `||\`${hubResult[0].secretKey}\`||` }
]
},{
description: `Options`,
color: 0x00AE86,
fields: [
{ name: "1. Edit Short Description", value: "Change the short description of the hub." },
{ name: "2. Edit Long Description", value: "Change the long description of the hub." },
{ name: "3. Toggle Allow Gift Purchase", value: "Enable or disable allowing users to buy gifts for others on this hub." },
{ name: "4. Edit Terms of Service", value: "Change the terms of service for this hub." },
{ name: "5. Regenerate Secret Key", value: "Generate a new secret key for this hub. (Old key will be invalidated)" },
{ name: "6. Parcel Auto-Import", value: "Set up automatic importing of Parcel purchases when linking." },
{ name: "7. Delete hub and all products", value: "***__WARNING: THIS IS DANGEROUS__***" }
]
}] });
await interaction.user.send({ content: "Say an option number, or `cancel` to exit!" });
interaction.editReply({ephemeral: true, content: "Check your DMs!"});
global.hubSettingsHandlers[interaction.user.id] = {
step: 1,
hub: hubResult[0].id
};
global.dmHandlers[interaction.user.id] = hubSettingsHandler;
} catch (err) {
console.error(err);
delete global.productCreationData[interaction.user.id];
return interaction.editReply({ content: "An error occurred.", ephemeral: true });
}
};
module.exports = { execute }