|
|
@@ -1,5 +1,5 @@
|
|
|
from pathlib import Path
|
|
|
-from typing import FrozenSet, Literal, Optional, Tuple, TypeAlias, Union
|
|
|
+from typing import List, Literal, Optional, Set, TypeAlias, Union
|
|
|
|
|
|
from pydantic import BaseModel, Field, HttpUrl, SecretStr
|
|
|
|
|
|
@@ -8,63 +8,51 @@ ModerationBackend: TypeAlias = Literal["omni", "gpt"]
|
|
|
LoggingLevel: TypeAlias = Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
|
|
|
|
|
|
|
|
|
-class Bot(BaseModel):
|
|
|
- token: Optional[SecretStr] = None
|
|
|
- timeout: int = 10
|
|
|
- model_config = {"frozen": True}
|
|
|
+class App(BaseModel):
|
|
|
+ language: str = "ru"
|
|
|
+ fallback_language: str = "ru"
|
|
|
|
|
|
|
|
|
-class BehaviorThrottling(BaseModel):
|
|
|
+class BotBehaviorThrottling(BaseModel):
|
|
|
enabled: bool = True
|
|
|
delay: float = 120
|
|
|
- model_config = {"frozen": True}
|
|
|
|
|
|
|
|
|
-class BehaviorSubscriptionRequirement(BaseModel):
|
|
|
+class BotBehaviorSubscriptionRequirement(BaseModel):
|
|
|
enabled: bool = True
|
|
|
- channel_ids: Tuple[int, ...] = Field(default_factory=tuple)
|
|
|
- model_config = {"frozen": True}
|
|
|
+ channel_ids: List[int] = Field(default_factory=list)
|
|
|
|
|
|
|
|
|
-class Behavior(BaseModel):
|
|
|
- throttling: BehaviorThrottling = BehaviorThrottling()
|
|
|
- subscription_requirement: BehaviorSubscriptionRequirement = BehaviorSubscriptionRequirement() # fmt: skip
|
|
|
- model_config = {"frozen": True}
|
|
|
+class BotBehavior(BaseModel):
|
|
|
+ throttling: BotBehaviorThrottling = Field(default_factory=BotBehaviorThrottling)
|
|
|
+ subscription_requirement: BotBehaviorSubscriptionRequirement = Field(default_factory=BotBehaviorSubscriptionRequirement) # fmt: skip
|
|
|
|
|
|
|
|
|
-class DatabaseRepositoriesUser(BaseModel):
|
|
|
- cache_size: int = 1024
|
|
|
- cache_ttl: int = 60
|
|
|
- model_config = {"frozen": True}
|
|
|
+class BotForwarding(BaseModel):
|
|
|
+ moderation_chat_id: Optional[int] = None
|
|
|
+ publication_channel_ids: List[int] = Field(default_factory=list)
|
|
|
+ types: Set[ForwardingType] = Field(default_factory=lambda: {"text", "photo", "video"})
|
|
|
|
|
|
|
|
|
-class DatabaseRepositories(BaseModel):
|
|
|
- user: DatabaseRepositoriesUser = DatabaseRepositoriesUser()
|
|
|
- model_config = {"frozen": True}
|
|
|
+class Bot(BaseModel):
|
|
|
+ token: Optional[SecretStr] = None
|
|
|
+ timeout: int = 10
|
|
|
+ behavior: BotBehavior = Field(default_factory=BotBehavior)
|
|
|
+ forwarding: BotForwarding = Field(default_factory=BotForwarding)
|
|
|
|
|
|
|
|
|
class DatabaseMigrations(BaseModel):
|
|
|
backend: str = "sqlite"
|
|
|
- model_config = {"frozen": True}
|
|
|
|
|
|
|
|
|
class Database(BaseModel):
|
|
|
backend: str = "sqlite+aiosqlite"
|
|
|
- name_or_path: Optional[Union[str, Path]] = None
|
|
|
+ name_or_path: Optional[Union[str, Path]] = "anonflow.db"
|
|
|
host: Optional[str] = None
|
|
|
port: Optional[int] = None
|
|
|
username: Optional[str] = None
|
|
|
password: Optional[SecretStr] = None
|
|
|
- repositories: DatabaseRepositories = DatabaseRepositories()
|
|
|
- migrations: DatabaseMigrations = DatabaseMigrations()
|
|
|
- model_config = {"frozen": True}
|
|
|
-
|
|
|
-
|
|
|
-class Forwarding(BaseModel):
|
|
|
- moderation_chat_ids: Tuple[int, ...] = Field(default_factory=tuple)
|
|
|
- publication_channel_ids: Tuple[int, ...] = Field(default_factory=tuple)
|
|
|
- types: FrozenSet[ForwardingType] = frozenset(["text", "photo", "video"])
|
|
|
- model_config = {"frozen": True}
|
|
|
+ migrations: DatabaseMigrations = Field(default_factory=DatabaseMigrations)
|
|
|
|
|
|
|
|
|
class OpenAI(BaseModel):
|
|
|
@@ -73,18 +61,15 @@ class OpenAI(BaseModel):
|
|
|
proxy: Optional[HttpUrl] = None
|
|
|
timeout: int = 10
|
|
|
max_retries: int = 0
|
|
|
- model_config = {"frozen": True}
|
|
|
|
|
|
|
|
|
class Moderation(BaseModel):
|
|
|
enabled: bool = True
|
|
|
model: str = "gpt-5-mini"
|
|
|
- backends: FrozenSet[ModerationBackend] = frozenset(["omni", "gpt"])
|
|
|
- model_config = {"frozen": True}
|
|
|
+ backends: Set[ModerationBackend] = Field(default_factory=lambda: {"omni", "gpt"})
|
|
|
|
|
|
|
|
|
class Logging(BaseModel):
|
|
|
level: LoggingLevel = "INFO"
|
|
|
fmt: Optional[str] = "%(asctime)s.%(msecs)03d %(levelname)s [%(name)s] %(message)s"
|
|
|
date_fmt: Optional[str] = "%Y-%m-%d %H:%M:%S"
|
|
|
- model_config = {"frozen": True}
|