Implemented query for the quantity of the search results via inline buttons. (Test functional for now.)

This commit is contained in:
T-BENZIN 2023-05-28 15:18:04 +05:00
parent 29ceb95404
commit 1df9a16643

61
main.py
View File

@ -1,9 +1,9 @@
import telebot
from telebot import types
import configparser
config = configparser.ConfigParser()
config.read()
config.read('config.ini')
TG_TOKEN = config.get('telebot', 'token')
API_TOKEN = config.get('hotels_api', 'token')
@ -13,33 +13,66 @@ DB_DATABASE = config.get('database', 'database')
DB_USER = config.get('database', 'user')
DB_PASSWORD = config.get('database', 'password')
bot = telebot.TeleBot(token=TG_TOKEN)
last_commands = {}
@bot.message_handler(commands=['start', 'help'])
def handle_start(message):
pass # TODO добавить логику обработки команд start и help
pass # TODO add logic for handling the start and help commands
@bot.message_handler(commands=['low'])
def handle_low(message):
pass # TODO добавить логику обработки команды low
@bot.message_handler(commands=['lowprice'])
def handle_lowprice(message):
last_commands[message.chat.id] = 'lowprice'
# Create InlineKeyboardMarkup with buttons
keyboard = types.InlineKeyboardMarkup(row_width=5)
buttons = [types.InlineKeyboardButton(str(i), callback_data=str(i)) for i in range(1, 11)]
keyboard.add(*buttons)
# Send keyboard with buttons
bot.send_message(message.chat.id, 'Выберите количество:', reply_markup=keyboard)
@bot.message_handler(commands=['high'])
def handle_high(message):
pass # TODO добавить логику обработки команды high
@bot.message_handler(commands=['highprice'])
def handle_highprice(message):
last_commands[message.chat.id] = 'highprice'
# Create InlineKeyboardMarkup with buttons
keyboard = types.InlineKeyboardMarkup(row_width=5)
buttons = [types.InlineKeyboardButton(str(i), callback_data=str(i)) for i in range(1, 11)]
keyboard.add(*buttons)
# Send keyboard with buttons
bot.send_message(message.chat.id, 'Выберите количество:', reply_markup=keyboard)
@bot.message_handler(commands=['custom'])
def handle_custom(message):
pass # TODO добавить логику обработки команды custom
@bot.message_handler(commands=['bestdeal'])
def handle_bestdeal(message):
pass # TODO add logic for handling the bestdeal command
@bot.message_handler(commands=['history'])
def handle_history(message):
pass # TODO добавить логику обработки команды history
pass # TODO add logic for handling the history command
@bot.callback_query_handler(func=lambda call: True) # Handler for button clicks
def handle_button_click(call):
if call.message.chat.id in last_commands:
command = last_commands[call.message.chat.id] # Get the current command from the last commands dict
bot.edit_message_reply_markup(call.message.chat.id, call.message.message_id) # Remove the keyboard
# Edit the message.
bot.edit_message_text(
text=f'Вы выбрали количество: {call.data} ({last_commands[call.message.chat.id]})',
chat_id=call.message.chat.id,
message_id=call.message.message_id
)
del last_commands[call.message.chat.id] # Remove the last command state after handling
bot.polling()