meme dupe snitching/misc

This commit is contained in:
2025-05-15 15:49:28 -04:00
parent 6a1fd659e8
commit 3dac803305
8 changed files with 105 additions and 55 deletions

View File

@ -257,7 +257,7 @@ 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:
@ -266,19 +266,20 @@ class Util:
headers={
"content-type": "application/json; charset=utf-8",
},
timeout=ClientTimeout(connect=5, sock_read=5)
timeout=ClientTimeout(connect=5, sock_read=5),
) as request:
request.raise_for_status()
response = await request.json()
no: str = response.get('no', None)
response = await request.json(encoding="utf-8")
no: str = response.get("no", None)
if not no:
logging.debug("Incorrect response received, JSON keys: %s",
response.keys())
logging.debug(
"Incorrect response received, JSON keys: %s",
response.keys(),
)
return "No."
return no
except Exception as e:
logging.debug("Exception: %s",
str(e))
logging.debug("Exception: %s", str(e))
return "No."
async def get_insult(self, recipient: str) -> str:
@ -323,13 +324,11 @@ class Util:
if not whisky_db:
return None
async with sqlite3.connect(database=whisky_db, timeout=2) as db_conn:
db_query: str = (
"SELECT name, category, description FROM whiskeys ORDER BY random() LIMIT 1"
)
db_query: str = "SELECT name, category, description FROM whiskeys ORDER BY random() LIMIT 1"
async with await db_conn.execute(db_query) as db_cursor:
db_result: Optional[Union[sqlite3.Row, tuple]] = (
await db_cursor.fetchone()
)
db_result: Optional[
Union[sqlite3.Row, tuple]
] = await db_cursor.fetchone()
if not db_result:
return None
(name, category, description) = db_result
@ -398,9 +397,7 @@ class Util:
async with sqlite3.connect(database=strains_db, timeout=2) as db_conn:
db_params: Optional[tuple] = None
if not strain:
db_query: str = (
"SELECT name, description FROM strains_w_desc ORDER BY random() LIMIT 1"
)
db_query: str = "SELECT name, description FROM strains_w_desc ORDER BY random() LIMIT 1"
else:
db_query = (
"SELECT name, description FROM strains_w_desc WHERE name LIKE ?"
@ -442,9 +439,7 @@ class Util:
if not rjokes_db:
return None
async with sqlite3.connect(database=rjokes_db, timeout=2) as db_conn:
db_query: str = (
"SELECT title, body, score FROM jokes WHERE score >= 100 ORDER BY RANDOM() LIMIT 1'"
)
db_query: str = "SELECT title, body, score FROM jokes WHERE score >= 100 ORDER BY RANDOM() LIMIT 1'"
async with await db_conn.execute(db_query) as cursor:
(title, body, score) = await cursor.fetchone()
return (title, body, score)