Compare commits

..

No commits in common. "eee43d2976cf1aebb3f2d441523dc9cd9f34333e" and "1e99783d0e27ce316d665ed71d7b2e62f841c104" have entirely different histories.

2 changed files with 30 additions and 191 deletions

View File

@ -1,5 +1,5 @@
import dotenv from 'dotenv'; import dotenv from 'dotenv';
import {Client, IntentsBitField, EmbedBuilder, MessageManager} from 'discord.js'; import {Client, IntentsBitField} from 'discord.js';
import sqlite3 from 'sqlite3'; import sqlite3 from 'sqlite3';
const db = new sqlite3.Database("./db/employeescoreboard.db", sqlite3.OPEN_READWRITE,(err) => { const db = new sqlite3.Database("./db/employeescoreboard.db", sqlite3.OPEN_READWRITE,(err) => {
@ -10,7 +10,6 @@ const db = new sqlite3.Database("./db/employeescoreboard.db", sqlite3.OPEN_READW
dotenv.config(); dotenv.config();
const client = new Client({ const client = new Client({
intents: [ intents: [
IntentsBitField.Flags.Guilds, IntentsBitField.Flags.Guilds,
@ -20,7 +19,6 @@ const client = new Client({
] ]
}); });
client
client.on('ready', (c) => { client.on('ready', (c) => {
console.log('The Swog is prepared.'); console.log('The Swog is prepared.');
@ -28,23 +26,12 @@ client.on('ready', (c) => {
//Chat commands are handled here //Chat commands are handled here
client.on('interactionCreate', async(interaction) => { client.on('interactionCreate', async(interaction) => {
if (!interaction.isChatInputCommand()) return; if (!interaction.isChatInputCommand()) return;
let isManager = await interaction.member.roles.cache.some(role => role.name === 'Manager');
if (interaction.commandName === 'croak') { if (interaction.commandName === 'croak') {
interaction.reply('Croak!'); interaction.reply('Croak!');
}; }
if (interaction.commandName == 'companyid') { if (interaction.commandName === 'gear') {
let employeeCard = await EmployeeCardEmbed(interaction.options.get('employee').value);
if (typeof employeeCard === 'string') {
interaction.reply(employeeCard);
}
else {
interaction.reply({embeds: [employeeCard]});
}
};
if (interaction.commandName === 'gear' && isManager) {
const addRemove = interaction.options.get('addremove').value; const addRemove = interaction.options.get('addremove').value;
const gearType = interaction.options.get('geartype').value; const gearType = interaction.options.get('geartype').value;
const employee = interaction.options.get('employee').value; const employee = interaction.options.get('employee').value;
@ -53,12 +40,10 @@ client.on('interactionCreate', async(interaction) => {
interaction.reply(`Added a gear to ${employee}`) 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' && isManager) { if (interaction.commandName === 'employee') {
const hireFirePromote = interaction.options.get('hire-fire').value; const hireFirePromote = interaction.options.get('hire-fire-promote').value;
const employeeName = interaction.options.get('employee-name').value; const employeeName = interaction.options.get('employee-name').value;
if (hireFirePromote == 'hire') { if (hireFirePromote == 'hire') {
CreateEmployee(employeeName); CreateEmployee(employeeName);
@ -66,40 +51,23 @@ client.on('interactionCreate', async(interaction) => {
} }
if (hireFirePromote == 'fire') { if (hireFirePromote == 'fire') {
DeleteEmployee(employeeName); DeleteEmployee(employeeName);
interaction.reply(`Fired ${employeeName}`)
} }
} else if (interaction.commandName === 'employee' && !isManager) { }
interaction.reply("You aren't a manager! Get back to work.")
};
if (interaction.commandName === 'promote' && isManager) { if (interaction.commandName === 'promote') {
const employeeName = interaction.options.get('employee-name').value; const employeeName = interaction.options.get('employee-name').value;
const rank = interaction.options.get('rank').value; const rank = interaction.options.get('rank').value;
PromoteEmployee(employeeName, rank); PromoteEmployee(employeeName, rank);
interaction.reply(`Changed ${employeeName}\'s rank to ${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 === 'rename' && isManager) { if (interaction.commandName === 'scoreboard') {
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; const updateOrDisplay = interaction.options.get('update-display').value;
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') { if (updateOrDisplay == 'display') {
const gearchannel = client.channels.cache.get('1306669146804715693');
let scoreBoardMessage = await BuildScoreboard();
console.log("Scoreboard goes here: " + scoreBoardMessage); console.log("Scoreboard goes here: " + scoreBoardMessage);
if (scoreBoardMessage != "") { if (scoreBoardMessage != "") {
gearchannel.send(scoreBoardMessage); gearchannel.send(scoreBoardMessage);
interaction.reply("Displaying Scoreboard"); interaction.reply("Displaying Scoreboard");
@ -108,150 +76,51 @@ client.on('interactionCreate', async(interaction) => {
console.log("Something went wrong when building the scoreboard."); console.log("Something went wrong when building the scoreboard.");
}; };
}; };
if (updateOrDisplay == 'update') {
const messagesInGearchannel = await gearchannel.messages.fetch()
const gearMessage = await messagesInGearchannel.find(msg => msg.author.id === '1306647733490290809')
if (gearMessage === undefined) {
interaction.reply("Could not find a message to update, did you remember to display it first?");
}
else {
gearMessage.edit(scoreBoardMessage);
interaction.reply("Updated scoreboard.")
}
}
} else if (interaction.commandName === 'scoreboard' && !isManager) {
interaction.reply("You aren't a manager! Get back to work.")
}; };
}); });
function CreateEmployee(Name) { function CreateEmployee(Name) {
db.run(`INSERT INTO Employees (name, coppergear) VALUES (\'${Name}\', 0)`); db.run(`INSERT INTO Employees (name) VALUES (\'${Name}\')`);
}; };
function DeleteEmployee(Name) { function DeleteEmployee(Name) {
db.run(`DELETE FROM Employees WHERE name = \'${Name}\'`); db.run(`DELETE FROM Employees WHERE name = \'${Name}\'`);
}; };
function PromoteEmployee(Name, rank) { function PromoteEmployee(Name, rank) {
db.run(`UPDATE Employees SET rank = \'${rank}\' WHERE name = \'${Name}\'`) db.run(`UPDATE Employees SET rank = \'${rank}\' WHERE name = \'${Name}\'`)
}; };
function AddGear(Type,Employee) { function AddGear(Type,Employee) {
if (Type == "copper" || Type == "silver" || Type == "gold" || Type == "purple"){ if (Type != "coppergear" | "silvergear" | "goldgear") return
Type += "gear";
}
if (Type != "coppergear" && Type != "silvergear" && Type != "goldgear" && Type != "purplegear") return
db.run(`UPDATE Employees SET ${Type} = ${Type} + 1 WHERE name = \'${Employee}\' `) 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) { function BuildScoreboard() {
return new Promise((resolve) => { return new Promise((resolve) => {
db.get(`SELECT name, rank, coppergear, silvergear, goldgear, purplegear, copperswog, silverswog, goldswog, purpleswog FROM Employees WHERE name = ?`,[employeeName], (err, character) => { let messageContent = "";
if (err != null) { db.each('SELECT name, rank, coppergear, silvergear, goldgear, purplegear FROM Employees', (err, character) => {
console.log(err.message)
resolve("Something went wrong when fetching employee info");
};
if(character === undefined) {
console.log("No data returned")
}
if (character !== undefined){
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);
}
else {
resolve("Something went wrong when fetching employee information");
}
});
})
};
function BuildScoreboard(rank) {
return new Promise((resolve) => {
let messageContent = `# ${rank} \n`;
db.each(`SELECT name, rank, coppergear, silvergear, goldgear, purplegear FROM Employees WHERE rank = ?`, [rank], (err, character) => {
if (err != null) { if (err != null) {
console.log(err.message); console.log(err.message);
}; };
let copperGearString = ""; let copperGearString = "";
//console.log(character.coppergear); console.log(character.coppergear);
if (character.coppergear >0) {copperGearString += "\n## "}
for (let i = 0; i < character.coppergear; i++) { for (let i = 0; i < character.coppergear; i++) {
copperGearString += "<:coppergear:1308166341622235179>"; copperGearString += ":coppergear:"
}; };
let silverGearString = ""; let silverGearString = "";
//console.log(character.silvergear); console.log(character.silvergear);
if (character.silvergear > 0) {silverGearString += "\n## "}
for (let i = 0; i < character.silvergear; i++) { for (let i = 0; i < character.silvergear; i++) {
silverGearString += ":gear:"; silvergearstring += ":gear:"
}; }
let goldGearString = ""; let goldGearString = "";
//console.log(character.goldgear); messageContent += `**${character.name}** \n ##${copperGearString} \n`;
if(character.goldgear > 0) {goldGearString += "\n## "};
for(let i = 0; i < character.goldgear; i++) {
goldGearString += "<:goldgear:1308166365550481499>";
};
let purplegearString ="";
//console.log(character.purplegear);
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); }); }, () => {resolve(messageContent); });
}); });
}; };
client.login(process.env.DISCORD_TOKEN); client.login(process.env.DISCORD_TOKEN);

View File

@ -10,18 +10,6 @@ const commands = [
name: 'croak', name: 'croak',
description: 'Makes Sir Hornsworth 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', name: 'gear',
description: 'Add or remove a gear to an employee', description: 'Add or remove a gear to an employee',
@ -51,7 +39,7 @@ const commands = [
description: 'Hire or Fire an employee', description: 'Hire or Fire an employee',
options: [ options: [
{ {
name: 'hire-fire', name: 'hire-fire-promote',
description: 'Hiring or Firing?', description: 'Hiring or Firing?',
type: ApplicationCommandOptionType.String, type: ApplicationCommandOptionType.String,
required: true, required: true,
@ -82,24 +70,6 @@ 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,
required: true,
}
]
},
{ {
name: 'scoreboard', name: 'scoreboard',
description: 'Related to the scoreboard', description: 'Related to the scoreboard',