Added getting bot settings from server

This commit is contained in:
2023-12-25 14:38:03 +03:00
parent 142d18bac3
commit 1893ab4ef9
5 changed files with 67 additions and 1 deletions

View File

@@ -0,0 +1,13 @@
from aiohttp import ClientSession
from neuroapi.types import BotSettings as BotSettingsType
from .api_method import ApiMethod
class BotSettings(ApiMethod):
async def get(self)-> BotSettingsType:
async with ClientSession() as session:
response = await session.get(self.api_url+'/settings')
settings = BotSettingsType.from_dict(await response.json())
return settings

View File

@@ -1,4 +1,5 @@
from ._methods.admin import Admin
from ._methods.bot_settings import BotSettings
from ._methods.image import Image
from ._methods.post import Post
from ._methods.user import User
@@ -9,3 +10,4 @@ class neuroapi:
admin = Admin()
user = User()
image = Image()
bot_settings = BotSettings()

View File

@@ -1,5 +1,6 @@
from ._admin import Admin
from ._bot import NeuroApiBot
from ._bot_settings import BotSettings
from ._image import Image
from ._post import Post
from ._singleton import Singleton

View File

@@ -0,0 +1,29 @@
from dataclasses import dataclass
from uuid import UUID
from ._helpers import *
@dataclass
class BotSettings:
uuid: UUID
message_times: List[str]
channel: str
is_active: bool
@staticmethod
def from_dict(obj: Any) -> 'BotSettings':
assert isinstance(obj, dict)
uuid = UUID(obj.get("uuid"))
message_times = from_list(from_str, obj.get("messageTimes"))
channel = from_str(obj.get("channel"))
is_active = from_bool(obj.get("isActive"))
return BotSettings(uuid, message_times, channel, is_active)
def to_dict(self) -> dict:
result: dict = {}
result["uuid"] = str(self.uuid)
result["messageTimes"] = from_list(from_str, self.message_times)
result["channel"] = from_str(self.channel)
result["isActive"] = from_bool(self.is_active)
return result