new file: api functions

This commit is contained in:
Anastasia Viktorova
2023-08-22 16:42:52 +03:00
committed by IgorL123
parent 24adab1e19
commit 4a1a93792d
2 changed files with 28 additions and 29 deletions
+26
View File
@@ -0,0 +1,26 @@
def isEnd(cur, trueChatID):
# cur.execute(f"SELECT ChatID FROM Chats WHERE TrueChatID = '{trueChatID}'")
# row = cur.fetchall()
# chatID = row[0]
#
# cur.execute(f"SELECT UserID FROM UsersChats WHERE ChatID = '{chatID}'")
# usersIDs = cur.fetchall()
#
# allAlive = True
# for id in usersIDs:
# cur.execute(f"SELECT isAlive FROM Users WHERE UserID = '{id}', role = ")
# row = cur.fetchall()
# if row[0] == False:
# allAlive = False
cur.execute(f"Select role from chats join userschats uc on uc.chatid = chats.chatid join "
f"users on users.userid = uc.userid where truechatid = '{trueChatID}' and isAlive = true")
roles = cur.fetchall()
m = roles.count(4)
if m == 0:
return "citizens"
elif m >= len(roles) - m:
return "mafia"
return ""