79 lines
2.6 KiB
Python
79 lines
2.6 KiB
Python
import telebot
|
|
from telebot import types
|
|
import configparser
|
|
|
|
config = configparser.ConfigParser()
|
|
config.read('config.ini')
|
|
|
|
TG_TOKEN = config.get('telebot', 'token')
|
|
API_TOKEN = config.get('hotels_api', 'token')
|
|
DB_HOST = config.get('database', 'host')
|
|
DB_PORT = config.get('database', 'port')
|
|
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 add logic for handling the start and help commands
|
|
|
|
|
|
@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=['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=['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 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()
|