Enabled all Ruff lint rules and resolved findings with justified inline suppressions.
CI / Formatting (push) Successful in 5s
CI / Linting (push) Successful in 5s
CI / Tests (Python 3.12) (push) Successful in 14s
CI / Tests (Python 3.13) (push) Successful in 14s
CI / Tests (Python 3.14) (push) Successful in 11s
CI / Type Checking (push) Successful in 10s
CI / Spelling (push) Successful in 5s

This commit is contained in:
2026-04-13 15:31:06 -04:00
parent b68c717845
commit 0ff3c7a6b4
44 changed files with 452 additions and 430 deletions
@@ -45,7 +45,7 @@ async def addcommand(ctx: CommandContext) -> None:
"""
prefix = ctx.commands.prefix
args = ctx.args_list
if len(args) < 2:
if len(args) < 2: # noqa: PLR2004 # just checking argument count
await ctx.owncast_client.send_message(
f"Usage: {prefix}addcommand {prefix}<name> <response text>"
)
@@ -53,7 +53,7 @@ async def addcommand(ctx: CommandContext) -> None:
name = _clean_name(args[0], prefix)
parts = ctx.args.split(maxsplit=1)
if len(parts) < 2:
if len(parts) < 2: # noqa: PLR2004 # just checking argument count
await ctx.owncast_client.send_message(
f"Usage: {prefix}addcommand {prefix}<name> <response text>"
)
@@ -87,7 +87,7 @@ async def editcommand(ctx: CommandContext) -> None:
"""
prefix = ctx.commands.prefix
args = ctx.args_list
if len(args) < 2:
if len(args) < 2: # noqa: PLR2004 # just checking argument count
await ctx.owncast_client.send_message(
f"Usage: {prefix}editcommand {prefix}<name> <new response>"
)
@@ -95,7 +95,7 @@ async def editcommand(ctx: CommandContext) -> None:
name = _clean_name(args[0], prefix)
parts = ctx.args.split(maxsplit=1)
if len(parts) < 2:
if len(parts) < 2: # noqa: PLR2004 # just checking argument count
await ctx.owncast_client.send_message(
f"Usage: {prefix}editcommand {prefix}<name> <new response>"
)
@@ -166,7 +166,7 @@ async def commandmodonly(ctx: CommandContext) -> None:
"""
prefix = ctx.commands.prefix
args = ctx.args_list
if len(args) < 2:
if len(args) < 2: # noqa: PLR2004 # just checking argument count
await ctx.owncast_client.send_message(
f"Usage: {prefix}commandmodonly {prefix}<name> <on|off>"
)
@@ -241,7 +241,7 @@ async def editcounter(ctx: CommandContext) -> None:
"""
prefix = ctx.commands.prefix
args = ctx.args_list
if len(args) != 2:
if len(args) != 2: # noqa: PLR2004 # just checking argument count
await ctx.owncast_client.send_message(
f"Usage: {prefix}editcounter <name> <value>"
)
@@ -291,7 +291,7 @@ async def commandcooldown(ctx: CommandContext) -> None:
"""
prefix = ctx.commands.prefix
args = ctx.args_list
if len(args) < 2:
if len(args) < 2: # noqa: PLR2004 # just checking argument count
await ctx.owncast_client.send_message(
f"Usage: {prefix}commandcooldown {prefix}<name> <seconds>"
)
@@ -344,7 +344,7 @@ async def addalias(ctx: CommandContext) -> None:
"""
prefix = ctx.commands.prefix
args = ctx.args_list
if len(args) < 2:
if len(args) < 2: # noqa: PLR2004 # just checking argument count
await ctx.owncast_client.send_message(
f"Usage: {prefix}addalias {prefix}<command> {prefix}<alias>"
)
@@ -127,16 +127,12 @@ class CommandManager:
raise CommandAlreadyExistsError(name)
default_cooldown: int = self._ctx.config.get("default_cooldown", 5)
command = await self._repo.create(name, response, default_cooldown)
self._commands.register(
name=name,
handler=custom_command_handler,
cooldown=default_cooldown,
)
try:
command = await self._repo.create(name, response, default_cooldown)
except Exception:
self._commands.unregister(name)
raise
self._ctx.logger.info("Custom command '%s' created.", name)
return command
@@ -336,7 +332,7 @@ def get_manager(ctx: ModuleContext) -> CommandManager:
"""
manager = ctx.state.get("manager")
if not isinstance(manager, CommandManager):
raise RuntimeError("CommandManager is not initialized.")
raise RuntimeError("CommandManager is not initialized.") # noqa: TRY004 # state error, not a type error
return manager
@@ -262,7 +262,7 @@ def _parse_placeholder_date(date_str: str) -> datetime | None:
"""
# Split off the timezone abbreviation (last token).
parts = date_str.rsplit(maxsplit=1)
if len(parts) != 2:
if len(parts) != 2: # noqa: PLR2004 # just checking argument count
return None
date_part, tz_abbrev = parts
@@ -321,7 +321,7 @@ async def _evaluate_arg(
async def _evaluate_user(
name: str,
name: str, # noqa: ARG001 # required by placeholder handler signature
args: list[str],
ctx: PlaceholderContext,
) -> str:
@@ -332,7 +332,7 @@ async def _evaluate_user(
async def _evaluate_count(
name: str,
name: str, # noqa: ARG001 # required by placeholder handler signature
args: list[str],
ctx: PlaceholderContext,
) -> str:
@@ -350,7 +350,7 @@ async def _evaluate_count(
)
modifier_str = args[1] if len(args) > 1 else "+1"
if len(args) > 2:
if len(args) > 2: # noqa: PLR2004 # just checking argument count
raise PlaceholderError(
"Invalid $(count): too many arguments, expected $(count name [modifier])"
)
@@ -369,7 +369,7 @@ async def _evaluate_count(
async def _evaluate_getcount(
name: str,
name: str, # noqa: ARG001 # required by placeholder handler signature
args: list[str],
ctx: PlaceholderContext,
) -> str:
@@ -391,16 +391,16 @@ async def _evaluate_getcount(
async def _evaluate_rand(
name: str,
name: str, # noqa: ARG001 # required by placeholder handler signature
args: list[str],
ctx: PlaceholderContext,
ctx: PlaceholderContext, # noqa: ARG001 # required by placeholder handler signature
) -> str:
"""``$(rand start stop)`` -- random integer in range."""
if len(args) < 2:
if len(args) < 2: # noqa: PLR2004 # just checking argument count
raise PlaceholderError(
"Invalid $(rand): too few arguments, expected $(rand start stop)"
)
if len(args) > 2:
if len(args) > 2: # noqa: PLR2004 # just checking argument count
raise PlaceholderError(
"Invalid $(rand): too many arguments, expected $(rand start stop)"
)
@@ -411,13 +411,13 @@ async def _evaluate_rand(
raise PlaceholderError(
"Invalid $(rand): arguments must be integers, e.g., $(rand 1 100)"
) from e
return str(random.randint(min(start, stop), max(start, stop))) # noqa: S311
return str(random.randint(min(start, stop), max(start, stop))) # noqa: S311 # not security-sensitive; chat command RNG
async def _evaluate_countdown(
name: str,
args: list[str],
ctx: PlaceholderContext,
ctx: PlaceholderContext, # noqa: ARG001 # required by placeholder handler signature
) -> str:
"""``$(countdown date)`` / ``$(countup date)`` -- time delta."""
date_str = " ".join(args)
@@ -204,6 +204,7 @@ def _parse_nodes(
template: str,
pos: int,
depth: int,
*,
inside_placeholder: bool,
max_depth: int,
) -> tuple[list[Node], int, bool]: