Skip to content

Conversation

@jsmnbom
Copy link
Member

@jsmnbom jsmnbom commented Sep 3, 2016

Not sure if the docstring is correct...
Also this PR should be squashed, since it has some derpy commits.

@rahiel rahiel self-assigned this Sep 3, 2016
@jsmnbom jsmnbom closed this Sep 3, 2016
@jsmnbom jsmnbom deleted the get-entities branch September 3, 2016 22:48
@jsmnbom jsmnbom restored the get-entities branch September 3, 2016 22:48
@jsmnbom jsmnbom reopened this Sep 3, 2016
@rahiel
Copy link
Contributor

rahiel commented Sep 4, 2016

Good work @bomjacob!

I think at this point it makes sense to add a get_entities function that takes as argument entity_type (string) and returns a list of all the matching entities, and when entity_type is None, it returns all of them. With that this PR is good to go.

@jh0ker
Copy link
Member

jh0ker commented Sep 4, 2016

Nice work @bomjacob and @rahiel!

I also like the idea @rahiel, and it would be best to add all possible values for MessageEntity.type as constants in MessageEntity too.

By the way, this PR is somewhat related to #362 because both add methods to Telegram classes.

@jsmnbom
Copy link
Member Author

jsmnbom commented Sep 4, 2016

Danm.. I wrote that before I saw what you wrote @jh0ker. I'll pull the possible values out and add them as a constant instead.
Also... this might be an issue (depending on what we want): text_link and text_mention has extra data than just some text, which currently wouldn't get returned by get_entities... Should we somehow add that?
And correct me if I'm wrong, but this shouldn't really affect #362, should it? I mean these methods kinda work as class methods anyways, right?

Also makes `get_entities` use it.
@jsmnbom
Copy link
Member Author

jsmnbom commented Sep 4, 2016

Was that what you had in mind in terms of constant @jh0ker ?

@jh0ker
Copy link
Member

jh0ker commented Sep 4, 2016

Actually I had something in mind like this or this.

On your other question, why not just return a list of MessageEntity instead of a list of strings?

@jsmnbom
Copy link
Member Author

jsmnbom commented Sep 4, 2016

Want them to be in the MessageEntity class, or in a seperate class?
And if in the same class, is there any easy way to get them all?
We could make it a subclass. So it would be fx. MessageEntity.Type.TEXT_MENTION.. but that might be annoying to write.

@jh0ker
Copy link
Member

jh0ker commented Sep 4, 2016

Yeah in the MessageEntity class is fine IMO. You can still have the list of all types, just add a constant for each of them too.

@jh0ker
Copy link
Member

jh0ker commented Sep 4, 2016

You renamed it to ALL_TYPES in messageentity.py but forgot to change it in message.py ;)

@jsmnbom
Copy link
Member Author

jsmnbom commented Sep 4, 2016

Forgot to push :P

@jsmnbom
Copy link
Member Author

jsmnbom commented Sep 4, 2016

Don't merge yet. I wanna quickly write a test.

Also change the test for get_entity slightly.. the setUp isn't actually
needed at all.
@jsmnbom
Copy link
Member Author

jsmnbom commented Sep 4, 2016

Should this be changed?

Args:
     types (Optional[list]): Only extract text of MessageEntities if its type
     in in this list. Defaults to all types.

Like do I need to specify that it's a list of MessageEntity types somehow, or is this okay?

@jh0ker
Copy link
Member

jh0ker commented Sep 4, 2016

I think most docstrings have to be updated since they are referring to text instead of entities. Additionally, it might be a good idea to document when and why you should not use Message.entities directly and instead use these helper methods.

Also, maybe it would be a good idea to rename get_entity to get_entity_text, just to make clear what it does. And can't you re-use get_entity_text in get_entities? I think there is some duplicate code there.

@jh0ker
Copy link
Member

jh0ker commented Sep 4, 2016

While discussing with @bomjacob, we were re-thinking the MessageEntity.text attribute. Right now, it's not there by default and only "magically appears" if the entity object is processed by Message.get_entities.

Possible courses of action:

  • Leave it like it is
  • Define it with None as default
  • Make it a property and raise a meaningful exception when queried before set
  • Remove it completely and instead return a dict from get_entities that maps a MessageEntity to their text

Also make parse_entities return a dict {MessageEntity: text} instead of a MessageEntiy.
@jsmnbom
Copy link
Member Author

jsmnbom commented Sep 6, 2016

Alright. It's been decited to go with: "Remove it completely and instead return a dict from get_entities that maps a MessageEntity to their text"
Latest commit should make the necessary changes and also rename the getters to something more appropriate.
Note: currently missing proper docstrings.. hold on

@jsmnbom jsmnbom merged commit 6647ae3 into python-telegram-bot:master Sep 7, 2016
@rahiel rahiel modified the milestone: 5.1 Sep 7, 2016
@rahiel
Copy link
Contributor

rahiel commented Sep 7, 2016

We might need an extra snippet at the end of https://github.com/python-telegram-bot/python-telegram-bot/wiki/Code-snippets for this.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 24, 2020
@Bibo-Joshi Bibo-Joshi added 🔌 enhancement pr description: enhancement and removed enhancement labels Nov 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

🔌 enhancement pr description: enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants