async def timerInlineHandler(inline_query: InlineQuery): secCount = evalSecondsCount(inline_query.query) if secCount > 7200 or secCount < 1: articleTitle = "Таймер не будет запущен" isWrong = True else: articleTitle = 'Запускает таймер' isWrong = False awaitingButton = inline_keyboard.InlineKeyboardButton( 'Запускаю...', callback_data='awaiting') awaitingKeyboard = inline_keyboard.InlineKeyboardMarkup(row_width=1). \ insert(awaitingButton) items = [ InlineQueryResultArticle(id=str(time()), title=articleTitle, description=f"на {secCount} секунд", reply_markup=awaitingKeyboard, thumb_url=foxLogoPreview, input_message_content=InputTextMessageContent( f"Таймер на {secCount} сек.")) ] if not isWrong: await bot.answer_inline_query(inline_query.id, results=items, cache_time=0)
async def send_confirm_message(chat_id, data): markup = kb.InlineKeyboardMarkup() markup.add( kb.InlineKeyboardButton( 'Подтвердить', callback_data=CallbackMethods.add_trunk_accept)) markup.add( kb.InlineKeyboardButton( 'Отклонить', callback_data=CallbackMethods.add_trunk_decline)) markup.add( kb.InlineKeyboardButton('Указать порт', callback_data=CallbackMethods.add_trunk_port)) markup.add( kb.InlineKeyboardButton('Указать прокси', callback_data=CallbackMethods.add_trunk_proxy)) message = ('Данные транка:\n' f'vats_id: {data.get("vats_id")}\n' f'domain: {data.get("domain")}\n' f'username: {data.get("username")}\n' f'password: {data.get("password")}\n') if data.get('port'): message += f'port: {data.get("port")}\n' if data.get('proxy'): message += f'proxy: {data.get("proxy")}\n' await bot.send_message(chat_id, f'{message}\nПодвердите добавление транка', reply_markup=markup)
def orders_by_phone(orders, phone, language, current_pos=0): k = inline_keyboard.InlineKeyboardMarkup() counter = 1 for order in orders: k.add( inline_keyboard.InlineKeyboardButton( order, callback_data='order_{0}'.format(order))) if counter == current_pos + 5: break counter += 1 if language == 'ru': more = 'Показать еще ⬇️' elif language == 'uk': more = 'Показати ще ⬇️' else: more = 'Show more ⬇️' if len(orders) > current_pos + 5: call_data_more = 'more_orders_{0}|{1}'.format(phone, current_pos + 5) k.add( inline_keyboard.InlineKeyboardButton(more, callback_data=call_data_more)) return k
async def settingsCallingHandler(message: Message, isBack: bool = False, userID: int = None): """Основное меню настроек""" if not isBack: addUser(message.from_user.id) if not userID: userID = message.chat.id buttonsData = [ ["Отправлено фото", "photoReceivedChanging"], ["Статистика", "statistics"], ["Изменить ник", "changeNickname"], ["Закрыть", "close"], ] buttons = buttonsList(buttonsData, rowWidth=2) reply_markup = inline_keyboard.InlineKeyboardMarkup( row_width=1, inline_keyboard=buttons) username = get_nick_by_id(userID) text = f"Что вы хотите изменить, {username}?" if not isBack: # Создаёт сообщение, если пользователь вызвал настройки await message.answer(text=text, reply_markup=reply_markup) else: # Изменяет сообщение, если пользователь нажал "back" await bot.edit_message_text(text=text, reply_markup=reply_markup, chat_id=message.chat.id, message_id=message.message_id)
def auth_kurs(): inline_kb_full = inline_keyboard.InlineKeyboardMarkup() inline_btn_0 = inline_keyboard.InlineKeyboardButton( '1', callback_data=f'kurs_{1}') inline_btn_1 = inline_keyboard.InlineKeyboardButton( '2', callback_data=f'kurs_{2}') inline_btn_2 = inline_keyboard.InlineKeyboardButton( '3', callback_data=f'kurs_{3}') inline_btn_3 = inline_keyboard.InlineKeyboardButton( '4', callback_data=f'kurs_{4}') inline_btn_4 = inline_keyboard.InlineKeyboardButton( '5', callback_data=f'kurs_{5}') inline_btn_5 = inline_keyboard.InlineKeyboardButton( '6', callback_data=f'kurs_{6}') inline_kb_full.row(inline_btn_0, inline_btn_1, inline_btn_2, inline_btn_3, inline_btn_4, inline_btn_5) inline_btn_3 = inline_keyboard.InlineKeyboardButton('Аспирант', callback_data='aspir') inline_btn_4 = inline_keyboard.InlineKeyboardButton('Перподаватель', callback_data='prepod') inline_btn_5 = inline_keyboard.InlineKeyboardButton('Закончил', callback_data='zak') inline_kb_full.add(inline_btn_3) inline_kb_full.add(inline_btn_4) inline_kb_full.add(inline_btn_5) return inline_kb_full
async def get_serial_categories(call): tel_id = call.from_user.id current_pos = int(call.data.split('_')[1]) href = 'service/tv-series/what-to-see/' soup = BeautifulSoup(requests.get(url + href).text, 'lxml') film_categories = soup.find_all('div', {'class': 'simpleMovie'}) k = inline_keyboard.InlineKeyboardMarkup() counter = current_pos while counter <= len(film_categories): if counter == current_pos + 8 or counter == len(film_categories): break category_href = film_categories[counter].find('a').get('href') category_name = film_categories[counter].find('img').get('alt') k.add( inline_keyboard.InlineKeyboardButton( str(counter + 1) + ') ' + category_name, switch_inline_query_current_chat='ser-category_{0}'.format( category_href))) counter += 1 if current_pos >= 8: call_data_previous = 'categories-series_{0}'.format(current_pos - 8) k.add( inline_keyboard.InlineKeyboardButton( 'Previous⬅', callback_data=call_data_previous)) if len(film_categories) > current_pos + 8: call_data_more = 'categories-series_{0}'.format(current_pos + 8) k.add( inline_keyboard.InlineKeyboardButton('Next \U000027a1', callback_data=call_data_more)) await bot.edit_message_text('Выберите категорию сериалов', tel_id, call.message.message_id, reply_markup=k)
async def statisticsCallingCallbackHandler(callback_query: CallbackQuery, isUpdate: bool = False): message = callback_query.message buttonsData = [["Обновить", "update"], ["←Назад", "back"]] buttons = buttonsList(buttonsData, rowWidth=2) reply_markup = inline_keyboard.InlineKeyboardMarkup( row_width=2, inline_keyboard=buttons) userStats = getUserStats(userID=callback_query.from_user.id) text = markdown.bold("Ваша статистика:\n\n") + \ "Создано демотиваторов — " + markdown.italic(f"{userStats['demoCreated']}\n") + \ "Выполнено inline\-комманд — " + markdown.italic(f"{userStats['inlineAnswered']}\n") try: await bot.edit_message_text(text=text, reply_markup=reply_markup, parse_mode='MarkdownV2', chat_id=message.chat.id, message_id=message.message_id) if isUpdate: await callback_query.answer(text="Статистика обновлена") except exceptions.MessageNotModified: await callback_query.answer(text="Статистика не поменялась")
def timekb_2(hour=None, minutes=None, num=None, tel_id=None): print('numt2:', num) inline_kb_full = inline_keyboard.InlineKeyboardMarkup() inline_btn_0 = inline_keyboard.InlineKeyboardButton( '➕ 1 час', callback_data=f'hourp_{hour}!{minutes}') inline_btn_1 = inline_keyboard.InlineKeyboardButton( '➕ 15 минут', callback_data=f'minut_{hour}!{minutes}') inline_kb_full.row(inline_btn_0, inline_btn_1) inline_btn_3 = inline_keyboard.InlineKeyboardButton(str(hour), callback_data='0') inline_btn_4 = inline_keyboard.InlineKeyboardButton(':', callback_data='0') inline_btn_5 = inline_keyboard.InlineKeyboardButton(str(minutes), callback_data='0') inline_kb_full.row(inline_btn_3, inline_btn_4, inline_btn_5) inline_btn_6 = inline_keyboard.InlineKeyboardButton( '➖ 1 час', callback_data=f'hourm_{hour}!{minutes}') inline_btn_7 = inline_keyboard.InlineKeyboardButton( '➖ 15 минут', callback_data=f'minum_{hour}!{minutes}') inline_kb_full.row(inline_btn_6, inline_btn_7) inline_btn_9 = inline_keyboard.InlineKeyboardButton( 'Подтвердить', callback_data=f'podtv{num}_{hour}:{minutes}') inline_kb_full.add(inline_btn_9) return inline_kb_full
def get_pagination_markup_by_spare_parts(model_search, category_spec_id, models, language, current_pos=0): k = inline_keyboard.InlineKeyboardMarkup() counter = 0 for m in models: text = m['name'] call_data = 'item_{0}'.format(m['code']) k.add( inline_keyboard.InlineKeyboardButton(text, callback_data=call_data)) counter += 1 if counter == current_pos + 5: break if language == 'ru': more = 'Показать еще ⬇️' elif language == 'uk': more = 'Показати ще ⬇️' else: more = 'Show more ⬇️' if len(models) > current_pos + 5: call_data_more = 'more_parts_{0}|{1}|{2}'.format( model_search, category_spec_id, current_pos + 5) k.add( inline_keyboard.InlineKeyboardButton(more, callback_data=call_data_more)) return k
def get_catalog_by_article(article, items, language): if language == 'ru': next = 'Вперед ➡️' elif language == 'uk': next = 'Вперед ➡️' else: next = 'Forward ➡️' k = inline_keyboard.InlineKeyboardMarkup() position = 0 if position + 5 > len(items): end = len(items) else: end = position + 5 for i in range(position, end): item = items[i] text = item['number'] call_data = 'item_{0}'.format(item['code']) k.add( inline_keyboard.InlineKeyboardButton(text, callback_data=call_data)) if len(items) > end: next_data = 'next|{0}|{1}'.format(article, end) k.add( inline_keyboard.InlineKeyboardButton(next, callback_data=next_data)) return k
def get_sv(): k = inline_keyboard.InlineKeyboardMarkup() k.add( inline_keyboard.InlineKeyboardButton('Написать ⌨️', callback_data='textman')) k.add( inline_keyboard.InlineKeyboardButton('Позвонить 📱️', callback_data='call_man')) return k
def onl(): k = inline_keyboard.InlineKeyboardMarkup() k.add( inline_keyboard.InlineKeyboardButton('Войти в чат с заказчиком', callback_data=f'enter_online')) k.add( inline_keyboard.InlineKeyboardButton('Связь с менеджером', callback_data=f'manager')) return k
def ready(): k = inline_keyboard.InlineKeyboardMarkup() k.add( inline_keyboard.InlineKeyboardButton('Готово 👌', callback_data='ready')) k.add( inline_keyboard.InlineKeyboardButton('❌ Пропустить отправку файлов ', callback_data='prop')) return k
def online_kb(): k = inline_keyboard.InlineKeyboardMarkup() k.add( inline_keyboard.InlineKeyboardButton('Подключить автора в чат', callback_data='get_author')) k.add( inline_keyboard.InlineKeyboardButton('Онлайн работы не будет ❌', callback_data='no_online')) return k
def pay_or_not(ord_id): k = inline_keyboard.InlineKeyboardMarkup() k.add( inline_keyboard.InlineKeyboardButton('💰Оплатить 💰', callback_data=f'pay_{ord_id}')) k.add( inline_keyboard.InlineKeyboardButton('❌ Отменить заказ ❌', callback_data=f'otmena_{ord_id}')) return k
def fifty_or_all(ord_id): k = inline_keyboard.InlineKeyboardMarkup() k.add( inline_keyboard.InlineKeyboardButton('Оплатил 50%', callback_data=f'fifty_{ord_id}')) k.add( inline_keyboard.InlineKeyboardButton('Оплатил 100%', callback_data=f'all_{ord_id}')) return k
def spare_part_specification(model_search, specifications): k = inline_keyboard.InlineKeyboardMarkup() for at in specifications.values(): k.add( inline_keyboard.InlineKeyboardButton( at['name'], callback_data='specify_spare_part_{0}|{1}'.format( model_search, at['id']))) return k
def appliance_type_secification(appliance_types, model_name): k = inline_keyboard.InlineKeyboardMarkup() for at in appliance_types.values(): k.add( inline_keyboard.InlineKeyboardButton( at['name'], callback_data='specify_appliance_{0}|{1}'.format( model_name, at['id']))) return k
def ord_1(ord_id): k = inline_keyboard.InlineKeyboardMarkup() k.add( inline_keyboard.InlineKeyboardButton( 'Оценить 💰', callback_data=f'otzenit_{ord_id}')) k.add( inline_keyboard.InlineKeyboardButton('Не интересно 🗑', callback_data=f'nint_{ord_id}')) return k
def otr(): k = inline_keyboard.InlineKeyboardMarkup() k.add( inline_keyboard.InlineKeyboardButton('От руки 📝', callback_data='ruk')) k.add( inline_keyboard.InlineKeyboardButton('Электронный вид ⌨️', callback_data='elect')) k.add( inline_keyboard.InlineKeyboardButton('Не принципиально', callback_data='ne_prcpl')) return k
def stats_keyboard(): k = inline_keyboard.InlineKeyboardMarkup() k.add( inline_keyboard.InlineKeyboardButton('За последние сутки', callback_data='stats_1')) k.add( inline_keyboard.InlineKeyboardButton('За последнюю неделю', callback_data='stats_7')) k.add( inline_keyboard.InlineKeyboardButton('За последний месяц', callback_data='stats_30')) return k
def back_to_orders(language): if language == 'ru': text = '⬅️ Назад' elif language == 'uk': text = '⬅️ Назад' else: text = '⬅️ Back' k = inline_keyboard.InlineKeyboardMarkup() k.add( inline_keyboard.InlineKeyboardButton(text, callback_data='back_to_orders')) return k
def go_to_site_keyboard(url, language): if language == 'ru': text = '🛒 Заказать на сайте' elif language == 'uk': text = '🛒 Замовити на сайті' else: text = '🛒 Make an order' url = url + '?utm_source=telegram&utm_medium=telegram_bot' k = inline_keyboard.InlineKeyboardMarkup() k.add(inline_keyboard.InlineKeyboardButton(text, url=url)) return k
def otz(ord_id): k = inline_keyboard.InlineKeyboardMarkup() one = inline_keyboard.InlineKeyboardButton('1️⃣', callback_data=f'one_{ord_id}') two = inline_keyboard.InlineKeyboardButton('2️⃣', callback_data=f'two_{ord_id}') three = inline_keyboard.InlineKeyboardButton( '3️⃣', callback_data=f'three_{ord_id}') four = inline_keyboard.InlineKeyboardButton('4️⃣', callback_data=f'four_{ord_id}') five = inline_keyboard.InlineKeyboardButton('5️⃣', callback_data=f'five_{ord_id}') k.row(one, two, three, four, five) return k
def timekb(tel_id, num): time = UsersDbManager.get_time_t(tel_id) s = str(UsersDbManager.sync_get_type(tel_id)) t = UsersDbManager.get_time(tel_id) if s == 'Online решение' or s == 'Тест дистанционно': s = True else: s = False if s is True and num == 3 and time is False: hour = '10' minutes = '00' elif s is True and num == 2 and time is False and t is None: hour = '9' minutes = '00' else: hour = '19' minutes = '00' inline_kb_full = inline_keyboard.InlineKeyboardMarkup() inline_btn_0 = inline_keyboard.InlineKeyboardButton( '➕ 1 час', callback_data=f'hourp_{hour}!{minutes}') inline_btn_1 = inline_keyboard.InlineKeyboardButton( '➕ 15 минут', callback_data=f'minut_{hour}!{minutes}') inline_kb_full.row(inline_btn_0, inline_btn_1) inline_btn_3 = inline_keyboard.InlineKeyboardButton(str(hour), callback_data='0') inline_btn_4 = inline_keyboard.InlineKeyboardButton(':', callback_data='0') inline_btn_5 = inline_keyboard.InlineKeyboardButton(str(minutes), callback_data='0') inline_kb_full.row(inline_btn_3, inline_btn_4, inline_btn_5) inline_btn_6 = inline_keyboard.InlineKeyboardButton( '➖ 1 час', callback_data=f'hourm_{hour}!{minutes}') inline_btn_7 = inline_keyboard.InlineKeyboardButton( '➖ 15 минут', callback_data=f'minum_{hour}!{minutes}') inline_kb_full.row(inline_btn_6, inline_btn_7) inline_btn_9 = inline_keyboard.InlineKeyboardButton( 'Подтвердить', callback_data=f'podtv{num}_{hour}:{minutes}') inline_kb_full.add(inline_btn_9) return inline_kb_full
def show_results_by_article(language, parameter): k = inline_keyboard.InlineKeyboardMarkup() if language == 'ru': text = 'Показать' elif language == 'uk': text = 'Показати' else: text = 'Show' k.add( inline_keyboard.InlineKeyboardButton( text, switch_inline_query_current_chat='show_by_article_{0}'.format( parameter))) return k
def show_results_by_model(language, search_query, sub_category_id): k = inline_keyboard.InlineKeyboardMarkup() if language == 'ru': text = 'Показать' elif language == 'uk': text = 'Показати' else: text = 'Show' k.add( inline_keyboard.InlineKeyboardButton( text, switch_inline_query_current_chat='show_by_model_{0}|{1}'.format( search_query, sub_category_id))) return k
def why_otm(ord_id): k = inline_keyboard.InlineKeyboardMarkup() k.add( inline_keyboard.InlineKeyboardButton('Дорого', callback_data=f'exp_{ord_id}')) k.add( inline_keyboard.InlineKeyboardButton('Сделал сам', callback_data=f'myself_{ord_id}')) k.add( inline_keyboard.InlineKeyboardButton('Заказал у других людей', callback_data=f'other_{ord_id}')) k.add( inline_keyboard.InlineKeyboardButton( 'Другое', callback_data=f'another_{ord_id}')) return k
def get_yes_no_phone(language): if language == 'ru': yes = 'Да' change = 'Нет' elif language == 'uk': yes = 'Так' change = 'Ні' else: yes = 'Yes' change = 'No' k = inline_keyboard.InlineKeyboardMarkup() k.add(inline_keyboard.InlineKeyboardButton(yes, callback_data='my_phone')) k.add( inline_keyboard.InlineKeyboardButton(change, callback_data='change_number')) return k
async def some_chosen_inline_handler(chosen_inline_query: ChosenInlineResult): txt = chosen_inline_query.query[3:] # Обрезаем "qr" voidInlineKeyboard = inline_keyboard.InlineKeyboardMarkup() qrCodePath = createQR(txt) imgID = await uploadInputFileToTelegram(qrCodePath, bot=bot) await bot.edit_message_reply_markup( reply_markup=voidInlineKeyboard, inline_message_id=chosen_inline_query.inline_message_id) await bot.edit_message_media( media=InputMediaPhoto(media=imgID), inline_message_id=chosen_inline_query.inline_message_id) remove(qrCodePath)