channel_dump.py 文件源码

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

项目:Red_Star 作者: medeor413 项目源码 文件源码
def _dump(self, msg):
        args = msg.content.split(" ", 3)
        if len(args) < 3:
            raise CommandSyntaxError("Wrong number of arguments.")
        try:
            m_start = int(args[1])
        except ValueError:
            raise CommandSyntaxError("First Argument is not a valid integer.")

        try:
            m_end = int(args[2])
        except ValueError:
            raise CommandSyntaxError("Second Argument is not a valid integer.")
        try:
            m_start = await msg.channel.get_message(m_start)
        except NotFound:
            raise CommandSyntaxError(f"No message with ID {m_start}")
        try:
            m_end = await msg.channel.get_message(m_end)
        except NotFound:
            raise CommandSyntaxError(f"No message with ID {m_end}")

        if len(args) > 3:
            t_name = args[3]+".txt"
        else:
            t_name = str(time.time())+".txt"

        s = "%Y-%m-%d %H:%M:%S"

        t_list = [f"{str(m_end.author)} @ {str(m_end.created_at.strftime(s))}\n{m_end.clean_content}\n\n"]

        async for message in msg.channel.history(before=m_start, after=m_end, reverse=True, limit=None):
            t_list.append(f"{str(message.author)} @ {str(message.created_at.strftime(s))}\n{message.clean_content}\n\n")

        t_list.append(f"{str(m_start.author)} @ {str(m_start.created_at.strftime(s))}\n{m_start.clean_content}")

        t_msg = await respond(msg, f"**AFFIRMATIVE. Processing file {t_name}.**")
        async with msg.channel.typing():
            await respond(msg, "**AFFIRMATIVE. Completed file upload.**",
                          file=File(BytesIO(bytes("".join(t_list), encoding="utf-8")), filename=t_name))
        await t_msg.delete()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号