Skip to content

Commit

Permalink
[Purge] remove copy doc and add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
japandotorg committed Oct 30, 2023
1 parent 5c8cdd7 commit bc8e93e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 19 deletions.
51 changes: 46 additions & 5 deletions purge/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
LINKS_RE,
_cleanup,
_create_case,
copy_doc,
get_message_from_reference,
get_messages_for_deletion,
has_hybrid_permissions,
Expand Down Expand Up @@ -388,14 +387,25 @@ 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,
ctx: commands.GuildContext,
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:**
- `<message_id>` The id of the message to cleanup after. This message won't be deleted.
- `<delete_pinned>` Whether to delete pinned messages or not. Defaults to False
"""
after: Optional[discord.Message] = None

if message_id:
Expand Down Expand Up @@ -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,
Expand All @@ -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:**
- `<message_id>` The id of the message to cleanup before. This message won't be deleted.
- `<number>` The max number of messages to cleanup. Must be a positive integer.
- `<delete_pinned>` Whether to delete pinned messages or not. Defaults to False
"""
before: Optional[discord.Message] = None

if message_id:
Expand Down Expand Up @@ -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,
Expand All @@ -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:**
- `<one>` The id of the message to cleanup after. This message won't be deleted.
- `<two>` The id of the message to cleanup before. This message won't be deleted.
- `<delete_pinned>` 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:
Expand Down Expand Up @@ -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:**
- `<number>` The number of messages to check for duplicates. Must be a positive integer.
"""
messages: List[discord.Message] = []
spam: List[discord.Message] = []

Expand Down
14 changes: 0 additions & 14 deletions purge/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit bc8e93e

Please sign in to comment.