This commit is contained in:
2025-01-23 13:02:03 -05:00
parent 2df8250ba2
commit e55485e7e8
11 changed files with 37 additions and 22 deletions

View File

@@ -45,7 +45,7 @@ class KarmaDB:
async def get_karma(self, keyword: str) -> int | dict:
"""Get Karma Value for Keyword"""
async with sqlite3.connect(self.db_path, timeout=2) as db_conn:
async with db_conn.execute("SELECT score FROM karma WHERE keyword LIKE ? LIMIT 1", (keyword,)) as db_cursor:
async with await db_conn.execute("SELECT score FROM karma WHERE keyword LIKE ? LIMIT 1", (keyword,)) as db_cursor:
try:
(score,) = await db_cursor.fetchone()
return score
@@ -59,7 +59,7 @@ class KarmaDB:
"""Get Top n=10 Karma Entries"""
try:
async with sqlite3.connect(self.db_path, timeout=2) as db_conn:
async with db_conn.execute("SELECT keyword, score FROM karma ORDER BY score DESC LIMIT ?", (n,)) as db_cursor:
async with await db_conn.execute("SELECT keyword, score FROM karma ORDER BY score DESC LIMIT ?", (n,)) as db_cursor:
return await db_cursor.fetchall()
except:
traceback.print_exc()
@@ -81,17 +81,17 @@ class KarmaDB:
logging.debug("Audit message: %s{audit_message}\nKeyword: %s{keyword}")
async with sqlite3.connect(self.db_path, timeout=2) as db_conn:
async with db_conn.execute(audit_query, (keyword, audit_message,)) as db_cursor:
async with await db_conn.execute(audit_query, (keyword, audit_message,)) as db_cursor:
await db_conn.commit()
await db_cursor.close()
async with db_conn.execute(query, (now, keyword,)) as db_cursor:
async with await db_conn.execute(query, (now, keyword,)) as db_cursor:
if db_cursor.rowcount:
await db_conn.commit()
return True
if db_cursor.rowcount < 1: # Keyword does not already exist
await db_cursor.close()
new_val = 1 if not flag else -1
async with db_conn.execute(new_keyword_query, (keyword, new_val, now,)) as db_cursor:
async with await db_conn.execute(new_keyword_query, (keyword, new_val, now,)) as db_cursor:
if db_cursor.rowcount >= 1:
await db_conn.commit()
return True