mirror of
https://github.com/MrSedan/neuro-reply-bot-reworked.git
synced 2026-01-14 21:49:42 +03:00
Added: settings file with time to post
This commit is contained in:
2
main.py
2
main.py
@@ -18,7 +18,7 @@ dp = Dispatcher()
|
|||||||
|
|
||||||
@dp.message(CommandStart())
|
@dp.message(CommandStart())
|
||||||
async def start_message(message: types.Message):
|
async def start_message(message: types.Message):
|
||||||
await message.answer('Абоба')
|
await message.answer('Добро пожаловать в бота ')
|
||||||
|
|
||||||
handlers_dir = join(dirname(__file__), 'handlers')
|
handlers_dir = join(dirname(__file__), 'handlers')
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import os
|
import os
|
||||||
from typing import Self
|
import tomllib
|
||||||
|
from typing import List, Self, TypeVar
|
||||||
|
|
||||||
|
from attr import dataclass
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
from .types._helpers import *
|
||||||
|
|
||||||
|
|
||||||
class _Singleton:
|
class _Singleton:
|
||||||
_instances = {}
|
_instances = {}
|
||||||
@@ -11,9 +15,29 @@ class _Singleton:
|
|||||||
if cls not in cls._instances:
|
if cls not in cls._instances:
|
||||||
cls._instances[cls] = super(_Singleton, cls).__new__(cls)
|
cls._instances[cls] = super(_Singleton, cls).__new__(cls)
|
||||||
return cls._instances[cls]
|
return cls._instances[cls]
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Settings:
|
||||||
|
time: List[str]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_dict(obj: Any) -> 'Settings':
|
||||||
|
assert isinstance(obj, dict)
|
||||||
|
time = from_list(from_str, obj.get("time", []))
|
||||||
|
return Settings(time)
|
||||||
|
|
||||||
|
def to_dict(self) -> dict:
|
||||||
|
result: dict = {}
|
||||||
|
result['time'] = from_list(from_str, self.time)
|
||||||
|
return result
|
||||||
|
|
||||||
class Config(_Singleton):
|
class Config(_Singleton):
|
||||||
api_url: str
|
api_url: str
|
||||||
|
settings: Settings
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
load_dotenv(os.path.join(os.path.dirname(__file__), '..', '.env'))
|
load_dotenv(os.path.join(os.path.dirname(__file__), '..', '.env'))
|
||||||
|
if not os.path.exists(os.path.join(os.path.dirname(__file__), '..', 'settings.toml')): raise Exception('Settings.toml must be in root folder')
|
||||||
|
with open(os.path.join(os.path.dirname(__file__), '..', 'settings.toml'), 'rb') as f:
|
||||||
|
settings = tomllib.load(f)
|
||||||
|
self.settings = Settings.from_dict(settings)
|
||||||
self.api_url = os.environ.get('API_URL')
|
self.api_url = os.environ.get('API_URL')
|
||||||
1
settings.toml
Normal file
1
settings.toml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
time = ["12:00", "14:00", "16:00", "18:00"]
|
||||||
Reference in New Issue
Block a user