From ed9f389bce71f34d962c6fc5c801ad15c0ba2a8d Mon Sep 17 00:00:00 2001 From: Florian SYLVAIN Date: Sat, 6 Mar 2021 18:08:18 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=20-=20Moved=20Riot's=20API=20inter?= =?UTF-8?q?action=20from=20main.py=20to=20riot=5Fapi.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/main.py | 17 ++++++++++------- python/riot_api.py | 13 ++++++++----- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/python/main.py b/python/main.py index 6771e81..b3f2a15 100644 --- a/python/main.py +++ b/python/main.py @@ -2,15 +2,18 @@ import asyncio import socket import re import discord -from private import * -from osu_api import * + from discord.ext import tasks, commands from discord.ext.commands.cooldowns import BucketType -from riot_api import rank_track, WATCHER, REGION -from riotwatcher import ApiError + +from private import * +from osu_api import * +from riot_api import rank_track, what_player + from emoji import demojize from twitch import TwitchClient + bot = commands.Bot(command_prefix='$') twitch_client = TwitchClient(client_id=ID_TWITCH, oauth_token=TOKEN_TWITCH) chats = dict() @@ -124,8 +127,8 @@ async def chat_stop(ctx): @commands.cooldown(1, 2, commands.BucketType.user) async def lol_rank(ctx, arg, argf=None): if argf is None: - try: - player = WATCHER.summoner.by_name(REGION, arg) + player = what_player(arg) + if player != 0: ranks = rank_track(player) embed = discord.Embed(title=arg, url='https://bit.ly/3biTekM') embed.set_thumbnail(url='http://ddragon.leagueoflegends.com/cdn/11.2.1/img/profileicon/' + str( @@ -140,7 +143,7 @@ async def lol_rank(ctx, arg, argf=None): else: embed.description = ranks await ctx.send(embed=embed) - except ApiError: + else: await ctx.send('The username you entered is unknown.') else: await ctx.send('If you are trying to use a username with spaces, please surround it with quotes.') diff --git a/python/riot_api.py b/python/riot_api.py index c72e7f4..4f3c5e7 100644 --- a/python/riot_api.py +++ b/python/riot_api.py @@ -1,16 +1,19 @@ -from riotwatcher import LolWatcher +from riotwatcher import LolWatcher, ApiError from private import TOKEN_RIOT WATCHER = LolWatcher(TOKEN_RIOT) REGION = 'EUW1' -def rank_track(player): - '''function that communicate with Riot API''' - ranked_stats = WATCHER.league.by_summoner(REGION, player['id']) +def what_player(name): + try: + return WATCHER.summoner.by_name(REGION, name) + except ApiError: + return 0 +def rank_track(player): + ranked_stats = WATCHER.league.by_summoner(REGION, player['id']) if not ranked_stats: return 'Unranked cette saison.' - liste = [] for infos in ranked_stats: if infos['queueType'] == 'RANKED_SOLO_5x5':