Add check_users_and_update_blocked

This commit is contained in:
Zakhar Izmaylov
2025-01-11 20:29:01 +03:00
parent 3c0a94a3f8
commit 520fad20e5
+22
View File
@@ -32,6 +32,28 @@ from logger import logger
router = Router()
async def check_users_and_update_blocked(bot: Bot):
conn = None
try:
conn = await asyncpg.connect(DATABASE_URL)
users = await conn.fetch("SELECT tg_id FROM users")
for user in users:
try:
await bot.send_chat_action(user['tg_id'], "typing")
except (TelegramForbiddenError,Exception):
await conn.execute(
"INSERT INTO blocked_users (tg_id) VALUES ($1) ON CONFLICT (tg_id) DO NOTHING",
user['tg_id']
)
logger.info(f"User {user['tg_id']} added to blocked_users")
except Exception as e:
logger.error(f"Error in check_users_and_update_blocked: {e}")
finally:
if conn:
await conn.close()
async def notify_expiring_keys(bot: Bot):
conn = None