mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 02:41:06 -05:00
refactor: Break out commands in all cogs - Convert birthday cog to use separate slash commands - Convert overseerr cog to use separate slash commands - Update interaction handling
This commit is contained in:
@@ -22,13 +22,7 @@ class Birthday(commands.Cog):
|
|||||||
self.config.register_guild(**default_guild)
|
self.config.register_guild(**default_guild)
|
||||||
self.birthday_tasks = {}
|
self.birthday_tasks = {}
|
||||||
|
|
||||||
birthdayset = app_commands.Group(
|
@app_commands.command(name="setrole")
|
||||||
name="birthdayset",
|
|
||||||
description="Birthday cog settings",
|
|
||||||
guild_only=True
|
|
||||||
)
|
|
||||||
|
|
||||||
@birthdayset.command(name="role")
|
|
||||||
@app_commands.guild_only()
|
@app_commands.guild_only()
|
||||||
@app_commands.describe(role="The role to set as the birthday role")
|
@app_commands.describe(role="The role to set as the birthday role")
|
||||||
@checks.is_owner()
|
@checks.is_owner()
|
||||||
@@ -37,7 +31,7 @@ class Birthday(commands.Cog):
|
|||||||
await self.config.guild(interaction.guild).birthday_role.set(role.id)
|
await self.config.guild(interaction.guild).birthday_role.set(role.id)
|
||||||
await interaction.response.send_message(f"Birthday role set to {role.name}")
|
await interaction.response.send_message(f"Birthday role set to {role.name}")
|
||||||
|
|
||||||
@birthdayset.command(name="timezone")
|
@app_commands.command(name="settimezone")
|
||||||
@app_commands.guild_only()
|
@app_commands.guild_only()
|
||||||
@app_commands.describe(tz="The timezone for role expiration (e.g., UTC, America/New_York)")
|
@app_commands.describe(tz="The timezone for role expiration (e.g., UTC, America/New_York)")
|
||||||
@checks.is_owner()
|
@checks.is_owner()
|
||||||
@@ -50,7 +44,7 @@ class Birthday(commands.Cog):
|
|||||||
except ZoneInfoNotFoundError:
|
except ZoneInfoNotFoundError:
|
||||||
await interaction.response.send_message(f"Invalid timezone: {tz}. Please use a valid IANA time zone identifier.")
|
await interaction.response.send_message(f"Invalid timezone: {tz}. Please use a valid IANA time zone identifier.")
|
||||||
|
|
||||||
@birthdayset.command(name="channel")
|
@app_commands.command(name="setchannel")
|
||||||
@app_commands.guild_only()
|
@app_commands.guild_only()
|
||||||
@app_commands.describe(channel="The channel for birthday announcements")
|
@app_commands.describe(channel="The channel for birthday announcements")
|
||||||
@checks.is_owner()
|
@checks.is_owner()
|
||||||
@@ -59,7 +53,7 @@ class Birthday(commands.Cog):
|
|||||||
await self.config.guild(interaction.guild).birthday_channel.set(channel.id)
|
await self.config.guild(interaction.guild).birthday_channel.set(channel.id)
|
||||||
await interaction.response.send_message(f"Birthday announcement channel set to {channel.mention}")
|
await interaction.response.send_message(f"Birthday announcement channel set to {channel.mention}")
|
||||||
|
|
||||||
@birthdayset.command(name="addrole")
|
@app_commands.command(name="addrole")
|
||||||
@app_commands.guild_only()
|
@app_commands.guild_only()
|
||||||
@app_commands.describe(role="The role to allow using the birthday command")
|
@app_commands.describe(role="The role to allow using the birthday command")
|
||||||
async def add_allowed_role(self, interaction: discord.Interaction, role: discord.Role):
|
async def add_allowed_role(self, interaction: discord.Interaction, role: discord.Role):
|
||||||
@@ -69,7 +63,7 @@ class Birthday(commands.Cog):
|
|||||||
allowed_roles.append(role.id)
|
allowed_roles.append(role.id)
|
||||||
await interaction.response.send_message(f"Added {role.name} to the list of roles that can use the birthday command.")
|
await interaction.response.send_message(f"Added {role.name} to the list of roles that can use the birthday command.")
|
||||||
|
|
||||||
@birthdayset.command(name="removerole")
|
@app_commands.command(name="removerole")
|
||||||
@app_commands.guild_only()
|
@app_commands.guild_only()
|
||||||
@app_commands.describe(role="The role to remove from using the birthday command")
|
@app_commands.describe(role="The role to remove from using the birthday command")
|
||||||
async def remove_allowed_role(self, interaction: discord.Interaction, role: discord.Role):
|
async def remove_allowed_role(self, interaction: discord.Interaction, role: discord.Role):
|
||||||
@@ -91,7 +85,7 @@ class Birthday(commands.Cog):
|
|||||||
|
|
||||||
birthday_role_id = await self.config.guild(interaction.guild).birthday_role()
|
birthday_role_id = await self.config.guild(interaction.guild).birthday_role()
|
||||||
if not birthday_role_id:
|
if not birthday_role_id:
|
||||||
return await interaction.response.send_message("The birthday role hasn't been set. An admin needs to set it using `/birthdayset role`.", ephemeral=True)
|
return await interaction.response.send_message("The birthday role hasn't been set. An admin needs to set it using `/setrole`.", ephemeral=True)
|
||||||
|
|
||||||
birthday_role = interaction.guild.get_role(birthday_role_id)
|
birthday_role = interaction.guild.get_role(birthday_role_id)
|
||||||
if not birthday_role:
|
if not birthday_role:
|
||||||
@@ -193,8 +187,3 @@ class Birthday(commands.Cog):
|
|||||||
continue
|
continue
|
||||||
remove_at = datetime.fromisoformat(task_info["remove_at"]).replace(tzinfo=ZoneInfo(await self.config.guild(guild).timezone()))
|
remove_at = datetime.fromisoformat(task_info["remove_at"]).replace(tzinfo=ZoneInfo(await self.config.guild(guild).timezone()))
|
||||||
self.birthday_tasks[guild.id] = self.bot.loop.create_task(self.remove_birthday_role(guild, member, role, remove_at))
|
self.birthday_tasks[guild.id] = self.bot.loop.create_task(self.remove_birthday_role(guild, member, role, remove_at))
|
||||||
|
|
||||||
async def setup(bot):
|
|
||||||
cog = Birthday(bot)
|
|
||||||
await bot.add_cog(cog)
|
|
||||||
await cog.reload_scheduled_tasks()
|
|
||||||
|
|||||||
@@ -17,13 +17,7 @@ class Overseerr(commands.Cog):
|
|||||||
}
|
}
|
||||||
self.config.register_global(**default_global)
|
self.config.register_global(**default_global)
|
||||||
|
|
||||||
overseerr = app_commands.Group(
|
@app_commands.command(name="seturl")
|
||||||
name="overseerr",
|
|
||||||
description="Overseerr configuration commands",
|
|
||||||
guild_only=True
|
|
||||||
)
|
|
||||||
|
|
||||||
@overseerr.command(name="url")
|
|
||||||
@app_commands.guild_only()
|
@app_commands.guild_only()
|
||||||
@app_commands.describe(url="The URL of your Overseerr instance")
|
@app_commands.describe(url="The URL of your Overseerr instance")
|
||||||
@commands.admin()
|
@commands.admin()
|
||||||
@@ -33,7 +27,7 @@ class Overseerr(commands.Cog):
|
|||||||
await self.config.overseerr_url.set(url)
|
await self.config.overseerr_url.set(url)
|
||||||
await interaction.response.send_message(f"Overseerr URL set to: {url}")
|
await interaction.response.send_message(f"Overseerr URL set to: {url}")
|
||||||
|
|
||||||
@overseerr.command(name="apikey")
|
@app_commands.command(name="setapikey")
|
||||||
@app_commands.guild_only()
|
@app_commands.guild_only()
|
||||||
@app_commands.describe(api_key="Your Overseerr API key")
|
@app_commands.describe(api_key="Your Overseerr API key")
|
||||||
@commands.admin()
|
@commands.admin()
|
||||||
@@ -42,7 +36,7 @@ class Overseerr(commands.Cog):
|
|||||||
await self.config.overseerr_api_key.set(api_key)
|
await self.config.overseerr_api_key.set(api_key)
|
||||||
await interaction.response.send_message("Overseerr API key has been set.")
|
await interaction.response.send_message("Overseerr API key has been set.")
|
||||||
|
|
||||||
@overseerr.command(name="adminrole")
|
@app_commands.command(name="setadminrole")
|
||||||
@app_commands.guild_only()
|
@app_commands.guild_only()
|
||||||
@app_commands.describe(role_name="The name of the admin role")
|
@app_commands.describe(role_name="The name of the admin role")
|
||||||
@commands.admin()
|
@commands.admin()
|
||||||
@@ -60,7 +54,7 @@ class Overseerr(commands.Cog):
|
|||||||
overseerr_api_key = await self.config.overseerr_api_key()
|
overseerr_api_key = await self.config.overseerr_api_key()
|
||||||
|
|
||||||
if not overseerr_url or not 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 `/overseerr url` and `/overseerr apikey`.", ephemeral=True)
|
await interaction.response.send_message("Overseerr is not configured. Please ask an admin to set it up using `/seturl` and `/setapikey`.", ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
search_url = f"{overseerr_url}/api/v1/search"
|
search_url = f"{overseerr_url}/api/v1/search"
|
||||||
@@ -179,7 +173,7 @@ class Overseerr(commands.Cog):
|
|||||||
overseerr_api_key = await self.config.overseerr_api_key()
|
overseerr_api_key = await self.config.overseerr_api_key()
|
||||||
|
|
||||||
if not overseerr_url or not 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 `/overseerr url` and `/overseerr apikey`.", ephemeral=True)
|
await interaction.response.send_message("Overseerr is not configured. Please ask an admin to set it up using `/seturl` and `/setapikey`.", ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
approve_url = f"{overseerr_url}/api/v1/request/{request_id}/approve"
|
approve_url = f"{overseerr_url}/api/v1/request/{request_id}/approve"
|
||||||
@@ -210,6 +204,3 @@ class Overseerr(commands.Cog):
|
|||||||
status += " (Requested)"
|
status += " (Requested)"
|
||||||
return status
|
return status
|
||||||
return "Status Unknown"
|
return "Status Unknown"
|
||||||
|
|
||||||
async def setup(bot: Red):
|
|
||||||
await bot.add_cog(Overseerr(bot))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user