From a55dd6c42cfd2d50fe63273b8e64f91ac1d3715c Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Mon, 15 Sep 2025 10:30:20 -0600 Subject: [PATCH] Add some more hub settings --- commands/settings.js | 2 + messageHandlers/hub_settings.js | 64 +++++++++++++++++++- migrations/006_update_hubs_add_logChannel | 3 +- migrations/008_update_hubs_add_parcelKey.sql | 2 + 4 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 migrations/008_update_hubs_add_parcelKey.sql diff --git a/commands/settings.js b/commands/settings.js index 290d6ff..aa75804 100644 --- a/commands/settings.js +++ b/commands/settings.js @@ -30,6 +30,7 @@ const execute = async (interaction) => { { 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: "Log Channel ID", value: hubResult[0].logChannel ? hubResult[0].logChannel.toString() : "Not Set" }, { name: "Secret Key", value: `||\`${hubResult[0].secretKey}\`||` } ] },{ @@ -43,6 +44,7 @@ const execute = async (interaction) => { { 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. Set Background Music", value: "Set or change the background music for this hub." }, + { name: "8. Set Log Channel", value: "Set or change the log channel for this hub." }, { name: "99. Delete hub and all products", value: "***__WARNING: THIS IS DANGEROUS__***" } ] }] }); diff --git a/messageHandlers/hub_settings.js b/messageHandlers/hub_settings.js index f76cce1..dfd6d5e 100644 --- a/messageHandlers/hub_settings.js +++ b/messageHandlers/hub_settings.js @@ -67,8 +67,8 @@ const opts = { // Map of option number to step number } }, 6: { - step: 1, exec: (hubId, uid) => { - return 'Parcel Auto-Import setup is not yet implemented. Type another option number, or `cancel` to exit.'; + step: 26, exec: (hubId, uid) => { + return 'Please provide your Parcel Secret Key. This can be found in your Parcel Settings module, or by running `/settings` on Parcel. Say `cancel` to exit.'; } }, 7: { @@ -76,6 +76,11 @@ const opts = { // Map of option number to step number return 'Please provide a Roblox Audio Asset ID, or say `none` to disable. Say `cancel` to exit.'; } }, + 8: { + step: 28, exec: (hubId, uid) => { + return 'Please provide a Discord Channel ID for logging, or say `none` to unset. Say `cancel` to exit.'; + } + }, 99: { step: 99, exec: async (hubId, uid) => { // generate a random confirmation code @@ -144,6 +149,34 @@ const execute = async (message) => { global.hubSettingsHandlers[message.author.id].step = 1; message.channel.send('Terms of Service updated.\n\nType an option number, or `cancel` to exit.'); break; + case 26: // Set Parcel Key + const parcelKey = message.content.trim(); + if (parcelKey.toLowerCase() === 'cancel') { + cancel(message.author); + return; + } + if (!/^[a-zA-Z0-9]{16,}$/.test(parcelKey)) { + message.channel.send('Invalid Parcel Secret Key. Please provide an alphanumeric string at least 16 characters long, or `cancel` to exit.'); + return; + } + + // Validate key against parcel API GET https://hub.parcelroblox.com/getSession Headers: { 'Authorization': parcelKey } should return 400 + const resp = await fetch('https://hub.parcelroblox.com/getSession', { + method: 'GET', + headers: { + 'Authorization': parcelKey + } + }); + + if (resp.status !== 400) { + message.channel.send('Parcel Secret Key validation failed. Please ensure the key is correct and has not been revoked. You can find your key in your Parcel Settings module, or by running `/settings` on Parcel.'); + return; + } + + await pool.query('UPDATE hubs SET parcelKey = ? WHERE id = ?', [parcelKey, global.hubSettingsHandlers[message.author.id].hub]); + global.hubSettingsHandlers[message.author.id].step = 1; + message.channel.send('Parcel Secret Key updated.\n\nType an option number, or `cancel` to exit.'); + break; case 27: // Set Background Music const bgmInput = message.content.trim(); if (bgmInput.toLowerCase() === 'cancel') { @@ -165,6 +198,33 @@ const execute = async (message) => { global.hubSettingsHandlers[message.author.id].step = 1; message.channel.send('Background music updated.\n\nType an option number, or `cancel` to exit.'); break; + case 28: // Set Log Channel + const channelInput = message.content.trim(); + if (channelInput.toLowerCase() === 'cancel') { + cancel(message.author); + return; + } + if (channelInput.toLowerCase() === 'none') { + await pool.query('UPDATE hubs SET logChannel = NULL WHERE id = ?', [global.hubSettingsHandlers[message.author.id].hub]); + global.hubSettingsHandlers[message.author.id].step = 1; + message.channel.send('Log channel unset.\n\nType an option number, or `cancel` to exit.'); + return; + } + const channelId = channelInput; + const channel = await client.channels.fetch(channelId).catch(() => null); + if (!channel) { + message.channel.send('Invalid Channel ID. Please provide a valid Discord Channel ID, or `none` to unset, or `cancel` to exit.'); + return; + } + channel.send("NotParcel will use this channel for logging important hub events.").then(() => { + pool.query('UPDATE hubs SET logChannel = ? WHERE id = ?', [channelId, global.hubSettingsHandlers[message.author.id].hub]); + global.hubSettingsHandlers[message.author.id].step = 1; + message.channel.send('Log channel updated.\n\nType an option number, or `cancel` to exit.'); + }).catch(() => { + message.channel.send('Failed to send a test message to the specified channel. Please ensure the bot has permission to send messages in that channel. Send a valid Discord Channel ID, or `none` to unset, or `cancel` to exit.'); + return; + }); + break; case 99: // Delete Hub const confirmMatch = message.content.trim().match(/^confirm (\w{16})$/); if (message.content.toLowerCase() === 'cancel') { diff --git a/migrations/006_update_hubs_add_logChannel b/migrations/006_update_hubs_add_logChannel index 9b3f9c3..f4c85c2 100644 --- a/migrations/006_update_hubs_add_logChannel +++ b/migrations/006_update_hubs_add_logChannel @@ -1,3 +1,2 @@ ALTER TABLE hubs -ADD COLUMN logChannel VARCHAR(255); --- Uhh \ No newline at end of file +ADD COLUMN logChannel VARCHAR(255); \ No newline at end of file diff --git a/migrations/008_update_hubs_add_parcelKey.sql b/migrations/008_update_hubs_add_parcelKey.sql new file mode 100644 index 0000000..6805dae --- /dev/null +++ b/migrations/008_update_hubs_add_parcelKey.sql @@ -0,0 +1,2 @@ +ALTER TABLE hubs +ADD COLUMN parcelKey VARCHAR(255); \ No newline at end of file