Add Asynchronous function for building scoreboard, fix skill issues

This commit is contained in:
Alexandertp 2024-11-18 02:16:11 +01:00
parent c312e971f5
commit 1e99783d0e

View File

@ -24,7 +24,7 @@ client.on('ready', (c) => {
console.log('The Swog is prepared.');
})
//Chat commands are handled here
client.on('interactionCreate', (interaction) => {
client.on('interactionCreate', async(interaction) => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'croak') {
@ -37,6 +37,7 @@ client.on('interactionCreate', (interaction) => {
const employee = interaction.options.get('employee').value;
if ( addRemove == 'add') {
AddGear(gearType, employee)
interaction.reply(`Added a gear to ${employee}`)
};
}
@ -63,18 +64,17 @@ client.on('interactionCreate', (interaction) => {
if (interaction.commandName === 'scoreboard') {
const updateOrDisplay = interaction.options.get('update-display').value;
if (updateOrDisplay == 'display') {
db.each("SELECT name, rank FROM Employees", (err, character) => {
if (err != null) {
console.log(err.message);
}
console.log("Character Name: " + character.name + " rank: " + character.rank);
});
const gearchannel = client.channels.cache.get('1306669146804715693');
const scoreBoardMessage = BuildScoreboard();
let scoreBoardMessage = await BuildScoreboard();
console.log("Scoreboard goes here: " + scoreBoardMessage);
//gearchannel.send(scoreBoardMessage);
if (scoreBoardMessage != "") {
gearchannel.send(scoreBoardMessage);
interaction.reply("Displaying Scoreboard");
}
else {
console.log("Something went wrong when building the scoreboard.");
};
};
};
@ -88,31 +88,39 @@ function DeleteEmployee(Name) {
};
function PromoteEmployee(Name, rank) {
db.run(`UPDATE Employees SET rank = \'${rank}\' WHERE name = \'${Name}\'`)
}
};
function AddGear(Type,Employee) {
if (Type != "coppergear" | "silvergear" | "goldgear") return
db.run(`UPDATE Employees SET ${Type} = ${Type} + 1 WHERE name = \'${Employee}\' `)
};
function BuildScoreboard() {
let messageContent = ""
return new Promise((resolve) => {
let messageContent = "";
db.each('SELECT name, rank, coppergear, silvergear, goldgear, purplegear FROM Employees', (err, character) => {
if (err != null) {
console.log(err.message);
}
};
let coppergearstring = "";
let copperGearString = "";
console.log(character.coppergear);
for (let i = 0; i < character.coppergear; i++) {
coppergearstring += ":coppergear:"
copperGearString += ":coppergear:"
};
let silverGearString = "";
console.log(character.silvergear);
for (let i = 0; i < character.silvergear; i++) {
silvergearstring += ":gear:"
}
let silvergearstring = "";
messageContent += `**${character.name}** \n ## ${coppergearstring} \n`;
let goldGearString = "";
messageContent += `**${character.name}** \n ##${copperGearString} \n`;
}, () => {resolve(messageContent); });
});
return messageContent;
}
};
client.login(process.env.DISCORD_TOKEN);