From bc8e93e55b27932efb3eadcd6eb007405f83116b Mon Sep 17 00:00:00 2001 From: Lemon Rose Date: Mon, 30 Oct 2023 21:37:13 +0530 Subject: [PATCH] [Purge] remove copy doc and add doc --- purge/core.py | 51 +++++++++++++++++++++++++++++++++++++++++++++----- purge/utils.py | 14 -------------- 2 files changed, 46 insertions(+), 19 deletions(-) diff --git a/purge/core.py b/purge/core.py index 2414082..ba61ed1 100644 --- a/purge/core.py +++ b/purge/core.py @@ -41,7 +41,6 @@ LINKS_RE, _cleanup, _create_case, - copy_doc, get_message_from_reference, get_messages_for_deletion, has_hybrid_permissions, @@ -388,7 +387,6 @@ async def _links( """ await _cleanup(ctx, number, lambda m: LINKS_RE.search(m.content)) - @copy_doc(CleanupCog.after) # type: ignore @_purge.command(name="after") # type: ignore async def _after( self, @@ -396,6 +394,18 @@ async def _after( message_id: Optional[RawMessageIdsConverter], delete_pinned: Optional[bool] = False, ): + """ + Delete all messages after a specified message. + + To get a message id, enable developer mode in Discord's + settings, 'appearance' tab. Then right click a message + and copy its id. + Replying to a message will cleanup all messages after it. + + **Arguments:** + - `` The id of the message to cleanup after. This message won't be deleted. + - `` Whether to delete pinned messages or not. Defaults to False + """ after: Optional[discord.Message] = None if message_id: @@ -446,7 +456,6 @@ async def _after( allowed_mentions=discord.AllowedMentions(replied_user=False), ) - @copy_doc(CleanupCog.before) # type: ignore @_purge.command(name="before") # type: ignore async def _before( self, @@ -455,6 +464,19 @@ async def _before( number: commands.Range[int, 1, 2000], delete_pinned: Optional[bool] = False, ): + """ + Deletes X messages before the specified message. + + To get a message id, enable developer mode in Discord's + settings, 'appearance' tab. Then right click a message + and copy its id. + Replying to a message will cleanup all messages before it. + + **Arguments:** + - `` The id of the message to cleanup before. This message won't be deleted. + - `` The max number of messages to cleanup. Must be a positive integer. + - `` Whether to delete pinned messages or not. Defaults to False + """ before: Optional[discord.Message] = None if message_id: @@ -506,7 +528,6 @@ async def _before( allowed_mentions=discord.AllowedMentions(replied_user=False), ) - @copy_doc(CleanupCog.between) # type: ignore @_purge.command(name="between") # type: ignore async def _between( self, @@ -515,6 +536,19 @@ async def _between( two: RawMessageIdsConverter, delete_pinned: Optional[bool] = None, ): + """ + Delete the messages between Message One and Message Two, providing the messages IDs. + + The first message ID should be the older message and the second one the newer. + + **Arguments:** + - `` The id of the message to cleanup after. This message won't be deleted. + - `` The id of the message to cleanup before. This message won't be deleted. + - `` Whether to delete pinned messages or not. Defaults to False. + + **Example:** + - `[p]cleanup between 123456789123456789 987654321987654321` + """ try: message_one: Optional[discord.Message] = await ctx.channel.fetch_message(one) # type: ignore except discord.NotFound: @@ -558,11 +592,18 @@ async def _between( allowed_mentions=discord.AllowedMentions(replied_user=False), ) - @copy_doc(CleanupCog.cleanup_duplicates) # type: ignore @_purge.command(name="duplicates", aliases=["duplicate", "spam"]) # type: ignore async def _duplicates( self, ctx: commands.GuildContext, number: commands.Range[int, 1, 2000] = 50 ): + """ + Deletes duplicate messages in the channel from the last X messages and keeps only one copy. + + Defaults to 50. + + **Arguments:** + - `` The number of messages to check for duplicates. Must be a positive integer. + """ messages: List[discord.Message] = [] spam: List[discord.Message] = [] diff --git a/purge/utils.py b/purge/utils.py index cf6848f..762b058 100644 --- a/purge/utils.py +++ b/purge/utils.py @@ -24,7 +24,6 @@ import datetime import re -import types from collections import Counter from typing import Any, Callable, Dict, List, Optional, Pattern, Tuple, TypeVar, Union @@ -259,16 +258,3 @@ def decorator(func: T) -> T: return func return decorator - - -def copy_doc( - original: Union[commands.Command, types.FunctionType] -) -> Callable[[Union[commands.Command, types.FunctionType]], Any]: - def decorator(overriden: Union[commands.Command, types.FunctionType]) -> None: - doc = original.help if isinstance(original, commands.Command) else original.__doc__ - if isinstance(overriden, commands.Command): - overriden._help_override = doc - else: - overriden.__doc__ = doc - - return decorator