mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 02:41:06 -05:00
fix: Properly implement slash commands - Use app_commands for slash command support - Add proper command group structure - Handle command registration and syncing
This commit is contained in:
@@ -1,13 +1,12 @@
|
|||||||
"""VideoArchiver cog for Red-DiscordBot"""
|
"""VideoArchiver cog for Red-DiscordBot"""
|
||||||
|
|
||||||
from redbot.core.bot import Red
|
from redbot.core.bot import Red
|
||||||
from redbot.core.utils import get_end_user_data_statement
|
from .video_archiver import VideoArchiver
|
||||||
|
|
||||||
from videoarchiver.video_archiver import VideoArchiver
|
async def setup(bot: Red) -> None:
|
||||||
from videoarchiver.ffmpeg.ffmpeg_manager import FFmpegManager
|
"""Load VideoArchiver."""
|
||||||
from videoarchiver.ffmpeg.exceptions import FFmpegError, GPUError, DownloadError
|
cog = VideoArchiver(bot)
|
||||||
|
await bot.add_cog(cog)
|
||||||
__red_end_user_data_statement__ = get_end_user_data_statement(__file__)
|
# Sync commands with Discord
|
||||||
|
if not hasattr(bot, "tree"):
|
||||||
async def setup(bot: Red):
|
return
|
||||||
await bot.add_cog(VideoArchiver(bot))
|
await bot.tree.sync()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"""Discord commands for VideoArchiver"""
|
"""Discord commands for VideoArchiver"""
|
||||||
import discord
|
import discord
|
||||||
from redbot.core import commands, checks
|
from redbot.core import commands, app_commands
|
||||||
from typing import Optional
|
from typing import Optional, Literal
|
||||||
import yt_dlp
|
import yt_dlp
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
@@ -15,185 +15,188 @@ class VideoArchiverCommands(commands.Cog):
|
|||||||
self.processor = processor
|
self.processor = processor
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
@commands.hybrid_group(name="videoarchiver", aliases=["va"], fallback="settings")
|
videoarchiver = app_commands.Group(
|
||||||
@commands.guild_only()
|
name="videoarchiver",
|
||||||
|
description="Video Archiver configuration commands",
|
||||||
|
guild_only=True
|
||||||
|
)
|
||||||
|
|
||||||
|
@videoarchiver.command(name="settings")
|
||||||
|
@app_commands.guild_only()
|
||||||
@commands.admin_or_permissions(administrator=True)
|
@commands.admin_or_permissions(administrator=True)
|
||||||
async def videoarchiver(self, ctx: commands.Context):
|
async def settings(self, interaction: discord.Interaction):
|
||||||
"""Video Archiver configuration commands"""
|
"""Show current settings"""
|
||||||
if ctx.invoked_subcommand is None:
|
embed = await self.config.format_settings_embed(interaction.guild)
|
||||||
embed = await self.config.format_settings_embed(ctx.guild)
|
await interaction.response.send_message(embed=embed)
|
||||||
await ctx.send(embed=embed)
|
|
||||||
|
|
||||||
@videoarchiver.command(name="updateytdlp")
|
@videoarchiver.command(name="updateytdlp")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
@checks.is_owner()
|
@commands.is_owner()
|
||||||
async def update_ytdlp(self, ctx: commands.Context):
|
async def update_ytdlp(self, interaction: discord.Interaction):
|
||||||
"""Update yt-dlp to the latest version"""
|
"""Update yt-dlp to the latest version"""
|
||||||
success, message = await self.update_checker.update_yt_dlp()
|
success, message = await self.update_checker.update_yt_dlp()
|
||||||
await ctx.send("✅ " + message if success else "❌ " + message)
|
await interaction.response.send_message("✅ " + message if success else "❌ " + message)
|
||||||
|
|
||||||
@videoarchiver.command(name="toggleupdates")
|
@videoarchiver.command(name="toggleupdates")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
@commands.admin_or_permissions(administrator=True)
|
@commands.admin_or_permissions(administrator=True)
|
||||||
async def toggle_update_check(self, ctx: commands.Context):
|
async def toggle_update_check(self, interaction: discord.Interaction):
|
||||||
"""Toggle yt-dlp update notifications"""
|
"""Toggle yt-dlp update notifications"""
|
||||||
state = await self.config.toggle_setting(ctx.guild.id, "disable_update_check")
|
state = await self.config.toggle_setting(interaction.guild.id, "disable_update_check")
|
||||||
status = "disabled" if state else "enabled"
|
status = "disabled" if state else "enabled"
|
||||||
await ctx.send(f"Update notifications {status}")
|
await interaction.response.send_message(f"Update notifications {status}")
|
||||||
|
|
||||||
@videoarchiver.command(name="addrole")
|
@videoarchiver.command(name="addrole")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
async def add_allowed_role(self, ctx: commands.Context, role: Optional[discord.Role] = None):
|
@app_commands.describe(role="The role to allow (leave empty for @everyone)")
|
||||||
"""Add a role that's allowed to trigger archiving (leave empty for @everyone)"""
|
async def add_allowed_role(self, interaction: discord.Interaction, role: Optional[discord.Role] = None):
|
||||||
role_id = role.id if role else ctx.guild.default_role.id
|
"""Add a role that's allowed to trigger archiving"""
|
||||||
role_name = role.name if role else "@everyone"
|
|
||||||
|
|
||||||
# If no role is specified, clear the list to allow everyone
|
|
||||||
if not role:
|
if not role:
|
||||||
await self.config.update_setting(ctx.guild.id, "allowed_roles", [])
|
# If no role is specified, clear the list to allow everyone
|
||||||
await ctx.send("Allowed role set to @everyone (all users can trigger archiving)")
|
await self.config.update_setting(interaction.guild.id, "allowed_roles", [])
|
||||||
|
await interaction.response.send_message("Allowed role set to @everyone (all users can trigger archiving)")
|
||||||
return
|
return
|
||||||
|
|
||||||
await self.config.add_to_list(ctx.guild.id, "allowed_roles", role_id)
|
await self.config.add_to_list(interaction.guild.id, "allowed_roles", role.id)
|
||||||
await ctx.send(f"Added {role_name} to allowed roles")
|
await interaction.response.send_message(f"Added {role.name} to allowed roles")
|
||||||
|
|
||||||
@videoarchiver.command(name="removerole")
|
@videoarchiver.command(name="removerole")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
async def remove_allowed_role(self, ctx: commands.Context, role: discord.Role):
|
@app_commands.describe(role="The role to remove")
|
||||||
|
async def remove_allowed_role(self, interaction: discord.Interaction, role: discord.Role):
|
||||||
"""Remove a role from allowed roles"""
|
"""Remove a role from allowed roles"""
|
||||||
await self.config.remove_from_list(ctx.guild.id, "allowed_roles", role.id)
|
await self.config.remove_from_list(interaction.guild.id, "allowed_roles", role.id)
|
||||||
await ctx.send(f"Removed {role.name} from allowed roles")
|
await interaction.response.send_message(f"Removed {role.name} from allowed roles")
|
||||||
|
|
||||||
@videoarchiver.command(name="listroles")
|
@videoarchiver.command(name="listroles")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
async def list_allowed_roles(self, ctx: commands.Context):
|
async def list_allowed_roles(self, interaction: discord.Interaction):
|
||||||
"""List all roles allowed to trigger archiving"""
|
"""List all roles allowed to trigger archiving"""
|
||||||
roles = await self.config.get_setting(ctx.guild.id, "allowed_roles")
|
roles = await self.config.get_setting(interaction.guild.id, "allowed_roles")
|
||||||
if not roles:
|
if not roles:
|
||||||
await ctx.send(
|
await interaction.response.send_message(
|
||||||
"No roles are currently set (all users can trigger archiving)"
|
"No roles are currently set (all users can trigger archiving)"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
role_names = [
|
role_names = [
|
||||||
r.name if r else "@everyone"
|
r.name if r else "@everyone"
|
||||||
for r in [ctx.guild.get_role(role_id) for role_id in roles]
|
for r in [interaction.guild.get_role(role_id) for role_id in roles]
|
||||||
]
|
]
|
||||||
await ctx.send(f"Allowed roles: {', '.join(role_names)}")
|
await interaction.response.send_message(f"Allowed roles: {', '.join(role_names)}")
|
||||||
|
|
||||||
@videoarchiver.command(name="setconcurrent")
|
@videoarchiver.command(name="setconcurrent")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
async def set_concurrent_downloads(self, ctx: commands.Context, count: int):
|
@app_commands.describe(count="Number of concurrent downloads (1-5)")
|
||||||
"""Set the number of concurrent downloads (1-5)"""
|
async def set_concurrent_downloads(self, interaction: discord.Interaction, count: app_commands.Range[int, 1, 5]):
|
||||||
if not 1 <= count <= 5:
|
"""Set the number of concurrent downloads"""
|
||||||
await ctx.send("Concurrent downloads must be between 1 and 5")
|
await self.config.update_setting(interaction.guild.id, "concurrent_downloads", count)
|
||||||
return
|
await interaction.response.send_message(f"Concurrent downloads set to {count}")
|
||||||
await self.config.update_setting(ctx.guild.id, "concurrent_downloads", count)
|
|
||||||
await ctx.send(f"Concurrent downloads set to {count}")
|
|
||||||
|
|
||||||
@videoarchiver.command(name="setchannel")
|
@videoarchiver.command(name="setchannel")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
async def set_archive_channel(
|
@app_commands.describe(channel="The archive channel")
|
||||||
self, ctx: commands.Context, channel: discord.TextChannel
|
async def set_archive_channel(self, interaction: discord.Interaction, channel: discord.TextChannel):
|
||||||
):
|
|
||||||
"""Set the archive channel"""
|
"""Set the archive channel"""
|
||||||
await self.config.update_setting(ctx.guild.id, "archive_channel", channel.id)
|
await self.config.update_setting(interaction.guild.id, "archive_channel", channel.id)
|
||||||
await ctx.send(f"Archive channel set to {channel.mention}")
|
await interaction.response.send_message(f"Archive channel set to {channel.mention}")
|
||||||
|
|
||||||
@videoarchiver.command(name="setnotification")
|
@videoarchiver.command(name="setnotification")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
async def set_notification_channel(
|
@app_commands.describe(channel="The notification channel")
|
||||||
self, ctx: commands.Context, channel: discord.TextChannel
|
async def set_notification_channel(self, interaction: discord.Interaction, channel: discord.TextChannel):
|
||||||
):
|
|
||||||
"""Set the notification channel (where archive messages appear)"""
|
"""Set the notification channel (where archive messages appear)"""
|
||||||
await self.config.update_setting(
|
await self.config.update_setting(
|
||||||
ctx.guild.id, "notification_channel", channel.id
|
interaction.guild.id, "notification_channel", channel.id
|
||||||
)
|
)
|
||||||
await ctx.send(f"Notification channel set to {channel.mention}")
|
await interaction.response.send_message(f"Notification channel set to {channel.mention}")
|
||||||
|
|
||||||
@videoarchiver.command(name="setlogchannel")
|
@videoarchiver.command(name="setlogchannel")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
async def set_log_channel(
|
@app_commands.describe(channel="The log channel")
|
||||||
self, ctx: commands.Context, channel: discord.TextChannel
|
async def set_log_channel(self, interaction: discord.Interaction, channel: discord.TextChannel):
|
||||||
):
|
|
||||||
"""Set the log channel for error messages and notifications"""
|
"""Set the log channel for error messages and notifications"""
|
||||||
await self.config.update_setting(ctx.guild.id, "log_channel", channel.id)
|
await self.config.update_setting(interaction.guild.id, "log_channel", channel.id)
|
||||||
await ctx.send(f"Log channel set to {channel.mention}")
|
await interaction.response.send_message(f"Log channel set to {channel.mention}")
|
||||||
|
|
||||||
@videoarchiver.command(name="addmonitor")
|
@videoarchiver.command(name="addmonitor")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
async def add_monitored_channel(
|
@app_commands.describe(channel="The channel to monitor (leave empty to monitor all channels)")
|
||||||
self, ctx: commands.Context, channel: Optional[discord.TextChannel] = None
|
async def add_monitored_channel(self, interaction: discord.Interaction, channel: Optional[discord.TextChannel] = None):
|
||||||
):
|
"""Add a channel to monitor for videos"""
|
||||||
"""Add a channel to monitor for videos (leave empty to monitor all channels)"""
|
|
||||||
if not channel:
|
if not channel:
|
||||||
# If no channel is specified, clear the list to monitor all channels
|
# If no channel is specified, clear the list to monitor all channels
|
||||||
await self.config.update_setting(ctx.guild.id, "monitored_channels", [])
|
await self.config.update_setting(interaction.guild.id, "monitored_channels", [])
|
||||||
await ctx.send("Now monitoring all channels for videos")
|
await interaction.response.send_message("Now monitoring all channels for videos")
|
||||||
return
|
return
|
||||||
|
|
||||||
await self.config.add_to_list(ctx.guild.id, "monitored_channels", channel.id)
|
await self.config.add_to_list(interaction.guild.id, "monitored_channels", channel.id)
|
||||||
await ctx.send(f"Now monitoring {channel.mention} for videos")
|
await interaction.response.send_message(f"Now monitoring {channel.mention} for videos")
|
||||||
|
|
||||||
@videoarchiver.command(name="removemonitor")
|
@videoarchiver.command(name="removemonitor")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
async def remove_monitored_channel(
|
@app_commands.describe(channel="The channel to stop monitoring")
|
||||||
self, ctx: commands.Context, channel: discord.TextChannel
|
async def remove_monitored_channel(self, interaction: discord.Interaction, channel: discord.TextChannel):
|
||||||
):
|
|
||||||
"""Remove a channel from monitoring"""
|
"""Remove a channel from monitoring"""
|
||||||
await self.config.remove_from_list(
|
await self.config.remove_from_list(
|
||||||
ctx.guild.id, "monitored_channels", channel.id
|
interaction.guild.id, "monitored_channels", channel.id
|
||||||
)
|
)
|
||||||
await ctx.send(f"Stopped monitoring {channel.mention}")
|
await interaction.response.send_message(f"Stopped monitoring {channel.mention}")
|
||||||
|
|
||||||
@videoarchiver.command(name="setformat")
|
@videoarchiver.command(name="setformat")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
async def set_video_format(self, ctx: commands.Context, format: str):
|
@app_commands.describe(format="The video format (e.g., mp4, webm)")
|
||||||
"""Set the video format (e.g., mp4, webm)"""
|
async def set_video_format(self, interaction: discord.Interaction, format: Literal["mp4", "webm"]):
|
||||||
await self.config.update_setting(ctx.guild.id, "video_format", format.lower())
|
"""Set the video format"""
|
||||||
await ctx.send(f"Video format set to {format.lower()}")
|
await self.config.update_setting(interaction.guild.id, "video_format", format.lower())
|
||||||
|
await interaction.response.send_message(f"Video format set to {format.lower()}")
|
||||||
|
|
||||||
@videoarchiver.command(name="setquality")
|
@videoarchiver.command(name="setquality")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
async def set_video_quality(self, ctx: commands.Context, quality: int):
|
@app_commands.describe(quality="Maximum video quality in pixels (e.g., 1080)")
|
||||||
"""Set the maximum video quality in pixels (e.g., 1080)"""
|
async def set_video_quality(self, interaction: discord.Interaction, quality: app_commands.Range[int, 144, 4320]):
|
||||||
await self.config.update_setting(ctx.guild.id, "video_quality", quality)
|
"""Set the maximum video quality"""
|
||||||
await ctx.send(f"Maximum video quality set to {quality}p")
|
await self.config.update_setting(interaction.guild.id, "video_quality", quality)
|
||||||
|
await interaction.response.send_message(f"Maximum video quality set to {quality}p")
|
||||||
|
|
||||||
@videoarchiver.command(name="setmaxsize")
|
@videoarchiver.command(name="setmaxsize")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
async def set_max_file_size(self, ctx: commands.Context, size: int):
|
@app_commands.describe(size="Maximum file size in MB")
|
||||||
"""Set the maximum file size in MB"""
|
async def set_max_file_size(self, interaction: discord.Interaction, size: app_commands.Range[int, 1, 100]):
|
||||||
await self.config.update_setting(ctx.guild.id, "max_file_size", size)
|
"""Set the maximum file size"""
|
||||||
await ctx.send(f"Maximum file size set to {size}MB")
|
await self.config.update_setting(interaction.guild.id, "max_file_size", size)
|
||||||
|
await interaction.response.send_message(f"Maximum file size set to {size}MB")
|
||||||
|
|
||||||
@videoarchiver.command(name="toggledelete")
|
@videoarchiver.command(name="toggledelete")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
async def toggle_delete_after_repost(self, ctx: commands.Context):
|
async def toggle_delete_after_repost(self, interaction: discord.Interaction):
|
||||||
"""Toggle whether to delete local files after reposting"""
|
"""Toggle whether to delete local files after reposting"""
|
||||||
state = await self.config.toggle_setting(ctx.guild.id, "delete_after_repost")
|
state = await self.config.toggle_setting(interaction.guild.id, "delete_after_repost")
|
||||||
await ctx.send(f"Delete after repost: {state}")
|
await interaction.response.send_message(f"Delete after repost: {state}")
|
||||||
|
|
||||||
@videoarchiver.command(name="setduration")
|
@videoarchiver.command(name="setduration")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
async def set_message_duration(self, ctx: commands.Context, hours: int):
|
@app_commands.describe(hours="Duration in hours (0 for permanent)")
|
||||||
"""Set how long to keep archive messages (0 for permanent)"""
|
async def set_message_duration(self, interaction: discord.Interaction, hours: app_commands.Range[int, 0, 720]):
|
||||||
await self.config.update_setting(ctx.guild.id, "message_duration", hours)
|
"""Set how long to keep archive messages"""
|
||||||
await ctx.send(f"Archive message duration set to {hours} hours")
|
await self.config.update_setting(interaction.guild.id, "message_duration", hours)
|
||||||
|
await interaction.response.send_message(f"Archive message duration set to {hours} hours")
|
||||||
|
|
||||||
@videoarchiver.command(name="settemplate")
|
@videoarchiver.command(name="settemplate")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
async def set_message_template(self, ctx: commands.Context, *, template: str):
|
@app_commands.describe(template="Message template using {author}, {url}, and {original_message}")
|
||||||
"""Set the archive message template. Use {author}, {url}, and {original_message} as placeholders"""
|
async def set_message_template(self, interaction: discord.Interaction, template: str):
|
||||||
await self.config.update_setting(ctx.guild.id, "message_template", template)
|
"""Set the archive message template"""
|
||||||
await ctx.send(f"Archive message template set to:\n{template}")
|
await self.config.update_setting(interaction.guild.id, "message_template", template)
|
||||||
|
await interaction.response.send_message(f"Archive message template set to:\n{template}")
|
||||||
|
|
||||||
@videoarchiver.command(name="enablesites")
|
@videoarchiver.command(name="enablesites")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
async def enable_sites(self, ctx: commands.Context, *, sites: Optional[str] = None):
|
@app_commands.describe(sites="Sites to enable (leave empty for all sites)")
|
||||||
"""Enable specific sites (leave empty for all sites). Separate multiple sites with spaces."""
|
async def enable_sites(self, interaction: discord.Interaction, sites: Optional[str] = None):
|
||||||
|
"""Enable specific sites"""
|
||||||
if sites is None:
|
if sites is None:
|
||||||
await self.config.update_setting(ctx.guild.id, "enabled_sites", [])
|
await self.config.update_setting(interaction.guild.id, "enabled_sites", [])
|
||||||
await ctx.send("All sites enabled")
|
await interaction.response.send_message("All sites enabled")
|
||||||
return
|
return
|
||||||
|
|
||||||
site_list = [s.strip().lower() for s in sites.split()]
|
site_list = [s.strip().lower() for s in sites.split()]
|
||||||
@@ -203,19 +206,19 @@ class VideoArchiverCommands(commands.Cog):
|
|||||||
valid_sites = set(ie.IE_NAME.lower() for ie in ydl._ies)
|
valid_sites = set(ie.IE_NAME.lower() for ie in ydl._ies)
|
||||||
invalid_sites = [s for s in site_list if s not in valid_sites]
|
invalid_sites = [s for s in site_list if s not in valid_sites]
|
||||||
if invalid_sites:
|
if invalid_sites:
|
||||||
await ctx.send(
|
await interaction.response.send_message(
|
||||||
f"Invalid sites: {', '.join(invalid_sites)}\nValid sites: {', '.join(valid_sites)}"
|
f"Invalid sites: {', '.join(invalid_sites)}\nValid sites: {', '.join(valid_sites)}"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
await self.config.update_setting(ctx.guild.id, "enabled_sites", site_list)
|
await self.config.update_setting(interaction.guild.id, "enabled_sites", site_list)
|
||||||
await ctx.send(f"Enabled sites: {', '.join(site_list)}")
|
await interaction.response.send_message(f"Enabled sites: {', '.join(site_list)}")
|
||||||
|
|
||||||
@videoarchiver.command(name="listsites")
|
@videoarchiver.command(name="listsites")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
async def list_sites(self, ctx: commands.Context):
|
async def list_sites(self, interaction: discord.Interaction):
|
||||||
"""List all available sites and currently enabled sites"""
|
"""List all available sites and currently enabled sites"""
|
||||||
enabled_sites = await self.config.get_setting(ctx.guild.id, "enabled_sites")
|
enabled_sites = await self.config.get_setting(interaction.guild.id, "enabled_sites")
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="Video Sites Configuration", color=discord.Color.blue()
|
title="Video Sites Configuration", color=discord.Color.blue()
|
||||||
@@ -243,14 +246,14 @@ class VideoArchiverCommands(commands.Cog):
|
|||||||
inline=False,
|
inline=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
await ctx.send(embed=embed)
|
await interaction.response.send_message(embed=embed)
|
||||||
|
|
||||||
@videoarchiver.command(name="queue")
|
@videoarchiver.command(name="queue")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
@commands.admin_or_permissions(administrator=True)
|
@commands.admin_or_permissions(administrator=True)
|
||||||
async def show_queue(self, ctx: commands.Context):
|
async def show_queue(self, interaction: discord.Interaction):
|
||||||
"""Show current queue status with basic metrics"""
|
"""Show current queue status with basic metrics"""
|
||||||
status = self.processor.queue_manager.get_queue_status(ctx.guild.id)
|
status = self.processor.queue_manager.get_queue_status(interaction.guild.id)
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="Video Processing Queue Status",
|
title="Video Processing Queue Status",
|
||||||
@@ -281,15 +284,15 @@ class VideoArchiverCommands(commands.Cog):
|
|||||||
inline=False
|
inline=False
|
||||||
)
|
)
|
||||||
|
|
||||||
embed.set_footer(text="Use [p]va queuemetrics for detailed performance metrics")
|
embed.set_footer(text="Use /videoarchiver queuemetrics for detailed performance metrics")
|
||||||
await ctx.send(embed=embed)
|
await interaction.response.send_message(embed=embed)
|
||||||
|
|
||||||
@videoarchiver.command(name="queuemetrics")
|
@videoarchiver.command(name="queuemetrics")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
@commands.admin_or_permissions(administrator=True)
|
@commands.admin_or_permissions(administrator=True)
|
||||||
async def show_queue_metrics(self, ctx: commands.Context):
|
async def show_queue_metrics(self, interaction: discord.Interaction):
|
||||||
"""Show detailed queue performance metrics"""
|
"""Show detailed queue performance metrics"""
|
||||||
status = self.processor.queue_manager.get_queue_status(ctx.guild.id)
|
status = self.processor.queue_manager.get_queue_status(interaction.guild.id)
|
||||||
metrics = status['metrics']
|
metrics = status['metrics']
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
@@ -333,12 +336,12 @@ class VideoArchiverCommands(commands.Cog):
|
|||||||
)
|
)
|
||||||
|
|
||||||
embed.set_footer(text="Metrics are updated in real-time as videos are processed")
|
embed.set_footer(text="Metrics are updated in real-time as videos are processed")
|
||||||
await ctx.send(embed=embed)
|
await interaction.response.send_message(embed=embed)
|
||||||
|
|
||||||
@videoarchiver.command(name="clearqueue")
|
@videoarchiver.command(name="clearqueue")
|
||||||
@commands.guild_only()
|
@app_commands.guild_only()
|
||||||
@commands.admin_or_permissions(administrator=True)
|
@commands.admin_or_permissions(administrator=True)
|
||||||
async def clear_queue(self, ctx: commands.Context):
|
async def clear_queue(self, interaction: discord.Interaction):
|
||||||
"""Clear the video processing queue for this guild"""
|
"""Clear the video processing queue for this guild"""
|
||||||
cleared = await self.processor.queue_manager.clear_guild_queue(ctx.guild.id)
|
cleared = await self.processor.queue_manager.clear_guild_queue(interaction.guild.id)
|
||||||
await ctx.send(f"Cleared {cleared} items from the queue")
|
await interaction.response.send_message(f"Cleared {cleared} items from the queue")
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from redbot.core import commands, Config, data_manager
|
from redbot.core import commands, Config, data_manager, app_commands
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import logging
|
import logging
|
||||||
import asyncio
|
import asyncio
|
||||||
@@ -29,13 +29,7 @@ from videoarchiver.exceptions import (
|
|||||||
|
|
||||||
logger = logging.getLogger('VideoArchiver')
|
logger = logging.getLogger('VideoArchiver')
|
||||||
|
|
||||||
def setup(bot):
|
class VideoArchiver(commands.Cog):
|
||||||
"""Load the VideoArchiver cog."""
|
|
||||||
cog = VideoArchiver(bot)
|
|
||||||
asyncio.create_task(bot.add_cog(cog))
|
|
||||||
return cog
|
|
||||||
|
|
||||||
class VideoArchiver(VideoArchiverCommands):
|
|
||||||
"""Archive videos from Discord channels"""
|
"""Archive videos from Discord channels"""
|
||||||
|
|
||||||
def __init__(self, bot: commands.Bot) -> None:
|
def __init__(self, bot: commands.Bot) -> None:
|
||||||
@@ -82,8 +76,13 @@ class VideoArchiver(VideoArchiverCommands):
|
|||||||
self.update_checker = UpdateChecker(self.bot, self.config_manager)
|
self.update_checker = UpdateChecker(self.bot, self.config_manager)
|
||||||
self.processor = VideoProcessor(self.bot, self.config_manager, self.components)
|
self.processor = VideoProcessor(self.bot, self.config_manager, self.components)
|
||||||
|
|
||||||
# Initialize base class last
|
# Initialize commands handler
|
||||||
super().__init__(self.bot, self.config_manager, self.update_checker, self.processor)
|
self.commands_handler = VideoArchiverCommands(
|
||||||
|
self.bot,
|
||||||
|
self.config_manager,
|
||||||
|
self.update_checker,
|
||||||
|
self.processor
|
||||||
|
)
|
||||||
|
|
||||||
# Initialize components for existing guilds
|
# Initialize components for existing guilds
|
||||||
for guild in self.bot.guilds:
|
for guild in self.bot.guilds:
|
||||||
@@ -124,6 +123,10 @@ class VideoArchiver(VideoArchiverCommands):
|
|||||||
# Wait for initialization to complete
|
# Wait for initialization to complete
|
||||||
await asyncio.wait_for(self.ready.wait(), timeout=30)
|
await asyncio.wait_for(self.ready.wait(), timeout=30)
|
||||||
|
|
||||||
|
# Add commands to the bot
|
||||||
|
for command in self.commands_handler.videoarchiver.commands:
|
||||||
|
self.bot.tree.add_command(command)
|
||||||
|
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
await self._cleanup()
|
await self._cleanup()
|
||||||
raise ProcessingError("Cog initialization timed out")
|
raise ProcessingError("Cog initialization timed out")
|
||||||
@@ -133,6 +136,10 @@ class VideoArchiver(VideoArchiverCommands):
|
|||||||
|
|
||||||
async def cog_unload(self) -> None:
|
async def cog_unload(self) -> None:
|
||||||
"""Clean up when cog is unloaded"""
|
"""Clean up when cog is unloaded"""
|
||||||
|
# Remove commands from the bot
|
||||||
|
for command in self.commands_handler.videoarchiver.commands:
|
||||||
|
self.bot.tree.remove_command(command.name)
|
||||||
|
|
||||||
await self._cleanup()
|
await self._cleanup()
|
||||||
|
|
||||||
async def _cleanup(self) -> None:
|
async def _cleanup(self) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user