Guest User

Untitled

a guest
Oct 27th, 2023
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. const axios = require('axios');
  2. const { ApplicationCommandOptionType } = require("discord.js");
  3. const { EmbedBuilder } = require('discord.js');
  4. const config = require('../config.json');
  5.  
  6. module.exports = {
  7. name: 'elo',
  8. description: 'Busca informações de um invocador no League of Legends',
  9. options: [
  10. {
  11. name: 'invocador',
  12. description: 'Nome de invocador',
  13. type: ApplicationCommandOptionType.String,
  14. required: true
  15. },
  16. ],
  17. async execute(interaction) {
  18. const summonerName = interaction.options.getString('invocador');
  19.  
  20. try {
  21. // Faz uma solicitação para obter informações do invocador
  22. const summonerResponse = await axios.get(`https://br1.api.riotgames.com/lol/summoner/v4/summoners/by-name/${summonerName}`, {
  23. headers: {
  24. 'X-Riot-Token': config.riotapi,
  25. },
  26. });
  27.  
  28. // ID do invocador
  29. const summonerId = summonerResponse.data.id;
  30.  
  31. // Faz uma solicitação para obter informações sobre as classificações do jogador
  32. const rankedResponse = await axios.get(`https://br1.api.riotgames.com/lol/league/v4/entries/by-summoner/${summonerId}`, {
  33. headers: {
  34. 'X-Riot-Token': config.riotapi,
  35. },
  36. });
  37.  
  38. // Informações sobre as classificações do jogador
  39. const rankedInfo = rankedResponse.data;
  40.  
  41. // Faz uma solicitação para obter informações sobre as partidas do jogador
  42. const matchlistResponse = await axios.get(`https://br1.api.riotgames.com/lol/match/v4/matchlists/by-account/${summonerResponse.data.accountId}`, {
  43. headers: {
  44. 'X-Riot-Token': config.riotapi,
  45. },
  46. });
  47.  
  48. // Informações sobre as partidas do jogador
  49. const matchlist = matchlistResponse.data.matches;
  50.  
  51. // Calcula o número de vitórias e derrotas
  52. let wins = 0;
  53. let losses = 0;
  54.  
  55. matchlist.forEach((match) => {
  56. if (match.participantIdentities.find((identity) => identity.player.accountId === summonerResponse.data.accountId)) {
  57. const participant = match.participants.find((participant) => participant.participantId === match.participantIdentities.find((identity) => identity.player.accountId === summonerResponse.data.accountId).participantId);
  58. if (participant.stats.win) {
  59. wins++;
  60. } else {
  61. losses++;
  62. }
  63. }
  64. });
  65.  
  66. // Calcula o winrate
  67. const winrate = (wins / (wins + losses)) * 100;
  68.  
  69. // Envia uma resposta com as informações do jogador
  70. // inside a command, event listener, etc.
  71. const exampleEmbed = new EmbedBuilder()
  72. .setColor(0x0099FF)
  73. .setTitle('Nome de Invocador')
  74. .setAuthor({ name: 'RITO GOMES', iconURL: 'https://i.imgur.com/lmIumW4.png' })
  75. .setDescription(`${summonerName}`)
  76. .setThumbnail('https://i.imgur.com/lmIumW4.png')
  77. .addFields(
  78. { name: '\u200B', value: ' ' },
  79. { name: '__RANQUEADA SOLO/DUO__', value: `${rankedInfo[0].tier} ${rankedInfo[0].rank}`, inline: true },
  80. { name: '__WINRATE__', value: `${winrate.toFixed(2)}%`, inline: true },
  81. )
  82. .addFields({ name: 'PDL', value: `${rankedInfo[0].leaguePoints}`, inline: true })
  83. .setImage('https://i.imgur.com/CMcOG1B.jpg')
  84. .setTimestamp()
  85. .setFooter({ text: 'Some footer text here', iconURL: 'https://i.imgur.com/lmIumW4.png' });
  86.  
  87. interaction.reply({ embeds: [exampleEmbed] });
  88.  
  89. } catch (error) {
  90. console.error(error);
  91. interaction.reply('Ocorreu um erro ao buscar informações do invocador.');
  92. }
  93. },
  94. };
  95.  
Advertisement
Add Comment
Please, Sign In to add comment