Skip to content

Conversation

@Eldinnie
Copy link
Member

@Eldinnie Eldinnie commented May 22, 2018

  • update_filter attribute on filters
  • add update_type filter
  • Messagehandler rework
    • remove allow_edited (deprecated for a while)
    • set deprecated defaults to None
    • Raise deprecation warning when they're used
    • add sensible defaults for filters.
    • rework tests
  • Commandhandler rework
    • deprecate allow_edited
    • Raise deprecation warning when used
    • default to allowing edited

Eldinnie added 4 commits May 22, 2018 22:28
Makes it possible to have filters work on an update instead of message, while keeping behavior for current filters
- remove allow_edited (deprecated for a while)
- set deprecated defaults to None
- Raise deprecation warning when they're used
- add sensible defaults for filters.
- rework tests
@Eldinnie Eldinnie requested review from jsmnbom and tsnoam May 22, 2018 23:36
Copy link
Member

@jsmnbom jsmnbom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good! :D Added a few comments as usual :)
We gotta remember to update the wiki page too

which is the text following the command split on single or consecutive whitespace characters.
By default the handler listens to messages as well as edited messages. To change this behavior
use ``~Filters.update_type.edited_message``.
Copy link
Member

@jsmnbom jsmnbom May 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add "[...] as the filter argument" maybe?

Oh and this should probably be on the messagehandler too?

operators (& for and, | for or, ~ for not).
allow_edited (:obj:`bool`, optional): Determines whether the handler should also accept
edited messages. Default is ``False``.
DEPRECATED: Edited is allowed by default. To change this behavior use
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question is weather edited should be allowed by default, cause I honestly don't think so. If I'm making a bot, I'd probably make it reply to messages it receives, right? Well if it does that with an edited_message, then the bot has sent two messages (one outdated, and the new one in reply to the edited one)..
If we wanna have this be the default, we should at least provide a reply_or_edit or similar convenience method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe it;s personal, but I hate bots that don't respond to me fixing my type in a message and it doesn't respond like it should. IMO handling edited message is a sane default.

I don;t really understand what you mean with a reply_or_edit method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the new behaviour of allowing edited messages by default.

self.filters = filters
self.allow_edited = allow_edited
if filters:
self.filters = Filters.update_type.messages & filters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&= ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.filters = Non-existent at this point.


self.filters = filters
self.allow_edited = allow_edited
if filters:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we test that self.filters is a subclass of BaseFilter? Otherwise it will give an obscure crash when we try to & it.
Also, wouldn't this actually break simple function filters? Or have we not supported those for a while?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we never checked before, we could introduce the check here but just let them get an error if they make a mistake imo.. function filters are removed in this version anyway

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add validation on the type of the filters argument, we should do it with other handlers as well. We can do it with another PR if we find it necessary.


super(PrefixHandler, self).__init__(
'nocommand', callback, filters=filters, allow_edited=allow_edited, pass_args=pass_args,
'nocommand', callback, filters=filters, allow_edited=None, pass_args=pass_args,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we change 'nocommand' to None, to make it more clear that it's simply not used?
This of course requires changing a few things in the CommandHandler

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would mean changing CommandHandlers logic to accomodate this. This seemed pretty clean to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think (second thought?) that PrefixHandler is a redundant code. a RegexHandler with ^prefix is so much cleaner without so much boilerplate.

def filter(self, update):
return self.messages(update) or self.channel_posts(update)

update_type = _UpdateType()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we name it updates instead? It's simply shorter and in my opinion as descriptive

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes aggreed

- rename update_types -> updates
- added some clarification to docstrings
@Eldinnie
Copy link
Member Author

@bomjacob I changed some things accoring to your review, left some comments on others.
The wiki is already up to date with these changes

Copy link
Member

@tsnoam tsnoam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments on the code

operators (& for and, | for or, ~ for not).
allow_edited (:obj:`bool`, optional): Determines whether the handler should also accept
edited messages. Default is ``False``.
DEPRECATED: Edited is allowed by default. To change this behavior use
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the new behaviour of allowing edited messages by default.


self.filters = filters
self.allow_edited = allow_edited
if filters:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add validation on the type of the filters argument, we should do it with other handlers as well. We can do it with another PR if we find it necessary.

"""
if (isinstance(update, Update) and
(update.message or update.edited_message and self.allow_edited)):
if (isinstance(update, Update) and update.effective_message):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: there are redundant '()'
(they were good before for elegantly handling line breaks)

nitpick2: You can negate the if clause for an early return. Then the indentation of the rest of the method will be easier on the eye.

update (:class:`telegram.Update`): Incoming telegram update.
Returns:
:obj:`bool`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return object is not bool any longer.


super(PrefixHandler, self).__init__(
'nocommand', callback, filters=filters, allow_edited=allow_edited, pass_args=pass_args,
'nocommand', callback, filters=filters, allow_edited=None, pass_args=pass_args,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think (second thought?) that PrefixHandler is a redundant code. a RegexHandler with ^prefix is so much cleaner without so much boilerplate.

name = 'Filters.text'

def filter(self, message):
print('text_filter_filter {}'.format(repr(self)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you print here?
also nitpicking: 'text_filter_filter {:r}'.format(self) is more idiomatic

@Eldinnie Eldinnie changed the base branch from master to V11 May 31, 2018 12:24
@Eldinnie Eldinnie closed this Sep 21, 2018
@jsmnbom jsmnbom changed the base branch from V11 to V12 September 21, 2018 12:46
@jsmnbom jsmnbom reopened this Sep 21, 2018
@jsmnbom jsmnbom closed this Sep 21, 2018
@github-actions github-actions bot locked and limited conversation to collaborators Aug 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants