mirror of https://github.com/stijndcl/didier
				
				
				
			Inspire
							parent
							
								
									a23ee3671a
								
							
						
					
					
						commit
						2638c5a3c4
					
				|  | @ -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()) | ||||
|  |  | |||
|  | @ -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() | ||||
		Loading…
	
		Reference in New Issue