-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Description
I have a filter to restrict some users from call some commands. I call AdminFilter and the relevant code can be seen below (actually, I check the admin users from a database).
class AdminFilter(BaseFilter):
def __init__(self, *admin_users):
self.admin_users = admin_users
def filter(self, message):
if message.from_user.username in self.admin_users:
return True
else:
message.reply_text("You're not an admin!", quote=True)
return FalseWith this filter applied, when an user that is not an admin calls the forbidden command, then receives a reply warning. And here is the issue.
Steps to reproduce
The following code illustrate the problem. In this scenario I have an administrative command /jungle and a normal command /rain.
If I am the admin, I call any command and see no issue, but If am not admin, I receive the warning for both commands.
def jungle(bot, update):
bot.send_message(update.message.chat_id, 'Welcome to the Jungle!')
def rain(bot, update):
bot.send_message(update.message.chat_id, 'November Rain...')
dispatcher.add_handler(CommandHandler('jungle', jungle, AdminFilter('wagnermacedo')))
dispatcher.add_handler(CommandHandler('rain', rain))Expected behaviour
Suppose I'm not the bot administrator, then in a conversation with the bot, I expect the following:
me: /jungle
bot: > reply /jungle
You're not an admin!
me: /rain
bot: November Rain...
Actual behaviour
What happens instead is that bot reply that I'm not an admin for both commands.
For /jungle, it's okay, it was expected
me: /jungle
bot: > reply /jungle
You're not an admin!
But /rain hasn't the admin filter, so it should not reply the warning.
me: /rain
bot: > reply /rain
You're not an admin!
bot: November Rain...
👆 Surprisingly the command still works, even replying I'm not admin...
Configuration
Version of Python, python-telegram-bot & dependencies:
I tested with the last version from master (59659ea).
$ python -m telegram
python-telegram-bot 10.0.1
certifi 2018.01.18
future 0.16.0
Python 3.4.8 (default, Apr 13 2018, 16:18:01) [GCC 5.4.0 20160609]
Fix
I have already fixed the issue in my machine, I'm going soon to create a pull request.