main.py 文件源码

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

项目:discord_bot 作者: Der-Eddy 项目源码 文件源码
def _fileCheck(msg):
    url = msg.attachments[0]['url']
    allowedExtension = ['.exe', '.zip', '.rar']
    if url[-4:] in allowedExtension:
        name = os.path.basename(url)
        downloadPath = 'tmp\\' + name
        async with aiohttp.get(url) as download:
            with open(downloadPath, 'wb') as f:
                f.write(await download.read())
        stats = os.stat(downloadPath)
        size = stats.st_size
        KBSize = round(size / 1024, 3)
        MBSize = round(size / 1024 / 1024, 3)
        MD5 = _getHash(downloadPath, hashlib.md5())
        SHA1 = _getHash(downloadPath, hashlib.sha1())
        SHA256 = _getHash(downloadPath, hashlib.sha256())
        SHA512 = _getHash(downloadPath, hashlib.sha512())
        msg = f'**Name:** {name}\n'
        msg += f'**Size:** {MBSize} MB ({size} Bytes)\n'
        msg += f'**MD5:** `{MD5}`\n'
        msg += f'**SHA1:** `{SHA1}`\n'
        msg += f'**SHA256:** `{SHA256}`\n'
        msg += f'**SHA512:** `{SHA512}`\n'
        os.remove(downloadPath)
        return msg
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号