From 3828bed0f2743b2d9daa1575af21c20499f6bd93 Mon Sep 17 00:00:00 2001 From: Neurofumo <142212465+neurofumo@users.noreply.github.com> Date: Sun, 14 Jul 2024 01:37:20 +0800 Subject: [PATCH 1/2] update intents so it only uses what it needs --- src/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.py b/src/main.py index 82fd1ab..f644668 100644 --- a/src/main.py +++ b/src/main.py @@ -20,7 +20,8 @@ ) load_dotenv() -intents = disnake.Intents.all() +intents = disnake.Intents(messages=True) +intents.message_content = True activity = disnake.Activity( type=disnake.ActivityType.watching, name="you placing those pixels 👀" ) From 19663e99104610601ce4385ff33838a881e2f877 Mon Sep 17 00:00:00 2001 From: Neurofumo <142212465+neurofumo@users.noreply.github.com> Date: Tue, 16 Jul 2024 01:49:25 +0800 Subject: [PATCH 2/2] Minor Imgur Fix Fixes template command not working for imgur links. Additionally, this patch should work on most links too as it has a valid user-agent (Windows 10 Google Chrome). --- src/utils/utils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/utils/utils.py b/src/utils/utils.py index 439033c..5e8c0af 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -26,6 +26,15 @@ async def get_content(url: str, content_type, **kwargs): Raise BadResponseError or ValueError.""" # check if the URL is a data URL data = check_data_url(url) + # set headers for user-agent + headers = { + 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36' + } + if content_type == "image": + if url.startswith('https://imgur.com/'): + reurl = re.search(r'https://imgur\.com/([^?#]*)', url) + image_hash = reurl.group(1) + url = f"https://i.imgur.com/{image_hash}.png" if data: return data timeout = aiohttp.ClientTimeout( @@ -33,7 +42,7 @@ async def get_content(url: str, content_type, **kwargs): ) # set a timeout of 10 seconds async with aiohttp.ClientSession(timeout=timeout, **kwargs) as session: try: - async with session.get(url) as r: + async with session.get(url, headers=headers) as r: if r.status == 200: if content_type == "json": return await r.json()