Add a little bit of color :)

This commit is contained in:
Christopher Cookman 2023-04-23 16:09:03 -06:00
parent 681142330c
commit 33fbad2a1e
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42
3 changed files with 31 additions and 15 deletions

View file

@ -1,7 +1,7 @@
//Load static files //Load static files
const config = require("./config.json"); const config = require("./config.json");
const funcs = require("./funcs.js"); const funcs = require("./funcs.js");
const colors = require("colors");
// FreePBX GraphQL Client // FreePBX GraphQL Client
const { const {
FreepbxGqlClient, FreepbxGqlClient,
@ -213,21 +213,21 @@ const rest = new REST({
}).setToken(config.discord.token); }).setToken(config.discord.token);
dcClient.on('ready', () => { dcClient.on('ready', () => {
console.log(`Logged in as ${dcClient.user.tag}!`); console.log(`${colors.cyan("[INFO]")} Logged in as ${dcClient.user.tag}!`);
// Set up application commands // Set up application commands
const commands = require('./commands.json'); const commands = require('./commands.json');
(async () => { (async () => {
try { try {
console.log('Started refreshing application (/) commands.'); console.log(`${colors.cyan("[INFO]")} Started refreshing application (/) commands.`);
await rest.put( await rest.put(
Routes.applicationGuildCommands(dcClient.user.id, config.discord.guildId), { Routes.applicationGuildCommands(dcClient.user.id, config.discord.guildId), {
body: commands body: commands
} }
); );
console.log('Successfully reloaded application (/) commands.'); console.log(`${colors.cyan("[INFO]")} Successfully reloaded application (/) commands.`);
} catch (error) { } catch (error) {
console.error(error); console.error(`${colors.red("[ERROR]")} ${error}`);
} }
})(); })();
@ -241,7 +241,7 @@ dcClient.on('ready', () => {
status: "online" status: "online"
}); });
}).catch((error) => { }).catch((error) => {
console.log(error); console.log(`${colors.red("[ERROR]")} ${error}`);
}); });
// Run every 5 minutes // Run every 5 minutes
@ -255,7 +255,7 @@ dcClient.on('ready', () => {
status: "online" status: "online"
}); });
}).catch((error) => { }).catch((error) => {
console.log(error); console.log(`${colors.red("[ERROR]")} ${error}`);
}); });
}, 300000); }, 300000);
@ -271,10 +271,11 @@ dcClient.on('ready', () => {
// They're in the server, do nothing // They're in the server, do nothing
}).catch((error) => { }).catch((error) => {
// They're not in the server, delete the extension // They're not in the server, delete the extension
console.log(`${colors.cyan("[INFO]")} ${extension.user.extension} is not in the server, deleting it`);
deleteExtension(extension.user.extension).then((result) => { deleteExtension(extension.user.extension).then((result) => {
console.log(`Deleted extension ${extension.user.extension} because the user is no longer in the server`); console.log(`${colors.cyan("[INFO]")} Deleted extension ${extension.user.extension} because the user is no longer in the server`);
}).catch((error) => { }).catch((error) => {
console.log(error); console.log(`${colors.red("[ERROR]")} ${error}`);
}); });
}); });
@ -287,18 +288,18 @@ dcClient.on('ready', () => {
dcClient.on("guildMemberRemove", (member) => { dcClient.on("guildMemberRemove", (member) => {
// Delete the extension if the user leaves the server // Delete the extension if the user leaves the server
console.log(`User ${member.id} left the server`) console.log(`${colors.cyan("[INFO]")} User ${member.id} left the server`)
lookupExtension(member.id, "uid").then((result) => { lookupExtension(member.id, "uid").then((result) => {
if (result.status == "exists") { if (result.status == "exists") {
console.log(`User ${member.id} has extension ${result.result.fetchVoiceMail.extension}, deleting it`) console.log(`${colors.cyan("[INFO]")} User ${member.id} has extension ${result.result.fetchVoiceMail.extension}, deleting it`)
deleteExtension(result.result.fetchVoiceMail.extension).then((result) => { deleteExtension(result.result.fetchVoiceMail.extension).then((result) => {
console.log(`Deleted extension ${result.result.fetchVoiceMail.extension} because the user left the server`); console.log(`${colors.cyan("[INFO]")} Deleted extension ${result.result.fetchVoiceMail.extension} because the user left the server`);
}).catch((error) => { }).catch((error) => {
console.log(error); console.log(`${colors.red("[ERROR]")} ${error}`);
}); });
} }
}).catch((error) => { }).catch((error) => {
console.log(error); console.log(`${colors.red("[ERROR]")} ${error}`);
}); });
}); });
@ -389,7 +390,7 @@ dcClient.on('interactionCreate', async interaction => {
} }
}).catch((error) => { }).catch((error) => {
// The user doesn't have an extension, create one // The user doesn't have an extension, create one
console.log(error) console.log(`${colors.red("[ERROR]")} ${error}`)
interaction.editReply({ interaction.editReply({
content: "You don't have an extension!", content: "You don't have an extension!",
ephemeral: true ephemeral: true

14
package-lock.json generated
View file

@ -9,6 +9,7 @@
"version": "1.0.0", "version": "1.0.0",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"colors": "^1.4.0",
"discord.js": "^14.7.1", "discord.js": "^14.7.1",
"freepbx-graphql-client": "^0.1.1", "freepbx-graphql-client": "^0.1.1",
"sqlite3": "^5.1.4" "sqlite3": "^5.1.4"
@ -323,6 +324,14 @@
"color-support": "bin.js" "color-support": "bin.js"
} }
}, },
"node_modules/colors": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
"integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==",
"engines": {
"node": ">=0.1.90"
}
},
"node_modules/combined-stream": { "node_modules/combined-stream": {
"version": "1.0.8", "version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
@ -1764,6 +1773,11 @@
"resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz", "resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz",
"integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==" "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg=="
}, },
"colors": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
"integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA=="
},
"combined-stream": { "combined-stream": {
"version": "1.0.8", "version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",

View file

@ -9,6 +9,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"colors": "^1.4.0",
"discord.js": "^14.7.1", "discord.js": "^14.7.1",
"freepbx-graphql-client": "^0.1.1", "freepbx-graphql-client": "^0.1.1",
"sqlite3": "^5.1.4" "sqlite3": "^5.1.4"