Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Support for snippets (#21) #85

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft

Conversation

jamievlin
Copy link
Member

Summary

Add support for snippets
Closes #21

Types of changes

What types of changes does your code introduce to Rodhaj
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (Updates to README.md, the documentation, etc)
  • Other (if none of the other choices apply)

Checklist

Put an x in the boxes that apply

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes. (if appropriate)
  • All workflows (except pre-commit.ci) pass with my new changes
  • This PR does not address a duplicate issue or PR

Copy link

sonarcloud bot commented Apr 13, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Member

@No767 No767 left a comment

Choose a reason for hiding this comment

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

@jamievlin First pass on reviewing snippets feature. Make sure to follow through with the suggestions at some point in the future.

bot/migrations/V5__add_table_for_snippets.sql Outdated Show resolved Hide resolved
"""

def __init__(self, bot: Rodhaj):
self._bot = bot
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self._bot = bot
self.bot = bot

I know that you might not agree with me here, but generally the bot attr of an cog is left public by custom. This is generally how it's done.


class Snippets(commands.Cog):
"""
Cog for snippet-related commands (#21)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Cog for snippet-related commands (#21)
Commands pertaining to snippets for Rodhaj

Generally you can shrink this to something more descriptive. Try to not include the PR number as most users would be more confused by it


@commands.guild_only()
@commands.group(name="snippet")
async def snippet_cmd(self, ctx: GuildContext):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
async def snippet_cmd(self, ctx: GuildContext):
async def snippet(self, ctx: GuildContext) -> None:

This is not documented but the convention for this project is to have each command function have the most simplest name. Thus, we can remove cmd out of the function name and just make it much more simpler.

await ctx.send("placeholder for base command")

@commands.guild_only()
@snippet_cmd.command()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@snippet_cmd.command()
@snippet.command()

Adjusting the decorator to align with the parent function. Make sure to do this for the rest of the grouped commands

"""
result = await self._bot.pool.fetchrow(query, ctx.guild.id, name)
if result is None:
await ctx.reply(
Copy link
Member

@No767 No767 May 30, 2024

Choose a reason for hiding this comment

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

Suggested change
await ctx.reply(
await ctx.send(...)

I would strongly recommend not using commands.Context.reply in this case. It sends an unnecessary ping to the user, and is generally considered extremely annoying and bad practice. Instead, replace it with commands.Context.send()

description=f"Snippet `{name}` was not found and "
+ "hence was not deleted.",
),
ephemeral=True,
Copy link
Member

Choose a reason for hiding this comment

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

The ephemeral keyword argument only works on interactions. It doesn't really make sense to have it enabled when in regular prefixed messages, that this message can be seen by everyone

result = await self._bot.pool.fetchrow(query, ctx.guild.id, name)
if result is None:
await ctx.reply(
embed=discord.Embed(
Copy link
Member

Choose a reason for hiding this comment

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

I would strongly recommend replacing these embeds with just an message. It isn't necessary to do this as most users will find an jarring differences compared to the rest of the codebase

@snippet_cmd.command()
async def edit(self, ctx: GuildContext, name: str, content: Optional[str]):
if content is None:
await self.edit_prompt_user(ctx, name)
Copy link
Member

Choose a reason for hiding this comment

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

If you have an function and it's only used once, then it would be better to contain the logic within the command function body instead.

@commands.guild_only()
@snippet_cmd.command()
async def show(self, ctx: GuildContext, name: str):
query = """
Copy link
Member

Choose a reason for hiding this comment

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

The rest of the code should follow the suggestions that are noted above

Copy link

sonarcloud bot commented Aug 15, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Snippets (or rebranding them to tags)
2 participants