Compare commits
	
		
			3 Commits
		
	
	
		
			d986b2cb7f
			...
			b7610ed59d
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| b7610ed59d | |||
| b79b6cdfe0 | |||
| 193f172ced | 
| @ -1,4 +1,5 @@ | ||||
| const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); | ||||
| const { getCoverURL, getGameJson } = require('../../igdbHelperFunctions.js'); | ||||
| 
 | ||||
| module.exports = { | ||||
|     data: new SlashCommandBuilder() | ||||
| @ -43,78 +44,4 @@ module.exports = { | ||||
| 
 | ||||
|         return interaction.reply({ embeds: [embed] }); | ||||
|     }, | ||||
| }; | ||||
| 
 | ||||
| async function getGameJson(body) { | ||||
|     let res; | ||||
| 
 | ||||
|     await fetch( | ||||
|         'https://api.igdb.com/v4/games', | ||||
|         { method: 'POST', | ||||
|           headers: { | ||||
|             'Accept': 'application/json', | ||||
|             'Client-ID': `${process.env.igdbClientId}`, | ||||
|             'Authorization': `Bearer ${process.env.igdbAccessToken}`, | ||||
|           }, | ||||
|           body: body, | ||||
|       }) | ||||
|         .then(response => response.json()) | ||||
|         .then(response => { | ||||
|             res = response; | ||||
|         }) | ||||
|         .catch(err => { | ||||
|             console.error(err); | ||||
|         }); | ||||
| 
 | ||||
|         return res; | ||||
| } | ||||
| 
 | ||||
| async function getPlatformID(platform) { | ||||
| 
 | ||||
|     await fetch( | ||||
|         'https://api.igdb.com/v4/platforms', | ||||
|         { method: 'POST', | ||||
|           headers: { | ||||
|             'Accept': 'application/json', | ||||
|             'Client-ID': `${process.env.igdbClientId}`, | ||||
|             'Authorization': `Bearer ${process.env.igdbAccessToken}`, | ||||
|           }, | ||||
|           body: `where name = "${platform}", alternative_name = "${platform}"; fields id;`, | ||||
|       }) | ||||
|       .then(response => response.json()) | ||||
|       .then(response => { | ||||
|             return response; | ||||
|         }) | ||||
|         .catch(err => { | ||||
|             console.error(err); | ||||
|         }); | ||||
| } | ||||
| 
 | ||||
| async function getCoverURL(id) { | ||||
|     let url = 'https://upload.wikimedia.org/wikipedia/commons/d/d1/Image_not_available.png'; | ||||
| 
 | ||||
|     await fetch( | ||||
|         'https://api.igdb.com/v4/covers', | ||||
|         { method: 'POST', | ||||
|           headers: { | ||||
|             'Accept': 'application/json', | ||||
|             'Client-ID': `${process.env.igdbClientId}`, | ||||
|             'Authorization': `Bearer ${process.env.igdbAccessToken}`, | ||||
|           }, | ||||
|           body: `where id = ${id}; fields url;`, | ||||
|         }) | ||||
|         .then(response => response.json()) | ||||
|         .then(response => { | ||||
|             if (response[0]) { | ||||
|                 url = 'https:'.concat(response[0].url); | ||||
|             } | ||||
|         }) | ||||
|         .then(response => { | ||||
|             url = url.replace('t_thumb', 't_1080p_2x'); | ||||
|         }) | ||||
|         .catch(err => { | ||||
|             console.error(err); | ||||
|         }); | ||||
| 
 | ||||
|         return url; | ||||
| } | ||||
| }; | ||||
| @ -1,8 +1,9 @@ | ||||
| const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); | ||||
| const { getGameJson } = require('../../igdbHelperFunctions.js'); | ||||
| 
 | ||||
| module.exports = { | ||||
| 	data: new SlashCommandBuilder() | ||||
| 		.setName('searchgame') | ||||
| 		.setName('searchgames') | ||||
| 		.setDescription('Searches the igdb database for matching games.') | ||||
|         .addStringOption(option => option.setName('gamename').setDescription('The name of the game').setRequired(true)), | ||||
| 
 | ||||
| @ -54,52 +55,4 @@ async function searchGamesWithoutMinimumReview(gamename) { | ||||
|     const games = await getGameJson(body); | ||||
| 
 | ||||
|     return games; | ||||
| } | ||||
| 
 | ||||
| async function getGameJson(body) { | ||||
|     let res; | ||||
| 
 | ||||
|     await fetch( | ||||
|         'https://api.igdb.com/v4/games', | ||||
|         { method: 'POST', | ||||
|           headers: { | ||||
|             'Accept': 'application/json', | ||||
|             'Client-ID': `${process.env.igdbClientId}`, | ||||
|             'Authorization': `Bearer ${process.env.igdbAccessToken}`, | ||||
|           }, | ||||
|           body: body, | ||||
|       }) | ||||
|         .then(response => response.json()) | ||||
|         .then(response => { | ||||
|             res = response; | ||||
|         }) | ||||
|         .catch(err => { | ||||
|             console.error(err); | ||||
|         }); | ||||
| 
 | ||||
|         return res; | ||||
| } | ||||
| 
 | ||||
| async function getReleaseDates(id) { | ||||
|     let date; | ||||
| 
 | ||||
|     await fetch( | ||||
|         'https://api.igdb.com/v4/release_dates', | ||||
|         { method: 'POST', | ||||
|           headers: { | ||||
|             'Accept': 'application/json', | ||||
|             'Client-ID': `${process.env.igdbClientId}`, | ||||
|             'Authorization': `Bearer ${process.env.igdbAccessToken}`, | ||||
|           }, | ||||
|           body: `where id = ${id}; fields category,checksum,created_at,date,game,human,m,platform,region,status,updated_at,y;`, | ||||
|       }) | ||||
|         .then(response => response.json()) | ||||
|         .then(response => { | ||||
|             date = response[0].human; | ||||
|         }) | ||||
|         .catch(err => { | ||||
|             console.error(err); | ||||
|         }); | ||||
| 
 | ||||
|     return date; | ||||
| } | ||||
							
								
								
									
										6
									
								
								igdb.js
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								igdb.js
									
									
									
									
									
								
							| @ -4,11 +4,11 @@ class igdb { | ||||
|         setInterval(() => { | ||||
|             this.makeClientCred(); | ||||
|         }, 86000000); | ||||
|         this.makeClientCred() | ||||
|         this.makeClientCred(); | ||||
|     } | ||||
| 
 | ||||
|    makeClientCred() { | ||||
|     console.log("Making a token"); | ||||
|     console.log('Making a token'); | ||||
| 
 | ||||
|     fetch( | ||||
|         `https://id.twitch.tv/oauth2/token?client_id=${process.env.igdbClientId}&client_secret=${process.env.igdbClientSecret}&grant_type=client_credentials`, | ||||
| @ -32,5 +32,5 @@ class igdb { | ||||
| } | ||||
| 
 | ||||
| module.exports = { | ||||
|     igdb | ||||
|     igdb, | ||||
| }; | ||||
							
								
								
									
										104
									
								
								igdbHelperFunctions.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										104
									
								
								igdbHelperFunctions.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,104 @@ | ||||
| async function getCoverURL(id) { | ||||
|     let url = 'https://upload.wikimedia.org/wikipedia/commons/d/d1/Image_not_available.png'; | ||||
| 
 | ||||
|     await fetch( | ||||
|         'https://api.igdb.com/v4/covers', | ||||
|         { method: 'POST', | ||||
|           headers: { | ||||
|             'Accept': 'application/json', | ||||
|             'Client-ID': `${process.env.igdbClientId}`, | ||||
|             'Authorization': `Bearer ${process.env.igdbAccessToken}`, | ||||
|           }, | ||||
|           body: `where id = ${id}; fields url;`, | ||||
|         }) | ||||
|         .then(response => response.json()) | ||||
|         .then(response => { | ||||
|             if (response[0]) { | ||||
|                 url = 'https:'.concat(response[0].url); | ||||
|             } | ||||
|         }) | ||||
|         .then(response => { | ||||
|             url = url.replace('t_thumb', 't_1080p_2x'); | ||||
|         }) | ||||
|         .catch(err => { | ||||
|             console.error(err); | ||||
|         }); | ||||
| 
 | ||||
|         return url; | ||||
| } | ||||
| 
 | ||||
| async function getPlatformID(platform) { | ||||
| 
 | ||||
|     await fetch( | ||||
|         'https://api.igdb.com/v4/platforms', | ||||
|         { method: 'POST', | ||||
|           headers: { | ||||
|             'Accept': 'application/json', | ||||
|             'Client-ID': `${process.env.igdbClientId}`, | ||||
|             'Authorization': `Bearer ${process.env.igdbAccessToken}`, | ||||
|           }, | ||||
|           body: `where name = "${platform}", alternative_name = "${platform}"; fields id;`, | ||||
|       }) | ||||
|       .then(response => response.json()) | ||||
|       .then(response => { | ||||
|             return response; | ||||
|         }) | ||||
|         .catch(err => { | ||||
|             console.error(err); | ||||
|         }); | ||||
| } | ||||
| 
 | ||||
| async function getGameJson(body) { | ||||
|     let res; | ||||
| 
 | ||||
|     await fetch( | ||||
|         'https://api.igdb.com/v4/games', | ||||
|         { method: 'POST', | ||||
|           headers: { | ||||
|             'Accept': 'application/json', | ||||
|             'Client-ID': `${process.env.igdbClientId}`, | ||||
|             'Authorization': `Bearer ${process.env.igdbAccessToken}`, | ||||
|           }, | ||||
|           body: body, | ||||
|       }) | ||||
|         .then(response => response.json()) | ||||
|         .then(response => { | ||||
|             res = response; | ||||
|         }) | ||||
|         .catch(err => { | ||||
|             console.error(err); | ||||
|         }); | ||||
| 
 | ||||
|         return res; | ||||
| } | ||||
| 
 | ||||
| async function getReleaseDates(id) { | ||||
|     let date; | ||||
| 
 | ||||
|     await fetch( | ||||
|         'https://api.igdb.com/v4/release_dates', | ||||
|         { method: 'POST', | ||||
|           headers: { | ||||
|             'Accept': 'application/json', | ||||
|             'Client-ID': `${process.env.igdbClientId}`, | ||||
|             'Authorization': `Bearer ${process.env.igdbAccessToken}`, | ||||
|           }, | ||||
|           body: `where id = ${id}; fields category,checksum,created_at,date,game,human,m,platform,region,status,updated_at,y;`, | ||||
|       }) | ||||
|         .then(response => response.json()) | ||||
|         .then(response => { | ||||
|             date = response[0].human; | ||||
|         }) | ||||
|         .catch(err => { | ||||
|             console.error(err); | ||||
|         }); | ||||
| 
 | ||||
|     return date; | ||||
| } | ||||
| 
 | ||||
| module.exports = { | ||||
|     getCoverURL, | ||||
|     getPlatformID, | ||||
|     getGameJson, | ||||
|     getReleaseDates, | ||||
| }; | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user