This commit is contained in:
nex 2022-12-28 21:14:14 +00:00
parent 53c87d5c27
commit 047eaa17c0
2 changed files with 24 additions and 16 deletions

View file

@ -1,6 +1,7 @@
import asyncio import asyncio
import io import io
import os import os
import time
from typing import Tuple, Optional from typing import Tuple, Optional
import discord import discord
@ -154,7 +155,11 @@ class OtherCog(commands.Cog):
"""Generates a "corrupted" file.""" """Generates a "corrupted" file."""
limit_mb = round(ctx.guild.filesize_limit / 1024 / 1024) limit_mb = round(ctx.guild.filesize_limit / 1024 / 1024)
if size_in_megabytes > limit_mb: if size_in_megabytes > limit_mb:
return await ctx.respond(f"File size must be less than {limit_mb} MB.") return await ctx.respond(
f"File size must be less than {limit_mb} MB.\n"
"Want to corrupt larger files? see https://github.com/EEKIM10/cli-utils#installing-the-right-way"
" (and then run `ruin <file>`)."
)
await ctx.defer() await ctx.defer()
size = max(min(int(size_in_megabytes * 1024 * 1024), ctx.guild.filesize_limit), 1) size = max(min(int(size_in_megabytes * 1024 * 1024), ctx.guild.filesize_limit), 1)
@ -178,13 +183,17 @@ class OtherCog(commands.Cog):
ctx: discord.ApplicationContext, ctx: discord.ApplicationContext,
file: discord.Attachment, file: discord.Attachment,
passes: int = 10, passes: int = 10,
metadata_safety_boundary: float = 5 metadata_safety_boundary: float = 5,
): ):
"""Takes a file and corrupts parts of it""" """Takes a file and corrupts parts of it"""
await ctx.defer() await ctx.defer()
attachment = file attachment = file
if attachment.size > 8388608: if attachment.size > 8388608:
return await ctx.respond("File is too large. Max size 8mb.") return await ctx.respond(
"File is too large. Max size 8mb.\n"
"Want to corrupt larger files? see https://github.com/EEKIM10/cli-utils#installing-the-right-way"
" (and then run `ruin <file>`)."
)
bound_pct = attachment.size * (0.01 * metadata_safety_boundary) bound_pct = attachment.size * (0.01 * metadata_safety_boundary)
bound_start = round(bound_pct) bound_start = round(bound_pct)
bound_end = round(attachment.size - bound_pct) bound_end = round(attachment.size - bound_pct)
@ -192,17 +201,17 @@ class OtherCog(commands.Cog):
file = io.BytesIO(await file.read()) file = io.BytesIO(await file.read())
file.seek(0) file.seek(0)
await ctx.edit(content="Corrupting file...") await ctx.edit(content="Corrupting file...")
file = await asyncio.to_thread( file = await asyncio.to_thread(self.do_file_corruption, file, passes, bound_start, bound_end)
self.do_file_corruption,
file,
passes,
bound_start,
bound_end
)
file.seek(0) file.seek(0)
await ctx.edit(content="Uploading file...") await ctx.edit(content="Uploading file...")
await ctx.edit(content="Here's your corrupted file!", file=discord.File(file, attachment.filename)) await ctx.edit(content="Here's your corrupted file!", file=discord.File(file, attachment.filename))
@commands.command(name="kys", aliases=['kill'])
@commands.is_owner()
async def end_your_life(self, ctx: commands.Context):
await ctx.send(":( okay")
await self.bot.close()
def setup(bot): def setup(bot):
bot.add_cog(OtherCog(bot)) bot.add_cog(OtherCog(bot))

View file

@ -1,5 +1,4 @@
# py-cord==2.2.0 py-cord==2.3.2
git+https://github.com/pycord-development/pycord.git@master#egg=py-cord
aiosmtplib==1.1.7 aiosmtplib==1.1.7
orm[sqlite]==0.3.1 orm[sqlite]==0.3.1
httpx==0.23.0 httpx==0.23.0