Compare commits

..

8 commits
main ... main

Author SHA1 Message Date
Christopher Cookman 0afd3e460a Fix some stuff 2026-07-03 14:12:49 -06:00
Christopher Cookman 730508a60a Blegh 2026-07-03 14:11:05 -06:00
Christopher Cookman 66be141aad Blegh 2026-07-03 14:10:34 -06:00
Christopher Cookman bf6ed36211 Add more logs 2026-07-03 14:09:50 -06:00
Christopher Cookman 9e4f8f6f73 Blegh 2026-07-03 14:08:02 -06:00
Christopher Cookman f373da8428 add log 2026-07-03 14:07:38 -06:00
Christopher Cookman 7d9d26c14d Add debug 2026-07-03 14:07:02 -06:00
Christopher Cookman 7cb2bcad3a Blegh 2026-07-03 14:05:44 -06:00
3 changed files with 56 additions and 15 deletions

View file

@ -221,15 +221,28 @@ 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)));
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; 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);

28
moduletest.js Normal file
View 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}`);
});