Untitled

mail@pastecode.io avatar
unknown
python
2 months ago
5.5 kB
2
Indexable
Never
# This Python file uses the following encoding: utf-8
import telebot
from telebot import types

TOKEN = '7155522222:AAGfBcubxszju-buXZf2Z9yKPLUDodWz6iw'
bot = telebot.TeleBot(TOKEN)


def generate_numbers_keyboard(numbers, current_page, total_pages):
    reply_markup = types.InlineKeyboardMarkup(row_width=2)
    row = []
    for number in numbers:
        button = types.InlineKeyboardButton(text=number, callback_data=number)
        row.append(button)
        if len(row) == 2:
            reply_markup.row(*row)
            row = []

    navigation_row = []
    if current_page > 1:
        prev_button = types.InlineKeyboardButton("⬅️ Назад", callback_data=f"prev_{current_page}")
        navigation_row.append(prev_button)

    next_button_text = "➡️ Вперед" if current_page < total_pages else "➡️ Вперед (пусто)"
    next_button = types.InlineKeyboardButton(next_button_text, callback_data=f"next_{current_page}")
    navigation_row.append(next_button)

    reply_markup.row(*navigation_row)

    return reply_markup

# Обработчик команды /start
@bot.message_handler(commands=['start'])
def send_welcome(message):

    with open('img/2.png', 'rb') as file_photo_greeting:
        welcome_message = (
            "\n*Добро пожаловать в магазин анонимных номеров!*🏴‍☠️\n"
            "\n*У нас вы можете приобрести анонимные номера для различных целей.*\n"
            "\n*Просто нажмите кнопку '🏴‍☠️ Anonymous Numbers' ниже, чтобы посмотреть доступные номера.*\n"
        )
        bot.send_photo(chat_id=message.from_user.id, photo=file_photo_greeting, caption=welcome_message, parse_mode="Markdown", reply_markup=generate_main_keyboard())


def generate_main_keyboard(): #здесь все наши кнопки
    keyboard = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True)
    button_anonymous_numbers = types.KeyboardButton('🏴‍☠️ Anonymous Numbers')
    keyboard.add(button_anonymous_numbers)
    button_tech_support = types.KeyboardButton('Support 🧑‍💻')
    keyboard.add(button_tech_support)
    return keyboard

@bot.message_handler(func=lambda message: message.text == '🏴‍☠️ Anonymous Numbers')
def handle_anonymous_numbers(message, current_page=1):
    with open('img/1.png', 'rb') as file_photo_numbers:
        numbers = [
            "+888 0217 4365", "+888 0217 4536",
            "+888 0235 7164", "+888 0241 7365", "+888 0243 6751",
            "+888 0245 1763", "+888 0245 6371",
            "+888 0247 1563", "+888 0247 3561", "+888 0247 5316",
            "+888 0251 3467", "+888 0256 4317", "+888 0263 1547",
            "+888 0267 3541", "+888 0267 5341", "+888 0267 5134"
        ]

        page_size = 4  # количество номеров на одной странице

        start_index = (current_page - 1) * page_size
        end_index = start_index + page_size

        current_numbers = numbers[start_index:end_index]

        total_pages = (len(numbers) + page_size - 1) // page_size  # calculate total pages
        reply_markup = generate_numbers_keyboard(current_numbers, current_page, total_pages)
        caption_message = f"Выберите анонимный номер из списка (Страница {current_page}):"

        # Send a new message with the updated content
        bot.send_photo(chat_id=message.chat.id, photo=file_photo_numbers, caption=caption_message, reply_markup=reply_markup)

@bot.callback_query_handler(func=lambda call: call.data.startswith(("prev_", "next_")))
def handle_pagination_callback(call):
    action, current_page = call.data.split("_")
    current_page = int(current_page)

    if action == "prev" and current_page > 1:
        current_page -= 1
    elif action == "next":
        current_page += 1

    # Delete the original message
    bot.delete_message(chat_id=call.message.chat.id, message_id=call.message.message_id)

    # Send a new message with the updated content
    handle_anonymous_numbers(call.message, current_page)

@bot.message_handler(func=lambda message: message.text == 'Support 🧑‍💻')
def support(message):
    reply_markup = types.InlineKeyboardMarkup(row_width=2)
    bot.send_message(message.chat.id, "*По всем вопросам/жалобам/предложениям писать: @id*", parse_mode="Markdown")

# Обработчик нажатия на инлайн кнопку с номером
@bot.callback_query_handler(func=lambda call: True)
def handle_callback_query(call):
    price = "35$"
    number = call.data
    message_text = f"3500 RUB🇷🇺 | 35 USDT🇺🇸 | 1300 UAH🇺🇦 |\n" f"🏴 Number: {number}  |  1 Месяц\n" "🏴‍☠ Для покупки анонимного номера нажмите кнопку ниже.\n" "Обратите внимание: средства за покупку не возвращаются\n" "После совершения покупки номер будет доступен только вам и привязан к вашему аккаунту на месяц.\n"
    reply_markup = types.InlineKeyboardMarkup()
    buy_button = types.InlineKeyboardButton("Арендовать ✅", callback_data=f"{number}")
    reply_markup.add(buy_button)
    bot.send_message(call.message.chat.id, message_text, reply_markup=reply_markup)

bot.polling()
Leave a Comment