Skip to content
Closed
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ __pycache__
.pytest_cache
.coverage
.hypothesis
.idea/
25 changes: 23 additions & 2 deletions techsupport_bot/commands/who.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import datetime
import io

from typing import TYPE_CHECKING, Self

import discord
Expand Down Expand Up @@ -69,6 +70,15 @@ class Who(cogs.BaseCog):

"""

def __init__(self, bot: bot.TechSupportBot, extension_name):
super().__init__(bot, extension_name=extension_name)
self.ctx_menu = app_commands.ContextMenu(
name="Whois",
callback=self.get_note_command,
extras={"brief": "Gets user data", "usage": "@user", "module": "who"},
)
self.bot.tree.add_command(self.ctx_menu)

notes = app_commands.Group(
name="note", description="Command Group for the Notes Extension"
)
Expand Down Expand Up @@ -136,15 +146,14 @@ async def is_reader(interaction: discord.Interaction) -> bool:
raise app_commands.MissingAnyRole(reader_roles)
return True

# Reader_roles are empty (not set)
# Reader_roles is 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 app_commands.AppCommandError(message)

@app_commands.check(is_reader)
@app_commands.command(
name="whois",
description="Gets Discord user information",
Expand All @@ -159,6 +168,18 @@ async def get_note(
interaction (discord.Interaction): The interaction that called this command
user (discord.Member): The member to lookup. Will not work on discord.User
"""
await self.get_note_command(interaction, user)

async def get_note_command(
self, interaction: discord.Interaction, user: discord.Member
) -> None:
"""Method to get notes assigned to a user."""
# Check if user is a note reader
if not await self.is_reader(interaction):
embed = auxiliary.prepare_deny_embed(message="You cannot run whois")
await interaction.response.send_message(embed=embed, ephemeral=True)
return

embed = discord.Embed(
title=f"User info for `{user}`",
description="**Note: this is a bot account!**" if user.bot else "",
Expand Down