mirror of
https://github.com/MrSedan/neuro-reply-bot-reworked.git
synced 2026-01-14 21:49:42 +03:00
Neuroapi fixes
This commit is contained in:
@@ -1,14 +1,20 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession
|
||||||
|
|
||||||
from .api_method import ApiMethod
|
from .api_method import ApiMethod
|
||||||
|
|
||||||
|
|
||||||
class Image(ApiMethod):
|
class Image(ApiMethod):
|
||||||
async def add(self, post_id: str, file_id: str, has_spoiler: bool, message_id: int):
|
async def add(self, post_id: str, file_id: str, has_spoiler: bool | None, message_id: int):
|
||||||
payload = {'post_id': post_id, 'file_id': file_id,
|
payload = {'post_id': post_id, 'file_id': file_id,
|
||||||
'has_spoiler': has_spoiler, 'message_id': message_id}
|
'has_spoiler': has_spoiler, 'message_id': message_id}
|
||||||
|
if has_spoiler is None:
|
||||||
|
payload.pop('has_spoiler')
|
||||||
|
payload = json.dumps(payload)
|
||||||
async with ClientSession() as session:
|
async with ClientSession() as session:
|
||||||
response = await session.post(
|
response = await session.post(
|
||||||
self.api_url+'/image/add', data=payload)
|
self.api_url+'/image/add', data=payload, headers={'Content-Type': 'application/json'})
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
if 'statusCode' in data:
|
if 'statusCode' in data:
|
||||||
raise Exception(data['message'])
|
raise Exception(data['message'])
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
from aiohttp import ClientSession, ClientResponse
|
import requests
|
||||||
from .enums import EGetAll
|
from aiohttp import ClientSession
|
||||||
|
|
||||||
from .api_method import ApiMethod
|
from .api_method import ApiMethod
|
||||||
|
from .enums import EGetAll
|
||||||
|
|
||||||
|
|
||||||
class Post(ApiMethod):
|
class Post(ApiMethod):
|
||||||
|
|
||||||
async def new(self, text: str, from_user_id: str, media_group_id: str):
|
async def new(self, text: str, from_user_id: str, media_group_id: str = "None"):
|
||||||
payload = {'text': text, 'from_user_id': from_user_id}
|
payload = {'text': text, 'from_user_id': from_user_id}
|
||||||
if media_group_id != 'None':
|
if media_group_id != 'None':
|
||||||
payload['media_group_id'] = media_group_id
|
payload['media_group_id'] = media_group_id
|
||||||
async with ClientSession() as session:
|
response = requests.post(self.api_url+'/post/new', data=payload)
|
||||||
response: ClientResponse = await session.post(self.api_url+'/post/new', data=payload)
|
data = response.json()
|
||||||
data = await response.json()
|
|
||||||
if 'statusCode' in data:
|
if 'statusCode' in data:
|
||||||
raise Exception(data['message'])
|
raise Exception(data['message'])
|
||||||
return data['status']
|
return data
|
||||||
|
|
||||||
async def __get_all(self, status: EGetAll):
|
async def __get_all(self, status: EGetAll):
|
||||||
async with ClientSession() as session:
|
async with ClientSession() as session:
|
||||||
@@ -42,9 +43,8 @@ class Post(ApiMethod):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
async def get_by_media_group_id(self, media_group_id: str):
|
async def get_by_media_group_id(self, media_group_id: str):
|
||||||
async with ClientSession() as session:
|
response = requests.get(self.api_url+f'/post/get-by-media-group-id/{media_group_id}')
|
||||||
response = await session.get(self.api_url+f'/post/get-by-media-group-id/{media_group_id}')
|
data = response.json()
|
||||||
data = await response.json()
|
|
||||||
if 'statusCode' in data:
|
if 'statusCode' in data:
|
||||||
raise Exception(data['message'])
|
raise Exception(data['message'])
|
||||||
return await response.json()
|
return data
|
||||||
|
|||||||
Reference in New Issue
Block a user