mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-06 09:22:31 -05:00
[ModLog API] Add default casetypes, remove need for a specific auditlog action (#2901)
* I know this needs a changelog entry and docs still * update tests for new behavior * update docs, filter; add changelog * Ready for review * stop fetching the same Audit logs when the bot is the mod * I forgot to press save * fix a comprehension * Fix AttributeError * And the other place that happens * timing fixes
This commit is contained in:
@@ -71,10 +71,7 @@ class Mod(
|
||||
self.settings.register_channel(**self.default_channel_settings)
|
||||
self.settings.register_member(**self.default_member_settings)
|
||||
self.settings.register_user(**self.default_user_settings)
|
||||
self.ban_queue: List[Tuple[int, int]] = []
|
||||
self.unban_queue: List[Tuple[int, int]] = []
|
||||
self.cache: dict = {}
|
||||
self.registration_task = self.bot.loop.create_task(self._casetype_registration())
|
||||
self.tban_expiry_task = self.bot.loop.create_task(self.check_tempban_expirations())
|
||||
self.last_case: dict = defaultdict(dict)
|
||||
|
||||
@@ -99,13 +96,6 @@ class Mod(
|
||||
await self.settings.guild(discord.Object(id=guild_id)).delete_repeats.set(val)
|
||||
await self.settings.version.set(__version__)
|
||||
|
||||
@staticmethod
|
||||
async def _casetype_registration():
|
||||
try:
|
||||
await modlog.register_casetypes(CASETYPES)
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
||||
# TODO: Move this to core.
|
||||
# This would be in .movetocore , but the double-under name here makes that more trouble
|
||||
async def bot_check(self, ctx):
|
||||
@@ -126,59 +116,3 @@ class Mod(
|
||||
guild_ignored = await self.settings.guild(ctx.guild).ignored()
|
||||
chann_ignored = await self.settings.channel(ctx.channel).ignored()
|
||||
return not (guild_ignored or chann_ignored and not perms.manage_channels)
|
||||
|
||||
@classmethod
|
||||
async def get_audit_entry_info(
|
||||
cls, guild: discord.Guild, action: discord.AuditLogAction, target
|
||||
):
|
||||
"""Get info about an audit log entry.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
guild : discord.Guild
|
||||
Same as ``guild`` in `get_audit_log_entry`.
|
||||
action : int
|
||||
Same as ``action`` in `get_audit_log_entry`.
|
||||
target : `discord.User` or `discord.Member`
|
||||
Same as ``target`` in `get_audit_log_entry`.
|
||||
|
||||
Returns
|
||||
-------
|
||||
tuple
|
||||
A tuple in the form``(mod: discord.Member, reason: str,
|
||||
date_created: datetime.datetime)``. Returns ``(None, None, None)``
|
||||
if the audit log entry could not be found.
|
||||
"""
|
||||
try:
|
||||
entry = await cls.get_audit_log_entry(guild, action=action, target=target)
|
||||
except discord.HTTPException:
|
||||
entry = None
|
||||
if entry is None:
|
||||
return None, None, None
|
||||
return entry.user, entry.reason, entry.created_at
|
||||
|
||||
@staticmethod
|
||||
async def get_audit_log_entry(guild: discord.Guild, action: discord.AuditLogAction, target):
|
||||
"""Get an audit log entry.
|
||||
|
||||
Any exceptions encountered when looking through the audit log will be
|
||||
propogated out of this function.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
guild : discord.Guild
|
||||
The guild for the audit log.
|
||||
action : int
|
||||
The audit log action (see `discord.AuditLogAction`).
|
||||
target : `discord.Member` or `discord.User`
|
||||
The target of the audit log action.
|
||||
|
||||
Returns
|
||||
-------
|
||||
discord.AuditLogEntry
|
||||
The audit log entry. Returns ``None`` if not found.
|
||||
|
||||
"""
|
||||
async for entry in guild.audit_logs(action=action):
|
||||
if entry.target == target:
|
||||
return entry
|
||||
|
||||
Reference in New Issue
Block a user