| 
									
										
										
										
											2023-12-19 22:19:08 +00:00
										 |  |  | const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); | 
					
						
							| 
									
										
										
										
											2025-01-10 18:16:32 +00:00
										 |  |  | const { getLeaderboardEntries, getLeaderboardEntriesBetweenDates } = require('../../databaseHelperFunctions.js'); | 
					
						
							| 
									
										
										
										
											2023-12-19 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = { | 
					
						
							|  |  |  |     data: new SlashCommandBuilder() | 
					
						
							|  |  |  |         .setName('leaderboard') | 
					
						
							| 
									
										
										
										
											2025-01-10 18:16:32 +00:00
										 |  |  |         .setDescription('Show the leaderboard!') | 
					
						
							|  |  |  |         .addIntegerOption(option => option.setName('year').setDescription('The year to check').addChoices({ name: '2024', value: 2024 }, { name: '2025', value: 2025 })), | 
					
						
							| 
									
										
										
										
											2023-12-19 22:19:08 +00:00
										 |  |  |     async execute(interaction) { | 
					
						
							| 
									
										
										
										
											2024-03-28 21:12:28 +00:00
										 |  |  |         await interaction.deferReply(); | 
					
						
							| 
									
										
										
										
											2023-12-19 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-10 18:16:32 +00:00
										 |  |  |         const yearOption = interaction.options.getInteger('year'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let leaderboard; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (yearOption) { | 
					
						
							|  |  |  |             leaderboard = await getLeaderboardEntriesBetweenDates(`${yearOption}-01-01`, `${yearOption}-12-31`); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             leaderboard = await getLeaderboardEntries(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-28 21:12:28 +00:00
										 |  |  |         if (!leaderboard) return interaction.editReply({ content: 'There was a problem!', ephemeral: true }); | 
					
						
							| 
									
										
										
										
											2023-12-19 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         let desc = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-20 16:24:37 +01:00
										 |  |  |         let count = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (let i = 0; i < leaderboard.length; i++) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (leaderboard[i].count > 0) { | 
					
						
							|  |  |  |                 count += leaderboard[i].count; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         desc = desc.concat('__Total: ', count, '__'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-19 22:19:08 +00:00
										 |  |  |         for (let i = 0; i < leaderboard.length; i++) { | 
					
						
							| 
									
										
										
										
											2023-12-27 21:33:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 17:54:49 +00:00
										 |  |  |             if (leaderboard[i].count > 0) { | 
					
						
							| 
									
										
										
										
											2024-02-28 18:12:04 +00:00
										 |  |  |                 let newLine = String.prototype.concat(leaderboard[i].username, ' - ', leaderboard[i].count, ' games'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 const number = String.prototype.concat('**#', (i + 1), '** '); | 
					
						
							| 
									
										
										
										
											2023-12-27 21:33:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 17:54:49 +00:00
										 |  |  |                 if (i == 0) newLine = String.prototype.concat('**', newLine, '**'); | 
					
						
							| 
									
										
										
										
											2023-12-27 21:33:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 17:54:49 +00:00
										 |  |  |                 if (leaderboard[i].username == interaction.user.username) newLine = String.prototype.concat('*', newLine, '*'); | 
					
						
							| 
									
										
										
										
											2023-12-27 21:33:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-28 18:12:04 +00:00
										 |  |  |                 newLine = String.prototype.concat(number, newLine); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 17:54:49 +00:00
										 |  |  |                 newLine = String.prototype.concat('\n', newLine); | 
					
						
							| 
									
										
										
										
											2023-12-27 21:33:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 17:54:49 +00:00
										 |  |  |                 desc = String.prototype.concat(desc, newLine); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2023-12-19 22:19:08 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const embed = new EmbedBuilder() | 
					
						
							|  |  |  |             .setColor(0x6441a5) | 
					
						
							|  |  |  |             .setTitle('The 100 Games Challenge Leaderboard!') | 
					
						
							|  |  |  |             .setDescription(desc) | 
					
						
							|  |  |  |             .setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() }) | 
					
						
							|  |  |  |             .setTimestamp(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-28 21:12:28 +00:00
										 |  |  |         return interaction.editReply({ embeds: [embed] }); | 
					
						
							| 
									
										
										
										
											2023-12-19 22:19:08 +00:00
										 |  |  |     }, | 
					
						
							|  |  |  | }; |