Add option to toggle auto-deletion of play command messages in ExtendedAudio cog
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run
This commit introduces a new configuration option, `delete_play_messages`, allowing users to enable or disable the automatic deletion of messages related to play commands. A new command, `deleteplay`, is added to toggle this setting, helping to maintain a cleaner chat environment during music playback. Additionally, the cog is updated to handle message deletion after play commands are invoked.
This commit is contained in:
parent
c517b95f7c
commit
640a9cf7af
1 changed files with 40 additions and 1 deletions
|
@ -35,6 +35,7 @@ class ExtendedAudio(commands.Cog):
|
||||||
"bot_managed_only": False, # Whether to only allow bot-created channels
|
"bot_managed_only": False, # Whether to only allow bot-created channels
|
||||||
"last_status_message": None, # ID of the last status message (for cleanup)
|
"last_status_message": None, # ID of the last status message (for cleanup)
|
||||||
"clean_old_messages": True, # Whether to delete old status messages
|
"clean_old_messages": True, # Whether to delete old status messages
|
||||||
|
"delete_play_messages": False, # Whether to delete play command messages
|
||||||
}
|
}
|
||||||
default_global = {
|
default_global = {
|
||||||
"disable_notify_command": True, # Whether to disable the audioset notify command
|
"disable_notify_command": True, # Whether to disable the audioset notify command
|
||||||
|
@ -172,6 +173,18 @@ class ExtendedAudio(commands.Cog):
|
||||||
state = "will" if enabled else "will not"
|
state = "will" if enabled else "will not"
|
||||||
await ctx.send(f"Old status messages {state} be deleted when new songs play.")
|
await ctx.send(f"Old status messages {state} be deleted when new songs play.")
|
||||||
|
|
||||||
|
@extendedaudioset.command(name="deleteplay")
|
||||||
|
async def toggle_delete_play(self, ctx: commands.Context):
|
||||||
|
"""Toggle whether play command messages should be automatically deleted.
|
||||||
|
|
||||||
|
When enabled, messages for play commands (like queue notifications) will be deleted after being sent.
|
||||||
|
This helps keep the chat clean when queuing multiple songs.
|
||||||
|
"""
|
||||||
|
current = await self.config.guild(ctx.guild).delete_play_messages()
|
||||||
|
await self.config.guild(ctx.guild).delete_play_messages.set(not current)
|
||||||
|
state = "enabled" if not current else "disabled"
|
||||||
|
await ctx.send(f"Auto-deletion of play command messages has been {state}.")
|
||||||
|
|
||||||
def format_duration(self, milliseconds: int) -> str:
|
def format_duration(self, milliseconds: int) -> str:
|
||||||
"""Format milliseconds into a readable duration."""
|
"""Format milliseconds into a readable duration."""
|
||||||
seconds = milliseconds // 1000
|
seconds = milliseconds // 1000
|
||||||
|
@ -425,4 +438,30 @@ class ExtendedAudio(commands.Cog):
|
||||||
await ctx.send("I cannot play music in this channel.")
|
await ctx.send("I cannot play music in this channel.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
async def maybe_delete_response(self, ctx: commands.Context, message: discord.Message):
|
||||||
|
"""Delete a message if delete_play_messages is enabled."""
|
||||||
|
try:
|
||||||
|
if await self.config.guild(ctx.guild).delete_play_messages():
|
||||||
|
await message.delete(delay=5) # Delete after 5 seconds
|
||||||
|
except (discord.Forbidden, discord.NotFound):
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def cog_after_invoke(self, ctx: commands.Context):
|
||||||
|
"""Handle message deletion after command invocation."""
|
||||||
|
if ctx.guild and hasattr(ctx, 'command'):
|
||||||
|
# Check if it's an audio play command
|
||||||
|
audio_play_commands = [
|
||||||
|
"play", "bumpplay", "forceplay", "playnow", "playnext",
|
||||||
|
"playlist play", "playlist start"
|
||||||
|
]
|
||||||
|
|
||||||
|
if ctx.command.qualified_name.lower() in audio_play_commands:
|
||||||
|
# If there's a stored response message
|
||||||
|
if hasattr(ctx, 'message') and ctx.message:
|
||||||
|
await self.maybe_delete_response(ctx, ctx.message)
|
||||||
|
# If there's a command response
|
||||||
|
if hasattr(ctx, 'sent_messages'):
|
||||||
|
for message in ctx.sent_messages:
|
||||||
|
await self.maybe_delete_response(ctx, message)
|
Loading…
Add table
Reference in a new issue