X Tutup
Skip to content

Implemented tools for Deep Linking#995

Closed
JosXa wants to merge 5 commits intomasterfrom
Filters_argument_equals
Closed

Implemented tools for Deep Linking#995
JosXa wants to merge 5 commits intomasterfrom
Filters_argument_equals

Conversation

@JosXa
Copy link
Copy Markdown
Contributor

@JosXa JosXa commented Feb 1, 2018

  • Implemented new helper-method create_deep_linked_url
  • Added Filters.regex and documented that it is not yet compliant with Expand Filters and remove unwanted parameters from Handlers #835 (i.e. not passing groups or groupdict)
  • Tests for all above
  • Added example for deep linking
  • Modified examples so that they all get their token from a settings.py. That way, you can set your token once and access all of the example bots. Added documentation to this in the appropriate places, especially that Updater(TOKEN), where TOKEN stems from the settings.py, requires you to replace the constant with a string if you users want to use the example standalone. This might be controversial, so please respond if you think it is a good addition.

Copy link
Copy Markdown
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.

@JosXa
This PR is actually consisted of three different and independent ideas.
Each of this deserves its own PR.
This has also been discussed in the developers group. Please separate the PR and we can go on from there.

bot.
"""

from examples.settings import TOKEN
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't like the examples folder treated as a package.
I also like the simplicity of each example looking its own token.
Please revert this.

To make my thought a bit more clear:

  1. The examples should be simple enough and maintain the concept of "code locality".
  2. The examples folder is by no mean to be treated as a python package which can be imported. These are all stand alone files each of them representing an example.

# Create the EventHandler and pass it your bot's token.
updater = Updater("TOKEN")
# Create the Updater and pass it your bot's token as a string.
updater = Updater(TOKEN)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

see comment about not treating examples/ folder as a package.

bot.
"""

from examples.settings import TOKEN
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

see comment about not treating examples/ folder as a package.

# Create the Updater and pass it your bot's token.
updater = Updater("TOKEN")
# Create the Updater and pass it your bot's token as a string.
updater = Updater(TOKEN)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

see comment about not treating examples/ folder as a package.


import logging

from examples.settings import TOKEN
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

see comment about not treating examples/ folder as a package.

self.name = 'Filters.regex({})'.format(self.pattern)

def filter(self, message):
return bool(re.search(self.pattern, message.text))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a reason not to do:

return bool(self.pattern.search(message.text))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

self.pattern can either be a regex compiled pattern or a string. You're solutions doesn't work for strings.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This should be okay

def filter(self, message):
return bool(re.search(self.pattern, message.text))


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

that's a redundant empty line.

command = _Command()
""":obj:`Filter`: Messages starting with ``/``."""

class regex(BaseFilter):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code for regex filter is good (regardless of some nitpicking).
However, it has nothing to do with the deep linking PR.
Please open a separate PR for it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See comment

assert expected == helpers.create_deep_linked_url(username, payload)
assert expected == helpers.create_deep_linked_url(username)

try:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please use pytest.raises() instead of the entire try...except... block

except Exception as e:
assert isinstance(e, ValueError)

try:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please use pytest.raises() instead of the entire try...except... block

@tsnoam tsnoam added the 📋 pending-reply work status: pending-reply label Feb 12, 2018
@JosXa
Copy link
Copy Markdown
Contributor Author

JosXa commented Feb 25, 2018

Hi @tsnoam,

please have a look at the example.
I depend on the Filters.regex addition there in order to differentiate between different payloads for the deep-linked callback. I don't see how I could split the Filters.regex, the example deeplinking.py, and the deep-link generator into separate PRs. Since you commented that the Filters.regex looks good, would it be okay to push them as a whole?

I will remove the other example token stuff however, that was more of an experiment and you're right, it doesn't have anything to do with the rest.

Cheers

@JosXa JosXa removed the 📋 pending-reply work status: pending-reply label Feb 25, 2018
@python-telegram-bot python-telegram-bot deleted a comment from codecov bot Mar 1, 2018
@tsnoam
Copy link
Copy Markdown
Member

tsnoam commented Mar 1, 2018

@JosXa
Please send Regex filter as a different PR and then we can proceed.

@JosXa
Copy link
Copy Markdown
Contributor Author

JosXa commented Mar 3, 2018

Status: Waiting for merge of #1028

@jh0ker
Copy link
Copy Markdown
Member

jh0ker commented Mar 16, 2018

@JosXa #1028 is merged

@JosXa
Copy link
Copy Markdown
Contributor Author

JosXa commented Mar 16, 2018

@jh0ker Neat!

@JosXa JosXa closed this Mar 16, 2018
@github-actions github-actions bot locked and limited conversation to collaborators Aug 21, 2020
@Bibo-Joshi Bibo-Joshi deleted the Filters_argument_equals branch November 23, 2020 09:00
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

X Tutup