fix some the signin and check recent but need to fix profile

This commit is contained in:
Rainy21
2026-04-23 00:36:34 -04:00
parent 0a972f6a3f
commit a8ddd363a7
13 changed files with 233 additions and 109 deletions
+23 -26
View File
@@ -1,11 +1,9 @@
import discord
from discord import app_commands
from discord.ext import commands
import aiohttp
import os
from database.db import save_user
RIOT_API_KEY = os.getenv("LEAGUEAPI")
from services.riot_api import get_account
class LoginCog(commands.Cog):
def __init__(self, bot):
@@ -13,7 +11,7 @@ class LoginCog(commands.Cog):
async def _handle_login(self, interaction: discord.Interaction, summoner: str):
await interaction.response.defer(ephemeral=True)
if "#" not in summoner:
await interaction.followup.send("❌ Use the format `Name#TAG`", ephemeral=True)
return
@@ -26,41 +24,40 @@ class LoginCog(commands.Cog):
discord_id = str(interaction.user.id)
url = (
f"https://americas.api.riotgames.com/riot/account/v1/accounts"
f"/by-riot-id/{game_name}/{tag_line}"
)
headers = {"X-Riot-Token": RIOT_API_KEY}
async with aiohttp.ClientSession() as session:
async with session.get(url, headers=headers) as resp:
if resp.status == 404:
await interaction.followup.send("❌ Summoner not found. Check your Riot ID.", ephemeral=True)
return
if resp.status != 200:
await interaction.followup.send(f"❌ Riot API error ({resp.status}). Try again later.", ephemeral=True)
return
# Use the service instead of direct API call
data = await get_account(game_name, tag_line)
data = await resp.json()
puuid = data["puuid"]
if data is None:
await interaction.followup.send("❌ Summoner not found. Check your Riot ID.", ephemeral=True)
return
if isinstance(data, dict) and "error" in data:
if data["error"] == 401:
await interaction.followup.send(
"❌ Riot API error (401): Unauthorized. "
"This usually means the bot's API key has expired. "
"Please notify the bot owner to refresh it at developer.riotgames.com.",
ephemeral=True
)
else:
await interaction.followup.send(
f"❌ Riot API error ({data['error']}). Try again later.",
ephemeral=True
)
return
puuid = data["puuid"]
save_user(discord_id, puuid, game_name, tag_line)
await interaction.followup.send(
f"✅ Linked **{game_name}#{tag_line}** to your Discord account!",
ephemeral=True
)
@app_commands.command(name="login", description="Link your Riot account")
@app_commands.describe(summoner="Your Riot ID (e.g. Name#TAG)")
async def login(self, interaction: discord.Interaction, summoner: str):
await self._handle_login(interaction, summoner)
@app_commands.command(name="signin", description="Link your Riot account")
@app_commands.describe(summoner="Your Riot ID (e.g. Name#TAG)")
async def signin(self, interaction: discord.Interaction, summoner: str):
await self._handle_login(interaction, summoner)
async def setup(bot):
await bot.add_cog(LoginCog(bot))