Spaces:
Running on Zero
Running on Zero
File size: 3,625 Bytes
48e7c8c b37ebd1 48e7c8c b37ebd1 48e7c8c b37ebd1 48e7c8c b37ebd1 48e7c8c a14f7f7 48e7c8c b37ebd1 48e7c8c a1983b7 48e7c8c a1983b7 a0261c0 48e7c8c a0261c0 a1983b7 48e7c8c a1983b7 4e64e70 48e7c8c 4e64e70 48e7c8c 4e64e70 48e7c8c a14f7f7 48e7c8c d896946 48e7c8c d896946 48e7c8c d896946 b37ebd1 48e7c8c b37ebd1 48e7c8c b37ebd1 | 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
from functools import lru_cache
from pydantic_settings import BaseSettings, SettingsConfigDict
from app.core.handles import parse_handles
class Settings(BaseSettings):
model_config = SettingsConfigDict(
env_file=".env",
extra="ignore",
)
# --------------------------------------------------------------
# Core application settings
# --------------------------------------------------------------
bot_token: str
database_url: str = "sqlite+aiosqlite:///./dev.db"
gate_channel: str = "@DBUCentral"
gate_channels: str = ""
hide_empty_courses: bool = True
admin_ids: str = ""
default_lang: str = "en"
library_channel_id: int = 0
log_level: str = "INFO"
# --------------------------------------------------------------
# PDF watermark settings
# --------------------------------------------------------------
watermark_enabled: bool = True
watermark_text: str = "DBU Freshman Central"
watermark_url: str = ""
watermark_diagonal: bool = True
@property
def watermark_link(self) -> str:
return (
self.watermark_url
or f"https://t.me/{self.gate_channel.lstrip('@')}"
)
# --------------------------------------------------------------
# Channel and group access
# --------------------------------------------------------------
@property
def gate_list(self) -> list[str]:
"""
Every listed channel/group must be joined.
Default:
Main channel + discussion forum.
"""
return (
parse_handles(self.gate_channels)
or parse_handles(
f"{self.gate_channel},@DBUcentralforum"
)
)
# --------------------------------------------------------------
# Student file contributions
# --------------------------------------------------------------
contributions_enabled: bool = True
contribution_xp: int = 20
contribution_bonus_xp: int = 5
contribution_weekly_cap: int = 5
contribution_min_days: int = 2
contribution_pending_limit: int = 5
contribution_daily_limit: int = 8
# --------------------------------------------------------------
# 60-day season and prizes
# --------------------------------------------------------------
# Prizes are enabled by default.
# Set PRIZES_ENABLED=false in .env to disable them.
prizes_enabled: bool = True
# Birr airtime prizes for the top three eligible players.
prize_top: str = "50,30,20"
# Weighted raffle prize in birr.
prize_raffle: int = 10
# Minimum XP and active-day requirements for season eligibility.
# Legacy field names are preserved for compatibility.
min_week_xp: int = 40
min_active_days: int = 4
# --------------------------------------------------------------
# Parsed settings
# --------------------------------------------------------------
@property
def prize_list(self) -> list[int]:
"""Return valid prize amounts in ranking order."""
return [
int(value)
for value in self.prize_top.replace(" ", "").split(",")
if value.isdigit()
]
@property
def admin_id_set(self) -> set[int]:
"""Return configured Telegram admin IDs."""
return {
int(value)
for value in self.admin_ids.replace(" ", "").split(",")
if value.isdigit()
}
@lru_cache
def get_settings() -> Settings:
"""Return the cached application settings."""
return Settings()
|