-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathwhois.py
More file actions
175 lines (149 loc) · 6.3 KB
/
whois.py
File metadata and controls
175 lines (149 loc) · 6.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
"""Module for the who extension for the discord bot."""
from __future__ import annotations
import datetime
from typing import TYPE_CHECKING, Self
import discord
import ui
from commands import application, moderator, notes
from core import auxiliary, cogs, moderation
from discord import app_commands
if TYPE_CHECKING:
import bot
async def setup(bot: bot.TechSupportBot) -> None:
"""Loading the Who plugin into the bot
Args:
bot (bot.TechSupportBot): The bot object to register the cogs to
"""
await bot.add_cog(Whois(bot=bot, extension_name="whois"))
class Whois(cogs.BaseCog):
"""The class for the /whois command"""
@app_commands.command(
name="whois",
description="Gets Discord user information",
extras={
"usage": "@user",
"module": "whois",
"ephemeral_error": True,
},
)
async def whois_command(
self: Self, interaction: discord.Interaction, member: discord.Member
) -> None:
"""This is the base of the /whois command
Args:
interaction (discord.Interaction): The interaction that called this command
member (discord.Member): The member to lookup. Will not work on discord.User
"""
await interaction.response.defer(ephemeral=True)
embed = auxiliary.generate_basic_embed(
title=f"User info for `{member.display_name}` (`{member.name}`)",
description="**Note: this is a bot account!**" if member.bot else "",
color=discord.Color.dark_blue(),
url=member.display_avatar.url,
)
embed.add_field(
name="Created", value=f"<t:{int(member.created_at.timestamp())}>"
)
embed.add_field(name="Joined", value=f"<t:{int(member.joined_at.timestamp())}>")
embed.add_field(
name="Status", value=interaction.guild.get_member(member.id).status
)
embed.add_field(name="Nickname", value=member.display_name)
role_string = ", ".join(role.name for role in member.roles[1:])
embed.add_field(name="Roles", value=role_string or "No roles")
config = self.bot.guild_configs[str(interaction.guild.id)]
if "application" in config.enabled_extensions:
try:
await application.command_permission_check(interaction)
embed = await add_application_info_field(interaction, member, embed)
except (app_commands.MissingAnyRole, app_commands.AppCommandError):
pass
if interaction.permissions.kick_members:
flags = []
if member.flags.automod_quarantined_username:
flags.append("Quarantined by Automod")
if not member.flags.completed_onboarding:
flags.append("Has not completed onboarding")
if member.flags.did_rejoin:
flags.append("Has left and rejoined the server")
if member.flags.guest:
flags.append("Is a guest")
if member.public_flags.staff:
flags.append("Is discord staff")
if member.public_flags.spammer:
flags.append("Is a flagged spammer")
if (
member.is_timed_out
and member.timed_out_until
and member.timed_out_until.astimezone(datetime.timezone.utc)
> datetime.datetime.now((datetime.timezone.utc))
):
flags.append(
f"Is timed out until <t:{int(member.timed_out_until.timestamp())}>"
)
flag_string = "\n - ".join(flag for flag in flags)
if flag_string:
embed.add_field(name="Flags", value=f"- {flag_string}", inline=False)
embeds = [embed]
if "notes" in config.enabled_extensions:
try:
await notes.is_reader(interaction)
all_notes = await moderation.get_all_notes(
self.bot, member, interaction.guild
)
notes_embeds = notes.build_note_embeds(
interaction.guild, member, all_notes
)
notes_embeds[0].description = (
f"Showing {min(len(all_notes), 6)}/{len(all_notes)} notes"
)
embeds.append(notes_embeds[0])
except (app_commands.MissingAnyRole, app_commands.AppCommandError):
pass
if (
"moderator" in config.enabled_extensions
and interaction.permissions.kick_members
):
all_warnings = await moderation.get_all_warnings(
self.bot, member, interaction.guild
)
warning_embeds = moderator.build_warning_embeds(
interaction.guild, member, all_warnings
)
warning_embeds[0].description = (
f"Showing {min(len(all_warnings), 6)}/{len(all_warnings)} warnings"
)
embeds.append(warning_embeds[0])
view = ui.PaginateView()
await view.send(
interaction.channel, interaction.user, embeds, interaction, True
)
return
async def add_application_info_field(
interaction: discord.Interaction,
user: discord.Member,
embed: discord.Embed,
) -> discord.Embed:
"""Makes modifications to the whois embed to add mod only information
Args:
interaction (discord.Interaction): The interaction where the /whois command was called
user (discord.Member): The user being looked up
embed (discord.Embed): The embed already filled with whois information
Returns:
discord.Embed: The embed with mod only information added
"""
# If the user has a pending application, show it
# If the user is banned from making applications, show it
application_cog = interaction.client.get_cog("ApplicationManager")
if application_cog:
has_application = await application_cog.search_for_pending_application(user)
is_banned = await application_cog.get_ban_entry(user)
embed.add_field(
name="Application information:",
value=(
f"Has pending application: {bool(has_application)}\nIs banned from"
f" making applications: {bool(is_banned)}"
),
inline=True,
)
return embed