Files
Roblox-Buyer/models/config.py
T

126 lines
3.9 KiB
Python

from dataclasses import dataclass, field
from typing import Any
@dataclass(slots=True)
class RateConfig:
name: str
price: float
min: int
max: int
type: str
@classmethod
def from_dict(cls, data: dict[str, Any]) -> "RateConfig":
return cls(
name=data.get("name", ""),
price=float(data.get("price", 0.0)),
min=int(data.get("min", 0)),
max=int(data.get("max", 0)),
type=data.get("type", "lifetime"),
)
def to_dict(self) -> dict[str, Any]:
return {
"name": self.name,
"price": self.price,
"min": self.min,
"max": self.max,
"type": self.type,
}
@dataclass(slots=True)
class BotConfig:
shop_enabled: bool = True
bot_enabled: bool = True
min_withdraw: float = 100.0
treasury: float = 0.0
referral_percent: int = 5
rates: dict[str, RateConfig] = field(default_factory=dict)
avg_min_cookies: int = 100
avg_min_price: float = 2.0
avg_max_price: float = 20.0
@classmethod
def default(cls) -> "BotConfig":
return cls(
shop_enabled=True,
bot_enabled=True,
min_withdraw=100.0,
treasury=0.0,
referral_percent=5,
rates={
"lifetime_low": RateConfig(
name="Lifetime 200-399 R$",
price=0.33,
min=200,
max=399,
type="lifetime",
),
"lifetime_mid": RateConfig(
name="Lifetime 400-4999 R$",
price=3.10,
min=400,
max=4999,
type="lifetime",
),
"lifetime_high": RateConfig(
name="Lifetime 5000+ R$",
price=8.88,
min=5000,
max=10**12,
type="lifetime",
),
"year_mid": RateConfig(
name="Year 1000-4999 R$",
price=8.40,
min=1000,
max=4999,
type="year",
),
"year_high": RateConfig(
name="Year 5000+ R$",
price=11.11,
min=5000,
max=10**12,
type="year",
),
},
avg_min_cookies=100,
avg_min_price=2.0,
avg_max_price=20.0,
)
@classmethod
def from_dict(cls, data: dict[str, Any] | None) -> "BotConfig":
data = data or {}
rates = data.get("rates") or {}
return cls(
shop_enabled=bool(data.get("shop_enabled", True)),
bot_enabled=bool(data.get("bot_enabled", True)),
min_withdraw=float(data.get("min_withdraw", 100.0)),
treasury=float(data.get("treasury", 0.0)),
referral_percent=int(data.get("referral_percent", 5)),
rates={
key: RateConfig.from_dict(value)
for key, value in rates.items()
},
avg_min_cookies=int(data.get("avg_min_cookies", 100)),
avg_min_price=float(data.get("avg_min_price", 2.0)),
avg_max_price=float(data.get("avg_max_price", 20.0)),
)
def to_dict(self) -> dict[str, Any]:
return {
"shop_enabled": self.shop_enabled,
"bot_enabled": self.bot_enabled,
"min_withdraw": self.min_withdraw,
"treasury": self.treasury,
"referral_percent": self.referral_percent,
"rates": {key: value.to_dict() for key, value in self.rates.items()},
"avg_min_cookies": self.avg_min_cookies,
"avg_min_price": self.avg_min_price,
"avg_max_price": self.avg_max_price,
}