if recipient is None

This commit is contained in:
2025-02-15 13:57:47 -05:00
parent 9d23438b13
commit 6463ace40c
9 changed files with 617 additions and 716 deletions

View File

@ -31,13 +31,13 @@ class DB:
if hates and loves:
raise LoveHateException("Both hates and loves may not be True")
elif hates:
flag: int = -1
flag = -1
elif loves:
flag: int = 1
flag = 1
elif not hates and not loves:
raise LoveHateException("Neither loves nor hates were requested")
params: tuple = (thing, flag,)
params = (thing, flag,)
async with sqlite3.connect(self.db_path, timeout=2) as db_conn:
async with await db_conn.execute(query, params) as db_cursor:
result: list[tuple] = await db_cursor.fetchall()
@ -47,7 +47,7 @@ class DB:
return result
async def get_lovehates(self, loves: bool = False, hates: bool = False,
user: str = None, thing: str = None) -> list[tuple]|bool:
user: Optional[str] = None, thing: Optional[str] = None) -> list[tuple]|bool:
"""
Get a list of either 1) what {user} loves/hates, or who loves/hates {thing}, depending on bools loves, hates
Args:
@ -70,18 +70,18 @@ class DB:
if hates and loves:
raise LoveHateException("Both hates and loves may not be True")
elif hates:
flag: int = -1
flag = -1
elif loves:
flag: int = 1
flag = 1
elif not hates and not loves:
raise LoveHateException("Neither loves nor hates were requested")
if user:
query: str = "SELECT thing FROM lovehate WHERE display_name LIKE ? AND flag == ?"
params: tuple = (user, flag,)
query = "SELECT thing FROM lovehate WHERE display_name LIKE ? AND flag == ?"
params = (user, flag,)
elif thing:
query: str = "SELECT display_name FROM lovehate WHERE thing LIKE ? AND flag == ?"
params: tuple = (thing, flag,)
query = "SELECT display_name FROM lovehate WHERE thing LIKE ? AND flag == ?"
params = (thing, flag,)
async with sqlite3.connect(self.db_path, timeout=2) as db_conn:
async with await db_conn.execute(query, params) as db_cursor:
@ -127,21 +127,21 @@ class DB:
db_query: str = ""
params: tuple = (user, thing,)
already_opinionated: bool = await self.check_existence(user, thing)
already_opinionated: Optional[int] = await self.check_existence(user, thing)
if already_opinionated:
if flag == 0:
db_query: str = "DELETE FROM lovehate WHERE display_name LIKE ? AND thing LIKE ?"
db_query = "DELETE FROM lovehate WHERE display_name LIKE ? AND thing LIKE ?"
else:
loves_or_hates: str = "loves"
if already_opinionated == -1:
loves_or_hates: str = "hates"
loves_or_hates = "hates"
raise LoveHateException(f"But {user} already {loves_or_hates} {thing}...")
else:
match flag:
case -1:
db_query: str = "INSERT INTO lovehate(display_name, flag, thing) VALUES(?, -1, ?)"
db_query = "INSERT INTO lovehate(display_name, flag, thing) VALUES(?, -1, ?)"
case 1:
db_query: str = "INSERT INTO lovehate(display_name, flag, thing) VALUES(?, 1, ?)"
db_query = "INSERT INTO lovehate(display_name, flag, thing) VALUES(?, 1, ?)"
case _:
raise LoveHateException("Unknown error, default case matched")