From 267079714a79f3e915f47d448919c0539bc51404 Mon Sep 17 00:00:00 2001 From: Florian SYLVAIN Date: Sat, 30 Jan 2021 14:31:51 +0100 Subject: [PATCH] Add files via upload --- main.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ riot_api.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 main.py create mode 100644 riot_api.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..50510cd --- /dev/null +++ b/main.py @@ -0,0 +1,44 @@ +import discord +import asyncio +from discord.ext import commands +from private import token_bot +from riot_api import rank_track, watcher, region +from riotwatcher import ApiError + +client = discord.Client() +bot = commands.Bot(command_prefix='$') +print("Loading...") + +@bot.event +async def on_ready(): + print('We have logged in as {0.user}'.format(bot)) + +# @client.event +# async def on_message(message): +# if message.author == client.user: +# return + +# if message.content.startswith('$hello'): +# await message.channel.send('Hello!') + + +# @bot.command() +# async def test(ctx, arg): +# await ctx.send(arg) + +@bot.command() +async def rank(ctx, arg): + try: + player = watcher.summoner.by_name(region, arg) + text = rank_track(arg, player) + embed= discord.Embed(title=arg, url="https://www.youtube.com/watch?v=dQw4w9WgXcQ", description=text) + embed.set_thumbnail(url="http://ddragon.leagueoflegends.com/cdn/11.2.1/img/profileicon/" + str(player['profileIconId']) + ".png") + await ctx.send(embed=embed) + except ApiError: + await ctx.send("Le pseudo est inconnu ou un problème est survenu. (ma gestion des erreurs est à chier, déso pas déso)") + +@bot.command() +async def aled(ctx): + await ctx.send("Tapez $rank suivit de votre pseudo League of Legend EUW pour connaître vos classements.") + +bot.run(token_bot) \ No newline at end of file diff --git a/riot_api.py b/riot_api.py new file mode 100644 index 0000000..f086bd8 --- /dev/null +++ b/riot_api.py @@ -0,0 +1,40 @@ +from riotwatcher import LolWatcher +from private import token_riot +# import pandas as pd + +watcher = LolWatcher(token_riot) +region = 'EUW1' + +def rank_track(nickname, player): + + ranked_stats = watcher.league.by_summoner(region, player['id']) + if not ranked_stats: + return str(nickname) + ' n\'est pas ranked.' + else: + for infos in ranked_stats: + if infos['queueType'] == 'RANKED_SOLO_5x5': + what_rank = 'Solo Queue' + elif infos['queueType'] == 'RANKED_FLEX_SR': + what_rank = 'Flexible' + return infos['summonerName'] + ' est ' + str(infos['tier']) + ' ' + str(infos['rank']) + ' ' + str(infos['leaguePoints']) + ' LP en ' + str(what_rank) + '. ' + str(infos['wins']) + ' W / ' + str(infos['losses']) + 'L.' + +# def match_track(nickname, player): +# matche = watcher.match.matchlist_by_account(region, player['accountId']) +# last_match = matche['matches'][0] +# match_detail = watcher.match.by_id(region, last_match['gameId']) + +# print(match_detail) + +# def main(): +# while 1: +# nickname = str(input("Entrez votre pseudo league of legend : ")) +# try: +# player = watcher.summoner.by_name(region, nickname) +# rank_track(nickname, rank_track, player) +# # match_track(nickname, player) +# break +# except ApiError: +# print("Le pseudo est inconnu.") + +# if __name__ == '__main__': +# main() \ No newline at end of file