Add some more hub settings

This commit is contained in:
Christopher Cookman 2025-09-15 10:30:20 -06:00
parent c006e56be0
commit a55dd6c42c
4 changed files with 67 additions and 4 deletions

View file

@ -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__***" }
]
}] });

View file

@ -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') {

View file

@ -1,3 +1,2 @@
ALTER TABLE hubs
ADD COLUMN logChannel VARCHAR(255);
-- Uhh
ADD COLUMN logChannel VARCHAR(255);

View file

@ -0,0 +1,2 @@
ALTER TABLE hubs
ADD COLUMN parcelKey VARCHAR(255);