utility.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:aryas 作者: lattkkthxbbye 项目源码 文件源码
def send(bot: commands.Bot, message: str, channel: Channel, delete=False,
         time=None, show_dots=True, bomb_themed_dots=False) -> None:
    """
    Sends a message to the server and deletes it after a period of time
    :param bot:     the bot used to send the message
    :param message: the content of the message
    :param channel: the channel in which the message will be sent
    :param delete: whether to delete the message after sending it
    :param time: the time to wait before deleting the message
    :param show_dots: whether to show countdown dots for message deletion (this will round down `time` if it is a float)
    :param bomb_themed_dots: whether to theme the dots using a bomb and fuse instead of plain dots
    """

    config = bot.cogs['Config']
    if time is None:
        time = config['aryas']['message_sleep_time']

    def dot_bar(progress):
        width = int(time)
        if bomb_themed_dots:
            return "\n`??" + "-" * (width - progress) + "*`" if width - progress > 0 else "??"
        return "\n`|" + "•" * (width - progress) + " " * max(progress, 0) + "|`"

    async def send_inner():
        msg = await bot.send_message(channel, message + (dot_bar(0) if delete and show_dots else ""))
        # Waits *time* seconds and deletes the confirmation message.
        if delete:
            if not show_dots:
                await asyncio.sleep(time)
            else:
                for i in range(int(time)):
                    await asyncio.sleep(1)
                    await bot.edit_message(msg, message + dot_bar(i + 1))
            await bot.delete_message(msg)

    asyncio.ensure_future(send_inner())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号