def get_reg_end(message): surname = message.text name = getTempName(file_db, message.from_user.id) newUser(file_db, message.from_user.id, name, surname) #Добавляем пользователя в БД deleteCode(file_db, message.from_user.id) markup = InlineKeyboardMarkup() markup.row_width = 2 markup.add( InlineKeyboardButton("Да", callback_data="cb_yes"), InlineKeyboardButton("Пока не готов", callback_data="cb_no")) bot.send_message( message.from_user.id, "Ура! Вот мы и познакомились =) Пора попить кофе?", reply_markup=markup)
def get_cat_or_products(call): kb = InlineKeyboardMarkup() category = Category.objects.get(id=call.data.split('_')[1]) if category.subcategory: buttons = [ InlineKeyboardButton(text=cat.title, switch_inline_query_current_chat='subcat_' + str(cat.id)) for cat in category.subcategory ] kb.add(*buttons) bot.edit_message_text(text=category.title, message_id=call.message.message_id, chat_id=call.message.chat.id, reply_markup=kb)
def generate_pages(total, page, message): """ НЕ ИСПОЛЬЗУЕТСЯ Получает количество документов запроса и текущую активную страницу Возвращает разметку для кнопок пагинаций """ total = math.ceil(total / per_page) total = 10 markup = InlineKeyboardMarkup() markup.row_width = 10 for i in range(1, total): markup.add(InlineKeyboardButton(i, callback_data=("%s#%s" % (message, i)))) return markup
def handle_message_text(self, msg: Message) -> None: bot.delete_message(self.user.tg_id, self._msg_id) try: amount = int(msg.text) self.user.do_deposit(amount) except ValueError: buttons = InlineKeyboardMarkup() buttons.add( InlineKeyboardButton(text="Назад", callback_data='back ')) self._msg_id = bot.send_message(self.user.tg_id, "Це не число, спробуй ще раз...", reply_markup=buttons).message_id
def __create_menu_item_markup(item_amount): amount_text = '0' show_basket = False if item_amount > 0: show_basket = True amount_text = '{} шт'.format(item_amount) markup = InlineKeyboardMarkup() markup.add(InlineKeyboardButton('+', callback_data='plus'), InlineKeyboardButton(amount_text, callback_data='price'), InlineKeyboardButton('-', callback_data='minus')) if show_basket: markup.add(InlineKeyboardButton('Корзина', callback_data='basket')) return markup
def divisions_keyboard(): """ Creates divisions keyboard :return: division keyboard :rtype: InlineKeyboardMarkup """ divisions = spbu.get_study_divisions() inline_keyboard = InlineKeyboardMarkup(row_width=2) inline_keyboard.add(*[ InlineKeyboardButton(text=d["Name"][:max_inline_button_text_len], callback_data=d["Alias"]) for d in divisions ]) return inline_keyboard
def get_order(game): keyboard = InlineKeyboardMarkup() keyboard.add( InlineKeyboardButton( text='✉ Получить приказ', callback_data='get order' ) ) bot.edit_message_text( f'{role_titles["don"].capitalize()} записал приказ. {role_titles["mafia"].capitalize()}, получите конверт со своим заданием!', chat_id=game['chat'], message_id=game['message_id'], reply_markup=keyboard )
def generate_markup(data): ''' Reply music inline buttons from received JSON data ''' markup = InlineKeyboardMarkup() markup.row_width = 1 # Receive info about founded tracks for row in data: code = row['stream_url'].replace(TRACKS_API + '/', '') code = code.replace('/stream', '') markup.add( InlineKeyboardButton(f"{row['title']}", callback_data=f"music|{code}")) return markup
def main_menu(): markup = InlineKeyboardMarkup() markup.row_width = 1 markup.add( InlineKeyboardButton(text="Передать ресурс", callback_data="send-resource"), InlineKeyboardButton(text="Распределить ресурсы на проект", callback_data="choice_date_for_distribute"), # callback_data="get-task"), InlineKeyboardButton(text="Свободные ресурсы на сегодня", callback_data="free_dev"), InlineKeyboardButton(text="Расписание", callback_data="сheck_schedule")) return markup
def subscribe(message): if postgre.get_user_type(message.chat.id) in config.ACCESS_LEVEL_2: markup = InlineKeyboardMarkup() markup.add(InlineKeyboardButton(text='Подписаться на обнавления', callback_data='add_subscription')) markup.add(InlineKeyboardButton(text='Отменить подписку', callback_data='remove_subscription')) text = 'Я могу уведомлять вас об изменениях вашей позиции в рейтинговом списке вашего направления\n' \ 'Выберите _Подписаться на обнавления_ чтобы настроить уведомления\n' \ 'Если вам не нужны уведомления из некоторых направлений, просто удалите их, выбрав _Отменить подписку_' bot.send_message(chat_id=message.chat.id, text=text, reply_markup=markup, parse_mode='Markdown') else: text = 'Простите, у вас нету прав доступа для использования этой функции\n' \ 'Чтобы неограниченно использовать возможности сервиса, перейдите на полную версию /buy, ' bot.send_message(chat_id=message.chat.id, text=text)
def points_markup(): markup = InlineKeyboardMarkup() markup.row_width = 2 markup.add( InlineKeyboardButton("Compulsory Attendance", callback_data="get_compulsory"), InlineKeyboardButton("Graduating Residents", callback_data="get_graduating"), InlineKeyboardButton("Points System", callback_data="get_points_system"), InlineKeyboardButton("Things to Note", callback_data="get_things2note"), InlineKeyboardButton("Back", callback_data="get_faq"), InlineKeyboardButton("Main Page", callback_data="get_main")) return markup
def got_payment(message): payment = message.successful_payment notification_id = int(payment.invoice_payload) if notification_id not in notification_by_id: return admin_notification.update_paid(notification_by_id[notification_id]) markup = InlineKeyboardMarkup() markup.add(InlineKeyboardButton('Меню', callback_data='menu')) bot.send_message(message.chat.id, 'Спасибо за покупку!', parse_mode='Markdown', reply_markup=markup)
def points_notes(): markup = InlineKeyboardMarkup() markup.row_width = 2 markup.add( InlineKeyboardButton("CCA Points", callback_data="get_cca_points"), InlineKeyboardButton("Bonus Points", callback_data="get_bonus_points"), InlineKeyboardButton("External CCA Points", callback_data="get_external_cca"), InlineKeyboardButton("Exchange", callback_data="get_exchange"), InlineKeyboardButton("Monitoring", callback_data="get_monitoring"), InlineKeyboardButton("Master's List", callback_data="get_masters_lists"), InlineKeyboardButton("Back", callback_data="get_points"), InlineKeyboardButton("Main Page", callback_data="get_main")) return markup
def send_message(bot: TeleBot, chat_id: str, entity: Entity): markup = InlineKeyboardMarkup(row_width=1) button = InlineKeyboardButton(text="Перейти", url=entity.url) markup.add(button) bot.send_message( chat_id, text= "{title}\n📍 {geo}\n⌛ {lifeTime}\n💲 {price} {priceCurrency}[]({imgUrl})" .format(title=entity.title, geo=entity.geo, lifeTime=entity.lifeTime, price=entity.price, priceCurrency=entity.priceCurrency, imgUrl=entity.imgUrl), reply_markup=markup)
def inline_markup(arr: dict, rw: int = 5): keys = list(arr.keys()) markup = InlineKeyboardMarkup() markup.row_width = rw for i, key in enumerate(keys.copy()): if type(arr[keys[i]]) == list: keys[i] = InlineKeyboardButton(key, url=arr[keys[i]][0]) else: keys[i] = InlineKeyboardButton(key, callback_data=key) markup.add(*keys) return markup
def send_movies_by_genre(genre_id, page): # Send 4 pages of movies in this genre starts with this page message = "\U0001F447Фильмы по этому жанру:\U0001F447 \n" film_number = 1 for i in range(5): movies = tmdb_obj.get_movies_by_genre(genre_id, page + i) for j in range(4): message += str(film_number) + ". " + movies[j][ "title"] + " - (" + "/mv" + str(movies[j]["id"]) + ")\n" film_number += 1 markup = InlineKeyboardMarkup() markup.add( InlineKeyboardButton("Следующая страница >>", callback_data="next")) return message, markup
def get_classlinks(message): if message.chat.id not in users_dict: bot.send_message(message.chat.id, "Please click /start again....") else: user = users_dict[message.chat.id] for course in user.enrolled_courses: markup = InlineKeyboardMarkup() if course in links.keys(): local_links = links[course] markup.row_width = len(local_links.keys()) for text, url in local_links.items(): markup.add(InlineKeyboardButton(text, url=url)) else: markup.add(InlineKeyboardButton("No links found")) bot.send_message(message.chat.id, course, reply_markup=markup)
def option_two_markup(info_id): choice = random.randint(0, 2) qs = Second.objects.get(message_id=info_id) opt1 = qs.option1 opt2 = qs.answer markup = InlineKeyboardMarkup() markup.row_width = 2 true = InlineKeyboardButton(opt1, callback_data="5opt1:{}".format(info_id)) false = InlineKeyboardButton(opt2, callback_data="5ans2:{}".format(info_id)) if choice == 1: markup.add(true, false) else: markup.add(false, true) return markup
def sub_cat_kb(call): sub_cat_kb = InlineKeyboardMarkup(row_width=2) sub_cat_buttons = [] category = Category.objects.get(id=call.data.split("_")[1]) for i in category.sub_categories: callback_data = 'category_' + str(i.id) if i.is_parent: callback_data = "subcategory_" + str(i.id) sub_cat_buttons.append( InlineKeyboardButton(text=i.title, callback_data=callback_data)) sub_cat_kb.add(*sub_cat_buttons) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Суб категории', reply_markup=sub_cat_kb)
def _create_markup_withdraw_request_to_redaction(self, withdraw_id): markup = InlineKeyboardMarkup() withdraw_completed_btn_text = "Підтвердити вивід" withdraw_completed_btn_callback = self.form_account_callback( action="ConfirmWithdraw", withdraw_id=withdraw_id, prev_msg_action="Edit") withdraw_completed_btn = InlineKeyboardButton( text=withdraw_completed_btn_text, callback_data=withdraw_completed_btn_callback) markup.add(withdraw_completed_btn) return markup
def sheriff_stage(game): keyboard = InlineKeyboardMarkup(row_width=8) keyboard.add( *[InlineKeyboardButton( text=f'{i + 1}', callback_data=f'check sheriff {i + 1}' ) for i, player in enumerate(game['players']) if player['alive']] ) bot.edit_message_text( f'{role_titles["don"].capitalize()} засыпает. Просыпается {role_titles["sheriff"]} и совершает свою проверку.\n{format_roles(game)}', chat_id=game['chat'], message_id=game['message_id'], reply_markup=keyboard )
def show_account(message): user = Users.get_user(user_id=str(message.chat.id)) kb = InlineKeyboardMarkup(row_width=1) kb.add(*[InlineKeyboardButton(text=ACCOUNT_PICS[button] + text[user.lang], callback_data=f'{ACCOUNT_IND}{SP}{button}') for button, text in ACCOUNT_KB.items()]) try: bot.delete_message(message.chat.id, user.last_message()) except Exception: pass lm = bot.send_message(message.chat.id, ACCOUNT_TEXT[user.lang], reply_markup=kb) user.last_message(lm.message_id)
def show_cats(message): cats_kb = InlineKeyboardMarkup() cats_buttons = [] all_cats = Category.objects.all() for i in all_cats: callback_data = 'category_' + str(i.id) if i.is_parent: callback_data = 'subcategory_' + str(i.id) cats_buttons.append(InlineKeyboardButton(text=i.title, callback_data=callback_data)) cats_kb.add(*cats_buttons) bot.send_message(message.chat.id, text='cat example', reply_markup=cats_kb)
def get_subthemes_keyboard(theme, is_admin): res = [] keyboard = InlineKeyboardMarkup() for subtheme in os.listdir(f'{path}/{theme}'): if subtheme not in ('.idea', 'main.py'): res.append(subtheme) res.sort(key=lambda x: os.path.getmtime(f'{theme}/{x}/cover.jpg'), reverse=True) for theme in res: keyboard.add(InlineKeyboardButton(text=theme, callback_data=theme)) if is_admin: keyboard.add( InlineKeyboardButton(text='➕Новая подтема', callback_data=f'n_subtheme')) return keyboard
def gen_markup_mag(): markup = InlineKeyboardMarkup() markup.row_width = 2 markup.add(InlineKeyboardButton("3.0", callback_data="mag_3.0"), InlineKeyboardButton("3.5", callback_data="mag_3.5"), InlineKeyboardButton("4.0", callback_data="mag_4.0"), InlineKeyboardButton("4.5", callback_data="mag_4.5"), InlineKeyboardButton("5.0", callback_data="mag_5.0"), InlineKeyboardButton("5.5", callback_data="mag_5.5"), InlineKeyboardButton("6.0", callback_data="mag_6.0"), InlineKeyboardButton("6.5", callback_data="mag_6.5"), InlineKeyboardButton("7.0", callback_data="mag_7.0"), InlineKeyboardButton("7.5", callback_data="mag_7.5"), InlineKeyboardButton("Todas", callback_data="mag_Todas")) return markup
def com_cancel(user_activity, cancel=True, reply=True): if cancel: reply_text = 'Request for input is canceled' else: reply_text = 'Stopped' send('%s <i>%s</i>' % (EMOJI_ATTACHING_STOPPED, reply_text), ReplyKeyboardRemove(), reply=reply) buttons = InlineKeyboardMarkup(row_width=1) buttons.add(button_my_tasks()) reply_text = '<i>Send a message to create new Task</i>' send(reply_text, buttons, reply=False) user_activity.activity = User.ACTIVITY_NONE user_activity.update_activity()
def facilitytype_markup(): markup = InlineKeyboardMarkup() markup.row_width = 2 markup.add( InlineKeyboardButton("External Sports", callback_data="get_external"), InlineKeyboardButton("Internal Sports", callback_data="get_internal"), InlineKeyboardButton("Internal Cultural", callback_data="get_cultural"), InlineKeyboardButton("Common Facilities", callback_data="get_common"), InlineKeyboardButton("Other Facilities", callback_data="get_others"), InlineKeyboardButton("Rooms within Hall", callback_data="get_rooms"), InlineKeyboardButton("Printer", callback_data="get_printer"), InlineKeyboardButton("Back", callback_data="get_faq"), InlineKeyboardButton("Main Page", callback_data="get_main")) return markup
def get_cart(message): cart = Cart.get_or_create_cart(user_id=message.from_user.id) if len(cart.get_cart_products()) == 0: bot.send_message(message.from_user.id, text='Вы еще не добавили товары в корзину', reply_markup='') else: products = { str(cart_product.product.id): cart_product.product for cart_product in cart.get_cart_products() } sum_total = 0 for id_pro, cart_pro in products.items(): sum_total += cart.get_count_product( product=cart_pro.id) * cart_pro.get_price() product_desc = f"{cart_pro.title}\n" \ f"Кол-во {cart.get_count_product(product=cart_pro.id)} Цена: {cart_pro.get_price()}\n" \ f"Сумма: {cart.get_count_product(product=cart_pro.id)*cart_pro.get_price()}\n" kb = InlineKeyboardMarkup() kb.add( InlineKeyboardButton(text=u'🔻 убрать', callback_data='cartdecrease_' + str(id_pro)), InlineKeyboardButton( text=cart.get_count_product(product=id_pro), callback_data='---'), InlineKeyboardButton(text=u'🔺 добавить', callback_data='cartincrease_' + str(id_pro)), InlineKeyboardButton(text=u'❌ ❗ удалить товар', callback_data='cartdelete_' + str(id_pro))) bot.send_message(message.from_user.id, product_desc, reply_markup=kb) kb1 = InlineKeyboardMarkup(row_width=2) kb1.add( InlineKeyboardButton(text='🆑 Очистить корзину', callback_data='clear_car'), InlineKeyboardButton(text='💚 Оформить заказ', callback_data='confirm_order'), ) bot.send_message(message.from_user.id, text='Желаете оформить заказ?', reply_markup=kb1)
def reaction(call): call.data = int(call.data.split('react-')[-1]) key = str(call.message.chat.id) + '_' + str(call.message.message_id) reactions = r.get(key) if reactions: reactions_json = ujson.loads(reactions) for reaction in range(len(reactions_json)): if call.from_user.id in reactions_json[reaction]['users']: if reaction == call.data: bot.answer_callback_query( call.id, text='Already ' + reactions_json[reaction]['label'] + ' this!') return else: reactions_json[reaction]['users'].remove(call.from_user.id) elif reaction == call.data: reactions_json[reaction]['users'].append(call.from_user.id) else: reactions_json = [{ 'label': '❤️', 'users': [] }, { 'label': '💔', 'users': [] }] reactions_json[call.data]['users'].append(call.from_user.id) r.set(key, ujson.dumps(reactions_json)) markup = InlineKeyboardMarkup() buttons = [] for reaction in range(len(reactions_json)): if len(reactions_json[reaction]['users']): button_text = reactions_json[reaction]['label'] + ' ' + str( len(reactions_json[reaction]['users'])) else: button_text = reactions_json[reaction]['label'] buttons.append( InlineKeyboardButton(button_text, callback_data='react-{}'.format(reaction))) markup.add(*buttons) try: bot.edit_message_reply_markup(call.message.chat.id, call.message.message_id, reply_markup=markup) except: pass bot.answer_callback_query( call.id, 'You ' + reactions_json[call.data]['label'] + ' this')
def select_types_handler(call_back): message_text_data = call_back.message.text.split("\n\n") answer = "{0}\n\n{1}\n<b>{2}</b>\n{3}\n\n".format( message_text_data[0], message_text_data[1].split("\n")[0], message_text_data[1].split("\n")[1], "\n".join(message_text_data[1].split("\n")[2:])) all_chosen_types = message_text_data[2].split(": ")[1].split("; ") chosen_type = call_back.data.strip("{0} ".format( emoji["heavy_check_mark"])) if chosen_type in all_chosen_types: all_chosen_types.remove(chosen_type) if len(all_chosen_types) == 0: all_chosen_types.append("Любой тип") else: if "Любой тип" in all_chosen_types: all_chosen_types.remove("Любой тип") all_chosen_types.append(chosen_type) answer += "Типы: <b>{0}</b>\n\nУкажи типы занятия, которые " \ "скрывать:".format("; ".join(all_chosen_types)) types_keyboard = InlineKeyboardMarkup(row_width=3) short_types = [short_type for short_type in subject_short_type.values()] is_special_type = chosen_type not in short_types for i in range(len(short_types)): if short_types[i] in all_chosen_types: short_types[i] = "{0} {1}".format(emoji["heavy_check_mark"], short_types[i]) types_keyboard.add(*[ InlineKeyboardButton(text=name, callback_data=name) for name in short_types ]) if is_special_type: if chosen_type in all_chosen_types: chosen_type = "{0} {1}".format(emoji["heavy_check_mark"], chosen_type) types_keyboard.row(*[ InlineKeyboardButton( text=name, callback_data=name[:max_inline_button_text_len]) for name in [chosen_type] ]) types_keyboard.row(*[ InlineKeyboardButton(text=name, callback_data=name) for name in ["Отмена", "Далее"] ]) bot.edit_message_text(text=answer, chat_id=call_back.message.chat.id, message_id=call_back.message.message_id, parse_mode="HTML", reply_markup=types_keyboard)
def dispatch(bot, chats, chat_id, command, message_id): command = command.strip() chat = chats.get(chat_id) if chats.get(chat_id) is not None else {} if command == 'Цитаты' or command == 'quotes': chat['processor'] = 'quotes' chats[chat_id] = chat key_board = InlineKeyboardMarkup(row_width=1) key_board.add(*main.buttons.get('end')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='\n\n' + generate(chat) + '\n\n' + main.greetings['end'], reply_markup=key_board) del chats[chat_id] return True return False
def dispatch(bot, chats, chat_id, command, message_id): command = command.strip() chat = chats.get(chat_id) if chats.get(chat_id) is not None else {} if command == 'Комплименты': chat['processor'] = 'compliments' key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('compliments_sex')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('compliments_sex'), reply_markup=key_board) chats[chat_id] = chat return True elif chat.get('processor') == 'compliments' and chat.get('sex') is None: chat['sex'] = command key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('compliments_type')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('compliments_type'), reply_markup=key_board) chats[chat_id] = chat return True elif chat.get('processor') == 'compliments' and chat.get('type_compl') is None: chat['type_compl'] = command chats[chat_id] = chat key_board = InlineKeyboardMarkup(row_width=1) key_board.add(*main.buttons.get('end')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='\n\n' + generate(chat) + '\n\n' + main.greetings['end'], reply_markup=key_board) del chats[chat_id] return True return False
def dispatch(bot, chats, chat_id, command, message_id): command = command.strip() chat = chats.get(chat_id) if chats.get(chat_id) is not None else {} if command.upper() == 'ИНН/ОГРН/UUID' or command.upper() == 'INN': chat['processor'] = 'inn' key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('inn_type')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('inn_type'), reply_markup=key_board) chats[chat_id] = chat return True elif chat.get('processor') == 'inn' and chat.get('type') is None and (command == 'uuid' or command == 'UUID'): chat["type"] = command key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('uuid_start')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('uuid_start'), reply_markup=key_board) chat['message_id'] = message_id chats[chat_id] = chat return True elif chat.get('processor') == 'inn' and chat.get('type') is None: chat["type"] = command key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('inn_start')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('inn_start'), reply_markup=key_board) chat['message_id'] = message_id chats[chat_id] = chat return True elif chat.get('processor') == 'inn' and chat.get('type') is not None: chat['inn'] = command chats[chat_id] = chat key_board = InlineKeyboardMarkup(row_width=1) key_board.add(*main.buttons.get('end')) if message_id is None: message_id = chat['message_id'] if chat.get('message_id') is not None: del chat['message_id'] bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='\n\n' + generate(chat) + '\n\n' + main.greetings['end'], reply_markup=key_board) del chats[chat_id] return True return False
def dispatch(bot, chats, chat_id, command, message_id): command = command.strip() chat = chats.get(chat_id) if chats.get(chat_id) is not None else {} if command == 'Пароли': chat['processor'] = 'passwords' key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('passwords_count')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('passwords_count'), reply_markup=key_board) chat['message_id'] = message_id chats[chat_id] = chat return True elif chat.get('processor') == 'passwords' and chat.get('count') is None: chat['count'] = str(command) key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('passwords_type')) if message_id is None: message_id = chat['message_id'] bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('passwords_type'), reply_markup=key_board) chats[chat_id] = chat return True elif chat.get('processor') == 'passwords' and chat.get('count') is not None: chat['upper'] = '0' chat['lower'] = '0' chat['num'] = '0' chat['symbol'] = '0' if command == 'Буквы и Цифры': chat['upper'] = '1' chat['lower'] = '1' chat['num'] = '1' elif command == 'Буквы': chat['upper'] = '1' chat['lower'] = '1' elif command == 'Буквы, Цифры и Символы': chat['upper'] = '1' chat['lower'] = '1' chat['num'] = '1' chat['symbol'] = '1' chats[chat_id] = chat key_board = InlineKeyboardMarkup(row_width=1) key_board.add(*main.buttons.get('end')) if chat.get('message_id') is not None: del chat['message_id'] bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='\n\n' + generate(chat) + '\n\n' + main.greetings['end'], reply_markup=key_board) del chats[chat_id] return True return False
def dispatch(bot, chats, chat_id, command, message_id): command = command.strip() chat = chats.get(chat_id) if chats.get(chat_id) is not None else {} if command == 'Имена': chat['processor'] = 'names' key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('names_sex')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('names_sex'), reply_markup=key_board) chats[chat_id] = chat return True elif chat.get('processor') == 'names' and chat.get('sex') is None: chat['sex'] = command if command == 'nick': key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('names_count')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('names_count'), reply_markup=key_board) else: key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('names_field')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('names_field'), reply_markup=key_board) chat['message_id'] = message_id chats[chat_id] = chat return True elif chat.get('processor') == 'names' and chat.get('sex') is not None and chat.get('sex') != 'nick' and \ chat.get('surname') is None and chat.get('name') is None and chat.get('patronymic') is None: chat['surname'] = '0' chat['name'] = '0' chat['patronymic'] = '0' if command == 'ФИО': chat['surname'] = '1' chat['name'] = '1' chat['patronymic'] = '1' elif command == 'Ф': chat['surname'] = '1' elif command == 'И': chat['name'] = '1' elif command == 'О': chat['patronymic'] = '1' elif command == 'ФИ': chat['surname'] = '1' chat['name'] = '1' elif command == 'ИО': chat['name'] = '1' chat['patronymic'] = '1' key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('names_count')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('names_count'), reply_markup=key_board) return True elif chat.get('processor') == 'names' and chat.get('count') is None: chat['count'] = command chats[chat_id] = chat key_board = InlineKeyboardMarkup(row_width=1) key_board.add(*main.buttons.get('end')) if message_id is None: message_id = chat['message_id'] if chat.get('message_id') is not None: del chat['message_id'] bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='\n\n' + generate(chat) + '\n\n' + main.greetings['end'], reply_markup=key_board) del chats[chat_id] return True return False
def dispatch(bot, chats, chat_id, command, message_id): command = command.strip() chat = chats.get(chat_id) if chats.get(chat_id) is not None else {} if command == 'Текст' or command == 'text': chat['processor'] = 'text' key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('text_type')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('text_type'), reply_markup=key_board) chats[chat_id] = chat return True elif chat.get('processor') == 'text' and (command == 'Классическая проза' or command == 'prose'): chat['type'] = 'prose' key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('text_paragraph')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('text_paragraph'), reply_markup=key_board) chat['message_id'] = message_id chats[chat_id] = chat return True elif chat.get('processor') == 'text' and (command == 'Бизнес и финансы' or command == 'business'): chat['type'] = 'business' key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('text_paragraph')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('text_paragraph'), reply_markup=key_board) chat['message_id'] = message_id chats[chat_id] = chat return True elif chat.get('processor') == 'text' and (command == 'Наука и техника' or command == 'science'): chat['type'] = 'science' key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('text_paragraph')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('text_paragraph'), reply_markup=key_board) chat['message_id'] = message_id chats[chat_id] = chat return True elif chat.get('processor') == 'text' and (command == 'Юмор и развлечения' or command == 'humor'): chat['type'] = 'humor' key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('text_paragraph')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('text_paragraph'), reply_markup=key_board) chat['message_id'] = message_id chats[chat_id] = chat return True elif chat.get('processor') == 'text' and (command == 'Дом и семья' or command == 'home'): chat['type'] = 'home' key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('text_paragraph')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('text_paragraph'), reply_markup=key_board) chat['message_id'] = message_id chats[chat_id] = chat return True elif chat.get('processor') == 'text' and (command == 'Медицина и здоровье' or command == 'med'): chat['type'] = 'med' key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('text_paragraph')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('text_paragraph'), reply_markup=key_board) chat['message_id'] = message_id chats[chat_id] = chat return True elif chat.get('processor') == 'text' and (command == 'Lorem Ipsum' or command == 'lorem'): chat['type'] = 'lorem' key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('text_paragraph')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('text_paragraph'), reply_markup=key_board) chat['message_id'] = message_id chats[chat_id] = chat return True elif chat.get('processor') == 'text' and (command == 'О рыбе...' or command == 'fish'): chat['type'] = 'fish' key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('text_paragraph')) bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('text_paragraph'), reply_markup=key_board) chat['message_id'] = message_id chats[chat_id] = chat return True elif chat.get('processor') == 'text' and chat.get("type") is not None and chat.get('paragraph') is None: chat['paragraph'] = command key_board = InlineKeyboardMarkup(row_width=3) key_board.add(*buttons.get('text_words')) if message_id is None: message_id = chat['message_id'] chat['message_id'] = message_id bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=greetings.get('text_words'), reply_markup=key_board) chats[chat_id] = chat return True elif chat.get('processor') == 'text' and chat.get("type") is not None and chat.get('paragraph') is not None: chat['word'] = command key_board = InlineKeyboardMarkup(row_width=1) key_board.add(*main.buttons.get('end')) if message_id is None: message_id = chat['message_id'] if chat.get('message_id') is not None: del chat['message_id'] bot.edit_message_text(chat_id=chat_id, message_id=message_id, text='\n\n' + generate(chat) + '\n\n' + main.greetings['end'], reply_markup=key_board) del chats[chat_id] return True return False
def gen_markup(): markup = InlineKeyboardMarkup() markup.row_width = 2 markup.add(InlineKeyboardButton("Yes", callback_data=f"cb_yes"), InlineKeyboardButton("No", callback_data=f"cb_no")) return markup