57 lines
2.4 KiB
Python
57 lines
2.4 KiB
Python
from aiogram import types, Router
|
||
from aiogram.filters import CommandStart
|
||
from database import create_player_if_not_exists, get_player, update_player # ← добавь update_player
|
||
from economy import (
|
||
calculate_effective_bandwidth, calculate_rating, calculate_client_retention,
|
||
calculate_daily_income, calculate_daily_offline_earnings
|
||
)
|
||
|
||
router = Router()
|
||
|
||
@router.message(CommandStart())
|
||
async def cmd_start(message: types.Message):
|
||
user_id = message.from_user.id
|
||
create_player_if_not_exists(user_id)
|
||
player = get_player(user_id)
|
||
|
||
# Оффлайн доход
|
||
offline_earn = calculate_daily_offline_earnings(player)
|
||
if offline_earn > 0:
|
||
player["balance"] += offline_earn
|
||
player["total_income"] += offline_earn
|
||
player["last_login_ts"] = int(__import__("time").time())
|
||
update_player(user_id, {
|
||
"balance": player["balance"],
|
||
"total_income": player["total_income"],
|
||
"last_login_ts": player["last_login_ts"]
|
||
})
|
||
|
||
effective_bw = calculate_effective_bandwidth(player)
|
||
lost, churn_msg = calculate_client_retention(player)
|
||
daily_income = calculate_daily_income(player)
|
||
|
||
status = ""
|
||
if player["outage_end_ts"] > 0:
|
||
remaining = player["outage_end_ts"] - int(__import__("time").time())
|
||
status = f"\n⚠️ АВАРИЯ: Отключение до {remaining // 3600}ч {remaining % 3600 // 60}м"
|
||
if player["backup_channel_active"]:
|
||
status += " (резерв активен)"
|
||
|
||
text = (
|
||
f"🌐 *ISP Tycoon* | 📡 Канал: {player['network_channel_level']} ✨\n\n"
|
||
f"⚡ *Канал:* {player['channel_capacity']} → {effective_bw} Мбит/с\n"
|
||
f"🔋 *Сеть:* {player['power_usage']:.1f}/{player['power_capacity']} кВт\n"
|
||
f"🖥 *Серверы:* {player['servers']} (ёмкость: {player['max_customers']} клиентов)\n"
|
||
f"📡 *Клиенты:* {player['coverage_customers']} (отток: {lost}/сутки)\n"
|
||
f"💰 *Бюджет:* {player['balance']:,.0f} ₡\n"
|
||
f"📊 *Доход/день:* {daily_income:,.0f} ₡\n"
|
||
f"🌟 *Рейтинг:* {calculate_rating(player)}\n"
|
||
f"{churn_msg}\n{status}"
|
||
)
|
||
|
||
from keyboards import get_main_menu
|
||
await message.answer(
|
||
text,
|
||
reply_markup=get_main_menu(player),
|
||
parse_mode="Markdown"
|
||
) |