From 259840b40e49eab2d36e1068ddcf7616df1822e7 Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 23 Feb 2021 21:34:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D0=B0=20/i?= =?UTF-8?q?d,=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20s?= =?UTF-8?q?et=5Fenv?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 1 + set_env.py => setenv.py | 5 +++-- telegram.py | 9 +++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) rename set_env.py => setenv.py (94%) diff --git a/.dockerignore b/.dockerignore index 74796ff..e78b5d6 100644 --- a/.dockerignore +++ b/.dockerignore @@ -18,6 +18,7 @@ __pycache__ # Environment *.env env_file +setenv.py # Docker docker-compose*.yml diff --git a/set_env.py b/setenv.py similarity index 94% rename from set_env.py rename to setenv.py index aa56e48..3fc7823 100644 --- a/set_env.py +++ b/setenv.py @@ -8,6 +8,7 @@ POSTGRES_DB=tgvkbot POSTGRES_PASSWORD=postgres BOT_TOKEN=%(tg_token)s VK_APP_ID=%(vk_app_id)s +ALLOWED_USER_IDS=%(allowed_user_ids)s """ @@ -55,9 +56,9 @@ def set_env(): break except HTTPError: print('❌ VK APP ID неверный, попробуйте снова!') - + with open('env_file', 'w') as env_file: - env_file.write(ENV_FILE_TEMPLATE % {'tg_token': tg_token, 'vk_app_id': vk_app_id or VK_APP_ID}) + env_file.write(ENV_FILE_TEMPLATE % {'tg_token': tg_token, 'vk_app_id': vk_app_id or VK_APP_ID}, 'allowed_user_ids': '') print('✅ Успешно!') diff --git a/telegram.py b/telegram.py index e35b145..a25f361 100644 --- a/telegram.py +++ b/telegram.py @@ -562,7 +562,7 @@ async def search_callback(call: types.CallbackQuery): async def send_welcome(msg: types.Message): if ALLOWED_USER_IDS: if str(msg.from_user.id) not in ALLOWED_USER_IDS.replace(' ','').split(','): - await msg.reply('⛔️ Бот недоступен для Вашего аккаунта.') + await msg.reply('⛔️ Бот недоступен для Вашего аккаунта.\nУзнать Telegram ID - /id') return user, created = await update_user_info(msg.from_user) tgchat, tgchat_created = await update_chat_info(msg.chat) @@ -697,10 +697,15 @@ async def help_command(msg: types.Message): '/search /s - Поиск по диалогам\n' \ '/chat - Список связанных чатов с диалогами ВКонтакте, привязать чат к диалогу можно добавив бота в группу\n' \ '/stop - Выход из ВКонтакте\n' \ - '/help - Помощь' + '/help - Помощь' \ + '/id - Узнать Telegram ID' await bot.send_message(msg.chat.id, HELP_MESSAGE, parse_mode=ParseMode.HTML) +@dp.message_handler(commands=['id']) +async def id_command(msg: types.Message): + user, created = await update_user_info(msg.from_user) + await bot.send_message(msg.chat.id, 'Ваш ID: {}'.format(msg.from_user.id), parse_mode=ParseMode.HTML) @dp.message_handler(content_types=['text']) async def handle_text(msg: types.Message):