This commit is contained in:
Christopher Cookman 2026-06-14 12:29:24 -06:00
parent 330a769b88
commit 42bb858134

View file

@ -11,55 +11,54 @@ module.exports = (interaction, client, bvs) => {
return interaction.reply({ content: `You must be boosting the server to use this command.`, ephemeral: true }); return interaction.reply({ content: `You must be boosting the server to use this command.`, ephemeral: true });
} }
const choice = interaction.options.getNumber('choice');
if (!choice) {
return interaction.reply({ content: `You must provide a choice from the latest run of \`/searchnumbers\`. Use \`/searchnumbers\` to see available DIDs and their corresponding choices.`, ephemeral: true });
}
if (global.purchaseConfirmations && global.purchaseConfirmations[interaction.user.id]) {
if (choice === 1) {
// proceed with purchase
const didToPurchase = global.purchaseConfirmations[interaction.user.id];
delete global.purchaseConfirmations[interaction.user.id];
delete global.tempPurchasableDIDs[interaction.user.id];
interaction.deferReply({ ephemeral: true }).then(() => {
// bvs.purchaseDID(didToPurchase, interaction.user.id).then(() => {
// interaction.editReply({ content: `Successfully purchased DID \`${bvs.formatPhoneNumber(didToPurchase)}\`. It may take a few minutes for the purchase to fully process. Please allow up to 5 hours for the number to become active. If you are having issues, please contact support!`, ephemeral: true });
// }).catch(error => {
// console.error("Error purchasing DID:", error);
// interaction.editReply({ content: `There was an error purchasing the DID. Please try again later.`, ephemeral: true });
// });
// DB Stuff for FreePBX
// check 'discord_users' table to get the users extension
global.db.query("SELECT extension FROM discord_users WHERE discordId = ?", [interaction.user.id]).then(results => {
if (results.length === 0) {
return interaction.editReply({ content: `You somehow got this far and don't actually have an extension. Go make one, then try again.`, ephemeral: true });
} else {
const extension = results[0].extension;
return interaction.editReply({ content: `dev: ${extension}` })
}
}).catch(error => {
console.error("Database error:", error);
return interaction.editReply({ content: `There was a database error. Please try again later.`, ephemeral: true });
});
});
// todo: impl actually buying did
} else {
delete global.purchaseConfirmations[interaction.user.id];
return interaction.reply({ content: `Cancelled. You can either choose a different DID from the latest run of \`/searchnumbers\` or start a new search by running \`/searchnumbers\` again.`, ephemeral: true });
}
}
if (!global.tempPurchasableDIDs || !global.tempPurchasableDIDs[interaction.user.id]) {
return interaction.reply({ content: `You must provide a choice from the latest run of \`/searchnumbers\`. Use \`/searchnumbers\` to see available DIDs and their corresponding choices.`, ephemeral: true });
}
// Check that the member doesn't already have a number. // Check that the member doesn't already have a number.
bvs.getPremiumDIDs().then(dids => { bvs.getPremiumDIDs().then(dids => {
const userDIDs = dids.filter(did => did.userId === interaction.user.id); const userDIDs = dids.filter(did => did.userId === interaction.user.id);
if (userDIDs.length === 0) { if (userDIDs.length === 0) {
const choice = interaction.options.getNumber('choice');
if (!choice) {
return interaction.reply({ content: `You must provide a choice from the latest run of \`/searchnumbers\`. Use \`/searchnumbers\` to see available DIDs and their corresponding choices.`, ephemeral: true });
}
if (global.purchaseConfirmations && global.purchaseConfirmations[interaction.user.id]) {
if (choice === 1) {
// proceed with purchase
const didToPurchase = global.purchaseConfirmations[interaction.user.id];
delete global.purchaseConfirmations[interaction.user.id];
delete global.tempPurchasableDIDs[interaction.user.id];
interaction.deferReply({ ephemeral: true }).then(() => {
// bvs.purchaseDID(didToPurchase, interaction.user.id).then(() => {
// interaction.editReply({ content: `Successfully purchased DID \`${bvs.formatPhoneNumber(didToPurchase)}\`. It may take a few minutes for the purchase to fully process. Please allow up to 5 hours for the number to become active. If you are having issues, please contact support!`, ephemeral: true });
// }).catch(error => {
// console.error("Error purchasing DID:", error);
// interaction.editReply({ content: `There was an error purchasing the DID. Please try again later.`, ephemeral: true });
// });
// DB Stuff for FreePBX
// check 'discord_users' table to get the users extension
global.db.query("SELECT extension FROM discord_users WHERE discordId = ?", [interaction.user.id]).then(results => {
if (results.length === 0) {
return interaction.editReply({ content: `You somehow got this far and don't actually have an extension. Go make one, then try again.`, ephemeral: true });
} else {
const extension = results[0].extension;
return interaction.editReply({ content: `dev: ${extension}`})
}
}).catch(error => {
console.error("Database error:", error);
return interaction.editReply({ content: `There was a database error. Please try again later.`, ephemeral: true });
});
});
// todo: impl actually buying did
} else {
delete global.purchaseConfirmations[interaction.user.id];
return interaction.reply({ content: `Cancelled. You can either choose a different DID from the latest run of \`/searchnumbers\` or start a new search by running \`/searchnumbers\` again.`, ephemeral: true });
}
}
if (!global.tempPurchasableDIDs || !global.tempPurchasableDIDs[interaction.user.id]) {
return interaction.reply({ content: `You must provide a choice from the latest run of \`/searchnumbers\`. Use \`/searchnumbers\` to see available DIDs and their corresponding choices.`, ephemeral: true });
}
const dids = global.tempPurchasableDIDs[interaction.user.id]; const dids = global.tempPurchasableDIDs[interaction.user.id];
const index = parseInt(choice) - 1; const index = parseInt(choice) - 1;
if (isNaN(index) || index < 0 || index >= dids.length) { if (isNaN(index) || index < 0 || index >= dids.length) {