Yves/utils.py

44 lines
1.3 KiB
Python

# import io
# import requests
# import mimetypes
import nerimity
# def construct_attachment_from_url(url: str = None) -> nerimity.Attachment | None:
# if not url: return None
# content = requests.get(url).content
# attachment = nerimity.Attachment()
# attachment.internal_type = nerimity.AttachmentTypes.OUTGOING
# attachment.data = content
# attachment.data_type, _ = mimetypes.guess_type(url=url)
# attachment.size = len(attachment.data)
# attachment.name = url.split("/")[-1]
# return attachment
# def construct_attachment_from_bytes(filename: str = "file", bytes_arr: io.BytesIO = None, file_type: str = None) -> nerimity.Attachment | None:
# if not bytes_arr: return None
# if not file_type: return None
# attachment = nerimity.Attachment()
# attachment.internal_type = nerimity.AttachmentTypes.OUTGOING
# attachment.data = bytes_arr.read()
# attachment.data_type = file_type
# attachment.size = len(attachment.data)
# attachment.name = filename
# return attachment
def error_msg(message: str) -> str:
return f"[#e5323b][Error] [#reset]{message}"
def good_msg(message: str) -> str:
return f"[#52ff54][Success] [#reset]{message}"
def is_mention(mention: str) -> bool:
if not mention: return None
return True if mention.startswith("[@:") else False