diff --git a/bvs.js b/bvs.js index f6009d7..31af0dc 100644 --- a/bvs.js +++ b/bvs.js @@ -207,5 +207,6 @@ module.exports = { searchDIDs, searchPurchasableDIDs, purchaseDID, - formatPhoneNumber + formatPhoneNumber, + deleteDID } \ No newline at end of file diff --git a/bvsTest.js b/bvsTest.js index 2ace6a7..a51e41a 100644 --- a/bvsTest.js +++ b/bvsTest.js @@ -37,4 +37,6 @@ bvs.searchPurchasableDIDs("910").then(dids => { } }).catch(error => { console.error("Error fetching DIDs with user ID 610548:", error); -}); \ No newline at end of file +}); + +console.log(bvs.deleteDID("15803163827")); \ No newline at end of file diff --git a/interactions/chatCommand/getnumber.js b/interactions/chatCommand/getnumber.js index dbb70ff..1c3b88e 100644 --- a/interactions/chatCommand/getnumber.js +++ b/interactions/chatCommand/getnumber.js @@ -36,8 +36,34 @@ module.exports = (interaction, client, bvs) => { 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}` }) + // Buy the thing + bvs.purchaseDID(didToPurchase, interaction.user.id).then(() => { + console.log(`Successfully purchased DID ${didToPurchase} for user ${interaction.user.id}`); + const extension = results[0].extension; + // insert into incoming, set extension = "+{did}", destination = from-did-direct,{extension},1, description = "NitroDID For {displayName} ({discordId})" + global.db.query("INSERT INTO incoming (extension, destination, description) VALUES (?, ?, ?)", [`+${didToPurchase}`, `from-did-direct,${extension},1`, `NitroDID For ${interaction.user.displayName} (${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 }); + // Run `fwconsole reload` on host + const { exec } = require("child_process"); + exec("fwconsole reload", (error, stdout, stderr) => { + if (error) { + console.error("Error reloading FreePBX:", error); + return; + } + if (stderr) { + console.error("Error output from reloading FreePBX:", stderr); + return; + } + console.log("Successfully reloaded FreePBX:", stdout); + }); + }).catch(error => { + console.error("Error inserting into database:", error); + return interaction.editReply({ content: `There was an error setting up your DID in the database. Please contact support!`, ephemeral: true }); + }); + }).catch(error => { + console.error("Error purchasing DID:", error); + return interaction.editReply({ content: `There was an error purchasing the DID. Please try again later.`, ephemeral: true }); + }); } }).catch(error => { console.error("Database error:", error);