mirror of
https://github.com/MrSedan/neuro-reply-bot-reworked.git
synced 2026-01-14 13:39:42 +03:00
Neuroapi fixes
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
import json
|
||||
|
||||
from aiohttp import ClientSession
|
||||
|
||||
from .api_method import 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,
|
||||
'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:
|
||||
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()
|
||||
if 'statusCode' in data:
|
||||
raise Exception(data['message'])
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
from aiohttp import ClientSession, ClientResponse
|
||||
from .enums import EGetAll
|
||||
import requests
|
||||
from aiohttp import ClientSession
|
||||
|
||||
from .api_method import ApiMethod
|
||||
from .enums import EGetAll
|
||||
|
||||
|
||||
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}
|
||||
if media_group_id != 'None':
|
||||
payload['media_group_id'] = media_group_id
|
||||
async with ClientSession() as session:
|
||||
response: ClientResponse = await session.post(self.api_url+'/post/new', data=payload)
|
||||
data = await response.json()
|
||||
response = requests.post(self.api_url+'/post/new', data=payload)
|
||||
data = response.json()
|
||||
if 'statusCode' in data:
|
||||
raise Exception(data['message'])
|
||||
return data['status']
|
||||
return data
|
||||
|
||||
async def __get_all(self, status: EGetAll):
|
||||
async with ClientSession() as session:
|
||||
@@ -42,9 +43,8 @@ class Post(ApiMethod):
|
||||
return data
|
||||
|
||||
async def get_by_media_group_id(self, media_group_id: str):
|
||||
async with ClientSession() as session:
|
||||
response = await session.get(self.api_url+f'/post/get-by-media-group-id/{media_group_id}')
|
||||
data = await response.json()
|
||||
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 await response.json()
|
||||
return data
|
||||
|
||||
Reference in New Issue
Block a user