本文整理匯總了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)))