-
-
Notifications
You must be signed in to change notification settings - Fork 255
Dadjoke #1693
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
base: main
Are you sure you want to change the base?
Dadjoke #1693
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, sorry for the slow review, this looks great, thank you!
I have two minor comments.
bot/exts/fun/fun.py
Outdated
async with aiohttp.ClientSession() as session, session.get( | ||
"https://icanhazdadjoke.com", | ||
headers={ | ||
"Accept":"application/json", | ||
"User-Agent": "Sir-lancebot" | ||
}) as res: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Reusing the bot's internal http_session is more efficient than creating a new one.
- Including a contact method (e.g. the URL to the project) in the user agent is good practice.
async with aiohttp.ClientSession() as session, session.get( | |
"https://icanhazdadjoke.com", | |
headers={ | |
"Accept":"application/json", | |
"User-Agent": "Sir-lancebot" | |
}) as res: | |
async with self.bot.http_session.get( | |
"https://icanhazdadjoke.com", | |
headers={ | |
"Accept": "application/json", | |
"User-Agent": "Sir-Lancebot (https://github.com/python-discord/sir-lancebot)", | |
} | |
) as res: |
bot/exts/fun/fun.py
Outdated
data = await res.json() | ||
await ctx.send(data["joke"]) | ||
else: | ||
await ctx.send("There is no dad joke now") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This path indicates something is wrong, it's probably a good idea to raise an error so it will be logged and we can look into it. res.raise_for_status()
can be used to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Relevant Issues
https://github.com//issues/1691?notification_referrer_id=NT_kwDOBivkC7UxODE0MTkwMjE5MjoxMDM1Mzk3MjM#event-19124053085Description
Changes made:
How it's implemented:
Did you: