mirror of
https://github.com/MrSedan/neuro-reply-bot-reworked.git
synced 2026-01-14 13:39:42 +03:00
Added getting bot settings from server
This commit is contained in:
13
neuroapi/_methods/bot_settings.py
Normal file
13
neuroapi/_methods/bot_settings.py
Normal 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
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
29
neuroapi/types/_bot_settings.py
Normal file
29
neuroapi/types/_bot_settings.py
Normal 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
|
||||
Reference in New Issue
Block a user