mirror of
https://github.com/MrSedan/neuro-reply-bot-reworked.git
synced 2026-01-14 13:39:42 +03:00
Added singleton config and changed module structure
This commit is contained in:
8
main.py
8
main.py
@@ -7,12 +7,7 @@ from os.path import dirname, join
|
||||
import aioschedule as schedule
|
||||
import dotenv
|
||||
from aiogram import Bot, Dispatcher, F, types
|
||||
from aiogram.filters import Command, CommandStart
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.fsm.state import State, StatesGroup
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
|
||||
from handlers.admin_commands import Admin_commands
|
||||
from aiogram.filters import CommandStart
|
||||
|
||||
dotenv.load_dotenv()
|
||||
|
||||
@@ -35,7 +30,6 @@ for filename in os.listdir(handlers_dir):
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
# dp.include_router(Admin_commands(bot)())
|
||||
await dp.start_polling(bot, skip_updates=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,17 +1 @@
|
||||
from .post import Post
|
||||
from .admin import Admin
|
||||
from .user import User
|
||||
from .image import Image
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
from os.path import join, dirname
|
||||
|
||||
|
||||
load_dotenv(join(dirname(__file__), "..", '.env'))
|
||||
|
||||
|
||||
class neuroapi:
|
||||
post = Post(os.environ.get('API_URL'))
|
||||
admin = Admin(os.environ.get('API_URL'))
|
||||
user = User(os.environ.get('API_URL'))
|
||||
image = Image(os.environ.get('API_URL'))
|
||||
from ._neuroapi import neuroapi
|
||||
|
||||
8
neuroapi/_methods/api_method.py
Normal file
8
neuroapi/_methods/api_method.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from ..config import Config
|
||||
|
||||
|
||||
class ApiMethod:
|
||||
api_url: str
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.api_url = Config().api_url
|
||||
@@ -1,4 +1,5 @@
|
||||
from aiohttp import ClientSession
|
||||
|
||||
from .api_method import ApiMethod
|
||||
|
||||
|
||||
11
neuroapi/_neuroapi.py
Normal file
11
neuroapi/_neuroapi.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from ._methods.admin import Admin
|
||||
from ._methods.image import Image
|
||||
from ._methods.post import Post
|
||||
from ._methods.user import User
|
||||
|
||||
|
||||
class neuroapi:
|
||||
post = Post()
|
||||
admin = Admin()
|
||||
user = User()
|
||||
image = Image()
|
||||
@@ -1,5 +0,0 @@
|
||||
class ApiMethod:
|
||||
api_url: str
|
||||
|
||||
def __init__(self, api_url: str) -> None:
|
||||
self.api_url = api_url
|
||||
19
neuroapi/config.py
Normal file
19
neuroapi/config.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import os
|
||||
from typing import Self
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
|
||||
class _Singleton:
|
||||
_instances = {}
|
||||
|
||||
def __new__(cls) -> Self:
|
||||
if cls not in cls._instances:
|
||||
cls._instances[cls] = super(_Singleton, cls).__new__(cls)
|
||||
return cls._instances[cls]
|
||||
|
||||
class Config(_Singleton):
|
||||
api_url: str
|
||||
def __init__(self):
|
||||
load_dotenv(os.path.join(os.path.dirname(__file__), '..', '.env'))
|
||||
self.api_url = os.environ.get('API_URL')
|
||||
Reference in New Issue
Block a user