mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-20 18:06:08 -05:00
Shorten the audit log reason appropriately, remove unused vars (#4189)
* [Mod] Check for reason length & remove unused vars This PR also remove unused variable. * Blame me * Apply Kowlin order. Text will get truncate in audit logs in case we're going over 512 characters. * This is already handled by ban_user() * Use `get_audit_reason()` in `[p]tempban` * Add a new kwarg to `get_audit_reason()` instead * Include `[p]voiceban` and `[p]voiceunban` * Include Mutes cog Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
@@ -67,7 +67,7 @@ async def slow_deletion(messages: Iterable[discord.Message]):
|
||||
pass
|
||||
|
||||
|
||||
def get_audit_reason(author: discord.Member, reason: str = None):
|
||||
def get_audit_reason(author: discord.Member, reason: str = None, *, shorten: bool = False):
|
||||
"""Construct a reason to appear in the audit log.
|
||||
|
||||
Parameters
|
||||
@@ -76,6 +76,9 @@ def get_audit_reason(author: discord.Member, reason: str = None):
|
||||
The author behind the audit log action.
|
||||
reason : str
|
||||
The reason behind the audit log action.
|
||||
shorten : bool
|
||||
When set to ``True``, the returned audit reason string will be
|
||||
shortened to fit the max length allowed by Discord audit logs.
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -83,11 +86,14 @@ def get_audit_reason(author: discord.Member, reason: str = None):
|
||||
The formatted audit log reason.
|
||||
|
||||
"""
|
||||
return (
|
||||
audit_reason = (
|
||||
"Action requested by {} (ID {}). Reason: {}".format(author, author.id, reason)
|
||||
if reason
|
||||
else "Action requested by {} (ID {}).".format(author, author.id)
|
||||
)
|
||||
if shorten and len(audit_reason) > 512:
|
||||
audit_reason = f"{audit_reason[:509]}..."
|
||||
return audit_reason
|
||||
|
||||
|
||||
async def is_allowed_by_hierarchy(
|
||||
|
||||
Reference in New Issue
Block a user