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:
pacnpal
2024-11-15 01:15:58 +00:00
parent 0f4fa8472e
commit f5a76bbd11
2 changed files with 11 additions and 31 deletions

View File

@@ -22,13 +22,7 @@ class Birthday(commands.Cog):
self.config.register_guild(**default_guild)
self.birthday_tasks = {}
birthdayset = app_commands.Group(
name="birthdayset",
description="Birthday cog settings",
guild_only=True
)
@birthdayset.command(name="role")
@app_commands.command(name="setrole")
@app_commands.guild_only()
@app_commands.describe(role="The role to set as the birthday role")
@checks.is_owner()
@@ -37,7 +31,7 @@ class Birthday(commands.Cog):
await self.config.guild(interaction.guild).birthday_role.set(role.id)
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.describe(tz="The timezone for role expiration (e.g., UTC, America/New_York)")
@checks.is_owner()
@@ -50,7 +44,7 @@ class Birthday(commands.Cog):
except ZoneInfoNotFoundError:
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.describe(channel="The channel for birthday announcements")
@checks.is_owner()
@@ -59,7 +53,7 @@ class Birthday(commands.Cog):
await self.config.guild(interaction.guild).birthday_channel.set(channel.id)
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.describe(role="The role to allow using the birthday command")
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)
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.describe(role="The role to remove from using the birthday command")
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()
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)
if not birthday_role:
@@ -193,8 +187,3 @@ class Birthday(commands.Cog):
continue
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))
async def setup(bot):
cog = Birthday(bot)
await bot.add_cog(cog)
await cog.reload_scheduled_tasks()

View File

@@ -17,13 +17,7 @@ class Overseerr(commands.Cog):
}
self.config.register_global(**default_global)
overseerr = app_commands.Group(
name="overseerr",
description="Overseerr configuration commands",
guild_only=True
)
@overseerr.command(name="url")
@app_commands.command(name="seturl")
@app_commands.guild_only()
@app_commands.describe(url="The URL of your Overseerr instance")
@commands.admin()
@@ -33,7 +27,7 @@ class Overseerr(commands.Cog):
await self.config.overseerr_url.set(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.describe(api_key="Your Overseerr API key")
@commands.admin()
@@ -42,7 +36,7 @@ class Overseerr(commands.Cog):
await self.config.overseerr_api_key.set(api_key)
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.describe(role_name="The name of the admin role")
@commands.admin()
@@ -60,7 +54,7 @@ class Overseerr(commands.Cog):
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 `/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
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()
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
approve_url = f"{overseerr_url}/api/v1/request/{request_id}/approve"
@@ -210,6 +204,3 @@ class Overseerr(commands.Cog):
status += " (Requested)"
return status
return "Status Unknown"
async def setup(bot: Red):
await bot.add_cog(Overseerr(bot))