mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-04-26 19:05:17 +00:00
242e0a5df1
PR #152 introduced trailing whitespace in several command files, set message.content_lower at runtime without declaring it on the MeshMessage dataclass, and left unused/unsorted imports in test and service files. All cause ruff/mypy CI failures on branches that rebase onto dev after that merge. Linting fixes (ruff --fix): - modules/command_manager.py: restore PUBLIC_CHANNEL_KEY_HEX re-export with noqa guard (core.py imports it from here; auto-fix silently dropped it) - modules/commands/multitest_command.py: strip W291/W293 trailing whitespace - modules/commands/path_command.py: strip W293 trailing whitespace - modules/commands/prefix_command.py: strip W291 trailing whitespace - modules/commands/roll_command.py: strip W293 trailing whitespace - modules/commands/sports_command.py: strip W293 trailing whitespace - modules/core.py: strip W293 blank-line whitespace - modules/service_plugins/packet_capture_service.py: sort imports (I001) - modules/version_info.py: remove unused typing.Any import (F401) - tests/integration/test_flood_scope_reply.py: remove unused call import - tests/unit/test_log_data_scope_fields.py: remove unused asyncio import - tests/unit/test_public_channel_guard.py: sort imports, remove unused patch and validate_config imports Dataclass fix (mypy attr-defined): - modules/models.py: declare content_lower field on MeshMessage so mypy resolves the attribute set by base_command.cleanup_message_for_matching Must be merged before or alongside PRs #155–#158 to clear CI on those branches.
56 lines
2.1 KiB
Python
56 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Data models for the MeshCore Bot
|
|
Contains shared data structures used across modules
|
|
"""
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Any, Optional
|
|
|
|
# Firmware reserves extra bytes for regional (non-global) TC_FLOOD scope on channel text.
|
|
CHANNEL_REGIONAL_FLOOD_SCOPE_BODY_OVERHEAD = 10
|
|
|
|
|
|
@dataclass
|
|
class MeshMessage:
|
|
"""Simplified message structure for our bot"""
|
|
content: str
|
|
sender_id: Optional[str] = None
|
|
sender_pubkey: Optional[str] = None
|
|
channel: Optional[str] = None
|
|
hops: Optional[int] = None
|
|
path: Optional[str] = None
|
|
is_dm: bool = False
|
|
timestamp: Optional[int] = None
|
|
snr: Optional[float] = None
|
|
rssi: Optional[int] = None
|
|
elapsed: Optional[str] = None
|
|
# When set from RF routing: path_nodes, path_hex, bytes_per_hop, path_length, route_type, etc.
|
|
routing_info: Optional[dict[str, Any]] = None
|
|
# Matched flood scope for the reply (e.g. "#west"), None means global flood
|
|
reply_scope: Optional[str] = None
|
|
# Lowercased content set by base_command.cleanup_message_for_matching
|
|
content_lower: str = ""
|
|
|
|
def effective_outgoing_flood_scope(self, bot: Any) -> str:
|
|
"""Resolve outbound flood scope the same way as ``CommandManager.send_channel_message``.
|
|
|
|
For channel replies: ``reply_scope`` when set, else ``[Channels] outgoing_flood_scope_override``.
|
|
Empty string means global flood. DMs return ``""`` (not applicable).
|
|
"""
|
|
if self.is_dm:
|
|
return ""
|
|
if self.reply_scope is not None:
|
|
return (self.reply_scope or "").strip()
|
|
scope_cfg = ""
|
|
if bot.config.has_section("Channels") and bot.config.has_option(
|
|
"Channels", "outgoing_flood_scope_override"
|
|
):
|
|
scope_cfg = (bot.config.get("Channels", "outgoing_flood_scope_override") or "").strip()
|
|
return scope_cfg
|
|
|
|
@staticmethod
|
|
def is_global_flood_scope(scope: str) -> bool:
|
|
"""Match ``send_channel_message`` global markers (before ``_normalize_scope_name``)."""
|
|
return scope in ("", "*", "0", "None")
|