This commit is contained in:
codey 2025-05-01 15:54:14 -04:00
parent a433dc2fb5
commit 6a1fd659e8
2 changed files with 30 additions and 0 deletions

View File

@ -1403,6 +1403,12 @@ class Misc(commands.Cog):
except Exception as e:
traceback.print_exc()
return await ctx.respond(f"Error: {str(e)}")
@bridge.bridge_command()
async def no(self, ctx) -> None:
"""No (As A Service)"""
no = await self.util.get_no()
return await ctx.respond(no)
""" User Commands """

View File

@ -17,6 +17,7 @@ class Util:
def __init__(self) -> None:
self.URL_URBANDICTIONARY: str = "http://api.urbandictionary.com/v0/define"
self.URL_NO: str = "https://api.codey.lol/misc/no"
self.URL_INSULTAPI: str = "https://insult.mattbas.org/api/insult"
self.COMPLIMENT_GENERATOR = ComplimentGenerator()
self.dbs: dict[str, str | LiteralString] = {
@ -256,6 +257,29 @@ class Util:
except Exception as e:
traceback.print_exc()
return (term, f"ERR: {str(e)}")
async def get_no(self) -> str:
try:
async with ClientSession() as session:
async with await session.get(
self.URL_NO,
headers={
"content-type": "application/json; charset=utf-8",
},
timeout=ClientTimeout(connect=5, sock_read=5)
) as request:
request.raise_for_status()
response = await request.json()
no: str = response.get('no', None)
if not no:
logging.debug("Incorrect response received, JSON keys: %s",
response.keys())
return "No."
return no
except Exception as e:
logging.debug("Exception: %s",
str(e))
return "No."
async def get_insult(self, recipient: str) -> str:
"""