mirror of
https://github.com/Floriansylvain/Risitas_BOT.git
synced 2026-08-19 11:43:16 +02:00
🏗 - Moved Riot's API interaction from main.py to riot_api.py
This commit is contained in:
+10
-7
@@ -2,15 +2,18 @@ import asyncio
|
|||||||
import socket
|
import socket
|
||||||
import re
|
import re
|
||||||
import discord
|
import discord
|
||||||
from private import *
|
|
||||||
from osu_api import *
|
|
||||||
from discord.ext import tasks, commands
|
from discord.ext import tasks, commands
|
||||||
from discord.ext.commands.cooldowns import BucketType
|
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 emoji import demojize
|
||||||
from twitch import TwitchClient
|
from twitch import TwitchClient
|
||||||
|
|
||||||
|
|
||||||
bot = commands.Bot(command_prefix='$')
|
bot = commands.Bot(command_prefix='$')
|
||||||
twitch_client = TwitchClient(client_id=ID_TWITCH, oauth_token=TOKEN_TWITCH)
|
twitch_client = TwitchClient(client_id=ID_TWITCH, oauth_token=TOKEN_TWITCH)
|
||||||
chats = dict()
|
chats = dict()
|
||||||
@@ -124,8 +127,8 @@ async def chat_stop(ctx):
|
|||||||
@commands.cooldown(1, 2, commands.BucketType.user)
|
@commands.cooldown(1, 2, commands.BucketType.user)
|
||||||
async def lol_rank(ctx, arg, argf=None):
|
async def lol_rank(ctx, arg, argf=None):
|
||||||
if argf is None:
|
if argf is None:
|
||||||
try:
|
player = what_player(arg)
|
||||||
player = WATCHER.summoner.by_name(REGION, arg)
|
if player != 0:
|
||||||
ranks = rank_track(player)
|
ranks = rank_track(player)
|
||||||
embed = discord.Embed(title=arg, url='https://bit.ly/3biTekM')
|
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(
|
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:
|
else:
|
||||||
embed.description = ranks
|
embed.description = ranks
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
except ApiError:
|
else:
|
||||||
await ctx.send('The username you entered is unknown.')
|
await ctx.send('The username you entered is unknown.')
|
||||||
else:
|
else:
|
||||||
await ctx.send('If you are trying to use a username with spaces, please surround it with quotes.')
|
await ctx.send('If you are trying to use a username with spaces, please surround it with quotes.')
|
||||||
|
|||||||
+8
-5
@@ -1,16 +1,19 @@
|
|||||||
from riotwatcher import LolWatcher
|
from riotwatcher import LolWatcher, ApiError
|
||||||
from private import TOKEN_RIOT
|
from private import TOKEN_RIOT
|
||||||
|
|
||||||
WATCHER = LolWatcher(TOKEN_RIOT)
|
WATCHER = LolWatcher(TOKEN_RIOT)
|
||||||
REGION = 'EUW1'
|
REGION = 'EUW1'
|
||||||
|
|
||||||
def rank_track(player):
|
def what_player(name):
|
||||||
'''function that communicate with Riot API'''
|
try:
|
||||||
ranked_stats = WATCHER.league.by_summoner(REGION, player['id'])
|
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:
|
if not ranked_stats:
|
||||||
return 'Unranked cette saison.'
|
return 'Unranked cette saison.'
|
||||||
|
|
||||||
liste = []
|
liste = []
|
||||||
for infos in ranked_stats:
|
for infos in ranked_stats:
|
||||||
if infos['queueType'] == 'RANKED_SOLO_5x5':
|
if infos['queueType'] == 'RANKED_SOLO_5x5':
|
||||||
|
|||||||
Reference in New Issue
Block a user