mirror of
https://github.com/alterware/aw-bot.git
synced 2025-10-26 22:16:58 +00:00
feat: black list for memes
This commit is contained in:
@@ -87,12 +87,39 @@ def add_user_to_role(user_id: int, role_id: int, user_name: str):
|
||||
conn.close()
|
||||
|
||||
|
||||
def user_has_role(user_id: int):
|
||||
def user_has_role(user_id: int) -> bool:
|
||||
"""Checks if a user is in the database."""
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("SELECT * FROM user_roles WHERE user_id = ?", (user_id,))
|
||||
cursor.execute("SELECT 1 FROM user_roles WHERE user_id = ?", (user_id,))
|
||||
result = cursor.fetchone()
|
||||
|
||||
conn.close()
|
||||
|
||||
return result is not None
|
||||
|
||||
|
||||
def add_user_to_blacklist(user_id: int, reason: str):
|
||||
"""Adds a user to the blacklist."""
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute(
|
||||
"INSERT OR IGNORE INTO black_list (user_id, date_assigned, reason) VALUES (?, ?, ?)",
|
||||
(user_id, aware_utcnow().isoformat(), reason),
|
||||
)
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def is_user_blacklisted(user_id: int) -> bool:
|
||||
"""Checks if a user is on the blacklist."""
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("SELECT 1 FROM black_list WHERE user_id = ?", (user_id,))
|
||||
result = cursor.fetchone()
|
||||
|
||||
conn.close()
|
||||
|
||||
@@ -10,3 +10,9 @@ CREATE TABLE IF NOT EXISTS user_roles (
|
||||
date_assigned TEXT,
|
||||
user_name TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS black_list (
|
||||
user_id INTEGER PRIMARY KEY,
|
||||
date_assigned TEXT,
|
||||
reason TEXT
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user