-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
51 lines (44 loc) · 1.56 KB
/
utils.py
File metadata and controls
51 lines (44 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import math
def xp_for_level(level: int) -> int:
"""XP needed to reach a given level (ProBot-style formula)."""
if level <= 0:
return 0
return 5 * (level ** 2) + 50 * level + 100
def total_xp_for_level(level: int) -> int:
"""Cumulative XP from level 0 to reach this level."""
return sum(xp_for_level(i) for i in range(level))
def level_from_xp(xp: int) -> int:
"""Calculate current level from total XP."""
level = 0
while xp >= total_xp_for_level(level + 1):
level += 1
if level > 500:
break
return level
def xp_progress(xp: int) -> tuple[int, int, int]:
"""Returns (current_level, xp_in_level, xp_needed_for_next)."""
level = level_from_xp(xp)
xp_at_level = total_xp_for_level(level)
xp_in_level = xp - xp_at_level
xp_needed = xp_for_level(level)
return level, xp_in_level, xp_needed
def progress_bar(current: int, total: int, length: int = 10) -> str:
"""Generate a text progress bar."""
filled = int(length * current / total) if total > 0 else 0
bar = "█" * filled + "░" * (length - filled)
pct = int(100 * current / total) if total > 0 else 0
return f"[{bar}] {pct}%"
def format_xp(xp: int) -> str:
"""Format large XP numbers nicely."""
if xp >= 1_000_000:
return f"{xp/1_000_000:.1f}M"
if xp >= 1_000:
return f"{xp/1_000:.1f}K"
return str(xp)
def format_time(minutes: int) -> str:
"""Format voice time in minutes."""
h = minutes // 60
m = minutes % 60
if h > 0:
return f"{h}s {m}d"
return f"{m} dəqiqə"