Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require("discord.js")
  2. const fetch = require("node-fetch");
  3. const client = new Discord.Client()
  4. const riotKey = ":c"
  5.  
  6. const patchVer = null;
  7. fetch("https://ddragon.leagueoflegends.com/api/versions.json").then(res => res.json())
  8. .then((patchVersions) => { patchVer = patchVersions[0];
  9.  
  10. const patchVer = await getPatchVer()
  11.  
  12.  
  13. async function findChamp(key) {
  14.     let champ = await fetch("http://ddragon.leagueoflegends.com/cdn/" + patchVer + "/data/en_US/champion.json")
  15.                 .then(res => res.json())
  16.                 .then(json => Object.values(json).find(champ => champ["key"] === key));
  17.     return champ.id;
  18. };
  19.  
  20. async function searchSummoner(summonerName){
  21.     let summonerId = null
  22.     await fetch("https://tr1.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + summonerName + "?api_key=" + riotKey)
  23.         .then(res => res.json())
  24.         .then(json => {
  25.             console.log(json.accountId)
  26.             summonerId = json.id
  27.         });
  28.         return summonerId;
  29.         }
  30.  
  31. async function getMastery(summonerId) {
  32.     let champ1 = null
  33.     let champ2 = null
  34.     let champ3 = null
  35.     await fetch("https://tr1.api.riotgames.com/lol/champion-mastery/v4/champion-masteries/by-summoner/" + summonerId + "?api_key=" + riotKey)
  36.         .then(res => res.json())
  37.         .then(async json =>  {
  38.             champ1 = [findChamp(json[0].championId), json[0].championPoints, json[0].championLevel]
  39.             champ2 = [json[1].championId, json[1].championPoints, json[1].championLevel]
  40.             champ3 = [json[2].championId, json[2].championPoints, json[2].championLevel]
  41.         })
  42.     return champ1;
  43. }
  44.  
  45. //-----------------------------------------------------------------------------------------------
  46.  
  47. client.on("ready", () =>{
  48.     const d = new Date();
  49.     console.log("[" + [d.getHours() + 3] + ":" + d.getMinutes() + "] Ready! ")
  50. })
  51.  
  52. //-----------------------------------------------------------------------------------------------
  53.  
  54. client.on("message", async message => {
  55.     const args = message.content.split(" ")
  56.     const command = args[0]
  57.     if (!message.author.bot) {
  58.         if (command === "/deneme") {
  59.                 message.channel.send(await getMastery(await searchSummoner(args[1])))
  60.             }
  61.         };
  62.     })
  63.  
  64. //-----------------------------------------------------------------------------------------------
  65.  
  66. client.login(":c")});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement