Improve channel message sending to use meshcore_py directly, initial implementation of optional flood scope

- Added `flood_scope` option to `[Channels]` section in `config.ini.example` for scoped flooding of channel messages.
- Updated `config-validation.md` to reflect the new `flood_scope` feature.
- Modified `CommandManager` to support optional flood scope during message sending, restoring global flood settings afterward.
- Removed unused imports from `core.py` related to meshcore-cli.
This commit is contained in:
agessaman
2026-03-01 13:33:02 -08:00
parent 7dc68cfb82
commit c115d446e1
4 changed files with 26 additions and 18 deletions
+6
View File
@@ -157,6 +157,12 @@ respond_to_dms = true
# Set a custom prefix length for the public keys to identify repeaters
prefix_bytes = 1
# Flood scope for channel messages (MeshCore regions; optional)
# Empty, * or 0: classic flood (default). Set to a region name (e.g. west) to limit
# channel sends to that scope. Dynamic "reply with same scope as sender" is not
# supported until the protocol exposes scope on received channel messages.
# flood_scope =
[Banned_Users]
# List of banned sender names (comma-separated). Matching is prefix (starts-with):
# "Awful Username" also matches "Awful Username 🍆". No bot responses in channels or DMs.
+1 -1
View File
@@ -31,7 +31,7 @@ The bot will not start without these sections. The validator reports them as **e
|----------------|----------------------------------------------|
| `[Connection]` | Serial, BLE, or TCP connection parameters |
| `[Bot]` | Database path, bot name, rate limits, etc. |
| `[Channels]` | Monitor channels, DM behavior |
| `[Channels]` | Monitor channels, DM behavior, optional flood_scope (scoped flooding) |
### Section names
+19 -14
View File
@@ -890,20 +890,13 @@ class CommandManager:
command_id: Optional[str] = None,
skip_user_rate_limit: bool = False,
rate_limit_key: Optional[str] = None,
scope: Optional[str] = None,
) -> bool:
"""Send a channel message using meshcore-cli command.
"""Send a channel message using meshcore_py (optional flood scope).
Resolves channel names to numbers and handles rate limiting.
Args:
channel: The channel name (e.g., "LongFast").
content: The message content to send.
command_id: Optional command_id for repeat tracking (if not provided, one will be generated).
skip_user_rate_limit: If True, skip user rate limiter checks (for automated responses).
rate_limit_key: Optional key for per-user rate limiting (e.g. from get_rate_limit_key(message)).
Returns:
bool: True if sent successfully, False otherwise.
If [Channels] flood_scope is set (or scope is passed), uses that scope
for this send then restores global flood. Scope values "" / "*" / "0" mean global.
"""
if not self.bot.connected or not self.bot.meshcore:
return False
@@ -943,9 +936,21 @@ class CommandManager:
self.logger.debug(f"Error recording transmission for repeat tracking: {e}")
# Don't fail the send if transmission tracking fails
# Use meshcore-cli send_chan_msg function
from meshcore_cli.meshcore_cli import send_chan_msg
result = await send_chan_msg(self.bot.meshcore, channel_num, content)
# Optional flood scope (region): set before send, restore after
scope_cfg = ""
if self.bot.config.has_section("Channels") and self.bot.config.has_option("Channels", "flood_scope"):
scope_cfg = (self.bot.config.get("Channels", "flood_scope") or "").strip()
scope_to_use = (scope if scope is not None else scope_cfg) or ""
scope_is_global = scope_to_use in ("", "*", "0", "None")
if not scope_is_global and hasattr(self.bot.meshcore.commands, "set_flood_scope"):
await self.bot.meshcore.commands.set_flood_scope(scope_to_use)
try:
# Use meshcore_py directly (no meshcore-cli for channel sends)
result = await self.bot.meshcore.commands.send_chan_msg(channel_num, content)
finally:
if not scope_is_global and hasattr(self.bot.meshcore.commands, "set_flood_scope"):
await self.bot.meshcore.commands.set_flood_scope("*")
# Handle result using unified handler
target = f"{channel} (channel {channel_num})"
-3
View File
@@ -23,9 +23,6 @@ from dataclasses import dataclass
import meshcore
from meshcore import EventType
# Import command functions from meshcore-cli
from meshcore_cli.meshcore_cli import send_cmd, send_chan_msg
# Import our modules
from .rate_limiter import RateLimiter, BotTxRateLimiter, PerUserRateLimiter, NominatimRateLimiter
from .message_handler import MessageHandler