buddy

node MVC discord bot
Log | Files | Refs | README

3party.js (3841B)


      1 const fetch = require('node-fetch');
      2 const config = require("../config/config.js")
      3 const ytcall  = require('youtube-api-v3-search');
      4 
      5 const urls = {
      6     iss: 'https://api.wheretheiss.at/v1/satellites/25544',
      7     joke:  'http://api.icndb.com/jokes/random',
      8     beer:  'https://sandbox-api.brewerydb.com/v2/beer/random/?',
      9     foas1: 'https://www.foaas.com/operations',
     10     foas2:'https://www.foaas.com',
     11     code: 'https://api.github.com/repos/underd0g1/buddy',
     12     stocks: 'https://query1.finance.yahoo.com/v7/finance/quote?symbols='
     13 }
     14 
     15 
     16 const iss = async(receivedMessage) =>{
     17   const response = await fetch(urls.iss)
     18   const data = await response.json()
     19   console.log(data)
     20   const {latitude, longitude} = data
     21   return "lat: " + latitude + " long: "+  longitude;
     22 }
     23 
     24 
     25 
     26 const joke = async (receivedMessage)=> {
     27   const response = await fetch(urls.joke);
     28   const data = await response.json()
     29   console.log(data)
     30   var joke = data.value.joke
     31   console.log(joke)
     32   return joke;
     33 }
     34 
     35 const  beer = async(receivedMessage)=> {
     36   const key = 'key=' +config.token.beerkey;
     37   var api = urls.beer + key
     38   const response = await fetch(api)
     39   const info = await response.json()
     40   console.log(info)
     41   var brand = info.data.name
     42   var name = info.data.style.category.name
     43   var abv = info.data.abv
     44   var desc = info.data.style.description
     45   return brand +"\n" + name + "\n" + abv + "\n" + desc
     46 }
     47 
     48 
     49 
     50 async function foas(arguements, receivedMessage){
     51   const response = await fetch(urls.foas1);
     52   const data = await response.json();
     53   var arr = [];
     54   for (i=0; i < data.length; i++){
     55     if (data[i].fields.length == 1){
     56       arr.push(data[i].url);
     57     }
     58   }
     59   var rand = Math.floor(Math.random()*46);
     60   var link = arr[rand];
     61   var glink = link.lastIndexOf('/');
     62   flink = link.slice(0,glink);
     63   var name = 'buddy';
     64   var link2 = urls.foas2 + flink +"/"+ name;
     65   console.log(link2.toString());
     66   return link2.toString();
     67 }
     68 
     69 const foas1 =async(receivedMessage)=>{
     70   var searchurl = await foas();
     71   const response = await fetch(searchurl , {
     72     method: 'GET',
     73     headers: {
     74     'Accept': 'application/json',
     75     'Content-Type': 'application/json'
     76   }
     77   });
     78   const data1 = await response.json();
     79   return data1.message  + " " +  data1.subtitle;
     80 }
     81 
     82 
     83 const code = async(recievedMessage) => {
     84     var req = await fetch(urls.code);
     85     var data = await req.json();
     86   return `▒█▀▀█ █░░█ █▀▀▄
     87 ▒█▀▀▄ █░░█ █░░█
     88 ▒█▄▄█ ░▀▀▀ ▀▀▀░ v1.0
     89 
     90 `
     91    + '\n' + "Author: " +data.owner.login +"\n" +
     92                     "Description: " +  data.description + '\n' +
     93                     "Repo: " + data.clone_url + '\n' +
     94                     "Open Issues: " + data.open_issues + " Forks: " + data.forks + "\n" +
     95                     "Subscribers: " + data.subscribers_count + "\n" +
     96                     "Language: " + data.language;
     97 }
     98 
     99 
    100 const stocks = async(arguements, message)=>{
    101 //if they type one symbol.
    102 // if they type more than one
    103 // if they type invalid ones
    104 console.log("just args:    " +arguements)
    105 console.log("index 0   " + arguements[0]);
    106           var req = await fetch(urls.stocks+arguements[0]);
    107           var data = await req.json();
    108           console.log(data.quoteResponse.result);
    109           return data.quoteResponse.result[0].displayName + ":   $ " + data.quoteResponse.result[0].regularMarketPrice
    110 
    111 }
    112 
    113 const ytresults =async (arguements, message) => {
    114 	let args = ""
    115 	for( var i=0; i < arguements.length; i++){
    116 		args += arguements[i]+" ";
    117 	}
    118   options ={
    119     q: args,
    120     part: "snippet",
    121     type: "video"
    122   }
    123   let result = await ytcall(config.token.youtubekey,options);
    124   var link = ("url: " + "https://youtube.com/watch?v=" + result.items[0].id.videoId);
    125   console.log(link);
    126   return link;
    127 	
    128 }
    129 
    130 module.exports = {
    131   iss,
    132   joke,
    133   beer,
    134   foas1,
    135   code,
    136   stocks,
    137   ytresults
    138 }