Skip to content

Commit

Permalink
All role modifications now have reasons (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajax146 authored Sep 1, 2023
1 parent 4793418 commit 3828198
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion techsupport_bot/extensions/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,4 +661,4 @@ async def post_update(self, ctx, application_data, status, reason=None):
continue
roles.append(role)

await user.add_roles(*roles)
await user.add_roles(*roles, reason=f"Application approved by {ctx.author}")
2 changes: 1 addition & 1 deletion techsupport_bot/extensions/gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async def response(self, config, ctx, content, _):
)
return

await ctx.author.add_roles(*roles)
await ctx.author.add_roles(*roles, reason="Gate passed successfully")

welcome_message = config.extensions.gate.welcome_message.value
delete_wait = config.extensions.gate.delete_wait.value
Expand Down
8 changes: 5 additions & 3 deletions techsupport_bot/extensions/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ async def role_command_base(
new_roles=view.select.values,
guild=interaction.guild,
user=member,
reason=f"Role command, ran by {interaction.user}",
)

def check_permissions(
Expand Down Expand Up @@ -188,7 +189,7 @@ def generate_options(self, user, guild, roles):
options.append(discord.SelectOption(label=role_name, default=default))
return options

async def modify_roles(self, config_roles, new_roles, guild, user):
async def modify_roles(self, config_roles, new_roles, guild, user, reason):
"""Modifies a set of roles based on an input and reference list
Args:
Expand All @@ -197,6 +198,7 @@ async def modify_roles(self, config_roles, new_roles, guild, user):
the user. Any roles not on this list will be removed
guild (discord.Guild): The guild to assign the roles in
user (discord.Member): The member to assign roles to
resaon (str): The reason to add to the audit log
"""
for role_name in config_roles:
real_role = discord.utils.get(guild.roles, name=role_name)
Expand All @@ -207,6 +209,6 @@ async def modify_roles(self, config_roles, new_roles, guild, user):

# If the role was requested to be added
if real_role.name in new_roles and real_role not in user_roles:
await user.add_roles(real_role)
await user.add_roles(real_role, reason=reason)
elif real_role.name not in new_roles and real_role in user_roles:
await user.remove_roles(real_role)
await user.remove_roles(real_role, reason=reason)
8 changes: 5 additions & 3 deletions techsupport_bot/extensions/who.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async def set_note(
await interaction.response.send_message(embed=embed, ephemeral=True)
return

await user.add_roles(role)
await user.add_roles(role, reason=f"First note was added by {interaction.user}")

embed = auxiliary.prepare_confirm_embed(message=f"Note created for `{user}`")
await interaction.response.send_message(embed=embed, ephemeral=True)
Expand Down Expand Up @@ -241,7 +241,9 @@ async def clear_notes(
interaction.guild.roles, name=config.extensions.who.note_role.value
)
if role:
await user.remove_roles(role)
await user.remove_roles(
role, reason=f"Notes were cleared by {interaction.user}"
)

embed = auxiliary.prepare_confirm_embed(message=f"Notes cleared for `{user}`")
await view.followup.send(embed=embed, ephemeral=True)
Expand Down Expand Up @@ -354,7 +356,7 @@ async def on_member_join(self, member: discord.Member) -> None:
if not user_notes:
return

await member.add_roles(role)
await member.add_roles(role, reason="Noted user has joined the guild")

log_channel = config.get("logging_channel")
await self.bot.logger.send_log(
Expand Down

0 comments on commit 3828198

Please sign in to comment.