mirror of
https://github.com/MrSedan/neuro-reply-bot-reworked.git
synced 2026-01-14 21:49:42 +03:00
edited: methods for new api types
This commit is contained in:
@@ -2,13 +2,15 @@ from aiohttp import ClientSession
|
||||
|
||||
from .api_method import ApiMethod
|
||||
|
||||
from neuroapi.types import Admin as AdminType
|
||||
|
||||
|
||||
class Admin(ApiMethod):
|
||||
|
||||
async def get(self):
|
||||
async with ClientSession() as session:
|
||||
response = await session.get(self.api_url+'/admin/get')
|
||||
return await response.json()
|
||||
return [AdminType.from_dict(admin) for admin in await response.json()]
|
||||
|
||||
async def is_admin(self, id: str):
|
||||
async with ClientSession() as session:
|
||||
|
||||
@@ -3,6 +3,7 @@ from aiohttp import ClientSession
|
||||
|
||||
from .api_method import ApiMethod
|
||||
from .enums import EGetAll
|
||||
import neuroapi.types as nat
|
||||
|
||||
|
||||
class Post(ApiMethod):
|
||||
@@ -15,7 +16,7 @@ class Post(ApiMethod):
|
||||
data = response.json()
|
||||
if 'statusCode' in data:
|
||||
raise Exception(data['message'])
|
||||
return data
|
||||
return nat.Post.from_dict(data)
|
||||
|
||||
async def __get_all(self, status: EGetAll):
|
||||
async with ClientSession() as session:
|
||||
@@ -24,15 +25,15 @@ class Post(ApiMethod):
|
||||
|
||||
async def get_all(self):
|
||||
result = await self.__get_all(EGetAll.all)
|
||||
return await result.json()
|
||||
return [nat.Post.from_dict(post) for post in await result.json()]
|
||||
|
||||
async def get_will_post(self):
|
||||
result = await self.__get_all(EGetAll.will_post)
|
||||
return await result.json()
|
||||
return [nat.Post.from_dict(post) for post in await result.json()]
|
||||
|
||||
async def get_posted(self):
|
||||
result = await self.__get_all(EGetAll.posted)
|
||||
return await result.json()
|
||||
return [nat.Post.from_dict(post) for post in await result.json()]
|
||||
|
||||
async def get(self, post_id: str):
|
||||
async with ClientSession() as session:
|
||||
@@ -40,18 +41,20 @@ class Post(ApiMethod):
|
||||
data = await response.json()
|
||||
if 'statusCode' in data:
|
||||
raise Exception(data['message'])
|
||||
return data
|
||||
return nat.Post.from_dict(data)
|
||||
|
||||
async def get_by_media_group_id(self, media_group_id: str):
|
||||
response = requests.get(self.api_url+f'/post/get-by-media-group-id/{media_group_id}')
|
||||
response = requests.get(
|
||||
self.api_url+f'/post/get-by-media-group-id/{media_group_id}')
|
||||
data = response.json()
|
||||
if 'statusCode' in data:
|
||||
raise Exception(data['message'])
|
||||
return data
|
||||
return nat.Post.from_dict(data)
|
||||
|
||||
async def edit_text(self, post_id: str, text: str):
|
||||
response = requests.post(self.api_url+f"/post/edit/{post_id}", data={"text": text})
|
||||
response = requests.post(
|
||||
self.api_url+f"/post/edit/{post_id}", data={"text": text})
|
||||
data = response.json()
|
||||
if 'statusCode' in data:
|
||||
raise Exception(data['message'])
|
||||
return data
|
||||
return nat.Post.from_dict(data)
|
||||
|
||||
Reference in New Issue
Block a user