Skip to content
Merged
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
42 changes: 37 additions & 5 deletions techsupport_bot/commands/who.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ async def setup(bot):
description="Users with roles in this list will be able to use whois",
default=[],
)
config.add(
key="note_writers",
datatype="list",
title="Note Writer Roles",
description="Users with roles in this list will be able to create or delete notes",
default=[],
)

await bot.add_cog(Who(bot=bot, extension_name="who"))
bot.add_extension_config("who", config)
Expand All @@ -51,6 +58,29 @@ class Who(cogs.BaseCog):
name="note", description="Command Group for the Notes Extension"
)

@staticmethod
async def is_writer(interaction: discord.Interaction) -> bool:
"""writes notes"""

config = interaction.client.guild_configs[str(interaction.guild.id)]
if reader_roles := config.extensions.who.note_writers.value:
roles = (
discord.utils.get(interaction.guild.roles, name=role)
for role in reader_roles
)
status = any((role in interaction.user.roles for role in roles))
if not status:
raise app_commands.MissingAnyRole(reader_roles)
return True

# Reader_roles are empty (not set)
message = "There aren't any `note_writers` roles set in the config!"
embed = auxiliary.prepare_deny_embed(message=message)

await interaction.response.send_message(embed=embed, ephemeral=True)

raise app_commands.AppCommandError(message)

@staticmethod
async def is_reader(interaction: discord.Interaction) -> bool:
"""Checks whether invoker can read notes. If at least one reader
Expand All @@ -72,16 +102,18 @@ async def is_reader(interaction: discord.Interaction) -> bool:
discord.utils.get(interaction.guild.roles, name=role)
for role in reader_roles
)

return any((role in interaction.user.roles for role in roles))
status = any((role in interaction.user.roles for role in roles))
if not status:
raise app_commands.MissingAnyRole(reader_roles)
return True

# Reader_roles are empty (not set)
message = "There aren't any `note_readers` roles set in the config!"
embed = auxiliary.prepare_deny_embed(message=message)

await interaction.response.send_message(embed=embed, ephemeral=True)

raise commands.CommandError(message)
raise app_commands.AppCommandError(message)

@app_commands.check(is_reader)
@app_commands.command(
Expand Down Expand Up @@ -182,7 +214,7 @@ async def modify_embed_for_mods(
)
return embed

@app_commands.checks.has_permissions(kick_members=True)
@app_commands.check(is_writer)
@notes.command(
name="set",
description="Sets a note for a user, which can be read later from their whois",
Expand Down Expand Up @@ -244,7 +276,7 @@ async def set_note(
embed = auxiliary.prepare_confirm_embed(message=f"Note created for `{user}`")
await interaction.response.send_message(embed=embed, ephemeral=True)

@app_commands.checks.has_permissions(kick_members=True)
@app_commands.check(is_writer)
@notes.command(
name="clear",
description="Clears all existing notes for a user",
Expand Down