本文整理汇总了Python中telegram.InlineKeyboardMarkup方法的典型用法代码示例。如果您正苦于以下问题:Python telegram.InlineKeyboardMarkup方法的具体用法?Python telegram.InlineKeyboardMarkup怎么用?Python telegram.InlineKeyboardMarkup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telegram
的用法示例。
在下文中一共展示了telegram.InlineKeyboardMarkup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: polo
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardMarkup [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: send_intro_template
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardMarkup [as 别名]
def send_intro_template(bot, chat_id, lang, key, text_key):
# Prepare Keyboard
lang_list = helper_const.LANG_LIST
width = helper_const.LANG_WIDTH
current_lang = lang
motd_keyboard = [[
InlineKeyboardButton(
lang_list[width * idx + delta] + (" (*)" if lang_list[width * idx + delta] == current_lang else ""),
callback_data="%s|%s" % (key, lang_list[width * idx + delta])
) for delta in range(width)
] for idx in range(len(lang_list) // width)] + [[
InlineKeyboardButton(
lang_list[idx] + (" (*)" if lang_list[idx] == current_lang else ""),
callback_data="%s|%s" % (key, lang_list[idx])
)
for idx in range(width * (len(lang_list) // width), len(lang_list))]]
motd_markup = InlineKeyboardMarkup(motd_keyboard)
bot.send_message(
chat_id=chat_id,
text=value(text_key, "", lang=current_lang),
reply_markup=motd_markup
)
示例3: get_help
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardMarkup [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)
示例4: send_settings
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardMarkup [as 别名]
def send_settings(chat_id, user_id, user=False):
if user:
if USER_SETTINGS:
settings = "\n\n".join(
"*{}*:\n{}".format(mod.__mod_name__, mod.__user_settings__(user_id)) for mod in USER_SETTINGS.values())
dispatcher.bot.send_message(user_id, "These are your current settings:" + "\n\n" + settings,
parse_mode=ParseMode.MARKDOWN)
else:
dispatcher.bot.send_message(user_id, "Seems like there aren't any user specific settings available :'(",
parse_mode=ParseMode.MARKDOWN)
else:
if CHAT_SETTINGS:
chat_name = dispatcher.bot.getChat(chat_id).title
dispatcher.bot.send_message(user_id,
text="Which module would you like to check {}'s settings for?".format(
chat_name),
reply_markup=InlineKeyboardMarkup(
paginate_modules(0, CHAT_SETTINGS, "stngs", chat=chat_id)))
else:
dispatcher.bot.send_message(user_id, "Seems like there aren't any chat settings available :'(\nSend this "
"in a group chat you're admin in to find its current settings!",
parse_mode=ParseMode.MARKDOWN)
示例5: get_settings
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardMarkup [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)
示例6: manage_subscription
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardMarkup [as 别名]
def manage_subscription(bot, update):
chat_id = update.effective_chat.id
user_id = update.effective_user.id
if util.is_group_message(update):
admins = bot.get_chat_administrators(chat_id)
if user_id not in admins:
bot.formatter.send_failure(chat_id, "Sorry, but only Administrators of this group are allowed "
"to manage subscriptions.")
return
text = "Would you like to be notified when new bots arrive at the @BotList?"
buttons = [[
InlineKeyboardButton(util.success("Yes"),
callback_data=util.callback_for_action(CallbackActions.SET_NOTIFICATIONS,
{'value': True})),
InlineKeyboardButton("No", callback_data=util.callback_for_action(CallbackActions.SET_NOTIFICATIONS,
{'value': False}))]]
reply_markup = InlineKeyboardMarkup(buttons)
msg = util.send_md_message(bot, chat_id, text, reply_markup=reply_markup)
return ConversationHandler.END
示例7: remove_favorite_menu
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardMarkup [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)
示例8: upcoming_sender
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardMarkup [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)
示例9: removeRemind
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardMarkup [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
示例10: time_options_keyboard
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardMarkup [as 别名]
def time_options_keyboard():
buttons = [
[
Button('5 Mins', callback_data=remind_time(5 * MINUTE)),
Button('10 Mins', callback_data=remind_time(10 * MINUTE)),
Button('20 Mins', callback_data=remind_time(20 * MINUTE)),
Button('30 Mins', callback_data=remind_time(30 * MINUTE)),
],
[
Button('1 Hour', callback_data=remind_time(HOUR)),
Button('2 Hours', callback_data=remind_time(2 * HOUR)),
Button('4 Hours', callback_data=remind_time(4 * HOUR)),
Button('8 Hours', callback_data=remind_time(8 * HOUR)),
],
[
Button('12 hours', callback_data=remind_time(12 * HOUR)),
Button('24 hours', callback_data=remind_time(24 * HOUR)),
Button('48 hours', callback_data=remind_time(48 * HOUR)),
],
]
return InlineKeyboardMarkup(buttons)
示例11: get_help
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardMarkup [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))
示例12: start
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardMarkup [as 别名]
def start(bot, update):
# Select language
langs_markup = InlineKeyboardMarkup([[
InlineKeyboardButton('English {}'.format(b'\xF0\x9F\x87\xAC\xF0\x9F\x87\xA7'.decode()), callback_data='en'),
InlineKeyboardButton('Русский {}'.format(b'\xF0\x9F\x87\xB7\xF0\x9F\x87\xBA'.decode()), callback_data='ru'),
InlineKeyboardButton('Português {}'.format(b'\xF0\x9F\x87\xA7\xF0\x9F\x87\xB7'.decode()), callback_data='pt')
]])
bot.send_message(
text='Choose your language / Выберите язык / Escolha seu idioma',
reply_markup=langs_markup,
chat_id=update.message.chat_id,
)
示例13: send_frequency_question
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardMarkup [as 别名]
def send_frequency_question(bot, chat_id):
lang = chat_storage.get_or_create(chat_id)['language']
frequency_markup = InlineKeyboardMarkup([[
InlineKeyboardButton(texts.FREQUENCY_NONE[lang], callback_data='none'),
InlineKeyboardButton(texts.FREQUENCY_DAILY[lang], callback_data='daily'),
InlineKeyboardButton(texts.FREQUENCY_WEEKLY[lang], callback_data='weekly')]])
bot.send_message(text=texts.FREQUENCY_QUESTION[lang], reply_markup=frequency_markup, chat_id=chat_id)
示例14: send_hars_question
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardMarkup [as 别名]
def send_hars_question(question, bot, chat_id):
keyboard = [[InlineKeyboardButton(answer, callback_data=i)] for i, answer in enumerate(question.answers)]
reply_markup = InlineKeyboardMarkup(keyboard)
bot.send_message(text=question.question, reply_markup=reply_markup, chat_id=chat_id)
示例15: send_madrs_question
# 需要导入模块: import telegram [as 别名]
# 或者: from telegram import InlineKeyboardMarkup [as 别名]
def send_madrs_question(question, bot, chat_id):
keyboard = [[InlineKeyboardButton(str(i), callback_data=i) for i in range(0, 7)]]
reply_markup = InlineKeyboardMarkup(keyboard)
question_text = '{}\n{}'.format(question.question, '\n'.join(question.answers))
bot.send_message(text=question_text, reply_markup=reply_markup, chat_id=chat_id)