From 9e29628dc18ae8c4ff306cf5ccab38e8ae0173e2 Mon Sep 17 00:00:00 2001 From: Joan Date: Sat, 15 Jul 2023 14:40:54 +0200 Subject: [PATCH] Prevent the bot from being used in groups --- wallamanta/walladb.py | 19 +++++++++++-------- wallamanta/wallamanta.py | 4 +++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/wallamanta/walladb.py b/wallamanta/walladb.py index 883dc7c..781a069 100644 --- a/wallamanta/walladb.py +++ b/wallamanta/walladb.py @@ -77,15 +77,18 @@ def setup_db(): con.close() def is_user_valid(telegram_user_id): - con = connect_db() - cur = con.cursor(prepared=True) - params = (telegram_user_id,) - cur.execute(f"SELECT * FROM users WHERE telegram_user_id=%s AND active=True", params) - try: - ret = cur.fetchone() != None - except: + if telegram_user_id < 0: ret = False - con.close() + else: + con = connect_db() + cur = con.cursor(prepared=True) + params = (telegram_user_id,) + cur.execute(f"SELECT * FROM users WHERE telegram_user_id=%s AND active=True", params) + try: + ret = cur.fetchone() != None + except: + ret = False + con.close() return ret def is_user_expired(telegram_user_id): diff --git a/wallamanta/wallamanta.py b/wallamanta/wallamanta.py index 4fa17b1..9c54b74 100644 --- a/wallamanta/wallamanta.py +++ b/wallamanta/wallamanta.py @@ -388,7 +388,9 @@ async def test_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No telegram_user_id = helpers.get_telegram_user_id(update) telegram_user_name = helpers.get_telegram_user_name(update) #if not walladb.is_user_valid(telegram_user_id): - if walladb.get_user(telegram_user_id) == "NoName": + if telegram_user_id < 0: + message = "Este bot no se puede usar en grupos." + elif walladb.get_user(telegram_user_id) == "NoName": until = helpers.get_date_ahead(7) walladb.add_test_user(telegram_user_id, telegram_user_name, until) message = f"Periodo de prueba activado hasta el {helpers.get_spanish_date(until)}."