Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require("discord.js")
- const fetch = require("node-fetch");
- const client = new Discord.Client()
- const riotKey = ":c"
- const patchVer = null;
- fetch("https://ddragon.leagueoflegends.com/api/versions.json").then(res => res.json())
- .then((patchVersions) => { patchVer = patchVersions[0];
- const patchVer = await getPatchVer()
- async function findChamp(key) {
- let champ = await fetch("http://ddragon.leagueoflegends.com/cdn/" + patchVer + "/data/en_US/champion.json")
- .then(res => res.json())
- .then(json => Object.values(json).find(champ => champ["key"] === key));
- return champ.id;
- };
- async function searchSummoner(summonerName){
- let summonerId = null
- await fetch("https://tr1.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + summonerName + "?api_key=" + riotKey)
- .then(res => res.json())
- .then(json => {
- console.log(json.accountId)
- summonerId = json.id
- });
- return summonerId;
- }
- async function getMastery(summonerId) {
- let champ1 = null
- let champ2 = null
- let champ3 = null
- await fetch("https://tr1.api.riotgames.com/lol/champion-mastery/v4/champion-masteries/by-summoner/" + summonerId + "?api_key=" + riotKey)
- .then(res => res.json())
- .then(async json => {
- champ1 = [findChamp(json[0].championId), json[0].championPoints, json[0].championLevel]
- champ2 = [json[1].championId, json[1].championPoints, json[1].championLevel]
- champ3 = [json[2].championId, json[2].championPoints, json[2].championLevel]
- })
- return champ1;
- }
- //-----------------------------------------------------------------------------------------------
- client.on("ready", () =>{
- const d = new Date();
- console.log("[" + [d.getHours() + 3] + ":" + d.getMinutes() + "] Ready! ")
- })
- //-----------------------------------------------------------------------------------------------
- client.on("message", async message => {
- const args = message.content.split(" ")
- const command = args[0]
- if (!message.author.bot) {
- if (command === "/deneme") {
- message.channel.send(await getMastery(await searchSummoner(args[1])))
- }
- };
- })
- //-----------------------------------------------------------------------------------------------
- client.login(":c")});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement