2023-11-26 23:02:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								const  {  SlashCommandBuilder ,  EmbedBuilder  }  =  require ( 'discord.js' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-30 23:37:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								const  {  getCoverURL ,  getGameJson  }  =  require ( '../../igdbHelperFunctions.js' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-11 20:23:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								const  {  checkGameStorage ,  getUserRegistration ,  createBeatenGameEntry ,  getBeatenGameCount ,  getPlanningGameCount ,  getPlayingGameCount  }  =  require ( '../../databaseHelperFunctions.js' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-18 00:35:28 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-11-26 23:02:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								module . exports  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    data :  new  SlashCommandBuilder ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        . setName ( 'beatgame' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        . setDescription ( 'Log a game that you have beat towards the 100 game challenge!' ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-31 01:12:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        . addStringOption ( option  =>  option . setName ( 'gamename' ) . setDescription ( 'The name of the game.' ) . setRequired ( true ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-27 21:34:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        . addNumberOption ( option  =>  option . setName ( 'gameid' ) . setDescription ( 'The IGDB game id.' ) . setMinValue ( 0 ) ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-26 23:02:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    async  execute ( interaction )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-18 23:53:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-31 01:12:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        await  interaction . reply ( {  content :  'Attempting to log game.' ,  ephemeral :  true  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-18 23:53:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        const  userDatabaseEntry  =  await  getUserRegistration ( interaction . user ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-31 01:12:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( ! userDatabaseEntry )  return  interaction . followUp ( {  content :  ` Issue checking registration with " ${ interaction . user . username } ". ` ,  ephemeral :  true  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-18 23:53:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-28 23:47:03 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        const  oldnum  =  await  getBeatenGameCount ( userDatabaseEntry ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-31 01:12:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( oldnum  >=  100 )  return  interaction . followUp ( {  content :  'You have already completed the 100 Games Challenge.' ,  ephemeral :  true  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-28 23:47:03 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-11-26 23:02:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        const  gamename  =  interaction . options . getString ( 'gamename' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        const  gameid  =  interaction . options . getNumber ( 'gameid' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-28 22:04:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-31 01:12:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( ! gamename  &&  ! gameid )  return  interaction . followUp ( {  content :  'No gamename or gameid supplied, please supply an option to register a game!' ,  ephemeral :  true  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-28 22:04:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        let  body  =  '' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-11-26 23:02:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( gameid )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-28 22:04:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            body  =  body . concat ( 'where id = ' ,  gameid ,  '; ' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-26 23:02:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  else  if  ( gamename )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-28 22:04:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            body  =  body . concat ( 'search "' ,  gamename ,  '"; ' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-27 22:28:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            body  =  body . concat ( 'limit 25; where (category = 0 | category = 4 | category = 8 | category = 9) & version_parent = null;' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-26 23:02:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-28 22:04:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-11-26 23:02:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        body  =  body . concat ( 'fields *;' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-28 22:04:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 19:48:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        let  res  =  await  getGameJson ( body ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        res  =  res . filter ( entry  =>  entry . status  !==  6 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        res . sort ( ( a ,  b )  =>  parseInt ( b . total _rating _count )  -  parseInt ( a . total _rating _count ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-28 22:04:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-31 01:12:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( ! res [ 0 ] )  return  interaction . followUp ( {  content :  'No game found for the options supplied.' ,  ephemeral :  true  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-28 22:04:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-19 19:47:26 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        const  game  =  res [ 0 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        const  release _date  =  game . first _release _date ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-31 01:12:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( ! release _date  ||  ( release _date  *  1000 )  >  Date . now ( ) )  return  interaction . followUp ( {  content :  ` ${ game . name }  is not yet released. ` ,  ephemeral :  true  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-19 19:47:26 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        const  gameDatabaseEntry  =  await  checkGameStorage ( game ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-31 01:12:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( ! ( await  createBeatenGameEntry ( userDatabaseEntry ,  gameDatabaseEntry ) ) )  return  interaction . followUp ( {  content :  ` ${ game . name }  already beaten. ` ,  ephemeral :  true  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-18 23:53:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-11 20:23:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        const  beatNum  =  await  getBeatenGameCount ( userDatabaseEntry ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        const  planNum  =  await  getPlanningGameCount ( userDatabaseEntry ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        const  playNum  =  await  getPlayingGameCount ( userDatabaseEntry ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-28 22:04:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-11-26 23:02:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        const  embed  =  new  EmbedBuilder ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            . setColor ( 0xFFD700 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            . setAuthor ( {  name :  ` ${ interaction . user . displayName }  beat a new game! ` ,  iconURL :  interaction . user . avatarURL ( )  } ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-19 19:47:26 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            . setTitle ( ` ${ game . name }  beaten! ` ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-26 23:02:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            . setFooter ( {  text :  'The Ochulus • 100 Games Challenge' ,  iconURL :  interaction . client . user . avatarURL ( )  } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            . setTimestamp ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-28 22:04:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 19:11:28 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( game . cover )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            const  coverUrl  =  await  getCoverURL ( game . cover ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            embed . setThumbnail ( ` ${ coverUrl } ` ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-18 20:47:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        embed . addFields ( {  name :  'Planned' ,  value :  ` ${ planNum }  game(s) ` ,  inline :  true  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        embed . addFields ( {  name :  'Now Playing' ,  value :  ` ${ playNum }  game(s) ` ,  inline :  true  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        embed . addFields ( {  name :  'Beaten' ,  value :  ` ${ beatNum } /100 ( ${ 100  -  beatNum }  game(s) remaining) ` ,  inline :  true  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-01 17:03:30 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-31 01:12:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        await  interaction . followUp ( {  embeds :  [ embed ]  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-28 23:47:03 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-11 20:23:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( beatNum  ==  100 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-28 23:47:03 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            const  challengeCompletedEmbed  =  new  EmbedBuilder ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            . setColor ( 0xFFD700 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            . setAuthor ( {  name :  ` ${ interaction . user . displayName }  has completed the 100 Game Challenge! ` ,  iconURL :  interaction . user . avatarURL ( )  } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            . setTitle ( ` Congratulations  ${ interaction . user . displayName } , you have completed the 100 Game Challenge! ` ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            . setFooter ( {  text :  'The Ochulus • 100 Games Challenge' ,  iconURL :  interaction . client . user . avatarURL ( )  } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            . setTimestamp ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            . setImage ( 'https://c.tenor.com/82zAqfFm7OMAAAAC/tenor.gif' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            await  interaction . followUp ( {  embeds :  [ challengeCompletedEmbed ]  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-26 23:02:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } , 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-30 23:37:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} ;