mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 03:40:11 +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 random
|
||||||
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
def eightball_command():
|
def eightball_command():
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import os
|
|||||||
import tempfile
|
import tempfile
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
import requests
|
import aiohttp
|
||||||
import random
|
import random
|
||||||
|
|
||||||
def mcquote_command():
|
def mcquote_command():
|
||||||
@@ -70,11 +70,13 @@ def mcquote_command():
|
|||||||
mc_quote_url = f'https://skinmc.net/achievement/{random_number}/Achievement+Unlocked!/{quote_text}'
|
mc_quote_url = f'https://skinmc.net/achievement/{random_number}/Achievement+Unlocked!/{quote_text}'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(mc_quote_url)
|
async with aiohttp.ClientSession() as session:
|
||||||
response.raise_for_status()
|
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:
|
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
|
temp_file_path = temp_file.name
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
@@ -101,7 +103,7 @@ def mcquote_command():
|
|||||||
await context.channel.send(file=file)
|
await context.channel.send(file=file)
|
||||||
|
|
||||||
os.remove(temp_file_path)
|
os.remove(temp_file_path)
|
||||||
except requests.exceptions.RequestException:
|
except aiohttp.ClientError:
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="Error",
|
title="Error",
|
||||||
description="Failed to generate Minecraft quote. Please try again later.",
|
description="Failed to generate Minecraft quote. Please try again later.",
|
||||||
|
|||||||
Reference in New Issue
Block a user