v1.1
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
from json import JSONEncoder
|
||||
import io
|
||||
from random import randint
|
||||
|
||||
from aiohttp import ClientSession
|
||||
|
||||
|
||||
class EnumEncoder(JSONEncoder):
|
||||
def default(self, obj):
|
||||
return obj.value
|
||||
|
||||
|
||||
def get_self_id(api):
|
||||
return api.groups.getById()[0]['id']
|
||||
|
||||
|
||||
def generate_random_id():
|
||||
return randint(-9 ** 99, 9 ** 99)
|
||||
|
||||
|
||||
async def get_user_name(user_id, api, name_case='nom'):
|
||||
user = (await api.users.get(user_ids=user_id, name_case=name_case))[0]
|
||||
return f'{user["first_name"]} {user["last_name"]}'
|
||||
|
||||
|
||||
def parse_attachments(attachments) -> tuple:
|
||||
out = []
|
||||
for attach in attachments:
|
||||
t = attach['type']
|
||||
if t == 'wall':
|
||||
out.append(f'{t}{attach[t]["from_id"]}_{attach[t]["id"]}')
|
||||
else:
|
||||
out.append(f'{t}{attach[t]["owner_id"]}_{attach[t]["id"]}')
|
||||
return tuple(out)
|
||||
|
||||
|
||||
async def reupload_attachments(attachments, upload):
|
||||
new_attachments = []
|
||||
for a in attachments:
|
||||
t = a['type']
|
||||
if t != 'photo':
|
||||
continue
|
||||
url = a[t]['sizes'][-1]['url']
|
||||
|
||||
async with ClientSession() as session, session.get(url) as response:
|
||||
file = io.BytesIO(await response.content.read())
|
||||
attachment = upload.photo_messages(file)[0]
|
||||
new_attachments.append(f'photo{attachment["owner_id"]}_{attachment["id"]}')
|
||||
return new_attachments
|
||||
Reference in New Issue
Block a user