Last active
May 5, 2020 08:08
-
-
Save Moekka/189ea1dc8d643b50267219fcdd01f582 to your computer and use it in GitHub Desktop.
[TelegramBot-Python] telgram bot代码片段 #telegram
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def build_menu(self, buttons, | |
n_cols, | |
header_buttons=None, | |
footer_buttons=None): | |
menu = [buttons[i:i + n_cols] for i in range(0, len(buttons), n_cols)] | |
if header_buttons: | |
menu.insert(0, [header_buttons]) | |
if footer_buttons: | |
menu.append([footer_buttons]) | |
return menu | |
button_list = [] | |
for i in range(int(len(project_list))): | |
button = InlineKeyboardButton( | |
f"{project_list[i]}", callback_data=f"project_manager-{project_list[i]}") | |
button_list.append(button) | |
reply_markup = InlineKeyboardMarkup(self.build_menu(button_list, n_cols=3)) | |
query.message.edit_text(text=text, parse_mode=ParseMode.MARKDOWN, | |
disable_web_page_preview=True, quote=False, reply_markup=reply_markup) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def project(self, update: Update, context: CallbackContext): | |
username = self.get_user_name(update) | |
userid = self.get_user_id(update) | |
chat_id = update.message.chat.id | |
help_text = ( | |
'***project命令使用说明:***\n\n' | |
'/project list 显示当前用户的所有项目.\n' | |
'/project create [num] 创建指定数目(num)个新项目,并在每个新项目中创建100个服务账号.\n' | |
'/project download [project id] [local/remote] 下载指定项目中的服务账号到本地或者远程服务器\n' | |
) | |
keyboard = [ | |
[InlineKeyboardButton("列表", callback_data="project_list")], | |
[InlineKeyboardButton("新建", callback_data="project_create")], | |
[InlineKeyboardButton("下载", callback_data="project_downlaod_svc")], | |
] | |
reply_markup = InlineKeyboardMarkup(keyboard) | |
text = ( | |
'***项目管理:***\n\n' | |
'- 列表:列出当前账号的所有项目\n' | |
'- 新建:新建一个项目,并自动生成100个服务账号\n' | |
'- 下载:下载已有项目中的已有服务账号' | |
) | |
update.message.reply_text(text=text, parse_mode=ParseMode.MARKDOWN, | |
disable_web_page_preview=True, quote=False, reply_markup=reply_markup) | |
self.add_callback_query_handle(self.project_manager_button) | |
def project_manager_button(self, update, context): | |
query = update.callback_query | |
if query.data == 'project_list': | |
# query.edit_message_text('Start Next Page.') | |
self.project_list(update, context) | |
elif query.data == 'project_create': | |
query.edit_message_text('Exit image preview.') | |
self.current_photo_index = 0 | |
self.photo_list = [] | |
return ConversationHandler.END | |
elif query.data == 'project_downlaod_svc': | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment