Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All role modifications now have reasons #619

Merged
merged 4 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
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 @@ -108,7 +108,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 @@ -186,7 +186,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 @@ -240,7 +240,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 @@ -343,7 +345,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")

await self.bot.guild_log(
member.guild,
Expand Down
Loading