Working copy

This commit is contained in:
Hash Borgir
2024-02-12 14:41:01 -07:00
parent 4e635b0042
commit 992fcec9ae
15 changed files with 226 additions and 121 deletions

View File

@@ -29,15 +29,20 @@ async def handle_command(room, message, bot, PREFIX):
(username TEXT PRIMARY KEY, points INTEGER)''')
c.execute('''INSERT OR IGNORE INTO karma (username, points) VALUES (?, ?)''', (sender, 0))
c.execute('''SELECT points FROM karma WHERE username = ?''', (sender,))
points = c.fetchone()[0]
row = c.fetchone()
if row is not None:
points = row[0]
await bot.api.send_markdown_message(room.room_id, f"💗 {sender}'s karma points: {points}")
logging.info(f"Sent {sender}'s karma points ({points}) to the room")
else:
await bot.api.send_markdown_message(room.room_id, f"💗 {sender} does not have any karma points yet.")
logging.info(f"Sent message that {sender} does not have any karma points yet.")
conn.close()
await bot.api.send_text_message(room.room_id, f"{sender}'s karma points: {points}")
logging.info(f"Sent {sender}'s karma points ({points}) to the room")
elif len(args) == 1:
username = args[0]
if username == sender:
await bot.api.send_text_message(room.room_id, "You cannot modify your own karma.")
await bot.api.send_markdown_message(room.room_id, "You cannot modify your own karma.")
logging.info("Sent self-modification warning message to the room")
return
@@ -47,19 +52,24 @@ async def handle_command(room, message, bot, PREFIX):
(username TEXT PRIMARY KEY, points INTEGER)''')
c.execute('''INSERT OR IGNORE INTO karma (username, points) VALUES (?, ?)''', (username, 0))
c.execute('''SELECT points FROM karma WHERE username = ?''', (username,))
points = c.fetchone()[0]
row = c.fetchone()
if row is not None:
points = row[0]
await bot.api.send_markdown_message(room.room_id, f"💗 {username}'s karma points: {points}")
logging.info(f"Sent {username}'s karma points ({points}) to the room")
else:
await bot.api.send_markdown_message(room.room_id, f"💗 {username} does not have any karma points yet.")
logging.info(f"Sent message that {username} does not have any karma points yet.")
conn.close()
await bot.api.send_text_message(room.room_id, f"{username}'s karma points: {points}")
logging.info(f"Sent {username}'s karma points ({points}) to the room")
elif len(args) == 2:
username, action = args
if action not in ['up', 'down']:
await bot.api.send_text_message(room.room_id, "Invalid action. Use 'up' or 'down'.")
await bot.api.send_markdown_message(room.room_id, "Invalid action. Use 'up' or 'down'.")
logging.info("Sent invalid action message to the room")
return
if username == sender:
await bot.api.send_text_message(room.room_id, "You cannot modify your own karma.")
await bot.api.send_markdown_message(room.room_id, "You cannot modify your own karma.")
logging.info("Sent self-modification warning message to the room")
return
@@ -69,17 +79,23 @@ async def handle_command(room, message, bot, PREFIX):
(username TEXT PRIMARY KEY, points INTEGER)''')
if action == 'up':
c.execute('''INSERT OR IGNORE INTO karma (username, points) VALUES (?, ?)''', (username, 0))
c.execute('''UPDATE karma SET points = points + 1 WHERE username = ?''', (username,))
else:
c.execute('''INSERT OR IGNORE INTO karma (username, points) VALUES (?, ?)''', (username, 0))
c.execute('''UPDATE karma SET points = points - 1 WHERE username = ?''', (username,))
conn.commit()
c.execute('''SELECT points FROM karma WHERE username = ?''', (username,))
points = c.fetchone()[0]
row = c.fetchone()
if row is not None:
points = row[0]
await bot.api.send_markdown_message(room.room_id, f"💗 {username}'s karma points: {points}")
logging.info(f"Sent {username}'s karma points ({points}) to the room")
else:
await bot.api.send_markdown_message(room.room_id, f"💗 {username} does not have any karma points yet.")
logging.info(f"Sent message that {username} does not have any karma points yet.")
conn.close()
await bot.api.send_text_message(room.room_id, f"{username}'s karma points: {points}")
logging.info(f"Sent {username}'s karma points ({points}) to the room")
else:
await bot.api.send_text_message(room.room_id, "Usage: !karma [username] [up/down]")
await bot.api.send_markdown_message(room.room_id, "Usage: !karma [username] [up/down]")
logging.info("Sent usage message to the room")