Skip to content

Commit

Permalink
Modlog: thread support
Browse files Browse the repository at this point in the history
  • Loading branch information
Akarys42 committed Sep 15, 2021
1 parent 11147c5 commit def3a5c
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions bot/exts/moderation/modlog.py
Expand Up @@ -768,6 +768,64 @@ async def on_raw_message_edit(self, event: discord.RawMessageUpdateEvent) -> Non
after_response, channel_id=Channels.message_log
)

@Cog.listener()
async def on_thread_update(self, before: Thread, after: Thread) -> None:
"""Log thread archiving, un-archiving and name edits."""
if before.name != after.name:
await self.send_log_message(
Icons.hash_blurple,
Colour.blurple(),
"Thread name edited",
(
f"Thread {after.mention} (`{after.id}`) from {after.parent.mention} (`{after.parent.id}`): "
f"`{before.name}` -> `{after.name}`"
)
)
return

if not before.archived and after.archived:
colour = Colour.red()
action = "archived"
icon = Icons.hash_red
elif before.archived and not after.archived:
colour = Colour.green()
action = "un-archived"
icon = Icons.hash_green
else:
return

await self.send_log_message(
icon,
colour,
f"Thread {action}",
f"Thread {after.mention} (`{after.id}`) from {after.parent.mention} (`{after.parent.id}`) {action}"
)

@Cog.listener()
async def on_thread_delete(self, thread: Thread) -> None:
"""Log thread deletion."""
await self.send_log_message(
Icons.hash_red,
Colour.red(),
"Thread deleted",
f"Thread {thread.mention} (`{thread.id}`) from {thread.parent.mention} (`{thread.parent.id}`) deleted"
)

@Cog.listener()
async def on_thread_join(self, thread: Thread) -> None:
"""Log thread creation."""
# If we are in the thread already we can most probably assume we already logged it?
# We don't really have a better way of doing this since the API doesn't make any difference between the two
if thread.me:
return

await self.send_log_message(
Icons.hash_green,
Colour.green(),
"Thread created",
f"Thread {thread.mention} (`{thread.id}`) from {thread.parent.mention} (`{thread.parent.id}`) created"
)

@Cog.listener()
async def on_voice_state_update(
self,
Expand Down

0 comments on commit def3a5c

Please sign in to comment.