Files
isp-tycoon/handlers/channel.py
2026-02-23 14:22:24 +07:00

70 lines
2.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from aiogram import types, Router
from database import get_player, update_player
from economy import calculate_channel_cost
router = Router() # ← ВАЖНО!
@router.callback_query(lambda c: c.data == "upgrade_channel")
async def upgrade_channel(callback: types.CallbackQuery):
user_id = callback.from_user.id
player = get_player(user_id)
current_level = player["network_channel_level"]
if current_level >= 6:
await callback.answer("⚠️ Максимальный уровень канала достигнут! 🌍", show_alert=True)
return
cost = calculate_channel_cost(current_level)
if player["balance"] < cost:
await callback.answer(f"Не хватает {cost - player['balance']}", show_alert=True)
return
next_level = current_level + 1
next_capacity = int(player["channel_capacity"] * 2.5)
upgrade_hours = 4 * current_level
update_player(user_id, {
"balance": player["balance"] - cost,
"next_build_end_ts": int(__import__("time").time()) + upgrade_hours * 3600,
"infrastructure_level": player["infrastructure_level"] + 0.4
})
keyboard = types.InlineKeyboardMarkup(inline_keyboard=[
[types.InlineKeyboardButton(
text="🚀 Ускорить (x2 за 500 ₡)",
callback_data=f"speedup_channel_{current_level}"
)]
])
await callback.message.edit_text(
f"🚀 Прокачка канала до уровня {next_level} (до {next_capacity} Мбит/с)...\n"
f"⏳ Ожидание: {upgrade_hours} ч\n"
f"💰 Остаток: {player['balance'] - cost}",
reply_markup=keyboard
)
await callback.answer("Процесс запущен 🛠️")
@router.callback_query(lambda c: c.data.startswith("speedup_channel_"))
async def speedup_channel(callback: types.CallbackQuery):
user_id = callback.from_user.id
player = get_player(user_id)
if player["balance"] < 500:
await callback.answer("❌ Нет средств на ускорение", show_alert=True)
return
new_end = max(
0,
int(__import__("time").time()) +
(player["next_build_end_ts"] - int(__import__("time").time())) // 2
)
update_player(user_id, {
"balance": player["balance"] - 500,
"next_build_end_ts": new_end
})
await callback.message.edit_text(
f"⚡ Ускорено! Канал будет готов через ~{(new_end - __import__('time').time()) / 3600:.1f} ч"
)
await callback.answer("🚀 Апгрейд ускорен!")