Add ffmeta cog

This commit is contained in:
Nexus 2024-02-06 23:03:49 +00:00
parent 6e04f4a97d
commit dcf4e1960a
3 changed files with 58 additions and 4 deletions

49
src/cogs/ffmeta.py Normal file
View file

@ -0,0 +1,49 @@
import asyncio
import logging
import discord
from discord.ext import commands
class FFMeta(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
self.log = logging.getLogger("jimmy.cogs.ffmeta")
@commands.slash_command()
async def ffprobe(self, ctx: discord.ApplicationContext, url: str = None, attachment: discord.Attachment = None):
"""Runs ffprobe on a given URL or attachment"""
if url is None:
if attachment is None:
return await ctx.respond("No URL or attachment provided")
url = attachment.url
await ctx.defer()
process = await asyncio.create_subprocess_exec(
"ffprobe",
"-hide_banner",
url,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
text=True
)
stdout, stderr = await process.communicate()
paginator = commands.Paginator(prefix="```", suffix="```")
for line in stdout:
if stderr:
paginator.add_line(f"[OUT] {line}"[:2000])
else:
paginator.add_line(line[:2000])
for line in stderr:
paginator.add_line(f"[ERR] {line}"[:2000])
for page in paginator.pages:
await ctx.respond(page)
def setup(bot: commands.Bot):
bot.add_cog(FFMeta(bot))

View file

@ -459,5 +459,6 @@ class YTDLCog(commands.Cog):
) )
) )
def setup(bot): def setup(bot):
bot.add_cog(YTDLCog(bot)) bot.add_cog(YTDLCog(bot))

View file

@ -65,6 +65,7 @@ class Client(commands.Bot):
self.web.cancel() self.web.cancel()
await super().close() await super().close()
bot = Client( bot = Client(
command_prefix=commands.when_mentioned_or("h!", "H!"), command_prefix=commands.when_mentioned_or("h!", "H!"),
case_insensitive=True, case_insensitive=True,
@ -72,10 +73,13 @@ bot = Client(
debug_guilds=CONFIG["jimmy"].get("debug_guilds") debug_guilds=CONFIG["jimmy"].get("debug_guilds")
) )
bot.load_extension("cogs.ytdl") for ext in ("ytdl", "net", "screenshot", "ollama", "ffmeta"):
bot.load_extension("cogs.net") try:
bot.load_extension("cogs.screenshot") bot.load_extension(f"cogs.{ext}")
bot.load_extension("cogs.ollama") except discord.ExtensionError as e:
log.error(f"Failed to load extension cogs.{ext}", exc_info=e)
else:
log.info(f"Loaded extension cogs.{ext}")
@bot.event @bot.event