Skip to content

Commit

Permalink
refactor: cleanup env var trace and improve docstrings (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
natelandau authored Sep 1, 2024
1 parent 584951b commit ee0cda0
Show file tree
Hide file tree
Showing 38 changed files with 2,536 additions and 940 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ repos:
entry: yamllint --strict --config-file .yamllint.yml

- repo: "https://github.com/charliermarsh/ruff-pre-commit"
rev: "v0.5.7"
rev: "v0.6.3"
hooks:
- id: ruff
exclude: tests/
- id: ruff-format

- repo: "https://github.com/crate-ci/typos"
rev: v1.23.6
rev: typos-dict-v0.11.27
hooks:
- id: typos

- repo: "https://github.com/djlint/djLint"
rev: v1.34.1
rev: v1.35.2
hooks:
- id: djlint
args: ["--configuration", "pyproject.toml"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Settings for Valentina are controlled by environment variables. The following is
| VALENTINA_GITHUB_TOKEN | | Optional: Sets the Github API Access token to use for Github integration |
| VALENTINA_WEBUI_ENABLE | `false` | Optional: Enables the web UI. Set to `true` to enable. |
| VALENTINA_WEBUI_HOST | `127.0.0.1` | Set the host IP for the web UI. Note: when running in Docker this should always be `0.0.0.0` |
| VALENTINA_WEBUI_PORT | `8000` | Set the port for the web UI. |
| VALENTINA_WEBUI_PORT | `8088` | Set the port for the web UI. |
| VALENTINA_WEBUI_LOG_LEVEL | `INFO` | Sets the log level for the web UI. One of `TRACE`, `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL` |
| VALENTINA_WEBUI_BASE_URL | `http://127.0.0.1:8088` | Base URL for the web service. |
| VALENTINA_WEBUI_DEBUG | `false` | Enables debug mode for the web UI. Set to `true` to enable. |
Expand Down
860 changes: 435 additions & 425 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
pdoc = "^14.4.0"
poethepoet = "^0.26.1"
pre-commit = "^3.7.1"
ruff = "^0.6.0"
ruff = "^0.6.3"
shellcheck-py = "^0.9.0.6"
types-aiofiles = "^23.2.0.0"
typos = "^1.23.2"
Expand Down
66 changes: 59 additions & 7 deletions src/valentina/characters/add_from_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import asyncio
import uuid
from typing import Any
from collections.abc import Callable

import discord
from beanie import WriteRules
Expand Down Expand Up @@ -74,7 +74,14 @@ async def button_pressed(self, interaction) -> None: # type: ignore [no-untyped


class AddFromSheetWizard:
"""A character generation wizard that walks the user through setting a value for each trait. This is used for entering a character that has already been created from a physical character sheet."""
"""A character generation wizard for entering pre-existing characters.
This wizard guides the user through the process of setting values for each trait
of a character that has already been created on a physical character sheet.
It provides an interactive interface to input trait values systematically,
ensuring all necessary information is captured for the digital representation
of the character.
"""

def __init__(
self,
Expand Down Expand Up @@ -151,7 +158,19 @@ async def __view_callback(
async def __finalize_character(
self,
) -> None:
"""Add the character to the database and inform the user they are done."""
"""Finalize character creation and notify the user.
Add the character to the database, create associated traits, link to a campaign
if applicable, update the user's character list, create a character channel
if in a campaign, and send a confirmation message to the user.
This method handles the final steps of character creation after all traits
have been input by the user.
Raises:
discord.errors.HTTPException: If there's an error creating the character's channel.
beanie.exceptions.DocumentSaveError: If there's an error saving the character or user data.
"""
# Add the character to the database
await self.character.insert()

Expand Down Expand Up @@ -210,7 +229,22 @@ async def __finalize_character(
async def __send_messages(
self, *, interaction: discord.Interaction | None = None, message: str | None = None
) -> None:
"""Query a trait."""
"""Send messages to query trait information during character creation.
This method handles the process of sending messages to the user to gather
trait information for character creation. It prepares and sends an embed
with the current trait being queried, and sets up the view for user interaction.
Args:
interaction (discord.Interaction | None): The interaction object if this
method is called in response to a user interaction. Defaults to None.
message (str | None): An optional message to include in the embed description.
Defaults to None.
Raises:
discord.errors.HTTPException: If there's an error sending the message.
discord.errors.Forbidden: If the bot doesn't have permission to send messages.
"""
trait_name, trait_category = self.trait_list[0]

description = "This wizard will guide you through the character creation process.\n\n"
Expand Down Expand Up @@ -248,14 +282,32 @@ async def __send_messages(
await interaction.response.edit_message(embed=embed, view=self.view)

async def __timeout(self) -> None:
"""Inform the user they took too long."""
"""Inform the user that their character generation session has timed out due to inactivity.
This method is called when the user fails to respond within the allotted time during
the character creation process. It sends a message to the user, cancels the character
generation, and logs the timeout event.
Raises:
discord.errors.HTTPException: If there's an error sending the message.
discord.errors.Forbidden: If the bot doesn't have permission to send messages.
"""
errmsg = f"Due to inactivity, your character generation on **{self.ctx.guild.name}** has been canceled."
await self.edit_message(content=errmsg, embed=None, view=None)
logger.info("CHARGEN: Timed out")

@property
def edit_message(self) -> Any:
"""Get the proper edit method for editing our message outside of an interaction."""
def edit_message(self) -> Callable:
"""Get the appropriate edit method for modifying messages outside of an interaction.
Returns:
Callable: The edit method to use. If self.msg exists, returns self.msg.edit,
otherwise returns self.ctx.respond.
This property determines the correct method to use for editing messages
in different contexts, allowing for flexible message manipulation
throughout the character creation process.
"""
if self.msg:
return self.msg.edit
return self.ctx.respond
Loading

0 comments on commit ee0cda0

Please sign in to comment.