Skip to content
Navigation Menu
{{ message }}
This repository was archived by the owner on May 14, 2026. It is now read-only.
forked from Newer1107/tux
-
Notifications
You must be signed in to change notification settings - Fork 1
Purge messages command #110
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
baf3c48
add purge.py
basil-squared 5775d09
update purge.py
basil-squared c2f8ad2
update .env.example
basil-squared 44ec859
saving some stuff to new branch so i can fw it somewhere else
basil-squared f67d83a
change how purge.py grabs permissions and begin using a json file for…
basil-squared 2935c56
Merge pull request #1 from yaboytabby/staging
basil-squared cba0a1c
Update README.md
basil-squared 97cb963
update purge.py
basil-squared 26eb6dc
Merge pull request #2 from yaboytabby/staging
basil-squared 378fb16
Moved user ID to constants.py
basil-squared dae2b95
Merge pull request #3 from yaboytabby/staging
basil-squared c7db631
refactor(purge.py): simplify role id access by using a single variabl…
kzndotsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,9 @@ | |
| __pycache__/ | ||
| *.py[cod] | ||
| *$py.class | ||
|
|
||
| # Replit Slop | ||
| *.replit | ||
| *.nix | ||
| # C extensions | ||
| *.so | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| { | ||
| "Permissions": { | ||
| "Owner": 1172248516370894869, | ||
| "Admin": [ | ||
| 1172248516370894869, | ||
| 1182064847052091484 | ||
| ], | ||
| "Mod": [ | ||
| 1172248516370894869, | ||
| 1182064847052091484, | ||
| 1172333934051336264 | ||
| ], | ||
| "Jr_Mod": [ | ||
| 1172248516370894869, | ||
| 1182064847052091484, | ||
| 1172333934051336264, | ||
| 1172643385425793156 | ||
| ], | ||
| "Testing": [ | ||
| 1223693346699214999, | ||
| 1224170906847416430 | ||
| ] | ||
| }, | ||
| "Feature_Permissions": { | ||
| "load": "Admin", | ||
| "unload": "Admin", | ||
| "sync": "Admin", | ||
| "clear": "Admin", | ||
| "reload": "Admin", | ||
| "ban": "Mod", | ||
| "kick": "Jr_Mod", | ||
| "ping": "Everyone", | ||
| "server": "Everyone", | ||
| "rolecount": "Everyone", | ||
| "help": "Everyone" | ||
| } | ||
| } | ||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import json | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| import discord | ||
| from discord import app_commands | ||
| from discord.ext import commands | ||
| from loguru import logger | ||
|
|
||
| from tux.utils.constants import Constants as CONST | ||
|
|
||
| config_file = Path("config/settings.json") | ||
| config = json.loads(config_file.read_text()) | ||
| role_ids = CONST.USER_IDS | ||
| testing_role_id = role_ids["TESTING"] if os.getenv("STAGING") == "True" else "foobar" | ||
|
|
||
|
|
||
| class Purge(commands.Cog): | ||
| def __init__(self, bot: commands.Bot) -> None: | ||
| self.bot = bot | ||
|
|
||
| async def send_embed( | ||
|
basil-squared marked this conversation as resolved.
|
||
| self, | ||
| interaction: discord.Interaction, | ||
| title: str, | ||
| description: str, | ||
| color: discord.Colour, | ||
| error_info: str | None = None, | ||
| ) -> None: | ||
| embed = discord.Embed( | ||
| title=title, description=description, color=color, timestamp=interaction.created_at | ||
| ) | ||
| if error_info: | ||
| embed.add_field(name="Error Details", value=f"`{error_info}`", inline=False) | ||
| embed.set_footer( | ||
| text=f"Requested by {interaction.user.display_name}", | ||
| icon_url=interaction.user.display_avatar.url, | ||
| ) | ||
|
|
||
| await interaction.followup.send(embed=embed) # Send the embed to the interaction | ||
|
|
||
| @app_commands.checks.has_any_role( | ||
| role_ids["ADMIN"], | ||
| role_ids["OWNER"], | ||
| role_ids["MOD"], | ||
| role_ids["JR MOD"], | ||
| *testing_role_id, | ||
| ) | ||
| @app_commands.command( | ||
| name="purge", description="Deletes a set number of messages in a channel." | ||
| ) | ||
| @app_commands.describe(number_messages="The number of messages to be purged.") | ||
| async def purge_messages( | ||
| self, interaction: discord.Interaction, number_messages: int = 10 | ||
| ) -> None: | ||
| if not interaction.channel or interaction.channel.type != discord.ChannelType.text: | ||
| return None | ||
|
|
||
| if number_messages <= 0: | ||
| await interaction.response.defer(ephemeral=True) | ||
| return await self.send_embed( | ||
|
basil-squared marked this conversation as resolved.
|
||
| interaction, | ||
| "Error", | ||
| "The number of messages to purge must be greater than 0.", | ||
| discord.Colour.red(), | ||
| ) | ||
|
|
||
| embed = discord.Embed | ||
|
|
||
| try: | ||
| await interaction.response.defer(ephemeral=True) | ||
| await interaction.edit_original_response(content="Purging messages...") | ||
|
|
||
| deleted = await interaction.channel.purge(limit=number_messages) | ||
|
basil-squared marked this conversation as resolved.
|
||
| description = f"Deleted {len(deleted)} messages in {interaction.channel.mention}" | ||
|
|
||
| await self.send_embed(interaction, "Success!", description, discord.Colour.blue()) | ||
|
|
||
| logger.info( | ||
| f"{interaction.user} purged {len(deleted)} messages from {interaction.channel.name}" | ||
| ) | ||
|
|
||
| except discord.Forbidden as e: | ||
| logger.error(f"Failed to purge messages in {interaction.channel.name}: {e}") | ||
|
|
||
| await self.send_embed( | ||
| interaction, | ||
| "Permission Denied", | ||
| "Failed to purge messages due to insufficient permissions.", | ||
| discord.Colour.red(), | ||
| error_info=str(e), | ||
| ) | ||
| embed.timestamp = interaction.created_at # Add timestamp to the error embed | ||
|
|
||
| except discord.HTTPException as e: | ||
| logger.error(f"Failed to purge messages in {interaction.channel.name}: {e}") | ||
|
|
||
| await self.send_embed( | ||
| interaction, | ||
| "Error", | ||
| f"An error occurred while purging messages: {e}", | ||
| discord.Colour.red(), | ||
| ) | ||
|
|
||
|
|
||
| async def setup(bot: commands.Bot) -> None: | ||
| await bot.add_cog(Purge(bot)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
You can’t perform that action at this time.

Uh oh!
There was an error while loading. Please reload this page.