33import os
44import sqlite3
55from time import time
6+
67from util import Cache
78
89
@@ -63,6 +64,7 @@ def create_database(database_path):
6364 "'games_won' INTEGER DEFAULT 0,"
6465 "'games_tie' INTEGER DEFAULT 0,"
6566 "'last_played' INTEGER DEFAULT 0,"
67+ "'banned' INTEGER DEFAULT 0,"
6668 "PRIMARY KEY('user_id'));" )
6769
6870 cursor .execute ("CREATE TABLE IF NOT EXISTS 'chats'"
@@ -73,14 +75,29 @@ def create_database(database_path):
7375 connection .close ()
7476
7577 def get_user (self , user_id ):
76- self .cursor .execute ("SELECT user_id, first_name, last_name, username, games_played, games_won, games_tie, last_played"
78+ self .cursor .execute ("SELECT user_id, first_name, last_name, username, games_played, games_won, games_tie, last_played, banned "
7779 " FROM users WHERE user_id=?;" , [str (user_id )])
7880
7981 result = self .cursor .fetchone ()
8082 if not result or len (result ) == 0 :
8183 return None
8284 return result
8385
86+ def is_user_banned (self , user_id ):
87+ """Checks if a user was banned by the admin of the bot from using it"""
88+ user = self .get_user (user_id )
89+ return user is not None and user [8 ] == 1
90+
91+ def ban_user (self , user_id ):
92+ """Bans a user from using a the bot"""
93+ self .cursor .execute ("UPDATE users SET banned=1 WHERE user_id=?;" , [str (user_id )])
94+ self .connection .commit ()
95+
96+ def unban_user (self , user_id ):
97+ """Unbans a user from using a the bot"""
98+ self .cursor .execute ("UPDATE users SET banned=0 WHERE user_id=?;" , [str (user_id )])
99+ self .connection .commit ()
100+
84101 def get_recent_players (self ):
85102 one_day_in_secs = 60 * 60 * 24
86103 current_time = int (time ())
0 commit comments