else: student = ' '.join(student[0:2]) bot_message = f"Имя - <b>{student}</b>\n\n" \ f"У нас нет информации об этом студенте" context.bot.edit_message_text(chat_id=query.message.chat_id, message_id=query.message.message_id, text=bot_message, reply_markup=keyboard) session.close() dp.add_handler(CommandHandler(command='project', callback=show_projects)) dp.add_handler( CallbackQueryHandler(callback=show_projects, pattern=project_buttons["choose"])) # First creative project handlers dp.add_handler( CallbackQueryHandler(callback=first_projects_themes_buttons, pattern=project_buttons["first"]["show"])) dp.add_handler( CallbackQueryHandler(callback=first_project_info, pattern=project_buttons["first"]["info"])) dp.add_handler( CallbackQueryHandler(callback=first_project_team_info, pattern=project_buttons["first"]["team_info"]))
from app import dp contacts_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'text') contacts_buttons = { button_name.split()[0]: button_name.replace('.txt', '') for button_name in os.listdir(contacts_dir) } def get_contacts_keyboard(): keyboard = [[InlineKeyboardButton(text, callback_data=button)] for button, text in contacts_buttons] return InlineKeyboardMarkup(keyboard) def do_contacts(update, context): chat_id = update.message.chat_id files = [ os.path.join(contacts_dir, text + '.txt') for data, text in contacts_buttons.items() ] for file in files: with open(file, 'r', encoding='utf8') as f: photo = f.readline() text = f.read() context.bot.send_photo(photo=photo, chat_id=chat_id, caption=text) dp.add_handler(CommandHandler(command='contacts', callback=do_contacts))
text=auth_replicas['logout']) else: context.bot.send_message(chat_id=update.message.chat_id, text=auth_replicas['not_logged']) session.close() dp.add_handler( ConversationHandler(entry_points=[ CommandHandler(command='login', callback=do_login, pass_args=True, pass_job_queue=True) ], states={ LOGIN_EMAIL: [ MessageHandler(filters=Filters.text, callback=do_login_email, pass_job_queue=True) ], LOGIN_PASSWORD: [ MessageHandler(filters=Filters.text, callback=do_login_password, pass_job_queue=True) ] }, fallbacks=[])) dp.add_handler(CommandHandler(command='logout', callback=do_logout))
def return_to_contests_list(update, context): bot_message = form_contests_list() keyboard_markup = InlineKeyboardMarkup([ [InlineKeyboardButton(text="Подробнее", callback_data='contests_more'), InlineKeyboardButton(text='Показать все', callback_data='contests_show_all')] ]) context.bot.edit_message_text( chat_id=update.callback_query.message.chat_id, message_id=update.callback_query.message.message_id, text=bot_message ) context.bot.edit_message_reply_markup( chat_id=update.callback_query.message.chat_id, message_id=update.callback_query.message.message_id, reply_markup=keyboard_markup ) dp.add_handler(CommandHandler(command='contests', callback=do_contests), group=2) dp.add_handler(CallbackQueryHandler(callback=more_contests, pattern='contests_more'), group=2) dp.add_handler(CallbackQueryHandler(callback=show_all_contests, pattern='contests_show_all'), group=2) dp.add_handler(CallbackQueryHandler(callback=find_contests, pattern=r'contests: .+'), group=2) dp.add_handler(CallbackQueryHandler(callback=contests_back, pattern='contests_back'), group=2) dp.add_handler(CallbackQueryHandler(callback=contests_back_to_all, pattern='contests_to_all'), group=2) dp.add_handler(CallbackQueryHandler(callback=return_to_contests_list, pattern='contests_return'), group=2)
from telegram.ext import CommandHandler from app.handlers.auth.permissions import get_user_info from app import dp def do_profile(update, context): user = get_user_info(update) if user: bot_message = str(user) context.bot.send_message( chat_id=user.tg_chat_id, text=bot_message ) else: context.bot.send_message( chat_id=update.message.chat_id, text='Вы не авторизованы' ) dp.add_handler(CommandHandler(command='profile', callback=do_profile))
founded_mentor = mentor bot_message = f"<b><i>{ mentor['surname'] } { mentor['name'] } { mentor['patronymic'] }</i></b>\n\n" \ f"<u>Почта</u>: { mentor['email'] }\n" \ f"<u>Телефон</u>: { mentor['phone'] }\n" \ f"<u>Должность</u>: { mentor['post'] }\n" \ f"<u>Направления</u>: { mentor['directions'] }\n" \ f"\n<i>Источник</i>: { mentors_url.replace('/api', '') }" # deleting choice message context.bot.delete_message( chat_id=update.callback_query.message.chat_id, message_id=update.callback_query.message.message_id, ) keyboard_markup = InlineKeyboardMarkup( [[InlineKeyboardButton(text='Назад', callback_data='mentors_back')]]) context.bot.send_photo(chat_id=update.callback_query.message.chat_id, photo=founded_mentor['avatar']['link'], caption=bot_message, reply_markup=keyboard_markup) dp.add_handler(CommandHandler(command='mentors', callback=do_mentors), group=0) dp.add_handler(CallbackQueryHandler(callback=find_mentor, pattern=r'mentor_show'), group=0) dp.add_handler(CallbackQueryHandler(callback=do_mentors, pattern='mentors_back'), group=0)
reply_markup=get_manual_keyboard(), ) def do_manual_section(update, context): query = update.callback_query data = query.data.replace('manual: ', '') chat_id = query.message.chat_id message_id = query.message.message_id section = os.path.join(manual_dir, manual_buttons[data] + '.txt') keyboard = InlineKeyboardMarkup( [[InlineKeyboardButton(text='Назад', callback_data='back_to_manual')]]) with open(section, encoding='utf8') as f: section_text = f.read() context.bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=section_text, reply_markup=keyboard) dp.add_handler(CommandHandler(command='manual', callback=do_manual)) dp.add_handler( CallbackQueryHandler(pattern='back_to_manual', callback=do_manual)) dp.add_handler( CallbackQueryHandler(pattern='manual', callback=do_manual_section)) if __name__ == '__main__': print(manual_buttons)
message_id=query.message.message_id, text=f'<b><i>Расписание {group}</i></b>:', reply_markup=reply_keyboard) # End schedule def schedule_end(update, context): query = update.callback_query context.bot.edit_message_reply_markup(chat_id=query.message.chat_id, message_id=query.message.message_id, reply_markup=None) dp.add_handler( CallbackQueryHandler(pattern=schedule_buttons["choice"], callback=choose_schedule_group)) dp.add_handler( CallbackQueryHandler(pattern=schedule_buttons["back"], callback=schedule_back)) dp.add_handler( CallbackQueryHandler(pattern=schedule_buttons["forward"], callback=schedule_forward)) dp.add_handler( CallbackQueryHandler(pattern=schedule_buttons["week"], callback=schedule_weekdays)) dp.add_handler( CallbackQueryHandler(pattern=schedule_buttons["day"], callback=schedule_from_week)) dp.add_handler( CallbackQueryHandler(pattern=schedule_buttons["all"],
necessary_team.member_7, necessary_team.member_8 ] for member in members: if member: member = member.replace(',', '').split()[:3] surname = member[0] name = members[1] patronymic = member[2] member_account = session.query(User).filter( User.surname == surname and User.name == name and User.patronymic == patronymic).first() if member_account is not None: context.bot.send_message(chat_id=member_account.tg_chat_id, text=message) session.close() return ConversationHandler.END dp.add_handler( ConversationHandler(entry_points=[ CallbackQueryHandler(pattern=communication_buttons['write']['team'], callback=write_team_ask_for_message) ], states={ WRITE: [ MessageHandler(filters=Filters.text, callback=write_team) ] }, fallbacks=[]))
def send_students(update, context): session = Session() bot_message = update.message.text students = session.query(User).filter(User.role == 'student') admin = session.query(User).filter( User.tg_chat_id == update.message.chat_id).first() bot_message = f'{admin.name} {admin.surname} пишет:\n' \ f'"{bot_message}"' for student in students: context.bot.send_message(chat_id=student.tg_chat_id, text=bot_message) session.close() return ConversationHandler.END dp.add_handler(CommandHandler(command='dbrefill', callback=admin_db_refill)) dp.add_handler( CommandHandler(command='dropusers', callback=do_drop_users_table)) dp.add_handler( ConversationHandler( entry_points=[ CommandHandler(command='newadmin', callback=add_admin_info), CommandHandler(command='deladmin', callback=remove_admin_info), CommandHandler(command='notestudent', callback=send_students_start) ], states={ ADD_ADMIN: [MessageHandler(filters=Filters.text, callback=add_admin)], REMOVE_ADMIN: [MessageHandler(filters=Filters.text, callback=remove_admin)], SEND_STUDENTS:
def return_to_news_list(update, context): bot_message = form_news_list() keyboard_markup = InlineKeyboardMarkup([ [InlineKeyboardButton(text="Подробнее", callback_data='news_more'), InlineKeyboardButton(text='Показать все', callback_data='news_show_all')] ]) context.bot.edit_message_text( chat_id=update.callback_query.message.chat_id, message_id=update.callback_query.message.message_id, text=bot_message ) context.bot.edit_message_reply_markup( chat_id=update.callback_query.message.chat_id, message_id=update.callback_query.message.message_id, reply_markup=keyboard_markup ) dp.add_handler(CommandHandler(command='news', callback=do_news), group=1) dp.add_handler(CallbackQueryHandler(callback=more_news, pattern='news_more'), group=1) dp.add_handler(CallbackQueryHandler(callback=show_all_news, pattern='news_show_all'), group=1) dp.add_handler(CallbackQueryHandler(callback=find_news, pattern=r'news: .+'), group=1) dp.add_handler(CallbackQueryHandler(callback=news_back, pattern='news_back'), group=1) dp.add_handler(CallbackQueryHandler(callback=news_back_to_all, pattern='news_to_all'), group=1) dp.add_handler(CallbackQueryHandler(callback=return_to_news_list, pattern='news_return'), group=1)
text=alt_login_replicas['stop']) return ConversationHandler.END dp.add_handler( ConversationHandler( entry_points=[ CommandHandler(command='altlogin', callback=alt_login_start) ], states={ ALT_LOGIN_ROLE: [MessageHandler(filters=Filters.text, callback=alt_login_role)], ALT_LOGIN_NAME: [MessageHandler(filters=Filters.text, callback=alt_login_name)], ALT_LOGIN_PATRONYMIC: [ MessageHandler(filters=Filters.text, callback=alt_login_patronymic) ], ALT_LOGIN_SURNAME: [MessageHandler(filters=Filters.text, callback=alt_login_surname)], ALT_LOGIN_GROUP: [MessageHandler(filters=Filters.text, callback=alt_login_group)], ALT_LOGIN_POST: [MessageHandler(filters=Filters.text, callback=alt_login_post)], ALT_LOGIN_DIRECTIONS: [ MessageHandler(filters=Filters.text, callback=alt_login_directions) ] }, fallbacks=[]))
None ) def stop_register(update, context): context.bot.send_message( chat_id=update.message.chat_id, text='Регистрация прервана.' ) return ConversationHandler.END dp.add_handler( ConversationHandler( entry_points=[CommandHandler(command='register', callback=register_start)], states={ REG_ROLE: [MessageHandler(filters=Filters.text, callback=register_role)], REG_NAME: [MessageHandler(filters=Filters.text, callback=register_name)], REG_PATRONYMIC: [MessageHandler(filters=Filters.text, callback=register_patronymic)], REG_SURNAME: [MessageHandler(filters=Filters.text, callback=register_surname)], REG_GROUP: [MessageHandler(filters=Filters.text, callback=register_group)], REG_POST: [MessageHandler(filters=Filters.text, callback=register_post)], REG_DIRECTIONS: [MessageHandler(filters=Filters.text, callback=register_directions)], REG_EMAIL: [MessageHandler(filters=Filters.text, callback=register_email)], REG_PHONE: [MessageHandler(filters=Filters.text, callback=register_phone)], REG_PASS: [MessageHandler(filters=Filters.text, callback=register_pass)] }, fallbacks=[] ) )
InlineKeyboardButton(text='Показать все', callback_data='achievements_show_all') ]]) context.bot.edit_message_text( chat_id=update.callback_query.message.chat_id, message_id=update.callback_query.message.message_id, text=bot_message) context.bot.edit_message_reply_markup( chat_id=update.callback_query.message.chat_id, message_id=update.callback_query.message.message_id, reply_markup=keyboard_markup) dp.add_handler(CommandHandler(command='achieves', callback=do_achievements), group=3) dp.add_handler(CallbackQueryHandler(callback=more_achievements, pattern='achievements_more'), group=3) dp.add_handler(CallbackQueryHandler(callback=show_all_achievements, pattern='achievements_show_all'), group=3) dp.add_handler(CallbackQueryHandler(callback=find_achievements, pattern=r'achievements: .+'), group=3) dp.add_handler(CallbackQueryHandler(callback=achievements_back, pattern='achievements_back'), group=3) dp.add_handler(CallbackQueryHandler(callback=achievements_back_to_all, pattern='achievements_to_all'), group=3)
<i>На данный момент бот не может узнать, обновил ли ты информацию на сайте</i>, так что для вступления новых данных в силу необходимо ввести команду /logout и повторно авторизоваться\n ''', 'admin_help': '''<b><i>Админ-панель</i></b>: /newadmin - добавить нового модератора /deladmin - убрать пользователя из списка модераторов /notestudent - написать сообщение всем студентам в боте /dbrefill - перезаполнить таблицы проектов (перезаполнит данные для функции /project, использовать в случае, если появились новые проекты и сформировались команды) /dropusers - сбросить таблицу пользователей\n ''', 'help_end': 'Если все понятно - напиши мне' } def do_start_and_help(update, context): help_message = help_replica['ordinary_help'] if is_admin(update): help_message += help_replica['admin_help'] help_message += help_replica['help_end'] context.bot.send_message(chat_id=update.message.chat_id, text=help_message) dp.add_handler( CommandHandler(command=['start', 'help'], callback=do_start_and_help))