Add CompanyID functionality.

This commit is contained in:
Alexandertp 2024-11-20 01:48:03 +01:00
parent 02863e7c1d
commit 819ca2fd52
2 changed files with 126 additions and 18 deletions

View File

@ -1,5 +1,5 @@
import dotenv from 'dotenv';
import {Client, IntentsBitField} from 'discord.js';
import {Client, IntentsBitField, EmbedBuilder} from 'discord.js';
import sqlite3 from 'sqlite3';
const db = new sqlite3.Database("./db/employeescoreboard.db", sqlite3.OPEN_READWRITE,(err) => {
@ -26,12 +26,18 @@ client.on('ready', (c) => {
//Chat commands are handled here
client.on('interactionCreate', async(interaction) => {
if (!interaction.isChatInputCommand()) return;
let isManager = await interaction.member.roles.cache.some(role => role.name === 'Manager');
if (interaction.commandName === 'croak') {
interaction.reply('Croak!');
}
if (interaction.commandName === 'gear') {
if (interaction.commandName == 'companyid') {
let employeeCard = await EmployeeCardEmbed(interaction.options.get('employee').value);
interaction.reply({embeds: [employeeCard]});
}
if (interaction.commandName === 'gear' && isManager) {
const addRemove = interaction.options.get('addremove').value;
const gearType = interaction.options.get('geartype').value;
const employee = interaction.options.get('employee').value;
@ -40,10 +46,12 @@ client.on('interactionCreate', async(interaction) => {
interaction.reply(`Added a gear to ${employee}`)
};
}
} else if (interaction.commandName === 'gear' && !isManager) {
interaction.reply("You aren't a manager! Get back to work.")
};
if (interaction.commandName === 'employee') {
const hireFirePromote = interaction.options.get('hire-fire-promote').value;
if (interaction.commandName === 'employee' && isManager) {
const hireFirePromote = interaction.options.get('hire-fire').value;
const employeeName = interaction.options.get('employee-name').value;
if (hireFirePromote == 'hire') {
CreateEmployee(employeeName);
@ -52,28 +60,36 @@ client.on('interactionCreate', async(interaction) => {
if (hireFirePromote == 'fire') {
DeleteEmployee(employeeName);
}
}
} else if (interaction.commandName === 'employee' && !isManager) {
interaction.reply("You aren't a manager! Get back to work.")
};
if (interaction.commandName === 'promote') {
if (interaction.commandName === 'promote' && isManager) {
const employeeName = interaction.options.get('employee-name').value;
const rank = interaction.options.get('rank').value;
PromoteEmployee(employeeName, rank);
interaction.reply(`Changed ${employeeName}\'s rank to ${rank}`);
}
} else if (interaction.commandName === 'promote' && !isManager) {
interaction.reply("You aren't a manager! Get back to work.")
};
if (interaction.commandName === 'scoreboard') {
if (interaction.commandName === 'rename' && isManager) {
RenameEmployee(interaction.options.get('old-name').value,interaction.options.get('new-name').value)
interaction.reply(`Renamed ${interaction.options.get('old-name').value} to ${interaction.options.get('new-name').value}`)
} else if (interaction.commandName === 'promote' && !isManager) {
interaction.reply("You aren't a manager! Get back to work.")
};
if (interaction.commandName === 'scoreboard' && isManager) {
const updateOrDisplay = interaction.options.get('update-display').value;
if (updateOrDisplay == 'display') {
const gearchannel = client.channels.cache.get('1306669146804715693');
let scoreBoardMessage = await BuildScoreboard("Beastboss");
const gearchannel = client.channels.cache.get('1255024866797682779');
let scoreBoardMessage = await BuildScoreboard("Beastboss");
scoreBoardMessage += await BuildScoreboard("Manager");
scoreBoardMessage += await BuildScoreboard("Muscle");
scoreBoardMessage += await BuildScoreboard("Moneymaker");
scoreBoardMessage += await BuildScoreboard("Mystic");
scoreBoardMessage += await BuildScoreboard("Intern");
if (updateOrDisplay == 'display') {
console.log("Scoreboard goes here: " + scoreBoardMessage);
if (scoreBoardMessage != "") {
@ -84,6 +100,11 @@ client.on('interactionCreate', async(interaction) => {
console.log("Something went wrong when building the scoreboard.");
};
};
if (updateOrDisplay == 'update') {
}
} else if (interaction.commandName === 'scoreboard' && !isManager) {
interaction.reply("You aren't a manager! Get back to work.")
};
});
@ -104,6 +125,60 @@ function AddGear(Type,Employee) {
if (Type != "coppergear" && Type != "silvergear" && Type != "goldgear" && Type != "purplegear") return
db.run(`UPDATE Employees SET ${Type} = ${Type} + 1 WHERE name = \'${Employee}\' `)
};
function RemoveGear(Type, Employee) {
if (Type != "coppergear" && Type != "silvergear" && Type != "goldgear" && Type != "purplegear") return
db.run(`UPDATE Employees SET ${Type} = ${Type} - 1 WHERE name = \'${Employee}\'`)
}
function RenameEmployee(oldName, newName) {
db.run(`UPDATE Employees SET name = \'${newName}\' WHERE name = \'${oldName}\'`);
}
function EmployeeCardEmbed(employeeName) {
return new Promise((resolve) => {
db.get(`SELECT name, rank, coppergear, silvergear, purplegear, copperswog, silverswog, goldswog, purpleswog FROM Employees WHERE name = \'${employeeName}\'`, (err, character) => {
if (err != null) {console.log(err.message)};
let copperGearString = " ";
console.log(character.coppergear);
for (let i = 0; i < character.coppergear; i++) {
copperGearString += "<:coppergear:1308166341622235179>";
};
let silverGearString = " ";
console.log(character.silvergear);
for (let i = 0; i < character.silvergear; i++) {
silverGearString += ":gear:";
};
let goldGearString = " ";
console.log(character.goldgear);
for(let i = 0; i < character.goldgear; i++) {
goldGearString += "<:goldgear:1308166365550481499>";
};
let purplegearString =" ";
console.log(character.purplegear);
for(let i = 0; i< character.purplegear; i++) {
purplegearString += "<:purplegear:1308166392864051250>";
};
const employeeCard = new EmbedBuilder()
.setColor(0x388E3C)
.setTitle(employeeName)
.setDescription(character.rank)
.addFields(
{name:`Copper`, value: copperGearString, inline: true},
{name:'Silver', value: silverGearString, inline: true},
{name:'Purple', value: purplegearString, inline: true},
)
.addFields(
{name:'Gold', value: goldGearString, inline: true},
)
.setFooter({text: 'ID Issued by Gearbeast Inc. Do not copy.'});
resolve(employeeCard);
});
})
}
function BuildScoreboard(rank) {
return new Promise((resolve) => {
@ -139,7 +214,7 @@ function BuildScoreboard(rank) {
if(character.purplegear > 0) {purplegearString += "\n## "};
for(let i = 0; i< character.purplegear; i++) {
purplegearString += "<:purplegear:1308166392864051250>";
}
};
messageContent += `**${character.name}** ${goldGearString} ${purplegearString} ${silverGearString} ${copperGearString} \n`;
}, () => {resolve(messageContent); });
@ -147,4 +222,8 @@ function BuildScoreboard(rank) {
};
function intToGearString(coppergearInt, silvergearInt, goldgearInt, copperswogInt, silverswogInt, goldswogInt) {
}
client.login(process.env.DISCORD_TOKEN);

View File

@ -10,6 +10,18 @@ const commands = [
name: 'croak',
description: 'Makes Sir Hornsworth Croak!',
},
{
name: 'companyid',
description: 'Request a Comapny ID of a specific employee',
options: [
{
name: 'employee',
description: 'Who do you want the id of?',
type: ApplicationCommandOptionType.String,
required: true,
}
]
},
{
name: 'gear',
description: 'Add or remove a gear to an employee',
@ -39,7 +51,7 @@ const commands = [
description: 'Hire or Fire an employee',
options: [
{
name: 'hire-fire-promote',
name: 'hire-fire',
description: 'Hiring or Firing?',
type: ApplicationCommandOptionType.String,
required: true,
@ -70,6 +82,23 @@ const commands = [
}
]
},
{
name: 'rename',
description: 'Rename an Employee',
options: [
{
name: 'old-name',
description: 'The old name of the employee',
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: 'new-name',
description: 'The new name of the employee',
type: ApplicationCommandOptionType.String,
}
]
},
{
name: 'scoreboard',
description: 'Related to the scoreboard',