pull/133/head
stijndcl 2022-09-19 23:04:20 +02:00
parent a23ee3671a
commit 2638c5a3c4
2 changed files with 24 additions and 1 deletions

View File

@ -7,7 +7,7 @@ from discord.ext import commands
from database.crud.links import get_link_by_name
from database.schemas import Link
from didier import Didier
from didier.data.apis import urban_dictionary
from didier.data.apis import inspirobot, urban_dictionary
from didier.data.embeds.google import GoogleSearch
from didier.data.scrapers import google
@ -48,6 +48,13 @@ class Other(commands.Cog):
embed = GoogleSearch(results).to_embed()
await ctx.reply(embed=embed, mention_author=False)
@commands.hybrid_command(name="inspire", description="Generate an InspiroBot quote.")
async def inspire(self, ctx: commands.Context):
"""Generate an [InspiroBot](https://inspirobot.me/) quote."""
async with ctx.typing():
link = await inspirobot.get_inspirobot_quote(self.client.http_session)
await ctx.reply(link, mention_author=False, ephemeral=False)
async def _get_link(self, name: str) -> Optional[Link]:
async with self.client.postgres_session as session:
return await get_link_by_name(session, name.lower())

View File

@ -0,0 +1,16 @@
from http import HTTPStatus
from aiohttp import ClientSession
from didier.exceptions import HTTPException
__all__ = ["get_inspirobot_quote"]
async def get_inspirobot_quote(http_session: ClientSession) -> str:
"""Get a new InspiroBot quote"""
async with http_session.get("https://inspirobot.me/api?generate=true") as response:
if response.status != HTTPStatus.OK:
raise HTTPException(response.status)
return await response.text()