Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moderation cog cleanup #462

Merged
merged 58 commits into from Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
653ffc6
Remove unused moderation utility functions
MarkKoz Sep 26, 2019
4a110a6
Make respect_role_hierarchy a decorator
MarkKoz Sep 27, 2019
689d203
Support positional target arg for respect_role_hierarchy
MarkKoz Sep 27, 2019
ae23753
Raise ValueError in respect_role_hierarchy instead of logging errors
MarkKoz Sep 27, 2019
4cb7b2d
Adjust type annotations of decorators
MarkKoz Sep 27, 2019
2f85c87
Fix thumbnail's type annotation for ModLog.send_log_message
MarkKoz Sep 27, 2019
8f5ff92
Add type alias for infraction objects
MarkKoz Sep 27, 2019
7a15665
Use None for default values for notify_infraction's parameters
MarkKoz Sep 27, 2019
a320d5b
Refactor user type annotations in moderation cog
MarkKoz Sep 27, 2019
0e9e5eb
Catch errors of fetch_user when calling in send_private_embed
MarkKoz Sep 27, 2019
40fa78e
Add general function for sending infraction messages
MarkKoz Sep 27, 2019
3fc0b87
Use send_messages function in infraction commands
MarkKoz Sep 27, 2019
dd49df8
Use lowercase infraction types
MarkKoz Sep 27, 2019
15aeccf
Format infraction timestamp inside send_messages
MarkKoz Sep 27, 2019
3d22d5d
Rework send_messages to actually apply the infractions
MarkKoz Sep 27, 2019
7baf8fc
Move infraction search and edit commands to a new cog
MarkKoz Sep 28, 2019
85a8be8
Replace with_role decorator with a cog check in the moderation cog
MarkKoz Sep 28, 2019
8114574
Create more generic functions for mute, kick, and ban
MarkKoz Sep 28, 2019
742b1e8
Revise moderation and infraction docstrings
MarkKoz Sep 28, 2019
290a2cb
Create a moderation sub-package for moderation-related cogs
MarkKoz Oct 1, 2019
22c3cee
Move Superstarify to moderation sub-package
MarkKoz Oct 1, 2019
394f687
Fix circular imports
MarkKoz Oct 1, 2019
5e3d4ca
Fix superstarify resource path
MarkKoz Oct 1, 2019
87426b7
Remove extension setup methods from the moderation modules
MarkKoz Oct 1, 2019
0b348e5
Fix stars.json resource test
MarkKoz Oct 1, 2019
3bdb900
Add infraction pardon icons to dictionary
MarkKoz Oct 1, 2019
f430c33
Rework deactivate_infraction to handle errors and send a mod log
MarkKoz Oct 1, 2019
d928ad0
Add a generic function to pardon infractions
MarkKoz Oct 1, 2019
5d8559e
Add reason for pardons in audit log
MarkKoz Oct 1, 2019
42b0117
Fix concatenation of log text dictionary
MarkKoz Oct 1, 2019
cbc6b1f
Refactor _scheduled_task & remove extraneous DM for expired infractions
MarkKoz Oct 1, 2019
6209d99
Fix string representation of bot user in mod log
MarkKoz Oct 1, 2019
42d3588
Display username in addition to id for unmutes in mod log
MarkKoz Oct 1, 2019
fc02216
Fix out-of-order and missing arguments for post_infraction calls
MarkKoz Oct 1, 2019
86ae9ac
Ignore the default unban event in the mod log
MarkKoz Oct 1, 2019
0596953
Remove redundant cancel_expiration method and use cancel_task
MarkKoz Oct 1, 2019
f02a734
Add comments and improve docstrings in the infractions cog
MarkKoz Oct 2, 2019
73ee225
Move DM notification functions to moderation utils module
MarkKoz Oct 2, 2019
bd7a9fe
Use consistent expiration format in superstarify
MarkKoz Oct 2, 2019
57af820
Tidy up imports
MarkKoz Oct 2, 2019
fea0bb3
Add an optional icon_url parameter with a default to notify_infraction
MarkKoz Oct 2, 2019
f60f604
Use has_active_infraction util function in superstarify
MarkKoz Oct 2, 2019
2efcc97
Add help category for Infractions and ModManagement cogs
MarkKoz Oct 2, 2019
610de3e
Format duration units as a list in infractions doctsrings
MarkKoz Oct 2, 2019
1bfa316
Format duration units as a list in management doctsrings
MarkKoz Oct 2, 2019
d92bc6e
Rename parameters to stop shadowing type built-in
MarkKoz Oct 2, 2019
276ecb6
Remove __all__ definition from moderation subpackage
MarkKoz Oct 2, 2019
c9b610a
Swap arguments for post_infraction calls
MarkKoz Oct 2, 2019
dc7ba8b
Mention moderators in the mod log when an infraction fails to expire
MarkKoz Oct 2, 2019
cbdd384
Merge remote-tracking branch 'origin/master' into moderation-cleanup
MarkKoz Oct 3, 2019
1eab211
Add note instead of failure to mod log during pardon when ban not found
MarkKoz Oct 3, 2019
b29f98b
Make warns, notes, and kicks always inactive
MarkKoz Oct 3, 2019
efd8a30
Fix rescheduling of infractions when cog is reloaded
MarkKoz Oct 3, 2019
700ecc0
Wait until the bot is ready before reschedule infractions
MarkKoz Oct 4, 2019
276e0dc
Make categories class attributes and support descriptions
MarkKoz Oct 5, 2019
66bfec3
Update the nickname policy URL
MarkKoz Oct 7, 2019
ee9d287
Only allow members currently in the guild to be warned
MarkKoz Oct 7, 2019
54063b1
Merge branch 'master' into moderation-cleanup
SebastiaanZ Oct 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions bot/__main__.py
Expand Up @@ -36,7 +36,6 @@
bot.load_extension("bot.cogs.error_handler")
bot.load_extension("bot.cogs.filtering")
bot.load_extension("bot.cogs.logging")
bot.load_extension("bot.cogs.modlog")
bot.load_extension("bot.cogs.security")

# Commands, etc
Expand Down Expand Up @@ -64,7 +63,6 @@
bot.load_extension("bot.cogs.reminders")
bot.load_extension("bot.cogs.site")
bot.load_extension("bot.cogs.snekbox")
bot.load_extension("bot.cogs.superstarify")
bot.load_extension("bot.cogs.sync")
bot.load_extension("bot.cogs.tags")
bot.load_extension("bot.cogs.token_remover")
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/antispam.py
Expand Up @@ -10,7 +10,7 @@
from discord.ext.commands import Bot, Cog

from bot import rules
from bot.cogs.modlog import ModLog
from bot.cogs.moderation import ModLog
from bot.constants import (
AntiSpam as AntiSpamConfig, Channels,
Colours, DEBUG_MODE, Event, Filter,
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/clean.py
Expand Up @@ -6,7 +6,7 @@
from discord import Colour, Embed, Message, User
from discord.ext.commands import Bot, Cog, Context, group

from bot.cogs.modlog import ModLog
from bot.cogs.moderation import ModLog
from bot.constants import (
Channels, CleanMessages, Colours, Event,
Icons, MODERATION_ROLES, NEGATIVE_REPLIES
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/defcon.py
Expand Up @@ -4,7 +4,7 @@
from discord import Colour, Embed, Member
from discord.ext.commands import Bot, Cog, Context, group

from bot.cogs.modlog import ModLog
from bot.cogs.moderation import ModLog
from bot.constants import Channels, Colours, Emojis, Event, Icons, Roles
from bot.decorators import with_role

Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/filtering.py
Expand Up @@ -7,7 +7,7 @@
from discord import Colour, DMChannel, Member, Message, TextChannel
from discord.ext.commands import Bot, Cog

from bot.cogs.modlog import ModLog
from bot.cogs.moderation import ModLog
from bot.constants import (
Channels, Colours, DEBUG_MODE,
Filter, Icons, URLs
Expand Down
48 changes: 40 additions & 8 deletions bot/cogs/help.py
@@ -1,5 +1,4 @@
import asyncio
import inspect
import itertools
from collections import namedtuple
from contextlib import suppress
Expand Down Expand Up @@ -61,6 +60,12 @@ class HelpSession:
The message object that's showing the help contents.
* destination: `discord.abc.Messageable`
Where the help message is to be sent to.

Cogs can be grouped into custom categories. All cogs with the same category will be displayed
under a single category name in the help output. Custom categories are defined inside the cogs
as a class attribute named `category`. A description can also be specified with the attribute
`category_description`. If a description is not found in at least one cog, the default will be
the regular description (class docstring) of the first cog found in the category.
"""

def __init__(
Expand Down Expand Up @@ -107,12 +112,31 @@ def _get_query(self, query: str) -> Union[Command, Cog]:
if command:
return command

cog = self._bot.cogs.get(query)
if cog:
# Find all cog categories that match.
cog_matches = []
description = None
for cog in self._bot.cogs.values():
if hasattr(cog, "category") and cog.category == query:
cog_matches.append(cog)
if hasattr(cog, "category_description"):
description = cog.category_description

# Try to search by cog name if no categories match.
if not cog_matches:
cog = self._bot.cogs.get(query)

# Don't consider it a match if the cog has a category.
if cog and not hasattr(cog, "category"):
cog_matches = [cog]

if cog_matches:
cog = cog_matches[0]
cmds = (cog.get_commands() for cog in cog_matches) # Commands of all cogs

return Cog(
name=cog.qualified_name,
description=inspect.getdoc(cog),
commands=[c for c in self._bot.commands if c.cog is cog]
name=cog.category if hasattr(cog, "category") else cog.qualified_name,
description=description or cog.description,
commands=tuple(itertools.chain.from_iterable(cmds)) # Flatten the list
)

self._handle_not_found(query)
Expand Down Expand Up @@ -207,8 +231,16 @@ def _category_key(self, cmd: Command) -> str:

A zero width space is used as a prefix for results with no cogs to force them last in ordering.
"""
cog = cmd.cog_name
return f'**{cog}**' if cog else f'**\u200bNo Category:**'
if cmd.cog:
try:
if cmd.cog.category:
return f'**{cmd.cog.category}**'
except AttributeError:
pass

return f'**{cmd.cog_name}**'
else:
return "**\u200bNo Category:**"

def _get_command_params(self, cmd: Command) -> str:
"""
Expand Down