Refactor leaderboard display logic in Leaderboard cog to improve user experience by ensuring only users with 10,000 or more credits are shown. Update error messages for clarity and enhance privacy options with an opt-out feature for the global leaderboard.
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run

This commit is contained in:
Valerie 2025-05-26 05:15:11 -04:00
parent 49902e8719
commit 6fbe4cda11
3 changed files with 137 additions and 0 deletions

View file

@ -0,0 +1,4 @@
from .extendedcommands import ExtendedCommands
async def setup(bot):
await bot.add_cog(ExtendedCommands(bot))

View file

@ -0,0 +1,114 @@
from redbot.core import commands, Config
from redbot.core.bot import Red
import discord
import shlex
import asyncio
class ExtendedCommands(commands.Cog):
"""Extended command functionality for Red bots."""
def __init__(self, bot: Red):
self.bot = bot
self.config = Config.get_conf(self, identifier=867530998, force_registration=True)
@commands.Cog.listener()
async def on_message(self, message: discord.Message):
if message.author.bot:
return
# Check if message starts with any bot prefix
prefixes = await self.bot.get_valid_prefixes(message.guild)
has_prefix = False
content = message.content
for prefix in prefixes:
if content.startswith(prefix):
has_prefix = True
content = content[len(prefix):]
break
if not has_prefix:
return
# Check if message contains &&
if "&&" not in content:
return
# Prevent the original message from triggering commands
await self.bot.process_commands(message)
# Split commands and execute them in sequence
commands_to_run = [cmd.strip() for cmd in content.split("&&")]
async with message.channel.typing():
for cmd in commands_to_run:
if not cmd: # Skip empty commands
continue
# Create a new message object with the command
new_message = discord.Message(
state=message._state,
channel=message.channel,
data={
"id": message.id,
"content": prefixes[0] + cmd, # Use first prefix
"author": message.author.to_dict(),
"pinned": False,
"mention_everyone": False,
"tts": False,
"type": 0,
"flags": 0,
}
)
try:
# Process the command
await self.bot.process_commands(new_message)
# Add a small delay between commands
await asyncio.sleep(0.5)
except Exception as e:
await message.channel.send(f"Error executing command `{cmd}`: {str(e)}")
break # Stop executing remaining commands on error
@commands.command()
async def chain(self, ctx: commands.Context, *, commands_str: str):
"""Chain multiple commands together using &&.
Example:
[p]chain ping && info && glb show
"""
if "&&" not in commands_str:
await ctx.send("Please provide multiple commands separated by &&")
return
commands_to_run = [cmd.strip() for cmd in commands_str.split("&&")]
async with ctx.typing():
for cmd in commands_to_run:
if not cmd: # Skip empty commands
continue
# Create a new message object with the command
new_message = discord.Message(
state=ctx.message._state,
channel=ctx.channel,
data={
"id": ctx.message.id,
"content": ctx.prefix + cmd,
"author": ctx.author.to_dict(),
"pinned": False,
"mention_everyone": False,
"tts": False,
"type": 0,
"flags": 0,
}
)
try:
# Process the command
await self.bot.process_commands(new_message)
# Add a small delay between commands
await asyncio.sleep(0.5)
except Exception as e:
await ctx.send(f"Error executing command `{cmd}`: {str(e)}")
break # Stop executing remaining commands on error

View file

@ -0,0 +1,19 @@
{
"author": [
"Valerie"
],
"name": "ExtendedCommands",
"disabled": false,
"short": "Chain multiple commands together using &&",
"description": "Allows users to chain multiple commands together using && operator. For example: [p]ping && info && glb show",
"tags": [
"utility",
"commands",
"chain",
"extended"
],
"min_bot_version": "3.5.0",
"hidden": false,
"install_msg": "Thanks for installing ExtendedCommands! You can now chain commands using && (e.g., [p]ping && info). Use [p]help ExtendedCommands for more information.",
"end_user_data_statement": "This cog does not store any user data."
}