aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Shirayuki Nekomata <[email protected]>2019-11-16 08:26:38 +0700
committerGravatar Shirayuki Nekomata <[email protected]>2019-11-16 08:26:38 +0700
commite66ed4b4f534e6fa4178d8b2a82bc486b97affd5 (patch)
tree7a14aa083d8fdde8bd9cc7314e223ffe9d14b50d
parentCondensed logic, now only check for `add` `remove` `same` diff_type only. (diff)
Renamed variables to be more explicit, added type hinting for `content_before` and `content_after`
-rw-r--r--bot/cogs/moderation/modlog.py48
1 files changed, 24 insertions, 24 deletions
diff --git a/bot/cogs/moderation/modlog.py b/bot/cogs/moderation/modlog.py
index ce2a5e1f7..41d7709e4 100644
--- a/bot/cogs/moderation/modlog.py
+++ b/bot/cogs/moderation/modlog.py
@@ -620,42 +620,42 @@ class ModLog(Cog, name="ModLog"):
)
@Cog.listener()
- async def on_message_edit(self, before: discord.Message, after: discord.Message) -> None:
+ async def on_message_edit(self, msg_before: discord.Message, msg_after: discord.Message) -> None:
"""Log message edit event to message change log."""
if (
- not before.guild
- or before.guild.id != GuildConstant.id
- or before.channel.id in GuildConstant.ignored
- or before.author.bot
+ not msg_before.guild
+ or msg_before.guild.id != GuildConstant.id
+ or msg_before.channel.id in GuildConstant.ignored
+ or msg_before.author.bot
):
return
- self._cached_edits.append(before.id)
+ self._cached_edits.append(msg_before.id)
- if before.content == after.content:
+ if msg_before.content == msg_after.content:
return
- author = before.author
- channel = before.channel
+ author = msg_before.author
+ channel = msg_before.channel
channel_name = f"{channel.category}/#{channel.name}" if channel.category else f"#{channel.name}"
# Getting the difference per words and group them by type - add, remove, same
# Note that this is intended grouping without sorting
- diff = difflib.ndiff(before.clean_content.split(), after.clean_content.split())
+ diff = difflib.ndiff(msg_before.clean_content.split(), msg_after.clean_content.split())
diff_groups = tuple(
(diff_type, tuple(s[2:] for s in diff_words))
for diff_type, diff_words in itertools.groupby(diff, key=lambda s: s[0])
)
- _before = []
- _after = []
+ content_before: t.List[str] = []
+ content_after: t.List[str] = []
for index, (diff_type, words) in enumerate(diff_groups):
sub = ' '.join(words)
if diff_type == '-':
- _before.append(f"[{sub}](http://o.hi)")
+ content_before.append(f"[{sub}](http://o.hi)")
elif diff_type == '+':
- _after.append(f"[{sub}](http://o.hi)")
+ content_after.append(f"[{sub}](http://o.hi)")
elif diff_type == ' ':
if len(words) > 2:
sub = (
@@ -663,31 +663,31 @@ class ModLog(Cog, name="ModLog"):
" ... "
f"{words[-1] if index < len(diff_groups) - 1 else ''}"
)
- _before.append(sub)
- _after.append(sub)
+ content_before.append(sub)
+ content_after.append(sub)
response = (
f"**Author:** {author} (`{author.id}`)\n"
f"**Channel:** {channel_name} (`{channel.id}`)\n"
- f"**Message ID:** `{before.id}`\n"
+ f"**Message ID:** `{msg_before.id}`\n"
"\n"
- f"**Before**:\n{' '.join(_before)}\n"
- f"**After**:\n{' '.join(_after)}\n"
+ f"**Before**:\n{' '.join(content_before)}\n"
+ f"**After**:\n{' '.join(content_after)}\n"
"\n"
- f"[jump to message]({after.jump_url})"
+ f"[jump to message]({msg_after.jump_url})"
)
- if before.edited_at:
+ if msg_before.edited_at:
# Message was previously edited, to assist with self-bot detection, use the edited_at
# datetime as the baseline and create a human-readable delta between this edit event
# and the last time the message was edited
- timestamp = before.edited_at
- delta = humanize_delta(relativedelta(after.edited_at, before.edited_at))
+ timestamp = msg_before.edited_at
+ delta = humanize_delta(relativedelta(msg_after.edited_at, msg_before.edited_at))
footer = f"Last edited {delta} ago"
else:
# Message was not previously edited, use the created_at datetime as the baseline, no
# delta calculation needed
- timestamp = before.created_at
+ timestamp = msg_before.created_at
footer = None
await self.send_log_message(