Merge pull request 'Fix logging spam for moved channels and roles' (#4) from pr/log-spam-fix into master
Reviewed-on: #4
This commit is contained in:
commit
be3a8998e6
@ -369,6 +369,28 @@ class LoggingCog(commands.Cog):
|
|||||||
# log.debug(f"Logging disabled for event '{event_key}' in guild {guild_id}")
|
# log.debug(f"Logging disabled for event '{event_key}' in guild {guild_id}")
|
||||||
return enabled
|
return enabled
|
||||||
|
|
||||||
|
async def _is_recent_audit_log_for_target(
|
||||||
|
self,
|
||||||
|
guild: discord.Guild,
|
||||||
|
action: discord.AuditLogAction,
|
||||||
|
target_id: int,
|
||||||
|
max_age: float = 5.0,
|
||||||
|
) -> bool:
|
||||||
|
"""Return True if the latest audit log entry matches the target within ``max_age`` seconds."""
|
||||||
|
try:
|
||||||
|
async for entry in guild.audit_logs(limit=1, action=action):
|
||||||
|
if (
|
||||||
|
entry.target.id == target_id
|
||||||
|
and (discord.utils.utcnow() - entry.created_at).total_seconds()
|
||||||
|
<= max_age
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
except discord.Forbidden:
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
# --- Log Command Group ---
|
# --- Log Command Group ---
|
||||||
|
|
||||||
@commands.group(name="log", invoke_without_command=True)
|
@commands.group(name="log", invoke_without_command=True)
|
||||||
@ -996,6 +1018,14 @@ class LoggingCog(commands.Cog):
|
|||||||
changes.append(f"**Position:** `{before.position}` → `{after.position}`")
|
changes.append(f"**Position:** `{before.position}` → `{after.position}`")
|
||||||
|
|
||||||
if changes:
|
if changes:
|
||||||
|
if (
|
||||||
|
len(changes) == 1
|
||||||
|
and changes[0].startswith("**Position:")
|
||||||
|
and not await self._is_recent_audit_log_for_target(
|
||||||
|
guild, discord.AuditLogAction.role_update, after.id
|
||||||
|
)
|
||||||
|
):
|
||||||
|
return
|
||||||
embed = self._create_log_embed(
|
embed = self._create_log_embed(
|
||||||
title="🔧 Role Updated (Event)",
|
title="🔧 Role Updated (Event)",
|
||||||
description=f"Role {after.mention} updated.\n*Audit log may contain updater and specific permission changes.*\n"
|
description=f"Role {after.mention} updated.\n*Audit log may contain updater and specific permission changes.*\n"
|
||||||
@ -1121,6 +1151,14 @@ class LoggingCog(commands.Cog):
|
|||||||
changes.append(f"**Category:** {before_cat} → {after_cat}")
|
changes.append(f"**Category:** {before_cat} → {after_cat}")
|
||||||
|
|
||||||
if changes:
|
if changes:
|
||||||
|
if (
|
||||||
|
len(changes) == 1
|
||||||
|
and changes[0].startswith("**Position:")
|
||||||
|
and not await self._is_recent_audit_log_for_target(
|
||||||
|
guild, discord.AuditLogAction.channel_update, after.id
|
||||||
|
)
|
||||||
|
):
|
||||||
|
return
|
||||||
embed = self._create_log_embed(
|
embed = self._create_log_embed(
|
||||||
title=f"📝 {ch_type} Channel Updated (Event)",
|
title=f"📝 {ch_type} Channel Updated (Event)",
|
||||||
description=f"Channel {after.mention} updated.\n*Audit log may contain updater and specific permission changes.*\n"
|
description=f"Channel {after.mention} updated.\n*Audit log may contain updater and specific permission changes.*\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user