naas
This commit is contained in:
parent
a433dc2fb5
commit
6a1fd659e8
@ -1404,6 +1404,12 @@ class Misc(commands.Cog):
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return await ctx.respond(f"Error: {str(e)}")
|
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 """
|
""" User Commands """
|
||||||
|
|
||||||
@commands.user_command(name="Give Joint") # type: ignore
|
@commands.user_command(name="Give Joint") # type: ignore
|
||||||
|
@ -17,6 +17,7 @@ class Util:
|
|||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.URL_URBANDICTIONARY: str = "http://api.urbandictionary.com/v0/define"
|
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.URL_INSULTAPI: str = "https://insult.mattbas.org/api/insult"
|
||||||
self.COMPLIMENT_GENERATOR = ComplimentGenerator()
|
self.COMPLIMENT_GENERATOR = ComplimentGenerator()
|
||||||
self.dbs: dict[str, str | LiteralString] = {
|
self.dbs: dict[str, str | LiteralString] = {
|
||||||
@ -257,6 +258,29 @@ class Util:
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return (term, f"ERR: {str(e)}")
|
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:
|
async def get_insult(self, recipient: str) -> str:
|
||||||
"""
|
"""
|
||||||
Get Insult
|
Get Insult
|
||||||
|
Loading…
x
Reference in New Issue
Block a user