本文整理汇总了Python中telegram.InlineKeyboardButton方法的典型用法代码示例。如果您正苦于以下问题:Python telegram.InlineKeyboardButton方法的具体用法?Python telegram.InlineKeyboardButton怎么用?Python telegram.InlineKeyboardButton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telegram
的用法示例。
在下文中一共展示了telegram.InlineKeyboardButton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: polo
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardButton [as 别名]
def polo(self, bot, update, user_data):
msg = update.message.text.upper()
conn = sqlite3.connect(self.mount_point + 'coders1.db')
c = conn.cursor()
c.execute("SELECT name FROM handles WHERE name=(?)", (msg,))
if c.fetchone():
keyboard = [[InlineKeyboardButton("Hackerearth", callback_data='HElist8'),
InlineKeyboardButton("Hackerrank", callback_data='HRlist8')],
[InlineKeyboardButton("Codechef", callback_data='CClist8'),
InlineKeyboardButton("Spoj", callback_data='SPlist8')],
[InlineKeyboardButton("Codeforces", callback_data='CFlist8'),
InlineKeyboardButton("ALL", callback_data='ALLlist8')]]
reply_markup = InlineKeyboardMarkup(keyboard)
update.message.reply_text('please select the judge or select all for showing all',
reply_markup=reply_markup)
user_data['name1'] = msg
conn.close()
return XOLO
else:
conn.close()
update.message.reply_text("Sorry this name is not registered with me.")
return ConversationHandler.END
# FUNCTION TO SHOW THE KIND OF RANKLIST USER WANTS
示例2: get_help
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardButton [as 别名]
def get_help(bot: Bot, update: Update):
chat = update.effective_chat # type: Optional[Chat]
args = update.effective_message.text.split(None, 1)
# ONLY send help in PM
if chat.type != chat.PRIVATE:
update.effective_message.reply_text("Contact me in PM to get the list of possible commands.",
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton(text="Help",
url="t.me/{}?start=help".format(
bot.username))]]))
return
elif len(args) >= 2 and any(args[1].lower() == x for x in HELPABLE):
module = args[1].lower()
text = "Here is the available help for the *{}* module:\n".format(HELPABLE[module].__mod_name__) \
+ HELPABLE[module].__help__
send_help(chat.id, text, InlineKeyboardMarkup([[InlineKeyboardButton(text="Back", callback_data="help_back")]]))
else:
send_help(chat.id, HELP_STRINGS)
示例3: get_settings
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardButton [as 别名]
def get_settings(bot: Bot, update: Update):
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
msg = update.effective_message # type: Optional[Message]
args = msg.text.split(None, 1)
# ONLY send settings in PM
if chat.type != chat.PRIVATE:
if is_user_admin(chat, user.id):
text = "Click here to get this chat's settings, as well as yours."
msg.reply_text(text,
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton(text="Settings",
url="t.me/{}?start=stngs_{}".format(
bot.username, chat.id))]]))
else:
text = "Click here to check your settings."
else:
send_settings(chat.id, user.id, True)
示例4: bot_article
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardButton [as 别名]
def bot_article(b):
txt = '{} ➡️ {}'.format(messages.rand_call_to_action(), b.detail_text)
txt += '\n\n' + messages.PROMOTION_MESSAGE
buttons = [
[InlineKeyboardButton(captions.ADD_TO_FAVORITES, callback_data=util.callback_for_action(
const.CallbackActions.ADD_TO_FAVORITES, {'id': b.id, 'discreet': True}))]]
reply_markup = InlineKeyboardMarkup(buttons)
return InlineQueryResultArticle(
id=uuid4(),
title=b.str_no_md,
input_message_content=InputTextMessageContent(message_text=txt,
parse_mode=ParseMode.MARKDOWN),
description=b.description if b.description else b.name if b.name else None,
reply_markup=reply_markup
# thumb_url='http://www.colorcombos.com/images/colors/FF0000.png'
)
示例5: remove_favorite_menu
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardButton [as 别名]
def remove_favorite_menu(bot, update):
uid = util.uid_from_update(update)
user = User.from_update(update)
favorites = Favorite.select_all(user)
fav_remove_buttons = [InlineKeyboardButton(
'✖️ {}'.format(str(f.bot.username)),
callback_data=util.callback_for_action(CallbackActions.REMOVE_FAVORITE, {'id': f.id}))
for f in favorites]
buttons = util.build_menu(fav_remove_buttons, 2, header_buttons=[
InlineKeyboardButton(captions.DONE,
callback_data=util.callback_for_action(CallbackActions.SEND_FAVORITES_LIST))
])
reply_markup = InlineKeyboardMarkup(buttons)
bot.formatter.send_or_edit(uid, util.action_hint("Select favorites to remove"),
to_edit=util.mid_from_update(update),
reply_markup=reply_markup)
示例6: set_country_menu
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardButton [as 别名]
def set_country_menu(bot, update, to_edit):
uid = util.uid_from_update(update)
countries = Country.select().order_by(Country.name).execute()
buttons = util.build_menu(
[InlineKeyboardButton(
'{} {}'.format(c.emojized, c.name),
callback_data=util.callback_for_action(
CallbackActions.SET_COUNTRY, {'cid': c.id, 'bid': to_edit.id})) for c in countries
], 3)
buttons.insert(0, [
InlineKeyboardButton(captions.BACK,
callback_data=util.callback_for_action(CallbackActions.EDIT_BOT,
{'id': to_edit.id})),
InlineKeyboardButton("None",
callback_data=util.callback_for_action(CallbackActions.SET_COUNTRY,
{
'cid': 'None',
'bid': to_edit.id
})),
])
return bot.formatter.send_or_edit(uid, util.action_hint(
"Please select a country/language for {}".format(to_edit)),
to_edit=util.mid_from_update(update),
reply_markup=InlineKeyboardMarkup(buttons))
示例7: upcoming_sender
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardButton [as 别名]
def upcoming_sender(self, update, contest_list):
i = 0
s = ""
keyboard = []
keyboard1 = []
for er in contest_list:
i = i + 1
# LIMITING NO OF EVENTS TO 20
if i == 16:
break
parsed_contest = self.contest_parser(er)
s = s + str(i) + ". " + parsed_contest["title"] + "\n" + "Start:\n" + \
parsed_contest["start"].replace("T", " ")\
+ " GMT\n" + str(parsed_contest["start1"]).replace("T", " ") + " IST\n" + \
"Duration: " + str(parsed_contest["duration"]) + "\n" + \
parsed_contest["host"] + "\n" + parsed_contest["contest"] + "\n\n"
keyboard1.append(InlineKeyboardButton(str(i), callback_data=str(i)))
if i % 5 == 0:
keyboard.append(keyboard1)
keyboard1 = []
keyboard.append(keyboard1)
reply_markup = InlineKeyboardMarkup(keyboard)
update.message.reply_text(s + "Select competition number to get notification" + "\n\n",
reply_markup=reply_markup)
示例8: removeRemind
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardButton [as 别名]
def removeRemind(self, bot, update):
conn = sqlite3.connect(self.mount_point + 'coders1.db')
c = conn.cursor()
c.execute("SELECT id FROM apscheduler_jobs WHERE id LIKE " + "'" + str(
update.message.chat_id) + "%' AND id LIKE " + "'%1'")
if c.fetchone():
c.execute("SELECT id FROM apscheduler_jobs WHERE id LIKE " + "'" + str(
update.message.chat_id) + "%' AND id LIKE " + "'%1'")
a = c.fetchall()
keyboard = []
for i in range(0, len(a)):
s = str(a[i]).replace("('", "").replace("',)", "").replace(
'("', "").replace('",)', "")
print(s)
keyboard.append([InlineKeyboardButton(str(self.schedule.get_job(job_id=s).args[1].split("\n")[0]),
callback_data=s[:-1] + "notiplz")])
reply_markup = InlineKeyboardMarkup(keyboard)
update.message.reply_text("Here are your pending reminders\nSelect the reminder you want to remove",
reply_markup=reply_markup)
c.close()
return REMNOTI
else:
c.close()
update.message.reply_text("You have no pending reminders")
return ConversationHandler.END
示例9: get_help
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardButton [as 别名]
def get_help(update, context):
chat = update.effective_chat # type: Optional[Chat]
args = update.effective_message.text.split(None, 1)
# ONLY send help in PM
if chat.type != chat.PRIVATE:
# update.effective_message.reply_text("Contact me in PM to get the list of possible commands.",
update.effective_message.reply_text(tl(update.effective_message, "Hubungi saya di PM untuk mendapatkan daftar perintah."),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton(text=tl(update.effective_message, "Tolong"),
url="t.me/{}?start=help".format(
context.bot.username))]]))
return
elif len(args) >= 2 and any(args[1].lower() == x for x in HELPABLE):
module = args[1].lower()
text = tl(update.effective_message, "Ini adalah bantuan yang tersedia untuk modul *{}*:\n").format(HELPABLE[module].__mod_name__) \
+ tl(update.effective_message, HELPABLE[module].__help__)
send_help(chat.id, text, InlineKeyboardMarkup([[InlineKeyboardButton(text=tl(update.effective_message, "Kembali"), callback_data="help_back")]]))
else:
send_help(chat.id, tl(update.effective_message, HELP_STRINGS))
示例10: get_settings
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardButton [as 别名]
def get_settings(update, context):
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
msg = update.effective_message # type: Optional[Message]
args = msg.text.split(None, 1)
# ONLY send settings in PM
if chat.type != chat.PRIVATE:
if is_user_admin(chat, user.id):
text = tl(update.effective_message, "Klik di sini untuk mendapatkan pengaturan obrolan ini, serta milik Anda.")
msg.reply_text(text,
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton(text="Pengaturan",
url="t.me/{}?start=stngs_{}".format(
context.bot.username, chat.id))]]))
# else:
# text = tl(update.effective_message, "Klik di sini untuk memeriksa pengaturan Anda.")
else:
send_settings(chat.id, user.id, True)
示例11: add_player
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardButton [as 别名]
def add_player(self, user_id, first_name, message_id, silent=False):
if self.game_running:
return
if self.get_player_by_id(user_id) is None and len(self.players) < self.MAX_PLAYERS:
self.logger.debug("Adding user '" + first_name + "' to players.")
player = Player(user_id, first_name, join_id=message_id)
self.players.append(player)
if silent:
return
# TODO When game is multiplayer then print current players?
keyboard = [[InlineKeyboardButton(text=translate("start_game", self.lang_id), callback_data="start_game")]]
reply_markup = InlineKeyboardMarkup(keyboard)
self.send_message(self.chat_id, translate("playerJoined", self.lang_id).format(first_name), message_id=message_id, reply_markup=reply_markup, game_id=self.__game_id)
else:
self.send_message(self.chat_id, translate("alreadyJoined", self.lang_id).format(first_name))
self.logger.debug("User '{}' already in player list. Or max players reached".format(first_name))
示例12: __order_notify_admins
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardButton [as 别名]
def __order_notify_admins(self, order):
# Notify the user of the order result
self.bot.send_message(self.chat.id, self.loc.get("success_order_created", order=order.text(loc=self.loc,
session=self.session,
user=True)))
# Notify the admins (in Live Orders mode) of the new order
admins = self.session.query(db.Admin).filter_by(live_mode=True).all()
# Create the order keyboard
order_keyboard = telegram.InlineKeyboardMarkup(
[
[telegram.InlineKeyboardButton(self.loc.get("menu_complete"), callback_data="order_complete")],
[telegram.InlineKeyboardButton(self.loc.get("menu_refund"), callback_data="order_refund")]
])
# Notify them of the new placed order
for admin in admins:
self.bot.send_message(admin.user_id,
self.loc.get('notification_order_placed',
order=order.text(loc=self.loc, session=self.session)),
reply_markup=order_keyboard)
示例13: quarantine_user
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardButton [as 别名]
def quarantine_user(user: User, chat_id: str, context: CallbackContext):
logger.info(f"put {user} in quarantine")
db.add_user(user.id)
markup = InlineKeyboardMarkup([
[InlineKeyboardButton(choice(I_AM_BOT), callback_data=MAGIC_NUMBER)]])
# messages from `rel_message` will be deleted after greeting or ban
db.add_user_rel_message(user.id, context.bot.send_message(
chat_id,
f"{user.name} НЕ нажимай на кнопку ниже, чтобы доказать, что ты не бот.\n"
"Просто ответь (reply) на это сообщение, кратко написав о себе (у нас так принято).\n"
"Я буду удалять твои сообщения, пока ты не сделаешь это.\n"
f"А коли не сделаешь, через {QUARANTINE_TIME} минут выкину из чата.\n"
"Ничего личного, просто боты одолели.\n",
reply_markup=markup
).message_id)
示例14: get_init_keyboard
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardButton [as 别名]
def get_init_keyboard(poll):
"""Get the initial inline keyboard for poll creation."""
locale = poll.user.locale
change_type = CallbackType.show_poll_type_keyboard.value
change_type_payload = f"{change_type}:{poll.id}:0"
change_type_text = i18n.t("creation.keyboard.change", locale=locale)
anonymity_text = i18n.t("keyboard.anonymity_settings", locale=locale)
anonymity_payload = f"{CallbackType.anonymity_settings.value}:{poll.id}:0"
buttons = [
[InlineKeyboardButton(change_type_text, callback_data=change_type_payload)],
[InlineKeyboardButton(anonymity_text, callback_data=anonymity_payload)],
]
return InlineKeyboardMarkup(buttons)
示例15: get_native_poll_merged_keyboard
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardButton [as 别名]
def get_native_poll_merged_keyboard(poll):
"""Get the initial inline keyboard for poll creation."""
locale = poll.user.locale
change_type = CallbackType.show_poll_type_keyboard.value
change_type_payload = f"{change_type}:{poll.id}:0"
change_type_text = i18n.t("creation.keyboard.change", locale=locale)
accept_text = i18n.t("keyboard.accept_continue", locale=locale)
accept_payload = f"{CallbackType.ask_description.value}:{poll.id}:0"
buttons = [
[InlineKeyboardButton(change_type_text, callback_data=change_type_payload)],
[InlineKeyboardButton(accept_text, callback_data=accept_payload)],
]
return InlineKeyboardMarkup(buttons)