mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 11:40:12 +01:00
fix(8ball && mcquote): fixes
Replaces the synchronous requests library with aiohttp in mcquote.py to enable asynchronous HTTP requests, improving performance and compatibility with async Discord bots. Also updates exception handling to use aiohttp.ClientError. Adds missing discord import in eightball.py.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import random
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
def eightball_command():
|
||||
|
||||
@@ -3,7 +3,7 @@ import os
|
||||
import tempfile
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import requests
|
||||
import aiohttp
|
||||
import random
|
||||
|
||||
def mcquote_command():
|
||||
@@ -70,11 +70,13 @@ def mcquote_command():
|
||||
mc_quote_url = f'https://skinmc.net/achievement/{random_number}/Achievement+Unlocked!/{quote_text}'
|
||||
|
||||
try:
|
||||
response = requests.get(mc_quote_url)
|
||||
response.raise_for_status()
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(mc_quote_url) as response:
|
||||
response.raise_for_status()
|
||||
content = await response.read()
|
||||
|
||||
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_file:
|
||||
temp_file.write(response.content)
|
||||
temp_file.write(content)
|
||||
temp_file_path = temp_file.name
|
||||
|
||||
embed = discord.Embed(
|
||||
@@ -101,7 +103,7 @@ def mcquote_command():
|
||||
await context.channel.send(file=file)
|
||||
|
||||
os.remove(temp_file_path)
|
||||
except requests.exceptions.RequestException:
|
||||
except aiohttp.ClientError:
|
||||
embed = discord.Embed(
|
||||
title="Error",
|
||||
description="Failed to generate Minecraft quote. Please try again later.",
|
||||
|
||||
Reference in New Issue
Block a user