UNPKG

disco-images

Version:

A powerful tool to generate anime images/gifs

126 lines (120 loc) 5.5 kB
require("dotenv").config(); const key = process.env.TENOR_KEY; import fetch from 'node-fetch'; // const fetch = require('node-fetch'); //Oops... Anyway, i didn't see your comment.. Could you say it again? // I don't think we need typescript only for this //Oh ok. // I'm thinking what to do lol // Btw you don't need to publish each time you make changes to your package; There is a CLI command called "npm link" // You can use that and do "npm install disco-images". Ohhh.... ty ty i didnt know.; Lol, try it // use another folder //Right. // npm init -y // Oops! //Tbh, i think i could make this much simpler instead of this repeated code for each function.; We can use classes; Wait lemme test something; Nop, doesn't work. Hmm okay..; We can use typescript for that tho. Aight. // You want to do it in TypeScript? //Sure! We can give it a try.; Alright, do "npm install -g typescript " Alright done.; Wait lemme check something on google;Alright.; OK now we can start; Do "tsc" on the terminal and see if it is working correctly till now;Ok. Hold on, 1 moment.; Okay //Yep, it works. // What did it return? //I'll send ss on discord; Ok; now run "tsc --init"; Alright; Do it here; There was an error.. I sent on discord. OH WAIT. I forgot to do something. //Okay done now.; Aye, see a tsconfig.json. yep.; That's our compiler //Ohhh nice.;; I have to go in a few mins so I'll do it fast and explain; Alright, that's fine. // Do you want it to only sends gifs or do more const object = { //Actions wave: async () => { let url = `https://api.tenor.com/v1/search?q=anime+wave&key=${key}&limit=50` let number = Math.floor(Math.random() * 50) let response = await fetch(url) let json = await response.json(); return json.results[number].url }, hug: async () => { let url = `https://api.tenor.com/v1/search?q=anime+hug&key=${key}&limit=50` let number = Math.floor(Math.random() * 50) let response = await fetch(url) let json = await response.json(); return json.results[number].url }, slap: async () => { let url = `https://api.tenor.com/v1/search?q=anime+slap&key=${key}&limit=50` let number = Math.floor(Math.random() * 50) let response = await fetch(url) let json = await response.json(); return json.results[number].url }, punch: async () => { let url = `https://api.tenor.com/v1/search?q=anime+punch&key=${key}&limit=50` let number = Math.floor(Math.random() * 50) let response = await fetch(url) let json = await response.json(); return json.results[number].url }, kill: async () => { let url = `https://api.tenor.com/v1/search?q=anime+dead&key=${key}&limit=50` let number = Math.floor(Math.random() * 50) let response = await fetch(url) let json = await response.json(); return json.results[number].url }, kiss: async () => { let url = `https://api.tenor.com/v1/search?q=anime+kiss&key=${key}&limit=50` let number = Math.floor(Math.random() * 50) let response = await fetch(url) let json = await response.json(); return json.results[number].url }, cry: async () => { let url = `https://api.tenor.com/v1/search?q=anime+cry&key=${key}&limit=50` let number = Math.floor(Math.random() * 50) let response = await fetch(url) let json = await response.json(); return json.results[number].url }, random: async () => { let url = `https://api.tenor.com/v1/search?q=random+anime&key=${key}&limit=50` let number = Math.floor(Math.random() * 50) let response = await fetch(url) let json = await response.json(); return json.results[number].url }, search: async (query) => { if (!query) throw new Error("Must pass in a query to find a GIF.") let url = `https://api.tenor.com/v1/search?q=${query}&key=${key}&limit=50` let number = Math.floor(Math.random() * 50) let response = await fetch(url) let json = await response.json(); return json.results[number].url }, //Animals pig: async () => { let url = `https://api.tenor.com/v1/search?q=pig&key=${key}&limit=50` let number = Math.floor(Math.random() * 50) let response = await fetch(url) let json = await response.json(); return json.results[number].url }, horse: async () => { let url = `https://api.tenor.com/v1/search?q=horse&key=${key}&limit=50` let number = Math.floor(Math.random() * 50) let response = await fetch(url) let json = await response.json(); return json.results[number].url }, dog: async () => { let url = `https://api.tenor.com/v1/search?q=dog&key=${key}&limit=50` let number = Math.floor(Math.random() * 50) let response = await fetch(url) let json = await response.json(); return json.results[number].url }, cat: async () => { let url = `https://api.tenor.com/v1/search?q=cat&key=${key}&limit=50` let number = Math.floor(Math.random() * 50) let response = await fetch(url) let json = await response.json(); return json.results[number].url } } export default object;