Skip to content

Commit

Permalink
Allow user filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
clemsau committed Mar 30, 2023
1 parent 56bd4b9 commit 0bd3f38
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)

import handlers
from src.config import openai_api_key, telegram_token
from src.config import allowed_telegram_users, openai_api_key, telegram_token
from src.openai_utils import Chat

openai_instance: Chat = Chat(openai_api_key)
Expand All @@ -34,11 +34,21 @@ def run_bot() -> None:
.build()
)

user_filter = filters.ALL
if len(allowed_telegram_users) > 0:
user_filter = filters.User(user_id=allowed_telegram_users)

application.add_handler(
MessageHandler(
filters.TEXT & ~filters.COMMAND & user_filter, handlers.message_handler
)
)
application.add_handler(
CommandHandler("reset", handlers.reset_handler, filters=user_filter)
)
application.add_handler(
MessageHandler(filters.TEXT & ~filters.COMMAND, handlers.message_handler)
CommandHandler("mention", handlers.mention_handler, filters=user_filter)
)
application.add_handler(CommandHandler("reset", handlers.reset_handler))
application.add_handler(CommandHandler("mention", handlers.mention_handler))

application.run_polling()

Expand Down
1 change: 1 addition & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@

telegram_token = config["telegram_token"]
openai_api_key = config["openai_api_key"]
allowed_telegram_users = config["allowed_telegram_users"]
answer_on_mention = False

0 comments on commit 0bd3f38

Please sign in to comment.