Implement improvements to building scoreboard. Fixed emoji and markdown header use.
This commit is contained in:
parent
1e99783d0e
commit
02863e7c1d
42
src/index.js
42
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); });
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user