Compare commits

..

No commits in common. "main" and "main" have entirely different histories.
main ... main

3 changed files with 15 additions and 56 deletions

View file

@ -221,28 +221,15 @@ class FreepbxManager {
const startExt = process.env.START_EXT ? parseInt(process.env.START_EXT, 10) : 1000; const startExt = process.env.START_EXT ? parseInt(process.env.START_EXT, 10) : 1000;
// Remove duplicates by using a Set // Remove duplicates by using a Set
const existingExtsSet = new Set(exts.map(ext => parseInt(ext.user.extension, 10))); const existingExtsSet = new Set(exts.map(ext => parseInt(ext.user.extension, 10)));
var existingExts = Array.from(existingExtsSet).sort((a, b) => a - b); const 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; let nextExt = startExt;
for (let i = 0; i < existingExts.length; i++) { 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 (existingExts[i] !== nextExt) {
if (process.env.DEBUG == 'true') console.log(`Found gap at ${nextExt}`)
break; break;
} }
if (process.env.DEBUG == 'true') console.log(`No gap, incrementing nextExt`)
nextExt++; nextExt++;
} }
if (process.env.DEBUG == 'true') console.log(`Next available extension is ${nextExt}`)
return nextExt; return nextExt;
} }
} }

View file

@ -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}\`||`, 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 color: 0x00ff00
}], }],
// components: [ components: [
// { {
// type: 1, type: 1,
// components: [ components: [
// { {
// type: Discord.ComponentType.Button, type: Discord.ComponentType.Button,
// label: "Reset Password", label: "Reset Password",
// emoji: "🔄", emoji: "🔄",
// style: Discord.ButtonStyle.Danger, style: Discord.ButtonStyle.Danger,
// custom_id: "resetPassword" custom_id: "resetPassword"
// } }
// ] ]
// } }
// ], ],
ephemeral: true ephemeral: true
}) })
if (process.env.EXTENSION_ROLE_ID) await interaction.member.roles.add(process.env.EXTENSION_ROLE_ID); if (process.env.EXTENSION_ROLE_ID) await interaction.member.roles.add(process.env.EXTENSION_ROLE_ID);

View file

@ -1,28 +0,0 @@
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}`);
});