tuxbot-bot/tuxbot/cogs/Crypto/functions/extractor.py

29 lines
805 B
Python
Raw Normal View History

from typing import Optional, NoReturn, Union
from discord import Attachment
from tuxbot.cogs.Crypto.functions.parser import data_parser
async def extract(
2021-04-20 17:12:38 +02:00
attachments: list[Optional[Attachment]], data: Optional[str], max_size: int
) -> dict:
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]
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}