Spaces:
Runtime error
Runtime error
Create app/state.py
Browse files- app/state.py +38 -0
app/state.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
from dataclasses import dataclass, field
|
| 3 |
+
from typing import Dict, Optional, Any
|
| 4 |
+
import asyncio
|
| 5 |
+
import secrets
|
| 6 |
+
import time
|
| 7 |
+
|
| 8 |
+
@dataclass
|
| 9 |
+
class UploadJob:
|
| 10 |
+
upload_id: str
|
| 11 |
+
user_id: int
|
| 12 |
+
chat_id: int
|
| 13 |
+
src_msg_id: int
|
| 14 |
+
file_type: str # "video" | "document"
|
| 15 |
+
tg_file_id: str
|
| 16 |
+
file_name: str
|
| 17 |
+
caption: str
|
| 18 |
+
|
| 19 |
+
privacy: str = "private"
|
| 20 |
+
title_mode: str = "caption" # caption | filename | custom
|
| 21 |
+
custom_title: str = ""
|
| 22 |
+
|
| 23 |
+
status_msg_id: Optional[int] = None
|
| 24 |
+
created_at: float = field(default_factory=time.time)
|
| 25 |
+
|
| 26 |
+
class MemoryState:
|
| 27 |
+
def __init__(self):
|
| 28 |
+
self.uploads: Dict[str, UploadJob] = {}
|
| 29 |
+
self.waiting_client_id: Dict[int, bool] = {}
|
| 30 |
+
self.waiting_client_secret: Dict[int, str] = {} # user_id -> client_id
|
| 31 |
+
self.waiting_custom_title: Dict[int, str] = {} # user_id -> upload_id
|
| 32 |
+
self.auto_mode: Dict[int, bool] = {} # user_id -> bool
|
| 33 |
+
self.sem = asyncio.Semaphore(1) # overwritten by settings at runtime
|
| 34 |
+
|
| 35 |
+
def new_upload_id(self) -> str:
|
| 36 |
+
return secrets.token_urlsafe(8)[:10]
|
| 37 |
+
|
| 38 |
+
STATE = MemoryState()
|