Add /right-behind-you
All checks were successful
Build and Publish college-bot-v2 / build_and_publish (push) Successful in 16s
All checks were successful
Build and Publish college-bot-v2 / build_and_publish (push) Successful in 16s
This commit is contained in:
parent
1e22644a6c
commit
aca86f8b64
2 changed files with 51 additions and 1 deletions
BIN
src/assets/right-behind-you.ogg
Normal file
BIN
src/assets/right-behind-you.ogg
Normal file
Binary file not shown.
|
@ -226,7 +226,7 @@ class FFMeta(commands.Cog):
|
||||||
if not fs:
|
if not fs:
|
||||||
await ctx.respond("Failed to convert audio. See below.")
|
await ctx.respond("Failed to convert audio. See below.")
|
||||||
else:
|
else:
|
||||||
await ctx.respond(file=discord.File(file, filename=filename))
|
return await ctx.respond(file=discord.File(file, filename=filename))
|
||||||
|
|
||||||
paginator = commands.Paginator()
|
paginator = commands.Paginator()
|
||||||
for line in stderr.splitlines():
|
for line in stderr.splitlines():
|
||||||
|
@ -236,6 +236,56 @@ class FFMeta(commands.Cog):
|
||||||
|
|
||||||
for page in paginator.pages:
|
for page in paginator.pages:
|
||||||
await ctx.respond(page, ephemeral=True)
|
await ctx.respond(page, ephemeral=True)
|
||||||
|
|
||||||
|
@commands.slash_command(name="right-behind-you")
|
||||||
|
async def right_behind_you(self, ctx: discord.ApplicationContext, image: discord.Attachment):
|
||||||
|
await ctx.defer()
|
||||||
|
if not Path("assets/right-behind-you.ogg").exists():
|
||||||
|
return await ctx.respond("The file `right-behind-you.ogg` is missing.")
|
||||||
|
if not image.content_type.startswith("image"):
|
||||||
|
return await ctx.respond("That's not an image!")
|
||||||
|
with tempfile.NamedTemporaryFile(suffix=Path(image.filename).suffix) as temp:
|
||||||
|
await image.save(temp.name)
|
||||||
|
process = await asyncio.create_subprocess_exec(
|
||||||
|
"ffmpeg",
|
||||||
|
"-hide_banner",
|
||||||
|
"-v",
|
||||||
|
"warning",
|
||||||
|
"-stats",
|
||||||
|
"-loop",
|
||||||
|
"1",
|
||||||
|
"-i",
|
||||||
|
temp.name,
|
||||||
|
"-i",
|
||||||
|
"assets/right-behind-you.ogg",
|
||||||
|
"-c:v",
|
||||||
|
"libx264",
|
||||||
|
"-tune",
|
||||||
|
"stillimage",
|
||||||
|
"-pix_fmt",
|
||||||
|
"yuv420p",
|
||||||
|
"-shortest",
|
||||||
|
"-y",
|
||||||
|
"pipe:1",
|
||||||
|
stdout=asyncio.subprocess.PIPE,
|
||||||
|
stderr=asyncio.subprocess.PIPE,
|
||||||
|
)
|
||||||
|
stdout, stderr = await process.communicate()
|
||||||
|
file = io.BytesIO(stdout)
|
||||||
|
if (fs := len(file.getvalue())) > (24.75 * 1024 * 1024):
|
||||||
|
return await ctx.respond("The file is too large to send ({:,.2f} MiB).".format(fs / 1024 / 1024))
|
||||||
|
if not fs:
|
||||||
|
await ctx.respond("Failed to convert audio. See below.")
|
||||||
|
else:
|
||||||
|
return await ctx.respond(file=discord.File(file, filename="right-behind-you.mp4"))
|
||||||
|
paginator = commands.Paginator()
|
||||||
|
for line in stderr.splitlines():
|
||||||
|
if line.strip().startswith(":"):
|
||||||
|
continue
|
||||||
|
paginator.add_line(f"{line}"[:2000])
|
||||||
|
|
||||||
|
for page in paginator.pages:
|
||||||
|
await ctx.respond(page, ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
def setup(bot: commands.Bot):
|
def setup(bot: commands.Bot):
|
||||||
|
|
Loading…
Reference in a new issue