1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00
royalnet/royalnet_console/utils/message.py

52 lines
1.2 KiB
Python
Raw Normal View History

2021-01-10 17:37:18 +00:00
# Module docstring
"""
An universal function to send messages to the console.
"""
# Special imports
from __future__ import annotations
import royalnet.royaltyping as t
# External imports
import logging
import royalnet.engineer as engi
import click
2021-01-10 17:37:18 +00:00
# Internal imports
# from . import something
# Special global objects
log = logging.getLogger(__name__)
# Code
async def console_message(*,
mag: engi.Magazine,
text: str = None,
files: t.List[t.BinaryIO] = None) -> engi.Message:
"""
Output a message to the console and return the resulting bullet.
:param mag: The :class:`.engi.Magazine` to use when instantiating the bullet.
:param text: The text of the message.
:param files: A :class:`list` of files to attach to the message.
:return: The sent :class:`.engi.Message`.
"""
2021-01-10 18:54:39 +00:00
if files is None:
files = []
2021-01-10 17:37:18 +00:00
if len(files) > 0:
raise engi.exc.NotSupportedError("Console does not allow sending files.")
log.debug("Sending message...")
click.echo(text)
2021-01-10 17:37:18 +00:00
log.debug("Creating bullet...")
return mag.Message(_text=text)
# Objects exported by this module
__all__ = (
"console_message",
)