started working on telegram bot
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import os
|
||||
from typing import List, Optional
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
case_sensitive=True,
|
||||
extra="allow"
|
||||
)
|
||||
|
||||
APP_NAME: str = "VibeLawyerBot"
|
||||
VERSION: str = "0.1.0"
|
||||
DEBUG: bool = True
|
||||
TELEGRAM_BOT_TOKEN: str = ""
|
||||
FREE_QUESTIONS_LIMIT: int = 5
|
||||
PAYMENT_AMOUNT: float = 500.0
|
||||
DATABASE_URL: str = "sqlite:///data/bot.db"
|
||||
LOG_LEVEL: str = "INFO"
|
||||
LOG_FILE: str = "logs/bot.log"
|
||||
|
||||
YOOKASSA_SHOP_ID: str = "1230200"
|
||||
YOOKASSA_SECRET_KEY: str = "test_GVoixmlp0FqohXcyFzFHbRlAUoA3B1I2aMtAkAE_ubw"
|
||||
YOOKASSA_RETURN_URL: str = "https://t.me/vibelawyer_bot"
|
||||
YOOKASSA_WEBHOOK_SECRET: Optional[str] = None
|
||||
|
||||
ADMIN_IDS_STR: str = ""
|
||||
|
||||
@property
|
||||
def ADMIN_IDS(self) -> List[int]:
|
||||
if not self.ADMIN_IDS_STR:
|
||||
return []
|
||||
try:
|
||||
return [int(x.strip()) for x in self.ADMIN_IDS_STR.split(",")]
|
||||
except:
|
||||
return []
|
||||
|
||||
|
||||
settings = Settings()
|
||||
@@ -0,0 +1,15 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from tg_bot.config.settings import settings
|
||||
|
||||
engine = create_engine(
|
||||
settings.DATABASE_URL,
|
||||
echo=settings.DEBUG
|
||||
)
|
||||
|
||||
SessionLocal = sessionmaker(bind=engine)
|
||||
|
||||
def create_tables():
|
||||
from .models import Base
|
||||
Base.metadata.create_all(bind=engine)
|
||||
print(f"Таблицы созданы: {settings.DATABASE_URL}")
|
||||
@@ -0,0 +1,39 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from sqlalchemy import Column, String, DateTime, Boolean, Integer, Text
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class UserModel(Base):
|
||||
__tablename__ = "users"
|
||||
user_id = Column("user_id", String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||
telegram_id = Column("telegram_id", String(100), nullable=False, unique=True)
|
||||
created_at = Column("created_at", DateTime, default=datetime.utcnow, nullable=False)
|
||||
role = Column("role", String(20), default="user", nullable=False)
|
||||
|
||||
is_premium = Column(Boolean, default=False, nullable=False)
|
||||
premium_until = Column(DateTime, nullable=True)
|
||||
questions_used = Column(Integer, default=0, nullable=False)
|
||||
|
||||
username = Column(String(100), nullable=True)
|
||||
first_name = Column(String(100), nullable=True)
|
||||
last_name = Column(String(100), nullable=True)
|
||||
|
||||
|
||||
class PaymentModel(Base):
|
||||
__tablename__ = "payments"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
payment_id = Column(String(36), default=lambda: str(uuid.uuid4()), nullable=False, unique=True)
|
||||
user_id = Column(Integer, nullable=False)
|
||||
amount = Column(String(20), nullable=False)
|
||||
currency = Column(String(3), default="RUB", nullable=False)
|
||||
status = Column(String(20), default="pending", nullable=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
yookassa_payment_id = Column(String(100), unique=True, nullable=True)
|
||||
description = Column(Text, nullable=True)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Payment(user_id={self.user_id}, amount={self.amount}, status={self.status})>"
|
||||
Reference in New Issue
Block a user