Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Imgur fix #23

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
)

load_dotenv()
intents = disnake.Intents.all()
intents = disnake.Intents(messages=True)
intents.message_content = True
Comment on lines +23 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause a merge conflict with #22.

activity = disnake.Activity(
type=disnake.ActivityType.watching, name="you placing those pixels 👀"
)
Expand Down
11 changes: 10 additions & 1 deletion src/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,23 @@ 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(
sock_connect=10.0, sock_read=10.0
) # 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()
Expand Down