-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Spunky Sputniks #9
base: main
Are you sure you want to change the base?
Conversation
This project contains documentation and recommended tooling configuration for projects to be submitted during a Python Discord Code Jam. Co-authored-by: Akarys42 <[email protected]> Co-authored-by: ChrisLovering <[email protected]> Co-authored-by: mbaruh <[email protected]> Co-authored-by: fisher60 <[email protected]>
Changes the local pre-commit hooks out for remote ones, as well as changes the action to use the pre-commit action, so pre-commit will no longer depend on your project manager's settings.
Global Actions
Renames workflow to Lint
Signed-off-by: GitHub <[email protected]>
Signed-off-by: GitHub <[email protected]>
Signed-off-by: GitHub <[email protected]>
Signed-off-by: GitHub <[email protected]>
Signed-off-by: GitHub <[email protected]>
- Use Python 3.10 instead of 3.9 - Update action versions to the newest major versions - Remove caching configuration since it's not doing anything useful (and we would rather not have teams deal with caching issues)
Signed-off-by: GitHub <[email protected]>
*although I added '.0' at the end of flake8-docstrings's requirement since it's present in the bot repository (where Kat got her versions anyway).
Update packaging and CI config for CJ9
Unfortunately installing isort from source errors out due to a poetry bug(?). Since isort 5.x has a stability policy active, let's just bump this so the template is usable (and upgrade the template properly later).
The screenshot is my own as I couldn't find a GitHub provided one that works unfortunately. Admittedly ugly.
Co-authored-by: Gimpy3887 <[email protected]> Co-authored-by: Peter Bierma <[email protected]>
Demobot is complete
Co-authored-by: enskyeing <[email protected]>
Co-authored-by: enskyeing <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's clear a lot of effort went into this project, well done. You wrote a library, gave it proper documentation, and prepared a demo all in the span of the code jam.
It's clear some things had to be rushed for it to be ready in time, but all the same I wrote comments below for your consideration. Hopefully you enjoyed building the project :)
description = "Database library using nothing but Discord. PyDis Codejam 2024." | ||
readme = "README.md" | ||
license = "MIT" | ||
dependencies = ["discord.py", "pydantic", "typing_extensions", "loguru", "aiocache"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should lock the dependencies to specific versions like you did in hatch.toml
except Exception as e: | ||
print(f"{e.__class__.__name__}: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few issues with this:
- It's better to print the full traceback in such cases, rather than just the error message.
- discord.py states which exceptions can be raised from
tree.sync
, so catching a base Exception is not justified here. - Why not
logger.exception
? - If syncing fails, your bot is left in an odd state that isn't handled here.
async def on_error(self, event_method: str, /, *args: asyncio.Any, **kwargs: asyncio.Any) -> None: | ||
return await super().on_error(event_method, *args, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does overriding the method do here, if you're just calling the super method as-is?
async with db.conn(os.getenv("DB_BOT_TOKEN")): | ||
try: | ||
await bot.start(os.getenv("BOOKMARK_BOT_TOKEN")) | ||
finally: | ||
await bot.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too indented
def build_bookmark_embed(record: models.BookmarkedMessage): | ||
embed = discord.Embed(title=record.title, description=record.message_content, colour=0x68C290) | ||
embed.set_author( | ||
name=record.author_name, | ||
icon_url=record.author_avatar_url | ||
) | ||
return embed | ||
|
||
def build_embeds_list(records: list[models.BookmarkedMessage]) -> list[discord.Embed]: | ||
embeds: list[discord.Embed] = [] | ||
for record in records: | ||
embed = build_bookmark_embed(record) | ||
embeds.append(embed) | ||
return embeds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I won't mark it everywhere, but you have several places with weird indentation.
self, | ||
interaction: discord.Interaction, | ||
table: discord.TextChannel, | ||
record: str, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nicer if you could specify a record ID instead.
await interaction.edit_original_response( | ||
content=f"Table `{table_name}` found! Gathering data..." | ||
) | ||
except IndexError as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KeyError
?
await interaction.response.send_message( | ||
content=f"Searching for table `{name}`..." | ||
) | ||
table_name = name.name.replace("-", " ").lower() | ||
|
||
try: | ||
table = self.db.tables[table_name] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A table resolution helper function would be useful here as well. A lot of code that repeats itself with small variations.
for game in table_values: | ||
for col in table_columns: | ||
data[col].append(getattr(game, col)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
game?
table_info: list | None = None | ||
table_schema: dict | None = None | ||
schemas: list[dict] | None = None | ||
embed_gen: discord.Embed | None = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"declaring" these ahead of time isn't necessary
No description provided.