This commit is contained in:
2026-02-27 20:54:16 +07:00
parent 399bffde1d
commit 3071e5a1a1
27 changed files with 158 additions and 701 deletions

10
app/config.py Normal file
View File

@@ -0,0 +1,10 @@
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
BOT_TOKEN: str
DATABASE_URL: str
class Config:
env_file = ".env"
settings = Settings()

5
app/database.py Normal file
View File

@@ -0,0 +1,5 @@
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker
from app.config import settings
engine = create_async_engine(settings.DATABASE_URL, echo=False)
async_session = async_sessionmaker(engine, expire_on_commit=False)

15
app/handlers/start.py Normal file
View File

@@ -0,0 +1,15 @@
from aiogram import Router
from aiogram.types import Message
from aiogram.filters import Command
from app.services.player_service import get_or_create_player
router = Router()
@router.message(Command("start"))
async def start_handler(message: Message):
player = await get_or_create_player(message.from_user.id)
await message.answer(
f"🚀 Добро пожаловать в Digital Provider!\n"
f"💰 Баланс: {player.money}"
)

0
app/main.py Normal file
View File

4
app/models/base.py Normal file
View File

@@ -0,0 +1,4 @@
from sqlalchemy.orm import DeclarativeBase
class Base(DeclarativeBase):
pass

11
app/models/district.py Normal file
View File

@@ -0,0 +1,11 @@
from sqlalchemy import String, Integer, ForeignKey
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base
class District(Base):
__tablename__ = "districts"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String(50))
max_clients: Mapped[int] = mapped_column(Integer)
owner_id: Mapped[int | None] = mapped_column(ForeignKey("players.id"), nullable=True)

11
app/models/player.py Normal file
View File

@@ -0,0 +1,11 @@
from sqlalchemy import BigInteger, Integer, Float
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base
class Player(Base):
__tablename__ = "players"
id: Mapped[int] = mapped_column(primary_key=True)
telegram_id: Mapped[int] = mapped_column(BigInteger, unique=True)
money: Mapped[int] = mapped_column(Integer, default=10000)
reputation: Mapped[float] = mapped_column(Float, default=1.0)

View File

@@ -0,0 +1,17 @@
from sqlalchemy import select
from app.database import async_session
from app.models.player import Player
async def get_or_create_player(telegram_id: int):
async with async_session() as session:
result = await session.execute(
select(Player).where(Player.telegram_id == telegram_id)
)
player = result.scalar_one_or_none()
if not player:
player = Player(telegram_id=telegram_id)
session.add(player)
await session.commit()
return player