More fixes to account checker, and test command

This commit is contained in:
Joan
2023-07-04 23:01:31 +02:00
parent addf9302c6
commit 5e4b8725cb
3 changed files with 13 additions and 5 deletions

View File

@@ -9,13 +9,18 @@ logging.basicConfig(
) )
async def work(sleep_time): async def work(sleep_time):
await asyncio.sleep(30)
while True: while True:
user_list = walladb.get_user_list() user_list = walladb.get_user_list()
for user in user_list: for user in user_list:
if walladb.is_user_valid(user['telegram_user_id']): if walladb.is_user_valid(user['telegram_user_id']):
if walladb.is_user_expired(user['telegram_user_id']): if walladb.is_user_expired(user['telegram_user_id']):
message = "¡Hola!\n\nTu cuenta ha caducado. Si quieres seguir usando @wallamanta_bot ponte en contacto con @jocarduck\n\n¡Gracias!" message = "¡Hola!\n\nTu cuenta ha caducado. Si quieres seguir usando @wallamanta_bot ponte en contacto con @jocarduck\n\n¡Gracias!"
await helpers.send_message(user['telegram_user_id'], message) try:
await asyncio.sleep(1)
await helpers.send_message(user['telegram_user_id'], message)
except Exception as e:
logging.error(f"Couldn't sent message to {user['telegram_user_id']}. Reason: {e}")
walladb.deactivate_user(user['telegram_user_id']) walladb.deactivate_user(user['telegram_user_id'])
await asyncio.sleep(sleep_time) await asyncio.sleep(sleep_time)

View File

@@ -147,13 +147,15 @@ def add_test_user(telegram_user_id, telegram_name, until):
con = connect_db() con = connect_db()
cur = con.cursor(prepared=True) cur = con.cursor(prepared=True)
params = (telegram_user_id,) params = (telegram_user_id,)
res = cur.execute(f"SELECT * FROM users WHERE telegram_user_id=%s", params) cur.execute(f"SELECT * FROM users WHERE telegram_user_id=%s", params)
if res.fetchone() is None: try:
cur.fetchone()
params = (telegram_user_id, True, 'testing', until, telegram_name.first_name) params = (telegram_user_id, True, 'testing', until, telegram_name.first_name)
cur.execute("INSERT INTO users VALUES (%s, %s, %s, %s, %s)", params) cur.execute("INSERT INTO users VALUES (%s, %s, %s, %s, %s)", params)
con.commit() con.commit()
else:
found = True found = True
except Exception as e:
logging.error(f"Couldn't find username with id {telegram_user_id}: {e}")
con.close() con.close()
logging.info(f"Added test user {telegram_user_id} until {until}") logging.info(f"Added test user {telegram_user_id} until {until}")
return not found return not found

View File

@@ -387,7 +387,8 @@ async def status_command(update: Update, context: ContextTypes.DEFAULT_TYPE) ->
async def test_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: async def test_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
telegram_user_id = helpers.get_telegram_user_id(update) telegram_user_id = helpers.get_telegram_user_id(update)
telegram_user_name = helpers.get_telegram_user_name(update) telegram_user_name = helpers.get_telegram_user_name(update)
if not walladb.is_user_valid(telegram_user_id): #if not walladb.is_user_valid(telegram_user_id):
if walladb.get_user(telegram_user_id) == "NoName":
until = helpers.get_date_ahead(7) until = helpers.get_date_ahead(7)
walladb.add_test_user(telegram_user_id, telegram_user_name, until) walladb.add_test_user(telegram_user_id, telegram_user_name, until)
message = f"Periodo de prueba activado hasta el {helpers.get_spanish_date(until)}." message = f"Periodo de prueba activado hasta el {helpers.get_spanish_date(until)}."