Explorar o código

Decrease the karma of the one who decreases others’ karmas (#201)

Roj %!s(int64=4) %!d(string=hai) anos
pai
achega
f4e5caff05
Modificáronse 1 ficheiros con 12 adicións e 0 borrados
  1. 12 0
      wbb/modules/karma.py

+ 12 - 0
wbb/modules/karma.py

@@ -115,6 +115,18 @@ async def downvote(_, message):
         return
 
     chat_id = message.chat.id
+    user_id = message.from_user.id
+    current_karma = await get_karma(chat_id, await int_to_alpha(user_id))
+    if current_karma:
+        current_karma = current_karma["karma"]
+        karma = current_karma - 1
+        new_karma = {"karma": karma}
+        await update_karma(chat_id, await int_to_alpha(user_id), new_karma)
+    else:
+        karma = 1
+        new_karma = {"karma": karma}
+        await update_karma(chat_id, await int_to_alpha(user_id), new_karma)
+
     user_id = message.reply_to_message.from_user.id
     user_mention = message.reply_to_message.from_user.mention
     current_karma = await get_karma(chat_id, await int_to_alpha(user_id))