More commands, some buttons, and whatnot

This commit is contained in:
Christopher Cookman 2025-01-25 08:48:02 -07:00
parent 33d1c8ae9c
commit 1451549928
8 changed files with 111 additions and 62 deletions

View file

@ -4,7 +4,7 @@
- [X] **/whoami** - Get your extension info if you have one. - [X] **/whoami** - Get your extension info if you have one.
- [X] **/new** - Get an extension on the LiteNet Phone System. - [X] **/new** - Get an extension on the LiteNet Phone System.
- [X] **/delete** - Remove your extension from 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)* - [ ] **/button** - Send the "Get an extension" button! *(Requires default_member_permissions: 0)*
## Admin Commands ## Admin Commands

View file

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

View file

@ -1,40 +1,3 @@
const pool = global.pool
const fpbx = global.fpbx
const client = global.client
const log = global.log
module.exports = {}; module.exports = {};
module.exports.execute = async (interaction) => { module.exports.execute = require("../common/createExt").execute;
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 });
});
}

View file

@ -1,25 +1,3 @@
const pool = global.pool
const fpbx = global.fpbx
const client = global.client
const log = global.log
module.exports = {}; module.exports = {};
module.exports.execute = async (interaction) => { module.exports.execute = require("../common/getExtInfo").execute;
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
}
]
});
}

View file

@ -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 });
});
}

View file

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

View file

@ -0,0 +1,3 @@
module.exports = {};
module.exports.execute = require("../common/getExtInfo").execute;

View file

@ -0,0 +1,3 @@
module.exports = {};
module.exports.execute = require("../common/createExt").execute;