diff --git a/TODO.md b/TODO.md index 0b319cc..de1b392 100644 --- a/TODO.md +++ b/TODO.md @@ -4,7 +4,7 @@ - [X] **/whoami** - Get your extension info if you have one. - [X] **/new** - Get an extension on the LiteNet Phone System. - [X] **/delete** - Remove your extension from the LiteNet Phone System. -- [ ] **/list** - List all extensions on the LiteNet Phone System. +- [X] **/list** - List all extensions on the LiteNet Phone System. - [ ] **/button** - Send the "Get an extension" button! *(Requires default_member_permissions: 0)* ## Admin Commands diff --git a/interactionHandlers/commands/button.js b/interactionHandlers/commands/button.js new file mode 100644 index 0000000..5c94be4 --- /dev/null +++ b/interactionHandlers/commands/button.js @@ -0,0 +1,37 @@ +const pool = global.pool +const fpbx = global.fpbx +const client = global.client +const log = global.log +const Discord = require("discord.js") + +module.exports = {}; + +module.exports.execute = async (interaction) => { + interaction.channel.send({ + embeds: [{ + title: "Placeholder", + description: "I'll put the full embed here once we get it finalized.", + }], + components: [ + { + type: 1, + components: [ + { + type: Discord.ComponentType.Button, + label: "Get an Extension", + emoji: "✅", + style: Discord.ButtonStyle.Success, + custom_id: "newExtension" + }, + { + type: Discord.ComponentType.Button, + label: "Get your extension info", + emoji: "ℹ️", + style: Discord.ButtonStyle.Primary, + custom_id: "getExtensionInfo" + } + ] + } + ] + }) +} \ No newline at end of file diff --git a/interactionHandlers/commands/new.js b/interactionHandlers/commands/new.js index 90123ea..5552d3e 100644 --- a/interactionHandlers/commands/new.js +++ b/interactionHandlers/commands/new.js @@ -1,40 +1,3 @@ -const pool = global.pool -const fpbx = global.fpbx -const client = global.client -const log = global.log - module.exports = {}; -module.exports.execute = async (interaction) => { - await interaction.deferReply({ ephemeral: true }); - const [lookup] = await pool.query('SELECT * FROM discord_users WHERE discordId = ?', [interaction.user.id]); - if (lookup) { - await interaction.editReply({ content: `You already have an extension, it's ${lookup.extension}!`, ephemeral: true }); - return; - } - await interaction.editReply({ content: `Finding available extension`, ephemeral: true }); - fpbx.getNextAvailableExtension().then(async (nextExt) => { - await interaction.editReply({ content: `Found ${nextExt}. Creating..`, ephemeral: true }); - fpbx.addExtension(nextExt, interaction.user.username).then(async (res) => { - if (res.addExtension.status != true) { - await interaction.editReply({ content: `Something went wrong :(`, ephemeral: true }); - return; - } - await pool.query('INSERT INTO discord_users (discordId, extension) VALUES (?, ?)', [interaction.user.id, nextExt]); - await interaction.editReply({ content: `Extension ${nextExt} created! Getting info..`, ephemeral: true }); - await fpbx.reload(); - const extInfo = await fpbx.getExtension(nextExt); - await interaction.editReply({ embeds: [{ - title: "Your Extension Info", - description: `**PBX Address:** \`${process.env.PBX_HOSTNAME}\`\n**Extension:** \`${extInfo.fetchExtension.user.extension}\`\n**Name:** \`${extInfo.fetchExtension.user.name}\`\n**Password:** ||\`${extInfo.fetchExtension.user.extPassword}\`||`, - color: 0x00ff00 - }], ephemeral: true }) - }).catch(async (error) => { - log.error(error); - await interaction.editReply({ content: 'There was an error while creating your extension!', ephemeral: true }); - }); - }).catch(async (error) => { - log.error(error); - await interaction.editReply({ content: 'There was an error while creating your extension!', ephemeral: true }); - }); -} \ No newline at end of file +module.exports.execute = require("../common/createExt").execute; \ No newline at end of file diff --git a/interactionHandlers/commands/whoami.js b/interactionHandlers/commands/whoami.js index e19c6c0..e76d000 100644 --- a/interactionHandlers/commands/whoami.js +++ b/interactionHandlers/commands/whoami.js @@ -1,25 +1,3 @@ -const pool = global.pool -const fpbx = global.fpbx -const client = global.client -const log = global.log - module.exports = {}; -module.exports.execute = async (interaction) => { - const [lookup] = await pool.query('SELECT * FROM discord_users WHERE discordId = ?', [interaction.user.id]); - if (!lookup) { - await interaction.reply({ content: `We're sorry, It doesn't look like you have an extension!`, ephemeral: true }); - return; - } - const extInfo = await fpbx.getExtension(lookup.extension); - return await interaction.reply({ - ephemeral: true, embeds: [ - { - title: "Your Extension Info", - description: `**PBX Address:** \`${process.env.PBX_HOSTNAME}\`\n**Extension:** \`${extInfo.fetchExtension.user.extension}\`\n**Name:** \`${extInfo.fetchExtension.user.name}\`\n**Password:** ||\`${extInfo.fetchExtension.user.extPassword}\`||`, - color: 0x00ff00 - } - ] - }); - -} \ No newline at end of file +module.exports.execute = require("../common/getExtInfo").execute; \ No newline at end of file diff --git a/interactionHandlers/common/createExt.js b/interactionHandlers/common/createExt.js new file mode 100644 index 0000000..90123ea --- /dev/null +++ b/interactionHandlers/common/createExt.js @@ -0,0 +1,40 @@ +const pool = global.pool +const fpbx = global.fpbx +const client = global.client +const log = global.log + +module.exports = {}; + +module.exports.execute = async (interaction) => { + await interaction.deferReply({ ephemeral: true }); + const [lookup] = await pool.query('SELECT * FROM discord_users WHERE discordId = ?', [interaction.user.id]); + if (lookup) { + await interaction.editReply({ content: `You already have an extension, it's ${lookup.extension}!`, ephemeral: true }); + return; + } + await interaction.editReply({ content: `Finding available extension`, ephemeral: true }); + fpbx.getNextAvailableExtension().then(async (nextExt) => { + await interaction.editReply({ content: `Found ${nextExt}. Creating..`, ephemeral: true }); + fpbx.addExtension(nextExt, interaction.user.username).then(async (res) => { + if (res.addExtension.status != true) { + await interaction.editReply({ content: `Something went wrong :(`, ephemeral: true }); + return; + } + await pool.query('INSERT INTO discord_users (discordId, extension) VALUES (?, ?)', [interaction.user.id, nextExt]); + await interaction.editReply({ content: `Extension ${nextExt} created! Getting info..`, ephemeral: true }); + await fpbx.reload(); + const extInfo = await fpbx.getExtension(nextExt); + await interaction.editReply({ embeds: [{ + title: "Your Extension Info", + description: `**PBX Address:** \`${process.env.PBX_HOSTNAME}\`\n**Extension:** \`${extInfo.fetchExtension.user.extension}\`\n**Name:** \`${extInfo.fetchExtension.user.name}\`\n**Password:** ||\`${extInfo.fetchExtension.user.extPassword}\`||`, + color: 0x00ff00 + }], ephemeral: true }) + }).catch(async (error) => { + log.error(error); + await interaction.editReply({ content: 'There was an error while creating your extension!', ephemeral: true }); + }); + }).catch(async (error) => { + log.error(error); + await interaction.editReply({ content: 'There was an error while creating your extension!', ephemeral: true }); + }); +} \ No newline at end of file diff --git a/interactionHandlers/common/getExtInfo.js b/interactionHandlers/common/getExtInfo.js new file mode 100644 index 0000000..3c7ae18 --- /dev/null +++ b/interactionHandlers/common/getExtInfo.js @@ -0,0 +1,25 @@ +const pool = global.pool +const fpbx = global.fpbx +const client = global.client +const log = global.log + +module.exports = {}; + +module.exports.execute = async (interaction) => { + const [lookup] = await pool.query('SELECT * FROM discord_users WHERE discordId = ?', [interaction.user.id]); + if (!lookup) { + await interaction.reply({ content: `We're sorry, It doesn't look like you have an extension!`, ephemeral: true }); + return; + } + const extInfo = await fpbx.getExtension(lookup.extension); + return await interaction.reply({ + ephemeral: true, embeds: [ + { + title: "Your Extension Info", + description: `**PBX Address:** \`${process.env.PBX_HOSTNAME}\`\n**Extension/Username:** \`${extInfo.fetchExtension.user.extension}\`\n**Name:** \`${extInfo.fetchExtension.user.name}\`\n**Password:** ||\`${extInfo.fetchExtension.user.extPassword}\`||`, + color: 0x00ff00 + } + ] + }); + +} \ No newline at end of file diff --git a/interactionHandlers/components/getExtensionInfo.js b/interactionHandlers/components/getExtensionInfo.js new file mode 100644 index 0000000..e76d000 --- /dev/null +++ b/interactionHandlers/components/getExtensionInfo.js @@ -0,0 +1,3 @@ +module.exports = {}; + +module.exports.execute = require("../common/getExtInfo").execute; \ No newline at end of file diff --git a/interactionHandlers/components/newExtension.js b/interactionHandlers/components/newExtension.js new file mode 100644 index 0000000..5552d3e --- /dev/null +++ b/interactionHandlers/components/newExtension.js @@ -0,0 +1,3 @@ +module.exports = {}; + +module.exports.execute = require("../common/createExt").execute; \ No newline at end of file