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
48 changes: 25 additions & 23 deletions src/discord_bot/cogs/moderator_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,19 @@
ctx : discord.ApplicationContext
Request message context.
"""
await ctx.defer(ephemeral=True)

Check warning on line 102 in src/discord_bot/cogs/moderator_commands.py

View check run for this annotation

Codecov / codecov/patch

src/discord_bot/cogs/moderator_commands.py#L102

Added line #L102 was not covered by tests

now = time.time()
msg = await ctx.respond("Syncing commands...", ephemeral=True)
await self.bot.sync_commands(
force=True,
guild_ids=[ctx.guild_id],
)
duration = int(time.time() - now)
await msg.edit(content="""Synced commands!
await ctx.respond("""Synced commands!

Check warning on line 110 in src/discord_bot/cogs/moderator_commands.py

View check run for this annotation

Codecov / codecov/patch

src/discord_bot/cogs/moderator_commands.py#L110

Added line #L110 was not covered by tests

Sync duration: {}s
Commands not showing up? Try restarting discord or clearing cache.
""".format(duration))
""".format(duration), ephemeral=True)

@mod_commands.command(
name="user-info",
Expand All @@ -135,47 +136,48 @@
user : discord.User
User to get information about.
"""
user = user or ctx.author
target_user = user or ctx.author

Check warning on line 139 in src/discord_bot/cogs/moderator_commands.py

View check run for this annotation

Codecov / codecov/patch

src/discord_bot/cogs/moderator_commands.py#L139

Added line #L139 was not covered by tests
embed = discord.Embed(
fields=[
discord.EmbedField(name="ID", value=str(user.id), inline=False), # User ID
discord.EmbedField(name="ID", value=str(target_user.id), inline=False), # User ID
discord.EmbedField(
name="Joined Discord at",
value=f'{discord.utils.format_dt(user.created_at, "R")}\n'
f'{discord.utils.format_dt(user.created_at, "F")}',
value=f'{discord.utils.format_dt(target_user.created_at, "R")}\n'
f'{discord.utils.format_dt(target_user.created_at, "F")}',
inline=False,
), # When the user's account was created
],
)
embed.set_author(name=user.name)
embed.set_thumbnail(url=user.display_avatar.url)
embed.set_author(name=target_user.name)
embed.set_thumbnail(url=target_user.display_avatar.url)

Check warning on line 152 in src/discord_bot/cogs/moderator_commands.py

View check run for this annotation

Codecov / codecov/patch

src/discord_bot/cogs/moderator_commands.py#L151-L152

Added lines #L151 - L152 were not covered by tests

embed.colour = user.color if user.color.value else colors['white']
embed.colour = target_user.color if target_user.color.value else colors['white']

Check warning on line 154 in src/discord_bot/cogs/moderator_commands.py

View check run for this annotation

Codecov / codecov/patch

src/discord_bot/cogs/moderator_commands.py#L154

Added line #L154 was not covered by tests

with self.bot.db as db:
user_data = db.get('discord_users', {}).get(str(user.id))
if user_data and user_data.get('github_username'):
users_table = db.table('discord_users')
user_doc = users_table.get(self.bot.db.query().id == str(target_user.id))
if user_doc and user_doc.get('github_username'):

Check warning on line 159 in src/discord_bot/cogs/moderator_commands.py

View check run for this annotation

Codecov / codecov/patch

src/discord_bot/cogs/moderator_commands.py#L157-L159

Added lines #L157 - L159 were not covered by tests
embed.add_field(
name="GitHub",
value=f"[{user_data['github_username']}](https://github.com/{user_data['github_username']})",
value=f"[{user_doc['github_username']}](https://github.com/{user_doc['github_username']})",
inline=False,
)

if isinstance(user, discord.User): # Checks if the user in the server
if isinstance(target_user, discord.User): # Checks if the user in the server

Check warning on line 166 in src/discord_bot/cogs/moderator_commands.py

View check run for this annotation

Codecov / codecov/patch

src/discord_bot/cogs/moderator_commands.py#L166

Added line #L166 was not covered by tests
embed.set_footer(text="This user is not in this server.")
await ctx.respond(embeds=[embed])
return

# We end up here if the user is a discord.Member object
embed.add_field(
name="Joined Server at",
value=f'{discord.utils.format_dt(user.joined_at, "R")}\n'
f'{discord.utils.format_dt(user.joined_at, "F")}',
value=f'{discord.utils.format_dt(target_user.joined_at, "R")}\n'
f'{discord.utils.format_dt(target_user.joined_at, "F")}',
inline=False,
) # When the user joined the server

# get User Roles
roles = [role.name for role in user.roles]
roles = [role.name for role in target_user.roles]

Check warning on line 180 in src/discord_bot/cogs/moderator_commands.py

View check run for this annotation

Codecov / codecov/patch

src/discord_bot/cogs/moderator_commands.py#L180

Added line #L180 was not covered by tests
roles.pop(0) # remove @everyone role
embed.add_field(
name="Server Roles",
Expand All @@ -185,21 +187,21 @@

# get User Status, such as Server Owner, Server Moderator, Server Admin, etc.
user_status = []
if user.guild.owner_id == user.id:
if target_user.guild.owner_id == target_user.id:

Check warning on line 190 in src/discord_bot/cogs/moderator_commands.py

View check run for this annotation

Codecov / codecov/patch

src/discord_bot/cogs/moderator_commands.py#L190

Added line #L190 was not covered by tests
user_status.append("Server Owner")
if user.guild_permissions.administrator:
if target_user.guild_permissions.administrator:

Check warning on line 192 in src/discord_bot/cogs/moderator_commands.py

View check run for this annotation

Codecov / codecov/patch

src/discord_bot/cogs/moderator_commands.py#L192

Added line #L192 was not covered by tests
user_status.append("Server Admin")
if user.guild_permissions.manage_guild:
if target_user.guild_permissions.manage_guild:

Check warning on line 194 in src/discord_bot/cogs/moderator_commands.py

View check run for this annotation

Codecov / codecov/patch

src/discord_bot/cogs/moderator_commands.py#L194

Added line #L194 was not covered by tests
user_status.append("Server Moderator")
embed.add_field(
name="User Status",
value='\n'.join(user_status),
inline=False,
)

if user.premium_since: # If the user is boosting the server
boosting_value = (f'{discord.utils.format_dt(user.premium_since, "R")}\n'
f'{discord.utils.format_dt(user.premium_since, "F")}')
if target_user.premium_since: # If the user is boosting the server
boosting_value = (f'{discord.utils.format_dt(target_user.premium_since, "R")}\n'

Check warning on line 203 in src/discord_bot/cogs/moderator_commands.py

View check run for this annotation

Codecov / codecov/patch

src/discord_bot/cogs/moderator_commands.py#L202-L203

Added lines #L202 - L203 were not covered by tests
f'{discord.utils.format_dt(target_user.premium_since, "F")}')
else:
boosting_value = "Not boosting"
embed.add_field(
Expand Down