midi.py 文件源码

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

项目:jose 作者: lnmds 项目源码 文件源码
def download_data(self, message: discord.Message) -> str:
        """Checks if an attachment is viable to be used as
        MIDI input and downloads it."""
        if not message.attachments:
            raise self.SayException('You did not attach a file to '
                                    'use as MIDI input!, `j!help midi`')

        attachment = message.attachments[0]

        if not attachment.filename.endswith('.txt'):
            raise self.SayException('File must be a .txt!')

        # see if the file is bigger than 20 KiB as we don't want
        # to download huge files
        if attachment.size >= 20 * 1024:
            raise self.SayException('File is too large. '
                                    'Your file may only be 20KiB big.')

        log.info('downloading file to use as MIDI input. '
                 f'{attachment.size} bytes large.')
        buffer = io.BytesIO()
        await attachment.save(buffer)

        return buffer.getvalue().decode('utf-8')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号