Add Asynchronous function for building scoreboard, fix skill issues
This commit is contained in:
parent
c312e971f5
commit
1e99783d0e
50
src/index.js
50
src/index.js
@ -24,7 +24,7 @@ client.on('ready', (c) => {
|
|||||||
console.log('The Swog is prepared.');
|
console.log('The Swog is prepared.');
|
||||||
})
|
})
|
||||||
//Chat commands are handled here
|
//Chat commands are handled here
|
||||||
client.on('interactionCreate', (interaction) => {
|
client.on('interactionCreate', async(interaction) => {
|
||||||
if (!interaction.isChatInputCommand()) return;
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
if (interaction.commandName === 'croak') {
|
if (interaction.commandName === 'croak') {
|
||||||
@ -37,6 +37,7 @@ client.on('interactionCreate', (interaction) => {
|
|||||||
const employee = interaction.options.get('employee').value;
|
const employee = interaction.options.get('employee').value;
|
||||||
if ( addRemove == 'add') {
|
if ( addRemove == 'add') {
|
||||||
AddGear(gearType, employee)
|
AddGear(gearType, employee)
|
||||||
|
interaction.reply(`Added a gear to ${employee}`)
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -63,18 +64,17 @@ client.on('interactionCreate', (interaction) => {
|
|||||||
if (interaction.commandName === 'scoreboard') {
|
if (interaction.commandName === 'scoreboard') {
|
||||||
const updateOrDisplay = interaction.options.get('update-display').value;
|
const updateOrDisplay = interaction.options.get('update-display').value;
|
||||||
if (updateOrDisplay == 'display') {
|
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 gearchannel = client.channels.cache.get('1306669146804715693');
|
||||||
const scoreBoardMessage = BuildScoreboard();
|
let scoreBoardMessage = await BuildScoreboard();
|
||||||
console.log("Scoreboard goes here: " + scoreBoardMessage);
|
console.log("Scoreboard goes here: " + scoreBoardMessage);
|
||||||
//gearchannel.send(scoreBoardMessage);
|
if (scoreBoardMessage != "") {
|
||||||
|
gearchannel.send(scoreBoardMessage);
|
||||||
interaction.reply("Displaying Scoreboard");
|
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) {
|
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 != "coppergear" | "silvergear" | "goldgear") return
|
||||||
|
db.run(`UPDATE Employees SET ${Type} = ${Type} + 1 WHERE name = \'${Employee}\' `)
|
||||||
};
|
};
|
||||||
|
|
||||||
function BuildScoreboard() {
|
function BuildScoreboard() {
|
||||||
let messageContent = ""
|
return new Promise((resolve) => {
|
||||||
|
let messageContent = "";
|
||||||
db.each('SELECT name, rank, coppergear, silvergear, goldgear, purplegear FROM Employees', (err, character) => {
|
db.each('SELECT name, rank, coppergear, silvergear, goldgear, purplegear FROM Employees', (err, character) => {
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
console.log(err.message);
|
console.log(err.message);
|
||||||
}
|
};
|
||||||
|
|
||||||
let coppergearstring = "";
|
let copperGearString = "";
|
||||||
|
console.log(character.coppergear);
|
||||||
for (let i = 0; i < character.coppergear; i++) {
|
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 = "";
|
let goldGearString = "";
|
||||||
|
messageContent += `**${character.name}** \n ##${copperGearString} \n`;
|
||||||
messageContent += `**${character.name}** \n ## ${coppergearstring} \n`;
|
|
||||||
|
|
||||||
|
|
||||||
|
}, () => {resolve(messageContent); });
|
||||||
});
|
});
|
||||||
return messageContent;
|
|
||||||
}
|
};
|
||||||
|
|
||||||
client.login(process.env.DISCORD_TOKEN);
|
client.login(process.env.DISCORD_TOKEN);
|
Loading…
Reference in New Issue
Block a user