Add slash command support for all cogs

This commit is contained in:
pacnpal
2024-11-14 21:43:01 +00:00
parent 73f142addd
commit 2622db6d3c
5 changed files with 203 additions and 64 deletions

View File

@@ -1,6 +1,6 @@
# Birthday Cog for Red-DiscordBot # Birthday Cog for Red-DiscordBot
This cog allows you to assign a special role to users on their birthday and send them a celebratory message with cake (or pie) emojis! This cog allows you to assign a special role to users on their birthday and send them a celebratory message with cake (or pie) emojis! Supports both traditional prefix commands and slash commands.
## Installation ## Installation
@@ -29,13 +29,17 @@ Replace `[p]` with your bot's prefix.
## Setup ## Setup
Before using the cog, you need to set it up: Before using the cog, you need to set it up. You can use either prefix commands or slash commands:
1. Set the birthday role: 1. Set the birthday role:
``` ```
[p]birthdayset role @Birthday [p]birthdayset role @Birthday
``` ```
or
```
/birthdayset role @Birthday
```
**Note:** The bot's role must be above the birthday role in the server's role hierarchy, but users assigning the birthday role do not need to have a role above it. **Note:** The bot's role must be above the birthday role in the server's role hierarchy, but users assigning the birthday role do not need to have a role above it.
@@ -44,18 +48,30 @@ Before using the cog, you need to set it up:
``` ```
[p]birthdayset addrole @Moderator [p]birthdayset addrole @Moderator
``` ```
or
```
/birthdayset addrole @Moderator
```
3. (Optional) Set the timezone for role expiration: 3. (Optional) Set the timezone for role expiration:
``` ```
[p]birthdayset timezone America/New_York [p]birthdayset timezone America/New_York
``` ```
or
```
/birthdayset timezone America/New_York
```
4. (Optional) Set a specific channel for birthday announcements: 4. (Optional) Set a specific channel for birthday announcements:
``` ```
[p]birthdayset channel #birthdays [p]birthdayset channel #birthdays
``` ```
or
```
/birthdayset channel #birthdays
```
If not set, the birthday message will be sent in the channel where the command is used. If not set, the birthday message will be sent in the channel where the command is used.
@@ -66,6 +82,10 @@ To assign the birthday role to a user:
``` ```
[p]birthday @User [p]birthday @User
``` ```
or
```
/birthday @User
```
This will assign the birthday role to the user and send a celebratory message with random cake (or pie) emojis. The role will be automatically removed at midnight in the specified timezone. This will assign the birthday role to the user and send a celebratory message with random cake (or pie) emojis. The role will be automatically removed at midnight in the specified timezone.
@@ -78,15 +98,19 @@ This will assign the birthday role to the user and send a celebratory message wi
- Option to set a specific channel for birthday announcements (defaults to the channel where the command is used) - Option to set a specific channel for birthday announcements (defaults to the channel where the command is used)
- Restricts usage of the birthday command to specified roles - Restricts usage of the birthday command to specified roles
- Users can assign the birthday role without needing a role higher than it in the hierarchy - Users can assign the birthday role without needing a role higher than it in the hierarchy
- Full slash command support for all commands
## Commands ## Commands
- `[p]birthdayset role`: Set the birthday role All commands support both prefix and slash command syntax:
- `[p]birthdayset addrole`: Add a role that can use the birthday command
- `[p]birthdayset removerole`: Remove a role from using the birthday command - `[p]birthdayset role` or `/birthdayset role`: Set the birthday role
- `[p]birthdayset timezone`: Set the timezone for the birthday role expiration - `[p]birthdayset addrole` or `/birthdayset addrole`: Add a role that can use the birthday command
- `[p]birthdayset channel`: Set the channel for birthday announcements - `[p]birthdayset removerole` or `/birthdayset removerole`: Remove a role from using the birthday command
- `[p]birthday`: Assign the birthday role to a user - `[p]birthdayset timezone` or `/birthdayset timezone`: Set the timezone for the birthday role expiration
- `[p]birthdayset channel` or `/birthdayset channel`: Set the channel for birthday announcements
- `[p]birthday` or `/birthday`: Assign the birthday role to a user
- `[p]bdaycheck` or `/bdaycheck`: Check upcoming birthday role removal tasks
## Support ## Support

View File

@@ -22,11 +22,12 @@ class Birthday(commands.Cog):
self.config.register_guild(**default_guild) self.config.register_guild(**default_guild)
self.birthday_tasks = {} self.birthday_tasks = {}
@commands.group() @commands.hybrid_group()
@checks.admin_or_permissions(manage_roles=True) @checks.admin_or_permissions(manage_roles=True)
async def birthdayset(self, ctx): async def birthdayset(self, ctx):
"""Birthday cog settings.""" """Birthday cog settings."""
pass if ctx.invoked_subcommand is None:
await ctx.send_help()
@birthdayset.command() @birthdayset.command()
@checks.is_owner() @checks.is_owner()
@@ -69,7 +70,7 @@ class Birthday(commands.Cog):
allowed_roles.remove(role.id) allowed_roles.remove(role.id)
await ctx.send(f"Removed {role.name} from the list of roles that can use the birthday command.") await ctx.send(f"Removed {role.name} from the list of roles that can use the birthday command.")
@commands.command() @commands.hybrid_command()
async def birthday(self, ctx, member: discord.Member): async def birthday(self, ctx, member: discord.Member):
"""Assign the birthday role to a user until midnight in the set timezone.""" """Assign the birthday role to a user until midnight in the set timezone."""
# Check if the user has permission to use this command # Check if the user has permission to use this command
@@ -79,7 +80,7 @@ class Birthday(commands.Cog):
birthday_role_id = await self.config.guild(ctx.guild).birthday_role() birthday_role_id = await self.config.guild(ctx.guild).birthday_role()
if not birthday_role_id: if not birthday_role_id:
return await ctx.send("The birthday role hasn't been set. An admin needs to set it using `[p]birthdayset role`.") return await ctx.send("The birthday role hasn't been set. An admin needs to set it using `/birthdayset role`.")
birthday_role = ctx.guild.get_role(birthday_role_id) birthday_role = ctx.guild.get_role(birthday_role_id)
if not birthday_role: if not birthday_role:
@@ -122,7 +123,7 @@ class Birthday(commands.Cog):
await self.schedule_birthday_role_removal(ctx.guild, member, birthday_role, midnight) await self.schedule_birthday_role_removal(ctx.guild, member, birthday_role, midnight)
@commands.command() @commands.hybrid_command()
async def bdaycheck(self, ctx): async def bdaycheck(self, ctx):
"""Check the upcoming birthday role removal tasks.""" """Check the upcoming birthday role removal tasks."""
# Check if the user has permission to use this command # Check if the user has permission to use this command

View File

@@ -1,6 +1,6 @@
# Overseerr Cog for Red Discord Bot # Overseerr Cog for Red Discord Bot
This cog allows interaction with [Overseerr](https://overseerr.dev/) directly from Discord. Users can search for movies or TV shows, request them, and have admins approve requests. It's designed for servers with Overseerr set up for managing media requests. This cog allows interaction with [Overseerr](https://overseerr.dev/) directly from Discord. Users can search for movies or TV shows, request them, and have admins approve requests. It's designed for servers with Overseerr set up for managing media requests. Supports both traditional prefix commands and slash commands.
## Installation ## Installation
@@ -30,62 +30,89 @@ Replace `[p]` with your bot's prefix.
## Setup ## Setup
Before using the cog, you'll need to configure it: Before using the cog, you'll need to configure it. You can use either prefix commands or slash commands:
1. Set the Overseerr URL and API key: 1. Set the Overseerr URL:
``` ```
[p]overseerr url https://your.overseerr.instance [p]overseerr url https://your.overseerr.instance
``` ```
or
```
/overseerr url https://your.overseerr.instance
```
2. Set the Overseerr API key: 2. Set the Overseerr API key:
``` ```
[p]overseerr apikey your_api_key [p]overseerr apikey your_api_key
``` ```
4. Set the admin role allowed to approve requests: or
``` ```
[p]adminrole @OverseerrAdmins /overseerr apikey your_api_key
```
3. Set the admin role allowed to approve requests:
```
[p]overseerr adminrole @OverseerrAdmins
```
or
```
/overseerr adminrole @OverseerrAdmins
``` ```
## Usage ## Usage
Users can request movies or TV shows using the following command: Users can request movies or TV shows using:
``` ```
[p]request Movie/TV Show Name [p]request Movie/TV Show Name
``` ```
or
```
/request Movie/TV Show Name
```
Admins can approve requests using: Admins can approve requests using:
``` ```
[p]approve request_id [p]approve request_id
``` ```
or
```
/approve request_id
```
## Features ## Features
- **Set Overseerr URL and API key**: Admins can configure the Overseerr URL and API key for API interactions. - **Set Overseerr URL and API key**: Admins can configure the Overseerr URL and API key for API interactions.
- **Search and request media**: Users can search for movies or TV shows and request them directly in Discord. - **Search and request media**: Users can search for movies or TV shows and request them directly in Discord.
- **Media availability status**: The cog checks if media is already available or has been requested before making new requests. - **Media availability status**: The cog checks if media is already available or has been requested before making new requests.
- **Approve requests**: Admins with the appropriate role can approve Overseerr requests within Discord. - **Approve requests**: Admins with the appropriate role can approve Overseerr requests within Discord.
- **Full slash command support**: All commands can be used as both traditional prefix commands and Discord slash commands.
## Commands ## Commands
All commands support both prefix and slash command syntax:
### Admin Commands ### Admin Commands
- **`[p]overseerr url <url>`** - **`[p]overseerr url <url>`** or **`/overseerr url <url>`**
- Set the Overseerr URL for the bot to communicate with Overseerr. - Set the Overseerr URL for the bot to communicate with Overseerr.
- Example: `[p]overseerr https://your-overseerr-url` - Example: `[p]overseerr url https://your-overseerr-url` or `/overseerr url https://your-overseerr-url`
- **`[p]overseerr apikey <apikey>`**
- Set the Overseerr API Key. retrieved from `https://your-overseerr-url/settings`. - **`[p]overseerr apikey <apikey>`** or **`/overseerr apikey <apikey>`**
- Example: `[p]overseerr apikey 4OK6WLU8Fv2TrZfcOskLZb2PK5WA3547Jz2fEfJqfkLiT34xUP0D48Z7jwC9lC8xU9` - Set the Overseerr API Key, retrieved from `https://your-overseerr-url/settings`.
- **`[p]overseerr adminrole <role_name>`** - Example: `[p]overseerr apikey 4OK6WLU8Fv2T...` or `/overseerr apikey 4OK6WLU8Fv2T...`
- **`[p]overseerr adminrole <role_name>`** or **`/overseerr adminrole <role_name>`**
- Set the name of the admin role that is allowed to approve Overseerr requests. - Set the name of the admin role that is allowed to approve Overseerr requests.
- Example: `[p]overseerr adminrole @Overseerr Admin` - Example: `[p]overseerr adminrole @Overseerr Admin` or `/overseerr adminrole @Overseerr Admin`
### User Commands ### User Commands
- **`[p]request <media name>`** - **`[p]request <media name>`** or **`/request <media name>`**
- Search for a movie or TV show and request it if it's not already available or requested. - Search for a movie or TV show and request it if it's not already available or requested.
- Example: `[p]request The Matrix` - Example: `[p]request The Matrix` or `/request The Matrix`
- **`[p]approve <request_id>`** - **`[p]approve <request_id>`** or **`/approve <request_id>`**
- Approve a media request by its request ID (requires the admin role). - Approve a media request by its request ID (requires the admin role).
- Example: `[p]approve 123` - Example: `[p]approve 123` or `/approve 123`
## Support ## Support

View File

@@ -1,9 +1,9 @@
import aiohttp import aiohttp
from redbot.core import commands, Config from redbot.core import commands, Config
from redbot.core.bot import Red from redbot.core.bot import Red
import asyncio # Import asyncio import asyncio
import json import json
import urllib.parse # Import for encoding URLs import urllib.parse
class Overseerr(commands.Cog): class Overseerr(commands.Cog):
def __init__(self, bot: Red): def __init__(self, bot: Red):
@@ -18,11 +18,12 @@ class Overseerr(commands.Cog):
### GROUP: SETTINGS COMMANDS ### ### GROUP: SETTINGS COMMANDS ###
@commands.group() @commands.hybrid_group()
@commands.admin() @commands.admin()
async def overseerr(self, ctx: commands.Context): async def overseerr(self, ctx: commands.Context):
"""Base command group for Overseerr configuration.""" """Base command group for Overseerr configuration."""
pass if ctx.invoked_subcommand is None:
await ctx.send_help()
@overseerr.command() @overseerr.command()
async def url(self, ctx: commands.Context, url: str): async def url(self, ctx: commands.Context, url: str):
@@ -45,14 +46,14 @@ class Overseerr(commands.Cog):
### REQUEST & APPROVAL COMMANDS ### ### REQUEST & APPROVAL COMMANDS ###
@commands.command() @commands.hybrid_command()
async def request(self, ctx: commands.Context, *, query: str): async def request(self, ctx: commands.Context, *, query: str):
"""Search and request a movie or TV show on Overseerr.""" """Search and request a movie or TV show on Overseerr."""
overseerr_url = await self.config.overseerr_url() overseerr_url = await self.config.overseerr_url()
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 ctx.send("Overseerr is not configured. Please ask an admin to set it up.") await ctx.send("Overseerr is not configured. Please ask an admin to set it up using `/overseerr url` and `/overseerr apikey`.")
return return
search_url = f"{overseerr_url}/api/v1/search" search_url = f"{overseerr_url}/api/v1/search"
@@ -135,7 +136,7 @@ class Overseerr(commands.Cog):
else: else:
await ctx.send(f"Failed to request {media_type} '{selected_result['title']}'. Please try again later.") await ctx.send(f"Failed to request {media_type} '{selected_result['title']}'. Please try again later.")
@commands.command() @commands.hybrid_command()
async def approve(self, ctx: commands.Context, request_id: int): async def approve(self, ctx: commands.Context, request_id: int):
"""Approve a request on Overseerr.""" """Approve a request on Overseerr."""
admin_role_name = await self.config.admin_role_name() admin_role_name = await self.config.admin_role_name()
@@ -147,7 +148,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 ctx.send("Overseerr is not configured. Please ask an admin to set it up.") await ctx.send("Overseerr is not configured. Please ask an admin to set it up using `/overseerr url` and `/overseerr apikey`.")
return return
approve_url = f"{overseerr_url}/api/v1/request/{request_id}/approve" approve_url = f"{overseerr_url}/api/v1/request/{request_id}/approve"
@@ -181,5 +182,5 @@ class Overseerr(commands.Cog):
return status return status
return "Status Unknown" return "Status Unknown"
def setup(bot: Red): async def setup(bot: Red):
bot.add_cog(Overseerr(bot)) await bot.add_cog(Overseerr(bot))

View File

@@ -1,6 +1,6 @@
# VideoArchiver Cog # VideoArchiver Cog
A Red-DiscordBot cog for automatically archiving videos from monitored Discord channels. A Red-DiscordBot cog for automatically archiving videos from monitored Discord channels. Supports both traditional prefix commands and Discord slash commands.
## Features ## Features
@@ -13,6 +13,7 @@ A Red-DiscordBot cog for automatically archiving videos from monitored Discord c
- Hardware-accelerated video processing (when available) - Hardware-accelerated video processing (when available)
- Customizable notification messages - Customizable notification messages
- Queue persistence across bot restarts - Queue persistence across bot restarts
- Full slash command support for all commands
## File Structure ## File Structure
@@ -43,43 +44,128 @@ The cog is organized into several modules for better maintainability:
## Configuration ## Configuration
Use the following commands to configure the cog: Use the following commands to configure the cog. All commands support both prefix and slash command syntax:
### Channel Settings ### Channel Settings
- `[p]va setchannel <channel>`: Set the archive channel - Set the archive channel:
- `[p]va setnotification <channel>`: Set the notification channel ```
- `[p]va setlogchannel <channel>`: Set the log channel [p]va setchannel <channel>
- `[p]va addmonitor <channel>`: Add a channel to monitor ```
- `[p]va removemonitor <channel>`: Remove a monitored channel or
```
/va setchannel <channel>
```
- Set the notification channel:
```
[p]va setnotification <channel>
```
or
```
/va setnotification <channel>
```
- Set the log channel:
```
[p]va setlogchannel <channel>
```
or
```
/va setlogchannel <channel>
```
- Add/remove a monitored channel:
```
[p]va addmonitor <channel>
[p]va removemonitor <channel>
```
or
```
/va addmonitor <channel>
/va removemonitor <channel>
```
### Role Management ### Role Management
- `[p]va addrole <role>`: Add a role allowed to trigger archiving - Add/remove allowed roles:
- `[p]va removerole <role>`: Remove an allowed role ```
- `[p]va listroles`: List allowed roles [p]va addrole <role>
[p]va removerole <role>
[p]va listroles
```
or
```
/va addrole <role>
/va removerole <role>
/va listroles
```
### Video Settings ### Video Settings
- `[p]va setformat <format>`: Set video format (e.g., mp4, webm) - Set video format and quality:
- `[p]va setquality <pixels>`: Set maximum video quality (e.g., 1080) ```
- `[p]va setmaxsize <MB>`: Set maximum file size in MB [p]va setformat <format>
- `[p]va setconcurrent <count>`: Set number of concurrent downloads (1-5) [p]va setquality <pixels>
[p]va setmaxsize <MB>
[p]va setconcurrent <count>
```
or
```
/va setformat <format>
/va setquality <pixels>
/va setmaxsize <MB>
/va setconcurrent <count>
```
### Message Settings ### Message Settings
- `[p]va setduration <hours>`: Set how long to keep archive messages - Configure message handling:
- `[p]va settemplate <template>`: Set archive message template ```
- `[p]va toggledelete`: Toggle deletion of local files after reposting [p]va setduration <hours>
[p]va settemplate <template>
[p]va toggledelete
```
or
```
/va setduration <hours>
/va settemplate <template>
/va toggledelete
```
### Site Management ### Site Management
- `[p]va enablesites [sites...]`: Enable specific sites (empty for all) - Manage supported sites:
- `[p]va listsites`: List available and enabled sites ```
[p]va enablesites [sites...]
[p]va listsites
```
or
```
/va enablesites [sites...]
/va listsites
```
### Queue Management ### Queue Management
- `[p]va queue`: Show detailed queue status and metrics - Manage the processing queue:
- `[p]va clearqueue`: Clear the processing queue ```
- `[p]va queuemetrics`: Display queue performance metrics [p]va queue
[p]va clearqueue
[p]va queuemetrics
```
or
```
/va queue
/va clearqueue
/va queuemetrics
```
### Update Management ### Update Management
- `[p]va updateytdlp`: Update yt-dlp to latest version - Manage yt-dlp updates:
- `[p]va toggleupdates`: Toggle update notifications ```
[p]va updateytdlp
[p]va toggleupdates
```
or
```
/va updateytdlp
/va toggleupdates
```
## Technical Details ## Technical Details