mirror of
https://github.com/pe1hvh/meshcore-gui.git
synced 2026-07-06 09:52:09 +02:00
fix(bot): per-sender cooldown + empty-channel fallback (v1.20.1)
- Replace global _last_reply float with _last_reply_per_sender dict. A reply to one node no longer blocks all other senders for 5 s. LRU eviction keeps the dict bounded at 200 entries. - _get_active_channels() now falls back to BotConfig defaults when the stored channel set is empty (user never saved a selection). Bot was silently deaf on first run despite the panel showing all channels pre-checked. Closes: bot only replies to first sender in multi-node #test session.
This commit is contained in:
@@ -167,6 +167,41 @@ class DeviceCache:
|
||||
self._data["channel_keys"] = keys
|
||||
self.save()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Channel names
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
def get_channel_names(self) -> Dict[int, str]:
|
||||
"""Return cached channel names as ``{idx: name}``.
|
||||
|
||||
Always available regardless of ``CHANNEL_CACHE_ENABLED``.
|
||||
Keys are returned as integers for direct use as channel indices.
|
||||
"""
|
||||
raw: Dict[str, str] = self._data.get("channel_names", {})
|
||||
result: Dict[int, str] = {}
|
||||
for k, v in raw.items():
|
||||
try:
|
||||
result[int(k)] = v
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
return result
|
||||
|
||||
def set_channel_names(self, names: Dict[int, str]) -> None:
|
||||
"""Store a complete channel-name mapping and persist to disk.
|
||||
|
||||
Replaces any previously cached names with the supplied mapping.
|
||||
Intended to be called after every successful channel discovery so
|
||||
the most recent names are always available at next startup,
|
||||
independent of ``CHANNEL_CACHE_ENABLED``.
|
||||
|
||||
Args:
|
||||
names: Mapping of channel index to channel name,
|
||||
e.g. ``{0: "Public", 1: "#localmesh"}``.
|
||||
"""
|
||||
self._data["channel_names"] = {str(k): v for k, v in names.items()}
|
||||
self.save()
|
||||
debug_print(f"Cache: channel names saved: {names}")
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Contacts (merge strategy)
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user