Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,21 @@ Changes since 2026.11.07

### Moderator
- Fixed edge case bugs when warning people causing the warn command to not work
- Warn modlogs now show total warnings after event
- Fixed edge case bug where a warn could be both applied and not applied at the same time

### Modmail
- Removed the invidiual ban commands in favor of a joint feature ban system.
- Made a new system for confirming new modmail threads

### Modlog
- Fixes edge case bugs if the moderator or member deleted their accounts
- Adds new channel field to all events

### Notes
- Note modlogs now show total notes after event
- Note modlogs now use the note as the reason instead of adding a different field

### Report
- Added ability to ban people from report

Expand Down
2 changes: 2 additions & 0 deletions database/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ class ModLog(Table, tablename="modlog"):
data (Varchar): Any extra data specific to the event logged
moderator_id (Varchar): The ID of the moderator who banned
member_id (Varchar): The ID of the user who was banned
channel_id (Varchar): The ID of the channel related to this event
action_time (Timestamptz): The date and time of the ban
until_time (Timestamptz): The time this action will expire
unique_guild_case (Unique): Prevents duplicate case numbers within a guild
Expand All @@ -243,6 +244,7 @@ class ModLog(Table, tablename="modlog"):
data: Varchar = Varchar(length=None, null=True, default=None)
moderator_id: Varchar = Varchar(length=None, null=True, default=None)
member_id: Varchar = Varchar(length=None, null=True, default=None)
channel_id: Varchar = Varchar(length=None, null=True, default=None)
action_time: Timestamptz = Timestamptz()
until_time: Timestamptz = Timestamptz(null=True, default=None)

Expand Down
4 changes: 4 additions & 0 deletions modules/moderation/automod.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ async def response(
action_type="timeout",
guild=ctx.guild,
member=ctx.author,
channel=ctx.channel,
reason=total_punishment.violation_string,
expires_at=expires_at,
data=f"**Violating message:** {ctx.message.clean_content[:200]}",
Expand Down Expand Up @@ -201,6 +202,7 @@ async def response(
action_type="warn",
guild=ctx.guild,
member=ctx.author,
channel=ctx.channel,
reason=total_punishment.violation_string,
data=f"**Violating message:** {ctx.message.clean_content[:200]}",
)
Expand Down Expand Up @@ -245,6 +247,7 @@ async def response(
action_type="ban",
guild=ctx.guild,
member=ctx.author,
channel=ctx.channel,
reason=total_punishment.violation_string,
data=f"**Violating message:** {ctx.message.clean_content[:100]}",
)
Expand All @@ -255,6 +258,7 @@ async def response(
action_type="automod notice",
guild=ctx.guild,
member=ctx.author,
channel=ctx.channel,
reason=total_punishment.violation_string,
data=f"**Violating message:** {ctx.message.clean_content[:200]}",
)
Expand Down
1 change: 1 addition & 0 deletions modules/moderation/featureban.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ async def update_feature_ban(
guild=interaction.guild,
member=user,
moderator=interaction.user,
channel=interaction.channel,
reason=reason,
)

Expand Down
1 change: 1 addition & 0 deletions modules/moderation/honeypot.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ async def response(
action_type="Honeypot",
guild=ctx.guild,
member=ctx.author,
channel=ctx.channel,
data=(
f"**Content:** {ctx.message.clean_content[:500]}\n"
f"**Attachments:** {len(ctx.message.attachments)}"
Expand Down
33 changes: 27 additions & 6 deletions modules/moderation/moderator.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ async def handle_ban_user(
guild=interaction.guild,
member=target,
moderator=interaction.user,
channel=interaction.channel,
reason=reason,
)

Expand Down Expand Up @@ -175,6 +176,7 @@ async def handle_unban_user(
guild=interaction.guild,
member=target,
moderator=interaction.user,
channel=interaction.channel,
reason=reason,
)

Expand Down Expand Up @@ -233,6 +235,7 @@ async def handle_kick_user(
guild=interaction.guild,
member=target,
moderator=interaction.user,
channel=interaction.channel,
reason=reason,
)

Expand Down Expand Up @@ -332,6 +335,7 @@ async def handle_mute_user(
guild=interaction.guild,
member=target,
moderator=interaction.user,
channel=interaction.channel,
reason=reason,
expires_at=expires_at,
)
Expand Down Expand Up @@ -402,6 +406,7 @@ async def handle_unmute_user(
guild=interaction.guild,
member=target,
moderator=interaction.user,
channel=interaction.channel,
reason=reason,
)
if not result:
Expand Down Expand Up @@ -458,13 +463,19 @@ async def handle_warn_user(
)
return

warnings = await moderation.get_all_warnings(
self.bot, target, interaction.guild
)

await modlog.log_action(
bot=self.bot,
action_type="warn",
guild=interaction.guild,
member=target,
moderator=interaction.user,
channel=interaction.channel,
reason=reason,
data=f"**Total warnings:** {len(warnings)}",
)
warning_count = len(
await moderation.get_all_warnings(self.bot, target, interaction.guild)
Expand Down Expand Up @@ -516,6 +527,7 @@ async def handle_warn_user(
guild=interaction.guild,
member=target,
moderator=interaction.user,
channel=interaction.channel,
reason=ban_reason,
)
else:
Expand Down Expand Up @@ -595,20 +607,28 @@ async def handle_unwarn_user(
result = await moderation.unwarn_user(
bot_object=self.bot, user=target, warning=warning
)

if not result:
embed = auxiliary.prepare_deny_embed(
message=f"Something went wrong when unwarning {target}"
)
await interaction.response.send_message(embed=embed)
return

warnings = await moderation.get_all_warnings(
self.bot, target, interaction.guild
)

await modlog.log_action(
bot=self.bot,
action_type="unwarn",
guild=interaction.guild,
member=target,
moderator=interaction.user,
channel=interaction.channel,
reason=reason,
data=f"**Remaining warnings:** {len(warnings)}",
)
if not result:
embed = auxiliary.prepare_deny_embed(
message=f"Something went wrong when unwarning {target}"
)
await interaction.response.send_message(embed=embed)
return

embed = generate_response_embed(user=target, action="unwarn", reason=reason)
await interaction.response.send_message(content=target.mention, embed=embed)
Expand Down Expand Up @@ -702,6 +722,7 @@ async def handle_warning_clear(
guild=interaction.guild,
member=target,
moderator=interaction.user,
channel=interaction.channel,
reason=reason,
data=f"**Total warnings:** {len(warnings)}",
)
Expand Down
64 changes: 54 additions & 10 deletions modules/moderation/modlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ async def on_automod_action(self: Self, execution: discord.AutoModAction) -> Non
# I hate everything about this
rule = await execution.fetch_rule()
member = await rule.guild.fetch_member(execution.user_id)
channel = execution.guild.get_channel_or_thread(execution.channel_id)
if any(
action.type == discord.AutoModRuleActionType.timeout
for action in rule.actions
Expand All @@ -390,6 +391,7 @@ async def on_automod_action(self: Self, execution: discord.AutoModAction) -> Non
action_type="timeout",
guild=rule.guild,
member=member,
channel=channel,
reason=rule.name,
expires_at=expires_at,
data=f"**Violating content:** {execution.content[:200]}",
Expand All @@ -408,6 +410,7 @@ async def on_automod_action(self: Self, execution: discord.AutoModAction) -> Non
action_type="quarantine",
guild=rule.guild,
member=member,
channel=channel,
reason=rule.name,
data=f"**Violating name:** {member.display_name}",
)
Expand All @@ -421,6 +424,7 @@ async def on_automod_action(self: Self, execution: discord.AutoModAction) -> Non
action_type="automod block",
guild=rule.guild,
member=member,
channel=channel,
reason=rule.name,
data=f"**Violating content:** {execution.content[:200]}",
)
Expand All @@ -430,6 +434,7 @@ async def on_automod_action(self: Self, execution: discord.AutoModAction) -> Non
action_type="automod notice",
guild=rule.guild,
member=member,
channel=channel,
reason=rule.name,
data=f"**Violating content:** {execution.content[:200]}",
)
Expand Down Expand Up @@ -509,12 +514,17 @@ async def generate_action_embed(
)
description_strs = []

# If this action has a member punished, display if
# Keep the recorded ID when an account can no longer be fetched.
if action_entry.member_id:
member_account = await bot.fetch_user(int(action_entry.member_id))
description_strs.append(
f"**Offender:** {member_account.name} {member_account.mention} ({member_account.id})"
)
try:
member_account = await bot.fetch_user(int(action_entry.member_id))
description_strs.append(
f"**Offender:** {member_account.name} {member_account.mention} ({member_account.id})"
)
except (ValueError, discord.HTTPException, discord.InvalidData):
description_strs.append(
f"**Offender:** Unavailable user ({action_entry.member_id})"
)

# Always display the reason line, just if no reason explicilty display that
if action_entry.reason:
Expand All @@ -525,14 +535,42 @@ async def generate_action_embed(
# If a moderator has been tied to this action, display that
# If no moderator has been listed, this must be automod
if action_entry.moderator_id:
moderator_account = await bot.fetch_user(int(action_entry.moderator_id))
description_strs.append(
f"**Responsible moderator:** {moderator_account.name} "
f"{moderator_account.mention} ({moderator_account.id})"
)
try:
moderator_account = await bot.fetch_user(int(action_entry.moderator_id))
description_strs.append(
f"**Responsible moderator:** {moderator_account.name} "
f"{moderator_account.mention} ({moderator_account.id})"
)
except (ValueError, discord.HTTPException, discord.InvalidData):
description_strs.append(
f"**Responsible moderator:** Unavailable user ({action_entry.moderator_id})"
)
else:
description_strs.append("**Responsible moderator:** No associated moderator")

if action_entry.channel_id:
channel = None
try:
guild = bot.get_guild(int(action_entry.guild_id))
channel_id = int(action_entry.channel_id)
if guild:
channel = guild.get_channel_or_thread(channel_id)
if channel is None:
channel = await guild.fetch_channel(channel_id)
except (ValueError, discord.HTTPException, discord.InvalidData):
pass

if channel:
description_strs.append(
f"**Channel:** {channel.name} {channel.mention} ({channel.id})"
)
else:
description_strs.append(
f"**Channel:** Unavailable channel ({action_entry.channel_id})"
)
else:
description_strs.append("**Channel:** No associated channel")

# If this action has extra data, display it as is.
if action_entry.data:
# This might need special handling for specific events, we will see
Expand Down Expand Up @@ -589,6 +627,7 @@ async def log_action(
guild: discord.Guild,
member: discord.abc.User | None = None,
moderator: discord.abc.User | None = None,
channel: discord.abc.GuildChannel | None = None,
reason: str = "",
data: str = "",
expires_at: datetime.datetime = None,
Expand All @@ -601,6 +640,7 @@ async def log_action(
guild (discord.Guild): The guild this action occured in
member (discord.abc.User | None, optional): The member being punished, if applicable.
moderator (discord.abc.User | None, optional): The moderator taking action, if applicable.
channel (discord.abc.GuildChannel | None, optional): The channel the action is assicoated with, if applicable.
reason (str, optional): The reason this action was taken, if applicable.
data (str, optional): Any extra data associated with this action, if applicable.
expires_at (datetime.datetime, optional): When this action expires, if applicable.
Expand All @@ -614,10 +654,13 @@ async def log_action(
# If the action has a member or moderator, get the IDs
member_id = None
moderator_id = None
channel_id = None
if member:
member_id = str(member.id)
if moderator:
moderator_id = str(moderator.id)
if channel:
channel_id = str(channel.id)

# This is done to prevent race conditions where two actions get the same case number
# We can detect the unique error and just try again. If so, this means
Expand All @@ -634,6 +677,7 @@ async def log_action(
data=data,
moderator_id=moderator_id,
member_id=member_id,
channel_id=channel_id,
until_time=expires_at,
)
await entry.save()
Expand Down
7 changes: 6 additions & 1 deletion modules/moderation/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,17 @@ async def set_note(

await note.save()

notes = await moderation.get_all_notes(self.bot, user, interaction.guild)

await modlog.log_action(
bot=self.bot,
action_type="note",
guild=interaction.guild,
reason=body,
member=user,
moderator=interaction.user,
data=f"**Note:** {body}",
channel=interaction.channel,
data=f"**Total notes:** {len(notes)}",
)

role = discord.utils.get(
Expand Down Expand Up @@ -237,6 +241,7 @@ async def clear_notes(
guild=interaction.guild,
member=user,
moderator=interaction.user,
channel=interaction.channel,
data=f"**Total notes:** {len(notes)}",
)

Expand Down
2 changes: 2 additions & 0 deletions modules/moderation/purge.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ async def purge_command(
action_type="purge",
guild=interaction.guild,
moderator=interaction.user,
channel=interaction.channel,
data=f"**Messages deleted:** {len(deleted)}",
)
await interaction.followup.edit_message(
message_id=sent_message.id,
Expand Down
1 change: 1 addition & 0 deletions modules/moderation/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ async def report_command(
bot=self.bot,
action_type="reported",
guild=interaction.guild,
channel=interaction.channel,
reason=reason,
member=user,
)
Expand Down
Loading