diff options
Diffstat (limited to 'bot/exts/fun')
| -rw-r--r-- | bot/exts/fun/fun.py | 53 | ||||
| -rw-r--r-- | bot/exts/fun/space.py | 7 | ||||
| -rw-r--r-- | bot/exts/fun/status_codes.py | 4 |
3 files changed, 61 insertions, 3 deletions
diff --git a/bot/exts/fun/fun.py b/bot/exts/fun/fun.py index 66c48517..25c46413 100644 --- a/bot/exts/fun/fun.py +++ b/bot/exts/fun/fun.py @@ -5,6 +5,7 @@ from pathlib import Path from typing import Literal import pyjokes +from aiohttp import ClientError, ClientResponseError from discord import Embed from discord.ext import commands from discord.ext.commands import BadArgument, Cog, Context @@ -14,6 +15,7 @@ from pydis_core.utils.logging import get_logger 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__) @@ -158,6 +160,57 @@ class Fun(Cog): joke = pyjokes.get_joke(category=category) await ctx.send(joke) + @commands.group(name="quote") + async def quote(self, ctx: Context) -> None: + """ + Retrieve a quote from zenquotes.io api. + + See `random`, `daily` subcommands. + """ + if ctx.invoked_subcommand is None: + await ctx.invoke(self.bot.get_command("help"), "quote") + + @quote.command(name="daily") + async def quote_daily(self, ctx: Context) -> None: + """Retrieve the daily quote from zenquotes.io api.""" + try: + quote = await daily_quote(self.bot) + embed = Embed( + title="Daily Quote", + description=f"> {quote}\n\n-# Powered by [zenquotes.io](https://zenquotes.io)", + colour=Colours.blue + ) + await ctx.send(embed=embed) + except ClientResponseError as e: + log.warning(f"ZenQuotes API error: {e.status} {e.message}") + await ctx.send(":x: Could not retrieve quote from API.") + except (ClientError, TimeoutError) as e: + log.error(f"Network error fetching quote: {e}") + await ctx.send(":x: Could not connect to the quote service.") + except Exception: + log.exception("Unexpected error fetching quote.") + await ctx.send(":x: Something unexpected happened. Try again later.") + + @quote.command(name="random") + async def quote_random(self, ctx: Context) -> None: + """Retrieve a random quote from zenquotes.io api.""" + try: + quote = await random_quote(self.bot) + embed = Embed( + title="Random Quote", + description=f"> {quote}\n\n-# Powered by [zenquotes.io](https://zenquotes.io)", + colour=Colours.blue + ) + await ctx.send(embed=embed) + except ClientResponseError as e: + log.warning(f"ZenQuotes API error: {e.status} {e.message}") + await ctx.send(":x: Could not retrieve quote from API.") + except (ClientError, TimeoutError) as e: + log.error(f"Network error fetching quote: {e}") + await ctx.send(":x: Could not connect to the quote service.") + except Exception: + log.exception("Unexpected error fetching quote.") + await ctx.send(":x: Something unexpected happened. Try again later.") async def setup(bot: Bot) -> None: """Load the Fun cog.""" diff --git a/bot/exts/fun/space.py b/bot/exts/fun/space.py index f2c934bc..c896a37f 100644 --- a/bot/exts/fun/space.py +++ b/bot/exts/fun/space.py @@ -1,3 +1,5 @@ +# XXX: Disabled due to issues with NASA API, see https://github.com/python-discord/sir-lancebot/issues/1709 + import random from datetime import UTC, date, datetime from typing import Any @@ -231,4 +233,7 @@ async def setup(bot: Bot) -> None: logger.warning("Can't find NASA API key. Not loading Space Cog.") return - await bot.add_cog(Space(bot)) + # XXX: Disabled due to issues with NASA API, see https://github.com/python-discord/sir-lancebot/issues/1709 + + # await bot.add_cog(Space(bot)) + return diff --git a/bot/exts/fun/status_codes.py b/bot/exts/fun/status_codes.py index cf544a19..f0605142 100644 --- a/bot/exts/fun/status_codes.py +++ b/bot/exts/fun/status_codes.py @@ -27,8 +27,8 @@ class HTTPStatusCodes(commands.Cog): self.bot = bot @commands.group( - name="http_status", - aliases=("status", "httpstatus"), + name="http", + aliases=("http_status", "httpstatus", "status"), invoke_without_command=True, ) async def http_status_group(self, ctx: commands.Context, code: int) -> None: |