mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 02:41:06 -05:00
refactor: Convert all cogs to use hybrid commands - Update birthday cog to use hybrid commands - Update overseerr cog to use hybrid commands - Update videoarchiver to use hybrid command group
This commit is contained in:
@@ -17,44 +17,44 @@ class Overseerr(commands.Cog):
|
||||
}
|
||||
self.config.register_global(**default_global)
|
||||
|
||||
@app_commands.command(name="seturl")
|
||||
@commands.hybrid_command(name="seturl")
|
||||
@app_commands.guild_only()
|
||||
@app_commands.describe(url="The URL of your Overseerr instance")
|
||||
@commands.admin()
|
||||
async def set_url(self, interaction: discord.Interaction, url: str):
|
||||
async def set_url(self, ctx: commands.Context, url: str):
|
||||
"""Set the Overseerr URL."""
|
||||
url = url.rstrip('/')
|
||||
await self.config.overseerr_url.set(url)
|
||||
await interaction.response.send_message(f"Overseerr URL set to: {url}")
|
||||
await ctx.send(f"Overseerr URL set to: {url}")
|
||||
|
||||
@app_commands.command(name="setapikey")
|
||||
@commands.hybrid_command(name="setapikey")
|
||||
@app_commands.guild_only()
|
||||
@app_commands.describe(api_key="Your Overseerr API key")
|
||||
@commands.admin()
|
||||
async def set_apikey(self, interaction: discord.Interaction, api_key: str):
|
||||
async def set_apikey(self, ctx: commands.Context, api_key: str):
|
||||
"""Set the Overseerr API key."""
|
||||
await self.config.overseerr_api_key.set(api_key)
|
||||
await interaction.response.send_message("Overseerr API key has been set.")
|
||||
await ctx.send("Overseerr API key has been set.")
|
||||
|
||||
@app_commands.command(name="setadminrole")
|
||||
@commands.hybrid_command(name="setadminrole")
|
||||
@app_commands.guild_only()
|
||||
@app_commands.describe(role_name="The name of the admin role")
|
||||
@commands.admin()
|
||||
async def set_adminrole(self, interaction: discord.Interaction, role_name: str):
|
||||
async def set_adminrole(self, ctx: commands.Context, role_name: str):
|
||||
"""Set the admin role name for Overseerr approvals."""
|
||||
await self.config.admin_role_name.set(role_name)
|
||||
await interaction.response.send_message(f"Admin role for Overseerr approvals set to: {role_name}")
|
||||
await ctx.send(f"Admin role for Overseerr approvals set to: {role_name}")
|
||||
|
||||
@app_commands.command(name="request")
|
||||
@commands.hybrid_command(name="request")
|
||||
@app_commands.guild_only()
|
||||
@app_commands.describe(query="The name of the movie or TV show to search for")
|
||||
async def request(self, interaction: discord.Interaction, query: str):
|
||||
async def request(self, ctx: commands.Context, query: str):
|
||||
"""Search and request a movie or TV show on Overseerr."""
|
||||
overseerr_url = await self.config.overseerr_url()
|
||||
overseerr_api_key = await self.config.overseerr_api_key()
|
||||
|
||||
if not overseerr_url or not overseerr_api_key:
|
||||
await interaction.response.send_message("Overseerr is not configured. Please ask an admin to set it up using `/seturl` and `/setapikey`.", ephemeral=True)
|
||||
await ctx.send("Overseerr is not configured. Please ask an admin to set it up using `/seturl` and `/setapikey`.", ephemeral=True)
|
||||
return
|
||||
|
||||
search_url = f"{overseerr_url}/api/v1/search"
|
||||
@@ -63,27 +63,27 @@ class Overseerr(commands.Cog):
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
# Defer the response since this might take a while
|
||||
await interaction.response.defer()
|
||||
# Send initial response
|
||||
initial_message = await ctx.send("Searching...")
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(search_url, headers=headers, params={"query": query}) as resp:
|
||||
if resp.status != 200:
|
||||
await interaction.followup.send(f"Error from Overseerr API: {resp.status}", ephemeral=True)
|
||||
await initial_message.edit(content=f"Error from Overseerr API: {resp.status}")
|
||||
return
|
||||
|
||||
try:
|
||||
search_results = await resp.json()
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"Failed to parse JSON: {e}", ephemeral=True)
|
||||
await initial_message.edit(content=f"Failed to parse JSON: {e}")
|
||||
return
|
||||
|
||||
if 'results' not in search_results:
|
||||
await interaction.followup.send(f"No results found for '{query}'. API Response: {search_results}", ephemeral=True)
|
||||
await initial_message.edit(content=f"No results found for '{query}'. API Response: {search_results}")
|
||||
return
|
||||
|
||||
if not search_results['results']:
|
||||
await interaction.followup.send(f"No results found for '{query}'.", ephemeral=True)
|
||||
await initial_message.edit(content=f"No results found for '{query}'.")
|
||||
return
|
||||
|
||||
# Create select menu for results
|
||||
@@ -114,6 +114,10 @@ class Overseerr(commands.Cog):
|
||||
)
|
||||
|
||||
async def select_callback(select_interaction: discord.Interaction):
|
||||
if select_interaction.user != ctx.author:
|
||||
await select_interaction.response.send_message("This menu is not for you!", ephemeral=True)
|
||||
return
|
||||
|
||||
selected_index = int(select_interaction.data['values'][0])
|
||||
selected_result = search_results['results'][selected_index]
|
||||
media_type = selected_result['mediaType']
|
||||
@@ -157,23 +161,23 @@ class Overseerr(commands.Cog):
|
||||
select.callback = select_callback
|
||||
view = discord.ui.View()
|
||||
view.add_item(select)
|
||||
await interaction.followup.send("Search results:", view=view)
|
||||
await initial_message.edit(content="Search results:", view=view)
|
||||
|
||||
@app_commands.command(name="approve")
|
||||
@commands.hybrid_command(name="approve")
|
||||
@app_commands.guild_only()
|
||||
@app_commands.describe(request_id="The ID of the request to approve")
|
||||
async def approve(self, interaction: discord.Interaction, request_id: int):
|
||||
async def approve(self, ctx: commands.Context, request_id: int):
|
||||
"""Approve a request on Overseerr."""
|
||||
admin_role_name = await self.config.admin_role_name()
|
||||
if not any(role.name == admin_role_name for role in interaction.user.roles):
|
||||
await interaction.response.send_message(f"You need the '{admin_role_name}' role to approve requests.", ephemeral=True)
|
||||
if not any(role.name == admin_role_name for role in ctx.author.roles):
|
||||
await ctx.send(f"You need the '{admin_role_name}' role to approve requests.", ephemeral=True)
|
||||
return
|
||||
|
||||
overseerr_url = await self.config.overseerr_url()
|
||||
overseerr_api_key = await self.config.overseerr_api_key()
|
||||
|
||||
if not overseerr_url or not overseerr_api_key:
|
||||
await interaction.response.send_message("Overseerr is not configured. Please ask an admin to set it up using `/seturl` and `/setapikey`.", ephemeral=True)
|
||||
await ctx.send("Overseerr is not configured. Please ask an admin to set it up using `/seturl` and `/setapikey`.", ephemeral=True)
|
||||
return
|
||||
|
||||
approve_url = f"{overseerr_url}/api/v1/request/{request_id}/approve"
|
||||
@@ -185,9 +189,9 @@ class Overseerr(commands.Cog):
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.post(approve_url, headers=headers) as resp:
|
||||
if resp.status == 200:
|
||||
await interaction.response.send_message(f"Request {request_id} has been approved!")
|
||||
await ctx.send(f"Request {request_id} has been approved!")
|
||||
else:
|
||||
await interaction.response.send_message(f"Failed to approve request {request_id}. Please check the request ID and try again.", ephemeral=True)
|
||||
await ctx.send(f"Failed to approve request {request_id}. Please check the request ID and try again.", ephemeral=True)
|
||||
|
||||
async def get_media_status(self, media_id, media_type):
|
||||
overseerr_url = await self.config.overseerr_url()
|
||||
|
||||
Reference in New Issue
Block a user