Skip to content

Commit

Permalink
fix(serverlogs): member roles edition hitting 1024 chars limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ZRunner committed Feb 11, 2025
1 parent 24c9e37 commit 01ff980
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions modules/serverlogs/serverlogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,26 @@ async def handle_member_roles(self, before: discord.Member, after: discord.Membe
description=f"**Member {before.mention} ({before.id}) updated**",
color=discord.Color.blurple()
)
emb.set_author(name=str(after), icon_url=after.display_avatar)

def add_fields(name: str, roles: list[discord.Role]):
"Add as many fields as necessary to avoid hitting the 1024 characters limit"
value = ""
for role in roles:
role_mention = role.mention
if len(value) + len(role_mention) + 1 > 1020:
emb.add_field(name=name, value=value, inline=False)
value = role_mention
else:
value += f" {role_mention}"
if value:
emb.add_field(name=name, value=value, inline=False)

if removed_roles:
emb.add_field(name="Roles revoked", value=' '.join(r.mention for r in removed_roles), inline=False)
add_fields("Roles revoked", removed_roles)
if added_roles:
emb.add_field(name="Roles granted", value=' '.join(r.mention for r in added_roles), inline=False)
emb.set_author(name=str(after), icon_url=after.display_avatar)
add_fields("Roles granted", added_roles)

# if we have access to audit logs and no role come from an integration, try to get the user who edited the roles
if any(not role.managed for role in added_roles+removed_roles):
if entry := await self.search_audit_logs(before.guild, discord.AuditLogAction.member_role_update,
Expand Down

0 comments on commit 01ff980

Please sign in to comment.