本文整理汇总了Python中telegram.CallbackQuery方法的典型用法代码示例。如果您正苦于以下问题:Python telegram.CallbackQuery方法的具体用法?Python telegram.CallbackQuery怎么用?Python telegram.CallbackQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telegram
的用法示例。
在下文中一共展示了telegram.CallbackQuery方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __wait_for_inlinekeyboard_callback
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import CallbackQuery [as 别名]
def __wait_for_inlinekeyboard_callback(self, cancellable: bool = False) \
-> Union[telegram.CallbackQuery, CancelSignal]:
"""Continue getting updates until an inline keyboard callback is received, then return it."""
log.debug("Waiting for a CallbackQuery...")
while True:
# Get the next update
update = self.__receive_next_update()
# If a CancelSignal is received...
if isinstance(update, CancelSignal):
# And the wait is cancellable...
if cancellable:
# Return the CancelSignal
return update
else:
# Ignore the signal
continue
# Ensure the update is a CallbackQuery
if update.callback_query is None:
continue
# Answer the callbackquery
self.bot.answer_callback_query(update.callback_query.id)
# Return the callbackquery
return update.callback_query
示例2: button
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import CallbackQuery [as 别名]
def button(bot: Bot, update: Update) -> str:
query = update.callback_query # type: Optional[CallbackQuery]
user = update.effective_user # type: Optional[User]
match = re.match(r"rm_warn\((.+?)\)", query.data)
if match:
user_id = match.group(1)
chat = update.effective_chat # type: Optional[Chat]
res = sql.remove_warn(user_id, chat.id)
if res:
update.effective_message.edit_text(
"Warn removed by {}.".format(mention_html(user.id, user.first_name)),
parse_mode=ParseMode.HTML)
user_member = chat.get_member(user_id)
return "<b>{}:</b>" \
"\n#UNWARN" \
"\n<b>Admin:</b> {}" \
"\n<b>User:</b> {}".format(html.escape(chat.title),
mention_html(user.id, user.first_name),
mention_html(user_member.user.id, user_member.user.first_name))
else:
update.effective_message.edit_text(
"User has already has no warns.".format(mention_html(user.id, user.first_name)),
parse_mode=ParseMode.HTML)
return ""
示例3: button
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import CallbackQuery [as 别名]
def button(bot: Bot, update: Update) -> str:
query = update.callback_query # type: Optional[CallbackQuery]
user = update.effective_user # type: Optional[User]
match = re.match(r"rm_warn\((.+?)\)", query.data)
if match:
user_id = match.group(1)
chat = update.effective_chat # type: Optional[Chat]
res = sql.remove_warn(user_id, chat.id)
if res:
update.effective_message.edit_text(
"Warn removed by {}.".format(mention_html(user.id, user.first_name)),
parse_mode=ParseMode.HTML)
user_member = chat.get_member(user_id)
return "<b>{}:</b>" \
"\n#UNWARN" \
"\n<b>Admin:</b> {}" \
"\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title),
mention_html(user.id, user.first_name),
mention_html(user_member.user.id, user_member.user.first_name),
user_member.user.id)
else:
update.effective_message.edit_text(
"User has already has no warns.".format(mention_html(user.id, user.first_name)),
parse_mode=ParseMode.HTML)
return ""
示例4: button
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import CallbackQuery [as 别名]
def button(update, context):
query = update.callback_query # type: Optional[CallbackQuery]
user = update.effective_user # type: Optional[User]
match = re.match(r"rm_warn\((.+?)\)", query.data)
if match:
user_id = match.group(1)
chat = update.effective_chat # type: Optional[Chat]
res = sql.remove_warn(user_id, chat.id)
if res:
update.effective_message.edit_text(
tl(update.effective_message, "Peringatkan dihapus oleh {}.").format(mention_html(user.id, user.first_name)),
parse_mode=ParseMode.HTML)
user_member = chat.get_member(user_id)
return "<b>{}:</b>" \
"\n#UNWARN" \
"\n<b>Admin:</b> {}" \
"\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title),
mention_html(user.id, user.first_name),
mention_html(user_member.user.id, user_member.user.first_name),
user_member.user.id)
else:
update.effective_message.edit_text(
tl(update.effective_message, "Pengguna sudah tidak memiliki peringatan.").format(mention_html(user.id, user.first_name)),
parse_mode=ParseMode.HTML)
return ""
示例5: button
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import CallbackQuery [as 别名]
def button(update, context):
query = update.callback_query # type: Optional[CallbackQuery]
user = update.effective_user # type: Optional[User]
match = re.match(r"set_lang\((.+?)\)", query.data)
if match:
set_lang = match.group(1)
chat = update.effective_chat # type: Optional[Chat]
sql.set_lang(chat.id, set_lang)
update.effective_message.edit_text(tl(query.message, "Bahasa telah di ubah ke {}!").format(LANGS_TEXT.get(set_lang)))