Add Asynchronous function for building scoreboard, fix skill issues
This commit is contained in:
		
							parent
							
								
									c312e971f5
								
							
						
					
					
						commit
						1e99783d0e
					
				
							
								
								
									
										60
									
								
								src/index.js
									
									
									
									
									
								
							
							
						
						
									
										60
									
								
								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 != "") { | ||||||
|             interaction.reply("Displaying Scoreboard"); |                 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) { | 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) => { | ||||||
|     db.each('SELECT name, rank, coppergear, silvergear, goldgear, purplegear FROM Employees', (err, character) => { |         let messageContent = ""; | ||||||
|         if (err != null) { |         db.each('SELECT name, rank, coppergear, silvergear, goldgear, purplegear FROM Employees', (err, character) => { | ||||||
|             console.log(err.message); |             if (err != null) { | ||||||
|         } |                 console.log(err.message); | ||||||
|  |             }; | ||||||
|      |      | ||||||
|         let coppergearstring = ""; |             let copperGearString = ""; | ||||||
|         for (let i = 0; i < character.coppergear; i++) { |             console.log(character.coppergear); | ||||||
|             coppergearstring += ":coppergear:"  |             for (let i = 0; i < character.coppergear; i++) { | ||||||
|         } |                 copperGearString += ":coppergear:"  | ||||||
|  |             }; | ||||||
|      |      | ||||||
|         let silvergearstring = ""; |             let silverGearString = ""; | ||||||
|          |             console.log(character.silvergear); | ||||||
|         messageContent += `**${character.name}** \n ## ${coppergearstring} \n`; |             for (let i = 0; i < character.silvergear; i++) { | ||||||
|  |                 silvergearstring += ":gear:" | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|  |             let goldGearString = ""; | ||||||
|  |             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