Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 17 additions & 0 deletions bot/exts/fun/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from bot.bot import Bot
from bot.constants import Client, Colours, Emojis
from bot.utils import helpers, messages
from bot.utils.quote import daily_quote, random_quote

log = get_logger(__name__)

Expand Down Expand Up @@ -158,6 +159,22 @@ async def joke(self, ctx: commands.Context, category: Literal["neutral", "chuck"
joke = pyjokes.get_joke(category=category)
await ctx.send(joke)

@commands.command(name="quote", aliases=("rquote", "randomquote", "random_quote",))
async def quote(self, ctx: commands.Context) -> None:
"""Retrieves a random quote from the zenquotes.io api."""
quote = await random_quote()
if quote.startswith("Error:"):
log.warning("Failed to fetch random quote.")
await ctx.send(quote if not quote.startswith("Error:") else "Couldn't fetch a quote 😢")

@commands.command(name="daily_quote", aliases=("dquote", "dailyquote"))
async def daily_quote(self, ctx: commands.Context) -> None:
"""Retrieves the daily quote from zenquotes.io api."""
quote = await daily_quote()
if quote.startswith("Error:"):
log.warning("Failed to fetch random quote.")
await ctx.send(quote if not quote.startswith("Error:") else "Couldn't fetch a quote 😢")


async def setup(bot: Bot) -> None:
"""Load the Fun cog."""
Expand Down
27 changes: 27 additions & 0 deletions bot/utils/quote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import aiohttp


async def random_quote() -> str:
"""Retrieves a random quote from zenquotes.io api."""
url = "https://zenquotes.io/api/random"

async with aiohttp.ClientSession() as session, session.get(url) as response:
if response.status != 200:
return "Error: Data not Retrieved"
data = await response.json()

quote = f"{data[0]['q']}\n-{data[0]['a']}"
return quote


async def daily_quote() -> str:
"""Retrieves the daily quote from zenquotes.io api."""
url = "https://zenquotes.io/api/today"

async with aiohttp.ClientSession() as session, session.get(url) as response:
if response.status != 200:
return "Error: Data not Retrieved"
data = await response.json()

quote = f"{data[0]['q']}\n-{data[0]['a']}"
return quote
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies = [
"PyYAML==6.0.2",
"rapidfuzz==3.12.2",
"sentry-sdk==2.19.2",
"aiohttp==3.10.10",
]

[dependency-groups]
Expand Down
39 changes: 19 additions & 20 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.