Compare commits
8 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0afd3e460a | ||
|
|
730508a60a | ||
|
|
66be141aad | ||
|
|
bf6ed36211 | ||
|
|
9e4f8f6f73 | ||
|
|
f373da8428 | ||
|
|
7d9d26c14d | ||
|
|
7cb2bcad3a |
15
freepbx.js
15
freepbx.js
|
|
@ -221,15 +221,28 @@ class FreepbxManager {
|
|||
const startExt = process.env.START_EXT ? parseInt(process.env.START_EXT, 10) : 1000;
|
||||
// Remove duplicates by using a Set
|
||||
const existingExtsSet = new Set(exts.map(ext => parseInt(ext.user.extension, 10)));
|
||||
const existingExts = Array.from(existingExtsSet).sort((a, b) => a - b);
|
||||
var existingExts = Array.from(existingExtsSet).sort((a, b) => a - b);
|
||||
|
||||
// Filter out extensions that are less than the starting extension
|
||||
existingExts = existingExts.filter(ext => ext >= startExt);
|
||||
|
||||
if (process.env.DEBUG == 'true') {
|
||||
console.log(`Existing extensions: ${existingExts.join(', ')}`);
|
||||
console.log(`Starting extension: ${startExt}`);
|
||||
// console.log(`Next available extension: ${this.findNextAvailableExtension(existingExts, startExt)}`);
|
||||
}
|
||||
|
||||
let nextExt = startExt;
|
||||
for (let i = 0; i < existingExts.length; i++) {
|
||||
if (process.env.DEBUG == 'true') console.log(`Finding next, cur is ${nextExt}`)
|
||||
if (existingExts[i] !== nextExt) {
|
||||
if (process.env.DEBUG == 'true') console.log(`Found gap at ${nextExt}`)
|
||||
break;
|
||||
}
|
||||
if (process.env.DEBUG == 'true') console.log(`No gap, incrementing nextExt`)
|
||||
nextExt++;
|
||||
}
|
||||
if (process.env.DEBUG == 'true') console.log(`Next available extension is ${nextExt}`)
|
||||
return nextExt;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,20 +30,20 @@ module.exports.execute = async (interaction) => {
|
|||
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
|
||||
}],
|
||||
components: [
|
||||
{
|
||||
type: 1,
|
||||
components: [
|
||||
{
|
||||
type: Discord.ComponentType.Button,
|
||||
label: "Reset Password",
|
||||
emoji: "🔄",
|
||||
style: Discord.ButtonStyle.Danger,
|
||||
custom_id: "resetPassword"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
// components: [
|
||||
// {
|
||||
// type: 1,
|
||||
// components: [
|
||||
// {
|
||||
// type: Discord.ComponentType.Button,
|
||||
// label: "Reset Password",
|
||||
// emoji: "🔄",
|
||||
// style: Discord.ButtonStyle.Danger,
|
||||
// custom_id: "resetPassword"
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// ],
|
||||
ephemeral: true
|
||||
})
|
||||
if (process.env.EXTENSION_ROLE_ID) await interaction.member.roles.add(process.env.EXTENSION_ROLE_ID);
|
||||
|
|
|
|||
28
moduletest.js
Normal file
28
moduletest.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
require("dotenv").config();
|
||||
const cron = require("node-cron")
|
||||
const fs = require('fs');
|
||||
const mariadb = require("mariadb");
|
||||
const pool = mariadb.createPool({
|
||||
host: process.env.DB_HOST,
|
||||
port: process.env.DB_PORT || 3306,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASS,
|
||||
database: "asterisk",
|
||||
connectionLimit: 5,
|
||||
});
|
||||
|
||||
console.log(process.env)
|
||||
|
||||
const FreepbxManager = require("./freepbx");
|
||||
const fpbx = new FreepbxManager({
|
||||
url: process.env.FREEPBX_URL,
|
||||
clientId: process.env.FREEPBX_CLIENT_ID,
|
||||
clientSecret: process.env.FREEPBX_CLIENT_SECRET,
|
||||
dbPool: pool,
|
||||
});
|
||||
|
||||
fpbx.getNextAvailableExtension().then((ext) => {
|
||||
console.log(`Next available extension: ${ext}`);
|
||||
}).catch((err) => {
|
||||
console.error(`Error getting next available extension: ${err}`);
|
||||
});
|
||||
Loading…
Reference in a new issue