From e3ab194c06be566c5e4b083f1f70fa6a7b019463 Mon Sep 17 00:00:00 2001 From: coolneng Date: Sat, 31 Oct 2020 14:20:46 +0100 Subject: [PATCH] Implement Two-factor authentification --- src/bot.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/bot.py b/src/bot.py index 10ad65b..2ccb6b4 100644 --- a/src/bot.py +++ b/src/bot.py @@ -1,6 +1,15 @@ +import logging + from telethon import TelegramClient, events from telethon.sessions import StringSession -from constants import API_ID, API_HASH, BOT_TOKEN, SESSION + +from constants import API_HASH, API_ID, BOT_TOKEN, CSV_FILE, SESSION +from database import search_csv +from notifier import send_mail + +logging.basicConfig( + format="[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s", level=logging.WARNING +) bot = TelegramClient(StringSession(SESSION), API_ID, API_HASH).start( bot_token=BOT_TOKEN @@ -15,6 +24,18 @@ async def start(event): raise events.StopPropagation +@bot.on(events.NewMessage(pattern=r"^[0-9]{8,8}[A-Za-z]")) +@bot.on( + events.NewMessage(pattern=r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)") +) +async def identify(event): + user = search_csv(filepath=CSV_FILE, id=event.raw_text) + send_mail(recipient=user["correo_institucional"]) + await event.respond( + "El usuario se ha identificado con éxito. Se ha mandado una clave alfanumérica a su correo institucional. Por favor envíe la clave para continuar con el proceso." + ) + + def main(): bot.run_until_disconnected()