Skip to content

Commit

Permalink
Merge pull request #23 from neurofumo/patch-1
Browse files Browse the repository at this point in the history
Minor Imgur fix
  • Loading branch information
VanillaSixtySix authored Jul 15, 2024
2 parents ddf6936 + 19663e9 commit 354b8eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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
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

0 comments on commit 354b8eb

Please sign in to comment.