Conversation
(pycharm can be an arse sometimes)
…ilters themselves
- Fixes per Eldinnie's comments. - Fixes per warnings when running sphinx.
Context Based Handlers -> Context Based Callbacks No longer use_context args on every single Handler Instead set dispatcher/updater .use_context=True to use Works with - Handler callbacks - Error handler callbacks - Job callbacks Change examples to context based callbacks so new users are not confused Rename and move the context object from Handlers.HandlerContext to CallbackContext, since it doesn't only apply to handlers anymore. Fix tests by adding a new fixture `cpd` which is a dispatcher with use_context=True
Only register valid botcommands, else raise ValueError
| else: | ||
| self.command = [x.lower() for x in command] | ||
| for comm in self.command: | ||
| if not re.match(r'^[\da-z_]{1,32}$', comm): |
There was a problem hiding this comment.
I'm not sure that 32 chars is a hard limit, dispite the docs... Do we care?
Both my phone and my desktop app, highlights commands that are longer than 32 chars at least.
There was a problem hiding this comment.


There's a discrepancy here. @Botfather won't let you add too long commands for suggestion, but they are recognised as entities.
I vote to stay with the docs and enforce 32 chars
telegram/ext/commandhandler.py
Outdated
| command = first_word[1:].split('@') | ||
| command.append( | ||
| message.bot.username) # in case the command was sent without a username | ||
| if message.entities and message.entities[0].type == MessageEntity.BOT_COMMAND and \ |
There was a problem hiding this comment.
Really not a fan of \ in code.. could we wrap it in parenthesis instead?
| message.bot.username) # in case the command was sent without a username | ||
| if message.entities and message.entities[0].type == MessageEntity.BOT_COMMAND and \ | ||
| message.entities[0].offset == 0: | ||
| command = message.text[1:message.entities[0].length] |
There was a problem hiding this comment.
I know this technically works because command can only be ascii, but maybe using the parse entity method would be a good idea here
There was a problem hiding this comment.
I think it's easiest and safest this way.
If we used parse_entities we would have to search the dict for either message.text.split()[0] or check every entity for it's offset. Dicts are not ordered on <py3.5.
Since as you pointed out the entity is ascii and we know for sure it should be the first one in message.entites I think this is the best way.
| if message.entities and message.entities[0].type == MessageEntity.BOT_COMMAND and \ | ||
| message.entities[0].offset == 0: | ||
| command = message.text[1:message.entities[0].length] | ||
| args = message.text.split()[1:] |
There was a problem hiding this comment.
Wouldn't it be more correct to do message.text[len(command):].split() ?
There was a problem hiding this comment.
This is the way we always calculated args, And the result should be the same I guess, except for an extra len() call in your proposal.
There was a problem hiding this comment.
Depending on the internals of .split() and telegrams entity calculations, but yeah, you're probably right ^^
telegram/ext/commandhandler.py
Outdated
| """Handler class to handle custom prefix commands | ||
|
|
||
| This is a intermediate handler between :class:`MessageHandler` and :class:`CommandHandler`. | ||
| It supports configurable commands with the same options as commandhandler. It will respond to |
| Filters. | ||
| allow_edited (:obj:`bool`): Determines Whether the handler should also accept | ||
| edited messages. | ||
| pass_args (:obj:`bool`): Determines whether the handler should be passed |
There was a problem hiding this comment.
Is there really a need to have the pass_ stuff on this new handler?
There was a problem hiding this comment.
hmm, In my mind It would be best to keep all handlers compatible to the same model for v11.0 You disagree?
There was a problem hiding this comment.
Kinda, but mostly from a "we shouldn't be writing code that's already deprecated" standpoint, but since you've already written it. I think it's fine :D
| context.args = check_result | ||
|
|
||
|
|
||
| class PrefixHandler(CommandHandler): |
There was a problem hiding this comment.
Should we add a docstring note about arguments being availible on the CallbackContext object? (applies to CommandHandler too I suppose)
|
|
||
| Attributes: | ||
| prefix (:obj:`str` | List[:obj:`str`]): The prefix(es) that will precede :attr:`command`. | ||
| command (:obj:`str` | List[:obj:`str`]): The command or list of commands this handler |
There was a problem hiding this comment.
? On the next line at the end of the sentence...
telegram/ext/commandhandler.py
Outdated
|
|
||
| Note: | ||
| :attr:`pass_user_data` and :attr:`pass_chat_data` determine whether a ``dict`` you | ||
| can use to keep any data in will be sent to the :attr:`callback` function.. Related to |
There was a problem hiding this comment.
I'll fix this in every handler then :D
telegram/ext/inlinequeryhandler.py
Outdated
| pass_user_data=False, | ||
| pass_chat_data=False): | ||
| pass_chat_data=False, | ||
| use_context=False): |
There was a problem hiding this comment.
leftover from my base. Fixed
telegram/ext/commandhandler.py
Outdated
|
|
||
| Commands are Telegram messages that start with ``/``, optionally followed by an ``@`` and the | ||
| bot's name and/or some additional text. | ||
| bot's name and/or some additional text. It will add a ``list`` to the :class:`CallbackContext` |
There was a problem hiding this comment.
"It" doesn't really make sense here (it works fine in the prefixhandler)
…"" This reverts commit 9e2357b
Only register valid botcommands, else raise ValueError
Make CommandHandler strict
Only register valid botcommands, else raise ValueError
Add PrefixHandler