diff --git a/src/cogs/ffmeta.py b/src/cogs/ffmeta.py new file mode 100644 index 0000000..8818734 --- /dev/null +++ b/src/cogs/ffmeta.py @@ -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)) diff --git a/src/cogs/ytdl.py b/src/cogs/ytdl.py index 94d2247..e7e31e4 100644 --- a/src/cogs/ytdl.py +++ b/src/cogs/ytdl.py @@ -459,5 +459,6 @@ class YTDLCog(commands.Cog): ) ) + def setup(bot): bot.add_cog(YTDLCog(bot)) diff --git a/src/main.py b/src/main.py index eaae55a..6053f19 100644 --- a/src/main.py +++ b/src/main.py @@ -65,6 +65,7 @@ class Client(commands.Bot): self.web.cancel() await super().close() + bot = Client( command_prefix=commands.when_mentioned_or("h!", "H!"), case_insensitive=True, @@ -72,10 +73,13 @@ bot = Client( debug_guilds=CONFIG["jimmy"].get("debug_guilds") ) -bot.load_extension("cogs.ytdl") -bot.load_extension("cogs.net") -bot.load_extension("cogs.screenshot") -bot.load_extension("cogs.ollama") +for ext in ("ytdl", "net", "screenshot", "ollama", "ffmeta"): + try: + bot.load_extension(f"cogs.{ext}") + 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