Skip to content

Conversation

@Atmois
Copy link
Contributor

@Atmois Atmois commented Aug 22, 2024

Add two subcommands to show role list and emote list
Closes #430
Closes #431

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Aug 22, 2024

Reviewer's Guide by Sourcery

This pull request adds two new subcommands to the existing 'info' command: 'roles' and 'emotes'. These subcommands allow users to list all roles and emotes in the server, respectively. The changes are implemented by adding two new asynchronous methods to the Info cog class.

File-Level Changes

Files Changes
tux/cogs/info/info.py Added a new 'roles' subcommand to list all roles in the server
tux/cogs/info/info.py Added a new 'emotes' subcommand to list all emotes in the server
tux/cogs/info/info.py Both new subcommands use EmbedCreator to create and send embedded messages
tux/cogs/info/info.py Both subcommands check if the interaction has a valid guild before proceeding

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Atmois - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

Comment on lines +110 to +134
@info.command(name="roles", description="Lists all roles in the server.")
async def roles(self, interaction: discord.Interaction) -> None:
"""
List all roles in the server.
Parameters
----------
interaction : discord.Interaction
The discord interaction object.
"""
if not interaction.guild:
return

guild = interaction.guild
roles = [role.mention for role in guild.roles]

embed = EmbedCreator.create_info_embed(
title="Server Roles",
description=f"Role list for {guild.name}",
interaction=interaction,
)

embed.add_field(name="Roles", value=", ".join(roles), inline=False)

await interaction.response.send_message(embed=embed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Refactor common code between 'roles' and 'emotes' commands

The 'roles' and 'emotes' commands have very similar structures. Consider refactoring the common parts into a separate method to reduce code duplication and improve maintainability.

async def _create_list_embed(self, interaction: discord.Interaction, title: str, items: list, item_name: str) -> None:
    if not interaction.guild:
        return
    embed = EmbedCreator.create_info_embed(
        title=title,
        description=f"{item_name} list for {interaction.guild.name}",
        interaction=interaction,
    )
    embed.add_field(name=item_name, value=", ".join(items), inline=False)
    await interaction.response.send_message(embed=embed)

Comment on lines +120 to +121
if not interaction.guild:
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Improve error handling when there's no associated guild

Instead of silently returning when there's no guild associated with the interaction, consider providing feedback to the user, explaining why the command couldn't be executed.

Suggested change
if not interaction.guild:
return
if not interaction.guild:
await interaction.response.send_message("This command can only be used in a server.", ephemeral=True)
return

@kzndotsh kzndotsh merged commit 62d39b4 into main Aug 23, 2024
@kzndotsh kzndotsh deleted the infocmd branch August 23, 2024 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/info roles /info emotes

3 participants