From 9ee51dc19ff012790bb142387dca7287e56f6d81 Mon Sep 17 00:00:00 2001 From: StNicolay Date: Sun, 13 Nov 2022 18:49:57 +0300 Subject: [PATCH] Added /gen_password command --- src/bot/__init__.py | 3 +++ src/bot/handlers.py | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/bot/__init__.py b/src/bot/__init__.py index 97f87b9..0fb9325 100644 --- a/src/bot/__init__.py +++ b/src/bot/__init__.py @@ -46,4 +46,7 @@ def create_bot(token: str, engine: Engine) -> telebot.TeleBot: bot.register_message_handler( functools.partial(handlers.import_accounts, bot, engine), commands=["import"] ) + bot.register_message_handler( + functools.partial(handlers.gen_password, bot), commands=["gen_password"] + ) return bot diff --git a/src/bot/handlers.py b/src/bot/handlers.py index bacc201..1626825 100644 --- a/src/bot/handlers.py +++ b/src/bot/handlers.py @@ -13,6 +13,7 @@ from .utils import ( check_account_name, check_login, check_passwd, + gen_passwd, get_all_accounts, json_to_accounts, send_tmp_message, @@ -471,3 +472,15 @@ def _import3( send_tmp_message(bot, mes.chat.id, mes_text, 10) del text, mes, accounts gc.collect() + + +def gen_password(bot: telebot.TeleBot, mes: Message) -> None: + # Generate 10 passwords and put 'em in the backticks + base_handler(bot, mes) + passwords = (f"`{gen_passwd()}`" for _ in range(10)) + text = ( + "Пароли:\n" + + "\n".join(passwords) + + "\nНажмите на пароль, чтобы его скопировать" + ) + send_tmp_message(bot, mes.chat.id, text)