From 02863e7c1d9e567be2b18f66f8791f735b6cb36b Mon Sep 17 00:00:00 2001 From: Alexandertp Date: Tue, 19 Nov 2024 14:32:35 +0100 Subject: [PATCH] Implement improvements to building scoreboard. Fixed emoji and markdown header use. --- src/index.js | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/index.js b/src/index.js index fc6672d..1bf4da3 100644 --- a/src/index.js +++ b/src/index.js @@ -66,8 +66,16 @@ client.on('interactionCreate', async(interaction) => { if (updateOrDisplay == 'display') { const gearchannel = client.channels.cache.get('1306669146804715693'); - let scoreBoardMessage = await BuildScoreboard(); + + 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"); + console.log("Scoreboard goes here: " + scoreBoardMessage); + if (scoreBoardMessage != "") { gearchannel.send(scoreBoardMessage); interaction.reply("Displaying Scoreboard"); @@ -83,41 +91,57 @@ client.on('interactionCreate', async(interaction) => { function CreateEmployee(Name) { db.run(`INSERT INTO Employees (name) VALUES (\'${Name}\')`); }; + function DeleteEmployee(Name) { db.run(`DELETE FROM Employees WHERE name = \'${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 + if (Type != "coppergear" && Type != "silvergear" && Type != "goldgear" && Type != "purplegear") return db.run(`UPDATE Employees SET ${Type} = ${Type} + 1 WHERE name = \'${Employee}\' `) }; -function BuildScoreboard() { +function BuildScoreboard(rank) { return new Promise((resolve) => { - let messageContent = ""; - db.each('SELECT name, rank, coppergear, silvergear, goldgear, purplegear FROM Employees', (err, character) => { + let messageContent = `# ${rank} \n`; + + db.each(`SELECT name, rank, coppergear, silvergear, goldgear, purplegear FROM Employees WHERE rank = \'${rank}\'`, (err, character) => { if (err != null) { console.log(err.message); }; - + let copperGearString = ""; console.log(character.coppergear); + if (character.coppergear >0) {copperGearString += "\n## "} for (let i = 0; i < character.coppergear; i++) { - copperGearString += ":coppergear:" + copperGearString += "<:coppergear:1308166341622235179>"; }; let silverGearString = ""; console.log(character.silvergear); + if (character.silvergear > 0) {silverGearString += "\n## "} for (let i = 0; i < character.silvergear; i++) { - silvergearstring += ":gear:" - } + silverGearString += ":gear:"; + }; let goldGearString = ""; - messageContent += `**${character.name}** \n ##${copperGearString} \n`; - + console.log(character.goldgear); + 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); }); });