Spunky Sputniks#9
Conversation
This project contains documentation and recommended tooling configuration for projects to be submitted during a Python Discord Code Jam. Co-authored-by: Akarys42 <matteobertucci2004@gmail.com> Co-authored-by: ChrisLovering <chris.lovering.95@gmail.com> Co-authored-by: mbaruh <8bee278@gmail.com> Co-authored-by: fisher60 <39353605+fisher60@users.noreply.github.com>
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 <noreply@github.com>
Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: GitHub <noreply@github.com>
- 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 <noreply@github.com>
*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 <gimpy2345@gmail.com> Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Demobot is complete
Co-authored-by: enskyeing <skyetsatsis@gmail.com>
Co-authored-by: enskyeing <skyetsatsis@gmail.com>
mbaruh
left a comment
There was a problem hiding this comment.
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.
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.
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.
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() |
| 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.
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.
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: |
| 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.
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)) |
| 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.
"declaring" these ahead of time isn't necessary
No description provided.