mirror of
				https://github.com/aydenjahola/discord-multipurpose-bot.git
				synced 2025-10-31 22:31:34 +00:00 
			
		
		
		
	games: add source and few changes to scramble
This commit is contained in:
		
							parent
							
								
									c298a22257
								
							
						
					
					
						commit
						916f150a5f
					
				
					 1 changed files with 24 additions and 4 deletions
				
			
		|  | @ -23,7 +23,7 @@ const scrambleWord = (word) => { | |||
|     .join(""); | ||||
| }; | ||||
| 
 | ||||
| const createScrambleEmbed = (scrambledWord, guild, timeLimit) => { | ||||
| const createScrambleEmbed = (scrambledWord, guild, timeLimit, source) => { | ||||
|   return new EmbedBuilder() | ||||
|     .setColor("#0099ff") | ||||
|     .setTitle("Word Scramble") | ||||
|  | @ -32,7 +32,9 @@ const createScrambleEmbed = (scrambledWord, guild, timeLimit) => { | |||
|     ) | ||||
|     .setTimestamp() | ||||
|     .setFooter({ | ||||
|       text: `${guild.name} | Answer within ${timeLimit / 1000} seconds`, | ||||
|       text: `${guild.name} | Answer within ${ | ||||
|         timeLimit / 1000 | ||||
|       } seconds | Source: ${source}`,
 | ||||
|       iconURL: guild.iconURL(), | ||||
|     }); | ||||
| }; | ||||
|  | @ -79,6 +81,23 @@ const handleScrambleAnswer = async ( | |||
|   } | ||||
| }; | ||||
| 
 | ||||
| const getUniqueWord = async () => { | ||||
|   let originalWord; | ||||
|   let source = "API"; | ||||
| 
 | ||||
|   while (true) { | ||||
|     originalWord = await fetchRandomWord(); | ||||
|     const existingWord = await ScrambledWord.findOne({ word: originalWord }); | ||||
| 
 | ||||
|     if (!existingWord) { | ||||
|       // Word is unique, break the loop
 | ||||
|       break; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   return { originalWord, source }; | ||||
| }; | ||||
| 
 | ||||
| module.exports = { | ||||
|   data: new SlashCommandBuilder() | ||||
|     .setName("scramble") | ||||
|  | @ -100,7 +119,7 @@ module.exports = { | |||
|     ACTIVE_GAMES.add(userId); | ||||
| 
 | ||||
|     try { | ||||
|       const originalWord = await fetchRandomWord(); | ||||
|       const { originalWord, source } = await getUniqueWord(); | ||||
|       const scrambledWord = scrambleWord(originalWord); | ||||
| 
 | ||||
|       // Save to database
 | ||||
|  | @ -113,7 +132,8 @@ module.exports = { | |||
|       const scrambleEmbed = createScrambleEmbed( | ||||
|         scrambledWord, | ||||
|         guild, | ||||
|         timeLimit | ||||
|         timeLimit, | ||||
|         source | ||||
|       ); | ||||
|       await interaction.reply({ embeds: [scrambleEmbed] }); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue