本文整理汇总了Python中telegram.MessageEntity.URL属性的典型用法代码示例。如果您正苦于以下问题:Python MessageEntity.URL属性的具体用法?Python MessageEntity.URL怎么用?Python MessageEntity.URL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类telegram.MessageEntity
的用法示例。
在下文中一共展示了MessageEntity.URL属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: disable_web_page_preview
# 需要导入模块: from telegram import MessageEntity [as 别名]
# 或者: from telegram.MessageEntity import URL [as 别名]
def disable_web_page_preview(update, context):
if not update.message.reply_to_message:
text = ("This command permits to remove the web page preview from a message with "
"a link.\n\nUse it replying to the message the bot already echoed and you "
"want to disable the preview with this command.")
update.message.reply_text(text=text)
return
if not update.message.reply_to_message.text:
text = "This message does not have a web page preview"
update.message.reply_to_message.reply_text(text=text, quote=True)
return
entities_list = [MessageEntity.URL, MessageEntity.TEXT_LINK]
entities = update.message.reply_to_message.parse_entities(entities_list)
if len(entities) == 0:
text = "This message does not have a web page preview"
update.message.reply_to_message.reply_text(text=text, quote=True)
return
text = update.message.reply_to_message.text_html
update.message.reply_to_message.reply_text(
text=text,
disable_web_page_preview=True,
parse_mode=ParseMode.HTML)
示例2: github
# 需要导入模块: from telegram import MessageEntity [as 别名]
# 或者: from telegram.MessageEntity import URL [as 别名]
def github(update: Update, context: CallbackContext):
message = update.message or update.edited_message
last = 0
thing_matches = []
things = {}
# Due to bug in ptb we need to convert entities of type URL to TEXT_LINK for them to be converted to html
for entity in message.entities:
if entity.type == MessageEntity.URL:
entity.type = MessageEntity.TEXT_LINK
entity.url = message.parse_entity(entity)
for match in GITHUB_PATTERN.finditer(get_text_not_in_entities(message.text_html)):
logging.debug(match.groupdict())
owner, repo, number, sha = [match.groupdict()[x] for x in ('owner', 'repo', 'number', 'sha')]
if number or sha:
thing_matches.append((owner, repo, number, sha))
for thing_match in thing_matches:
last = keep_typing(last, update.effective_chat, ChatAction.TYPING)
owner, repo, number, sha = thing_match
if number:
issue = github_issues.get_issue(int(number), owner, repo)
things[issue.url] = github_issues.pretty_format_issue(issue)
elif sha:
commit = github_issues.get_commit(sha, owner, repo)
things[commit.url] = github_issues.pretty_format_commit(commit)
if things:
reply_or_edit(update, context, '\n'.join([f'<a href="{url}">{name}</a>' for url, name in things.items()]))