Initial commit
This commit is contained in:
1
modules/config/__init__.py
Normal file
1
modules/config/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .db import config, sessions
|
||||
17
modules/config/db.py
Normal file
17
modules/config/db.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import sqlitedict
|
||||
import json
|
||||
|
||||
|
||||
class ConfigDatabase(sqlitedict.SqliteDict):
|
||||
def __init__(self, tablename):
|
||||
super().__init__(
|
||||
filename='config.storage',
|
||||
tablename=tablename,
|
||||
encode=json.dumps,
|
||||
decode=json.loads,
|
||||
autocommit=True
|
||||
)
|
||||
|
||||
|
||||
config = ConfigDatabase('config')
|
||||
sessions = ConfigDatabase('sessions')
|
||||
15
modules/config/models.py
Normal file
15
modules/config/models.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from dataclasses import dataclass, asdict
|
||||
|
||||
|
||||
@dataclass
|
||||
class SessionConfig:
|
||||
def __str__(self):
|
||||
return f'{self.phone} - {self.id} - {self.profile_name} {f"- @{self.username}" if self.username else ""}'
|
||||
|
||||
def json(self):
|
||||
return asdict(self)
|
||||
|
||||
phone: str
|
||||
profile_name: str
|
||||
id: int
|
||||
username: str | None = None
|
||||
Reference in New Issue
Block a user