Загрузка данных


import telebot
from telebot import types
import random

TOKEN = "ТВОЙ_ТОКЕН_ЗДЕСЬ"
bot = telebot.TeleBot(TOKEN)

ITEMS = {
    "💩": ("Какаха", 10), "🤡": ("Клоун", 12), "🤖": ("Робот", 15), "👻": ("Призрак", 15),
    "🕶️": ("Очки", 40), "🦊": ("Лиса", 50), "🦁": ("Лев", 60), "🥷": ("Ниндзя", 70),
    "🌋": ("Вулкан", 150), "🌌": ("Космос", 200), "🧬": ("ДНК", 250), "⚔️": ("Мечи", 300),
    "💎": ("Алмаз", 1000), "🦄": ("Единорог", 1200), "🏆": ("Кубок", 1500), "🐲": ("Дракон", 2000)
}

DROP_CHANCES = [
    (["💩", "🤡", "🤖", "👻"], 65),
    (["🕶️", "🦊", "🦁", "🥷"], 25),
    (["🌋", "🌌", "🧬", "⚔️"], 8),
    (["💎", "🦄", "🏆", "🐲"], 2)
]

users_data = {}

def get_user_profile(user_id):
    if user_id not in users_data:
        users_data[user_id] = {"inventory": ["💩", "🤡"], "selected_upgrade_item": None}
    return users_data[user_id]

def main_menu_keyboard():
    markup = types.InlineKeyboardMarkup(row_width=2)
    btn_inv = types.InlineKeyboardButton("🎒 Мой Инвентарь", callback_data="menu_inventory")
    btn_case = types.InlineKeyboardButton("📦 Открыть Кейс", callback_data="menu_cases")
    btn_upg = types.InlineKeyboardButton("⚡ Апгрейд", callback_data="menu_upgrade")
    markup.add(btn_inv)
    markup.add(btn_case, btn_upg)
    return markup

@bot.message_handler(commands=['start'])
def start_cmd(message):
    get_user_profile(message.chat.id)
    bot.send_message(
        message.chat.id, 
        "👋 **Добро пожаловать в Смайл-Кейсы!**\n\nЗдесь ты можешь открывать коробки, собирать редкие алмазные смайлики и рисковать в Апгрейдере!", 
        reply_markup=main_menu_keyboard(),
        parse_mode="Markdown"
    )

@bot.callback_query_handler(func=lambda call: True)
def callback_handler(call):
    user_id = call.message.chat.id
    profile = get_user_profile(user_id)
    
    if call.data == "to_main":
        bot.edit_message_text("📱 **Главное меню:**", user_id, call.message.message_id, reply_markup=main_menu_keyboard(), parse_mode="Markdown")

    elif call.data == "menu_inventory":
        inv = profile["inventory"]
        if not inv:
            text = "🎒 **Твой инвентарь пуст!**\n\nОткрой кейсы, чтобы выбить первые смайлики."
        else:
            text = "🎒 **Твой инвентарь:**\n\n"
            counted = {}
            for item in inv:
                counted[item] = counted.get(item, 0) + 1
            for item, count in counted.items():
                name, price = ITEMS[item]
                text += f"{item} *{name}* — {price} 💰 (x{count})\n"
        
        markup = types.InlineKeyboardMarkup()
        markup.add(types.InlineKeyboardButton("⬅️ В меню", callback_data="to_main"))
        bot.edit_message_text(text, user_id, call.message.message_id, reply_markup=markup, parse_mode="Markdown")

    elif call.data == "menu_cases":
        markup = types.InlineKeyboardMarkup()
        markup.add(types.InlineKeyboardButton("🎰 Открыть БЕСПЛАТНЫЙ Кейс", callback_data="open_case"))
        markup.add(types.InlineKeyboardButton("⬅️ В меню", callback_data="to_main"))
        bot.edit_message_text("📦 **Доступные кейсы:**\n\nУ тебя есть один бесконечный тренировочный кейс со смайликами!", user_id, call.message.message_id, reply_markup=markup, parse_mode="Markdown")

    elif call.data == "open_case":
        rand = random.randint(1, 100)
        current_sum = 0
        winning_pool = DROP_CHANCES
        for pool, chance in DROP_CHANCES:
            current_sum += chance
            if rand <= current_sum:
                winning_pool = pool
                break
        dropped_item = random.choice(winning_pool)
        name, price = ITEMS[dropped_item]
        profile["inventory"].append(dropped_item)
        text = f"🎰 **Рулетка крутится...**\n\n🎉 Тебе выпадает предмет:\n👉 {dropped_item} **{name}** (Стоимость: {price} 💰)!"
        markup = types.InlineKeyboardMarkup()
        markup.add(types.InlineKeyboardButton("🎰 Открыть еще раз", callback_data="open_case"))
        markup.add(types.InlineKeyboardButton("⬅️ В меню", callback_data="to_main"))
        bot.edit_message_text(text, user_id, call.message.message_id, reply_markup=markup, parse_mode="Markdown")

    elif call.data == "menu_upgrade":
        inv = profile["inventory"]
        if not inv:
            markup = types.InlineKeyboardMarkup()
            markup.add(types.InlineKeyboardButton("⬅️ В меню", callback_data="to_main"))
            bot.edit_message_text("⚠️ Тебе нечего апгрейдить! Сначала выбей смайлики в кейсах.", user_id, call.message.message_id, reply_markup=markup)
            return
        text = "⚡ **АПГРЕЙДЕР**\n\nВыбери скин из инвентаря, который хочешь закинуть в апгрейд:"
        markup = types.InlineKeyboardMarkup(row_width=1)
        for idx, item in enumerate(inv):
            name, price = ITEMS[item]
            markup.add(types.InlineKeyboardButton(f"{item} {name} ({price} 💰)", callback_data=f"select_upg_{idx}"))
        markup.add(types.InlineKeyboardButton("⬅️ Назад", callback_data="to_main"))
        bot.edit_message_text(text, user_id, call.message.message_id, reply_markup=markup, parse_mode="Markdown")

    elif call.data.startswith("select_upg_"):
        item_idx = int(call.data.split("_"))
        profile["selected_upgrade_item"] = item_idx
        item = profile["inventory"][item_idx]
        name, price = ITEMS[item]
        text = f"⚙️ **Выбран предмет:** {item} {name} ({price} 💰)\n\nВыбери множитель для апгрейда. Чем выше ИКС, тем круче смайлик ты можешь получить, но шанс на победу будет ниже!"
        markup = types.InlineKeyboardMarkup(row_width=2)
        markup.add(
            types.InlineKeyboardButton("❌1.5 (Шанс ~66%)", callback_data="run_upg_1.5"),
            types.InlineKeyboardButton("❌2.0 (Шанс ~50%)", callback_data="run_upg_2.0")
        )
        markup.add(
            types.InlineKeyboardButton("❌3.0 (Шанс ~33%)", callback_data="run_upg_3.0"),
            types.InlineKeyboardButton("❌5.0 (Шанс ~20%)", callback_data="run_upg_5.0")
        )
        markup.add(types.InlineKeyboardButton("⬅️ Сменить предмет", callback_data="menu_upgrade"))
        bot.edit_message_text(text, user_id, call.message.message_id, reply_markup=markup, parse_mode="Markdown")

    elif call.data.startswith("run_upg_"):
        multiplier = float(call.data.split("_"))
        item_idx = profile["selected_upgrade_item"]
        if item_idx is None or item_idx >= len(profile["inventory"]):
            bot.answer_callback_query(call.id, "Ошибка! Предмет не найден.")
            return
        old_item = profile["inventory"][item_idx]
        old_name, old_price = ITEMS[old_item]
        profile["inventory"].pop(item_idx)
        profile["selected_upgrade_item"] = None
        target_price = old_price * multiplier
        available_targets = [k for k, v in ITEMS.items() if v >= target_price]
        if not available_targets:
            new_item = "🐲"
        else:
            available_targets.sort(key=lambda k: ITEMS[k])
            new_item = available_targets
        new_name, new_price = ITEMS[new_item]
        win_chance = round((old_price / new_price) * 100 * 0.95, 2)
        if win_chance > 95: win_chance = 95
        roll = random.uniform(0, 100)
        markup = types.InlineKeyboardMarkup()
        markup.add(types.InlineKeyboardButton("⚡ Сыграть еще раз", callback_data="menu_upgrade"))
        markup.add(types.InlineKeyboardButton("⬅️ Меню", callback_data="to_main"))
        if roll <= win_chance:
            profile["inventory"].append(new_item)
            text = f"🌀 **АПГРЕЙД...**\n\n🎯 Шанс был: `{win_chance}%`\n🎲 Выпало число: `{round(roll, 2)}` \n\n🎉 **УСПЕХ!**\nТвой {old_item} превратился в {new_item} **{new_name}** ({new_price} 💰)!"
        else:
            text = f"🌀 **АПГРЕЙД...**\n\n🎯 Шанс был: `{win_chance}%`\n🎲 Выпало число: `{round(roll, 2)}` \n\n💥 **НЕУДАЧА!**\nПредмет сгорел... Повезет в следующий раз!"
        bot.edit_message_text(text, user_id, call.message.message_id, reply_markup=markup, parse_mode="Markdown")

print("Бот успешно собран и запущен в IDLE!")
bot.infinity_polling()