Created
December 16, 2022 20:21
-
-
Save rainrisa/b1f7a9304e910aad24ca5e40ea7b7e08 to your computer and use it in GitHub Desktop.
pyrogram parse entities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# source: gramjs library | |
# https://github.com/gram-js/gramjs/blob/babc668a6d2b0c193b2b640173ae1935fe02f959/gramjs/tl/custom/message.ts#L839-L854 | |
# https://github.com/gram-js/gramjs/blob/babc668a6d2b0c193b2b640173ae1935fe02f959/gramjs/Utils.ts#L261-L269 | |
def get_inner_text(text, entities): | |
result = [] | |
for entity in entities: | |
start = entity.offset | |
end = start + entity.length | |
result.append(text[start:end]) | |
return result | |
@app.on_message() | |
async def print_inner_text(_, message): | |
chat_id = message.chat.id | |
if message.entities: | |
inner_text = get_inner_text(message.text, message.entities) | |
print(inner_text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment