Add modular Roblox buyer bot and documentation
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from config import ADMIN_ID
|
||||
from db.storage import load_stats, save_stats
|
||||
from db.users import get, save
|
||||
|
||||
|
||||
async def apply_referral_payout(bot, user_id: int, username: str | None, payout: float, referral_percent: int) -> float:
|
||||
profile = get(user_id)
|
||||
if not profile or not profile.referrer:
|
||||
return 0.0
|
||||
|
||||
ref_amount = round(payout * referral_percent / 100, 2)
|
||||
ref_profile = get(profile.referrer)
|
||||
if not ref_profile:
|
||||
return 0.0
|
||||
|
||||
ref_profile.balance += ref_amount
|
||||
ref_profile.total_earned += ref_amount
|
||||
ref_profile.referral_earned += ref_amount
|
||||
save(profile.referrer, ref_profile)
|
||||
|
||||
stats = load_stats()
|
||||
stats.total_paid_referral += ref_amount
|
||||
save_stats(stats)
|
||||
|
||||
try:
|
||||
await bot.send_message(
|
||||
profile.referrer,
|
||||
f"💸 Реферал @{username or '—'} заработал {payout:.2f} ₽\n"
|
||||
f"Вам начислено: <b>{ref_amount:.2f} ₽</b>",
|
||||
parse_mode="HTML",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return ref_amount
|
||||
|
||||
Reference in New Issue
Block a user