2021-02-24 00:53:05 +01:00
|
|
|
from typing import Optional, NoReturn, Union
|
|
|
|
|
|
|
|
from discord import Attachment
|
|
|
|
from tuxbot.cogs.Crypto.functions.parser import data_parser
|
|
|
|
|
|
|
|
|
|
|
|
async def extract(
|
|
|
|
attachments: list[Optional[Attachment]], data: str, max_size: int
|
|
|
|
) -> Union[dict, NoReturn]:
|
|
|
|
if not data and len(attachments) == 0:
|
|
|
|
raise ValueError
|
|
|
|
|
|
|
|
kwargs = data_parser(data)
|
|
|
|
|
2021-03-31 18:08:41 +02:00
|
|
|
if attachments and attachments[0]:
|
|
|
|
file: Attachment = attachments[0]
|
2021-02-24 00:53:05 +01:00
|
|
|
if file.size > max_size:
|
|
|
|
raise ValueError
|
|
|
|
|
|
|
|
kwargs["message"] = await file.read()
|
|
|
|
|
|
|
|
params = {
|
|
|
|
"compressed": "compressed" in kwargs.keys(),
|
|
|
|
"graphical": "graphical" in kwargs.keys(),
|
|
|
|
"chars": kwargs["chars"] if "chars" in kwargs.keys() else (".", ","),
|
|
|
|
}
|
|
|
|
|
|
|
|
return {"message": kwargs["message"], "params": params}
|