From 76da87bb315514e39568bb690e52a76f605801e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Sauvage?= Date: Tue, 14 Mar 2023 13:22:06 +0100 Subject: [PATCH] Add support for user ids in config * Add support for user ids * Allow both usernames and user ids at the same time --- bot/bot.py | 9 +++++---- config/config.example.yml | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index f5b72f7..115098f 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -308,10 +308,11 @@ def run_bot() -> None: ) # add handlers - if len(config.allowed_telegram_usernames) == 0: - user_filter = filters.ALL - else: - user_filter = filters.User(username=config.allowed_telegram_usernames) + user_filter = filters.ALL + if len(config.allowed_telegram_usernames) > 0: + usernames = [x for x in config.allowed_telegram_usernames if isinstance(x, str)] + user_ids = [x for x in config.allowed_telegram_usernames if isinstance(x, int)] + user_filter = filters.User(username=usernames) | filters.User(user_id=user_ids) application.add_handler(CommandHandler("start", start_handle, filters=user_filter)) application.add_handler(CommandHandler("help", help_handle, filters=user_filter)) diff --git a/config/config.example.yml b/config/config.example.yml index 9a44c85..08b17b7 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -1,7 +1,7 @@ telegram_token: "" openai_api_key: "" use_chatgpt_api: true -allowed_telegram_usernames: [] # if empty, the bot is available to anyone +allowed_telegram_usernames: [] # if empty, the bot is available to anyone. pass a username string to allow it and/or user ids as integers new_dialog_timeout: 600 # new dialog starts after timeout (in seconds) chatgpt_price_per_1000_tokens: 0.002