mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-10-22 14:01:14 +00:00
fix(region): never warn the synthetic "Channel User" sender
A channel message with no "Name: " prefix falls back to a stand-in name. That is not a node: every such message shares the identity, so they would accumulate a run together and then get a DM addressed to a contact that does not exist. The hook now passes no sender for those, so they are still counted but can never earn a warning. The literal is a named constant and a test pins the hook's guard to it. Also folds the channel body-budget formula into models.channel_body_limit rather than letting the web viewer keep a fourth copy of "max(130, 160 - len(name) - 2)"; BaseCommand and CommandManager now call it too, and 158 becomes models.DM_BODY_LIMIT.
This commit is contained in:
1 parent
147cc588e1
commit
0c1aa4fd15
8 files changed
+146
-18
No files matched your search
@@ -30,7 +30,12 @@ from .config_validation import (
|
||||
_channel_name_is_public,
|
||||
strip_optional_quotes,
|
||||
)
|
||||
from .models import CHANNEL_REGIONAL_FLOOD_SCOPE_BODY_OVERHEAD, MeshMessage
|
||||
from .models import (
|
||||
CHANNEL_REGIONAL_FLOOD_SCOPE_BODY_OVERHEAD,
|
||||
DM_BODY_LIMIT,
|
||||
MeshMessage,
|
||||
channel_body_limit,
|
||||
)
|
||||
from .plugin_loader import PluginLoader
|
||||
from .security_utils import sanitize_name, validate_safe_path
|
||||
from .utils import check_internet_connectivity_async, decode_escape_sequences, format_keyword_response_with_placeholders
|
||||
@@ -687,7 +692,7 @@ class CommandManager:
|
||||
can be called outside of a specific command instance.
|
||||
"""
|
||||
if message.is_dm:
|
||||
return 158
|
||||
return DM_BODY_LIMIT
|
||||
username: str | None = None
|
||||
try:
|
||||
if hasattr(self.bot, 'meshcore') and self.bot.meshcore:
|
||||
@@ -701,7 +706,7 @@ class CommandManager:
|
||||
pass
|
||||
if not username:
|
||||
username = self.bot.config.get('Bot', 'bot_name', fallback='Bot')
|
||||
max_length = max(130, 160 - len(str(username).encode('utf-8')) - 2)
|
||||
max_length = channel_body_limit(username)
|
||||
if not MeshMessage.is_global_flood_scope(message.effective_outgoing_flood_scope(self.bot)):
|
||||
max_length -= CHANNEL_REGIONAL_FLOOD_SCOPE_BODY_OVERHEAD
|
||||
return max_length
|
||||
|
||||
Reference in new issue
Block a user