Commit Graph

222 Commits

Author SHA1 Message Date
agessaman
9423178b33 fix: Improve channel validation logic in BaseCommand
- Added checks for empty channels and normalized channel names for case-insensitive comparison.
- Updated allowed channels validation to ensure consistent handling of channel names, enhancing command execution accuracy.
2026-01-27 15:47:56 -08:00
agessaman
ffdc906b22 fix: Update help text for commands to avoid truncation and tx issues 2026-01-26 21:11:36 -08:00
agessaman
b50d02aee9 feat: Add command prefix support and enhance message handling
- Introduced a new configuration option for command prefix in config.ini.example, allowing users to customize command invocation.
- Updated CommandManager to load and utilize the command prefix, ensuring commands are processed correctly based on the configured prefix.
- Enhanced message handling logic to check for the command prefix, maintaining backward compatibility with the legacy "!" prefix.
- Improved keyword matching to ensure bot responses are only triggered when the bot is mentioned, refining interaction accuracy.
2026-01-26 21:02:30 -08:00
agessaman
ec4b4dbc66 feat: Enhance PathCommand with SNR integration and location validation
- Added SNR (Signal-to-Noise Ratio) data handling to improve zero-hop bonus calculations for repeaters, enhancing selection accuracy.
- Implemented location validation checks to prioritize repeaters with valid geographic data, especially for final hop scenarios.
- Updated scoring logic to apply penalties for repeaters lacking valid location data, ensuring better routing decisions.
- Enhanced logging for SNR bonuses and location penalties to improve debugging and performance tracking.
2026-01-26 17:37:36 -08:00
agessaman
1559860dcb feat: Introduce prefix best location feature and enhance message handling
- Added configuration options for the "prefix best <location>" command in config.ini.example, allowing users to enable/disable the feature and customize its behavior.
- Implemented logic in the PrefixCommand class to find the best prefix for a given location, considering neighbor prefixes and user-defined criteria.
- Enhanced MessageHandler to skip processing old cached messages based on connection time, improving message handling efficiency.
- Updated core bot to track connection time, ensuring accurate message processing and cache management.
2026-01-26 17:15:25 -08:00
agessaman
d97c0886e7 feat: Refactor multitest command to support user sessions and improve path tracking
- Introduced a new MultitestSession dataclass to manage active multitest sessions per user, enhancing concurrency handling.
- Replaced global variables with session-specific attributes to track listening duration, collected paths, and target packet hashes.
- Updated message handling logic to check active sessions and prevent race conditions during multitest execution.
- Enhanced path collection and RF data scanning to be user-specific, improving accuracy and logging for each session.
- Implemented execution locks to ensure thread safety during multitest command execution.
2026-01-25 20:47:01 -08:00
agessaman
df8dc8cafb feat: Enhance path selection and observation tracking
- Added new configuration options for path selection presets and proximity methods in config.ini.example, allowing users to customize routing behavior.
- Implemented a new database table for storing observed paths, enabling better tracking of paths from advertisements and messages.
- Updated MessageHandler to store complete paths in the observed_paths table, improving path validation and selection accuracy.
- Enhanced the PathCommand class to utilize new proximity and recency settings, optimizing repeater selection based on user-defined criteria.
- Improved web viewer functionality to display multiple paths for contacts, enhancing user experience and interaction with path data.
2026-01-25 10:12:46 -08:00
agessaman
bd2849655c feat: Enhance mesh graph functionality and path validation
- Added a new mesh graph feature for improved path validation, allowing for enhanced routing accuracy.
- Introduced configuration options for recency decay half-life and graph-based validation settings in config.ini.example.
- Updated the PathCommand class to utilize graph-based selection methods, combining graph and geographic scores for better repeater selection.
- Implemented new methods in MessageHandler to update the mesh graph with advertisement paths and trace packet data.
- Created a new database table for mesh connections to support graph-based path validation.
- Enhanced web viewer integration to display mesh graph updates in real-time, improving user interaction and monitoring capabilities.
2026-01-23 20:26:56 -08:00
agessaman
ed1e541bed feat: Add Aurora command
- Introduced a new section in configuration files for the Aurora command, allowing users to enable/disable the feature and set default coordinates.
- Updated English translations to include descriptions, usage instructions, and error messages for the Aurora command, enhancing user interaction and support.
2026-01-20 21:38:19 -08:00
agessaman
ba33fed1a8 feat: Implement service health checks and restart logic
- Added a new configuration option for service restart backoff timing in config.ini.example.
- Enhanced the MeshCoreBot class to track service health and manage restarts for unhealthy services.
- Introduced a new method for service health checks in the BaseServicePlugin class, allowing for custom health validation in subclasses.
- Updated the PacketCaptureService to include specific health check logic based on connection status.
2026-01-20 20:35:29 -08:00
agessaman
04478acf51 feat: Refactor geocoding and country/state handling in commands
- Updated utility functions to improve country name validation, ensuring accurate identification of country names and US states.
- Enhanced geocoding logic in multiple command classes to handle default state and country configurations more effectively.
- Modified error messages to reflect the correct region based on user input, improving user experience.
- Added short usage descriptions for satellite pass commands in multiple languages, enhancing internationalization support.
2026-01-19 22:01:47 -08:00
agessaman
c53bfce4b7 feat: Enhance elapsed time handling in messages
- Updated the message handling logic to format elapsed time more accurately, displaying "Nms" when the device clock is valid or "Sync Device Clock" when invalid.
- Introduced a new utility function `format_elapsed_display` to centralize elapsed time formatting, improving code maintainability.
- Modified configuration examples to clarify the usage of the {elapsed} placeholder.
- Added translations for the "Sync Device Clock" message in multiple languages to support internationalization.
2026-01-19 09:55:31 -08:00
agessaman
abe8e57ae3 feat: Update banned user handling to support prefix matching
- Modified configuration examples to clarify that banned users are now identified by sender names using prefix matching.
- Implemented a new method in CommandManager to check if a user is banned based on prefix matching, enhancing the bot's ability to ignore messages from banned senders.
- Updated message handling logic to utilize the new prefix matching functionality for improved user management.
2026-01-18 20:04:50 -08:00
agessaman
93c4004e2d feat: Add unique advert packet tracking and leaderboard functionality
- Introduced a new database table 'unique_advert_packets' for tracking unique advert packets by their hash.
- Enhanced the RepeaterManager to handle unique packet tracking during daily advertisement statistics.
- Updated StatsCommand to include a new subcommand for displaying the leaderboard of nodes with the most unique advert packets in the last 24 hours.
- Modified translations to support the new advert statistics feature, ensuring user-friendly command descriptions and error messages.
2026-01-18 14:16:04 -08:00
agessaman
9a74144a8f feat: Add ZIP code geocoding support to GlobalWxCommand
- Implemented geocode_zipcode_sync to handle US ZIP code queries, ensuring accurate geocoding results.
- Enhanced location handling to prevent foreign matches for ZIP codes, improving the reliability of location-based commands.
- Added error handling for reverse geocoding failures, ensuring robust logging and feedback for invalid ZIP codes.
2026-01-18 08:08:31 -08:00
agessaman
aa3951827a feat: Implement command queuing for global cooldowns in CommandManager
- Added QueuedCommand dataclass to represent commands waiting for cooldown expiration.
- Enhanced CommandManager to support queuing commands when near global cooldown expiration, allowing for smoother command execution.
- Implemented background task to process queued commands, ensuring they are executed once cooldowns expire.
- Updated BaseCommand to include a method for retrieving queue threshold seconds, improving flexibility in command handling.
- Adjusted core.py to initiate the command queue processor upon bot startup.
2026-01-17 21:12:24 -08:00
agessaman
951ded4244 feat: Add support for custom WXSIM weather sources in wx_command and wx_international modules
- Introduced functionality to configure custom weather sources in config.ini, allowing users to specify URLs for different locations.
- Enhanced WxCommand and GlobalWxCommand classes to fetch weather data from custom WXSIM sources, improving flexibility in weather reporting.
- Implemented methods to retrieve and parse weather data from specified sources, ensuring compatibility with existing weather command structures.
- Updated documentation in config.ini.example to guide users on configuring custom weather sources.
2026-01-17 16:52:15 -08:00
agessaman
58901a2857 chore: Update docker-setup.sh and documentation for improved serial device handling and logging
- Enhanced docker-setup.sh to ensure device mappings are correctly moved from the volumes section to the devices section in Docker Compose files.
- Added checks for serial device permissions and provided detailed instructions in DOCKER.md for resolving permission issues.
- Updated Dockerfile to add the meshcore user to the dialout group for serial port access, improving compatibility with serial devices.
- Improved logging functionality in core.py to handle log file paths more robustly, ensuring directories are created as needed and handling errors gracefully.
2026-01-17 12:12:33 -08:00
agessaman
db0db96f7e feat: Add reload configuration functionality and update admin commands
- Introduced a new method `reload_config` to allow dynamic reloading of the configuration without restarting the bot, ensuring seamless updates to settings.
- Added a helper method `_get_radio_settings` to retrieve current radio settings for comparison during reload.
- Updated `admin_commands` in `config.ini.example` to include the new `reload` command, enabling admin users to reload configurations on-the-fly.
- Enhanced the `setup_scheduled_messages` method in the scheduler to clear existing jobs before reloading, preventing duplicates.
2026-01-16 19:55:44 -08:00
agessaman
d2abc49048 feat: Enhance command documentation and usage information
- Updated the `generate_html` function to include detailed command usage information, including syntax, examples, and parameters for better user guidance.
- Added CSS styles for improved presentation of command usage and parameters in the generated website documentation.
- Enhanced command classes with structured documentation fields, allowing for consistent and informative command descriptions across the platform.
2026-01-15 20:04:58 -08:00
agessaman
2b3f3489bd feat: Enhance command help functionality with channel restrictions
- Updated the CommandManager to include channel restrictions for help keyword processing, ensuring that help requests are only handled in monitored channels or DMs when enabled.
- Improved the HTML documentation for commands by adding a new "General Commands" section and refining existing command descriptions.
- Added new CSS styles for better presentation of command subcommands in the website documentation.
2026-01-15 17:56:27 -08:00
agessaman
76ba4f1c0e fix: Refine content matching logic in CommandManager
- Updated the content matching logic in the CommandManager to ensure only exact matches are considered, preventing false positives from substring matches.
- Enhanced comments to clarify the purpose of the changes and the importance of accurate timestamp checks in transmission linking.
2026-01-15 17:10:37 -08:00
Adam Gessaman
4bd48e5165 feat: Add sub-command support and usage information retrieval for commands
- Implemented `get_usage_info` method in `BaseCommand` to provide structured usage information, including descriptions, sub-commands, usage patterns, and examples.
- Enhanced `generate_html` function to display sub-commands in the generated HTML output, improving command documentation.
- Updated translations in `en.json` to include sub-command details for various commands, enhancing user guidance and interaction.
2026-01-15 10:04:09 -08:00
agessaman
11dc22ae46 feat: Implement companion location features in weather commands
- Added methods to retrieve companion and bot locations from the database and configuration.
- Enhanced weather command execution to utilize companion location if no user-specified location is provided.
- Improved location handling by supporting coordinates, zip codes, and city names, with reverse geocoding for display.
2026-01-13 21:30:27 -08:00
Adam Gessaman
f3d33b68c7 feat: Enhance rate limiting flexibility in command responses
- Updated the `CommandManager` and `BaseCommand` classes to include an optional `skip_user_rate_limit` parameter in the `send_response`, `send_dm`, and `send_channel_message` methods, allowing automated responses to bypass user rate limits.
- Adjusted the `GreeterCommand` to utilize the new parameter, ensuring that automated greetings do not trigger user rate limiting checks.
- Enhanced documentation to clarify the purpose of the new parameter and its impact on message sending behavior.
2026-01-13 12:43:30 -08:00
Adam Gessaman
c04ecd9ffd fix: Update escape sequence documentation for consistency
- Revised `config.ini.example` and `README.md` to clarify the usage of escape sequences for newlines, changing from double backslashes (`\\n`) to single backslashes (`\n`).
- Enhanced comments in `CommandManager` and `GreeterCommand` to reflect the updated escape sequence behavior, ensuring accurate processing of newline characters and literal backslashes.
- Improved logging in `GreeterCommand` for better debugging of mesh info formatting.
2026-01-13 10:55:59 -08:00
agessaman
89ecc34ef6 feat: Enhance geocoding capabilities with country and state normalization
- Added optional geocoding helper libraries for improved country name validation and US state handling.
- Implemented functions to normalize country names and US state abbreviations, enhancing location parsing accuracy.
- Updated weather command to utilize new geocoding features for better location handling in weather queries.
- Adjusted message length calculations in weather responses to accommodate dynamic content based on location information.
2026-01-12 21:10:51 -08:00
agessaman
3d654d1fba feat: Add airplanes command for aircraft tracking
- Introduced the `airplanes` command to retrieve aircraft tracking information using ADS-B API data.
- Added detailed usage instructions, location options, and filter options for enhanced functionality.
- Updated `config.ini.example` to include configuration settings for the new command.
- Included translations for command descriptions and error messages in `en.json` to support user interaction.
2026-01-12 20:05:02 -08:00
agessaman
01dc2679fd feat: Add escape sequence decoding for greeting messages
- Implemented `_decode_escape_sequences` method in `GreeterCommand` to process escape sequences like `\\n`, `\\t`, and `\\r` in greeting messages.
- Updated `_load_config` to decode escape sequences in `greeting_message` and `mesh_info_format`, enhancing user flexibility in message formatting.
- Added decoding for per-channel greetings to ensure consistent message formatting across different channels.
2026-01-12 15:51:26 -08:00
Adam Gessaman
8bef8ed485 refactor: Clarify repeater prefix extraction in message handling
- Updated comments in `message_handler.py` and `transmission_tracker.py` to specify that the repeater prefix is extracted from the last hop in the message path.
- Modified the `extract_repeater_prefixes_from_path` method to focus on the last node, improving clarity and functionality by returning only the prefix from the last hop instead of intermediate nodes.
2026-01-12 09:51:34 -08:00
Adam Gessaman
ce561c18db feat: Enhance keyword response handling with escape sequence support
- Updated `config.ini.example` and `README.md` to document the use of escape sequences for newlines and other formatting in keyword responses.
- Implemented `_decode_escape_sequences` method in `CommandManager` to process escape sequences like `\\n`, `\\t`, and `\\r`, allowing users to format responses more flexibly.
- Modified `load_keywords` and `load_syntax_patterns` methods to decode escape sequences in keyword responses and formats, improving user experience.
2026-01-12 09:16:34 -08:00
agessaman
7984fa3af6 feat: Enhance command messaging with repeat tracking and transmission monitoring
- Updated `send_dm` and `send_channel_message` methods to include an optional `command_id` for tracking message repeats.
- Integrated transmission tracking to record and manage repeat messages, improving message handling and response accuracy.
- Enhanced `capture_command` method in `BotIntegration` to store repeat information for better analysis in the web viewer.
- Added favicon support and improved web viewer templates to display repeat information effectively.
- Implemented JavaScript updates in the web viewer to handle command updates and display repeat counts dynamically.
2026-01-11 20:30:02 -08:00
agessaman
106e7efca8 feat: Add light mode support for modal and UI elements in web viewer
- Implemented comprehensive light mode styles for various components in the web viewer, including modals, segment cards, and tables.
- Enhanced visual consistency by applying theme-based background and text colors across different UI elements.
- Updated styles for header and message content to ensure readability and aesthetic appeal in light mode.
2026-01-10 19:44:24 -08:00
agessaman
ca80924e38 feat: Enhance web viewer functionality and configuration options
- Updated `config.ini.example` to include a new option for additional hashtag channels to decode in the packet stream.
- Modified `BotDataViewer` to retrieve and display additional decode-only channels from the configuration.
- Improved packet handling in `message_handler.py` to capture full packet data for web viewer integration.
- Enhanced the web viewer's JavaScript to support detailed packet analysis and display, including color-coded hex breakdowns and improved user interface elements.
- Added new styles and scripts to the web viewer templates for better visual representation of packet data and improved user experience.
2026-01-10 16:39:07 -08:00
agessaman
760bf7ad1f feat: Enhance logging and client management in BotDataViewer
- Added a rotating file handler for logging to manage log file size and backups.
- Implemented thread safety for connected clients using a lock to prevent race conditions.
- Introduced a method to clean up stale clients based on inactivity, improving resource management.
- Updated logging messages to reflect changes in logging setup and client connection status.
2026-01-10 10:34:37 -08:00
agessaman
e14574580a fix: Improve database cleanup process in BotDataViewer
- Enhanced error logging to include stack traces for better debugging.
- Optimized the cleanup of old packet stream data by implementing smaller batch deletions to reduce lock contention.
- Adjusted database connection settings for improved concurrency and added handling for database busy errors.
- Removed periodic cleanup from BotIntegration, delegating this responsibility to the web viewer subprocess to avoid contention.
2026-01-10 09:42:28 -08:00
agessaman
cc3fffeb54 feat: Add command enable/disable configuration for various commands
- Implemented a configuration option for enabling or disabling commands across multiple command classes.
- Each command now checks its enabled state before execution, improving control over command availability.
- Updated the configuration loading mechanism to retrieve the enabled state from the config file for commands like Advert, AQI, Catfact, and others.
2026-01-10 09:33:15 -08:00
agessaman
7ee77c16c0 feat: Implement message queuing and rate limiting for Discord webhook posts
- Introduced a QueuedMessage dataclass to manage messages queued for posting to Discord.
- Added a background task to process message queues, handling rate limits and retries.
- Updated message posting methods to support queuing and retry logic, ensuring robust message delivery.
- Implemented proactive rate limiting to prevent exceeding Discord's message limits.
2026-01-09 16:03:30 -08:00
agessaman
1acbee0b5b feat: Enhance bot signal handling and update dependencies
- Refactored bot's main execution flow to use asyncio.run() with improved signal handling for graceful shutdown on Unix systems.
- Added new dependencies in pyproject.toml: urllib3, paho-mqtt, cryptography, and pynacl for enhanced functionality.
- Updated Nix flake to include flake-parts for better modularization and added translation path for NixOS module compatibility.
- Improved argument parsing in web viewer to maintain clarity and consistency.
2026-01-07 20:06:43 -08:00
agessaman
070e02554e Merge branch 'pr-27' into pr-27-integrated 2026-01-07 19:18:29 -08:00
agessaman
f054cd5f35 fix: Improve weather string handling to prevent emoji truncation
- Updated the weather string concatenation logic to use display width for checking available space, ensuring emojis are not cut off.
- Added a buffer of 5 characters to the maximum length check to enhance the user experience when displaying weather information.
2026-01-07 17:36:49 -08:00
Tilman Baumann
2be93ebf6f Allowign to pass --config to web viewer 2026-01-07 15:15:42 +01:00
Tilman Baumann
a6c56ecd3c Add Nix flake with NixOS module and modernize Python packaging
This commit adds comprehensive Nix/NixOS support and modernizes the
Python packaging structure to enable declarative system-wide deployments.

Added complete Nix flake infrastructure in nix/:
- packages.nix: Package definition with all dependencies
- nixos-module.nix: NixOS module for declarative service configuration
- nixos-test.nix: Comprehensive NixOS VM tests (basic + web viewer)
- shell.nix: Development shell with all build tools

The NixOS module (services.meshcore-bot) provides:
- Automatic user/group creation (meshcore-bot:meshcore-bot)
- Serial port access (dialout group membership)
- Systemd service with security hardening
- Automatic directory management via StateDirectory/LogsDirectory
- INI config generation from Nix attribute sets
- Sensible defaults for system paths

Example NixOS configuration:
  services.meshcore-bot = {
    enable = true;
    settings = {
      Connection.connection_type = "serial";
      Connection.serial_port = "/dev/ttyUSB0";
      Bot.bot_name = "MyBot";
    };
  };

Migrated from requirements.txt to pyproject.toml:
- Defined proper package metadata and dependencies
- Created entry points: meshcore-bot, meshcore-viewer
- Enables standard 'pip install -e .' workflow
- Maintains compatibility with existing setups

Changes to existing code are minimal and only where necessary:

1. **Added --config parameter** (meshcore_bot.py, app.py)
   - Wrapped main logic in main() function for entry point
   - Added argparse to accept --config parameter
   - Required for NixOS to pass generated config from /nix/store
   - Backwards compatible: defaults to 'config.ini' in current directory
   - No changes to core bot logic

2. **Fixed web viewer subprocess spawning** (modules/web_viewer/integration.py)
   - Changed from sys.executable to 'meshcore-viewer' entry point
   - Ensures Nix wrapper script sets up correct PYTHONPATH
   - Resolves Flask module import issues in Nix environment
   - No functional change for traditional installations

Note: The dev branch's resolve_path() utility already handles both
relative and absolute paths correctly, making it compatible with
NixOS system paths (/var/lib, /var/log) without additional changes.

All NixOS VM tests passing:
- nixos-module-basic: Service startup, file creation, TCP connection
- nixos-module-webviewer: Flask available, port listening, HTTP responses

No breaking changes to existing workflows. The bot continues to work
exactly as before when run with traditional Python methods.
2026-01-07 14:01:39 +01:00
agessaman
578fa2caa4 fix: Prevent potential segfaults by deep copying event payloads
- Added deep copy of event payloads in multiple modules to avoid segmentation faults when events are freed.
- Updated the handling of payloads in ChannelManager, MessageHandler, DiscordBridgeService, MapUploaderService, and PacketCaptureService to ensure safe access to event data.
- Enhanced logging for cases where payloads are missing, improving error handling and debugging capabilities.
2026-01-05 17:20:15 -08:00
agessaman
a34f816af5 bug: fixed path decoding logic in PathCommand
- Improved the path decoding functionality to handle single nodes more effectively by checking for hex values.
- Added regex pattern matching to identify hex values in path parts, allowing for better decoding of repeater names.
- Updated fallback behavior for unknown formats to return the raw path string when decoding fails.
2026-01-04 15:57:56 -08:00
agessaman
5b06289ac1 feat: Add Discord bridge configuration to example and update README
- Introduced a new section in `config.ini.example` for the Discord bridge service, including options for enabling the service and configuring avatar styles and channel mappings.
- Updated `README.md` to document the new Discord bridge service and its integration, enhancing the overall service plugin section with relevant details.
2026-01-04 10:30:14 -08:00
agessaman
6ca74723c9 fix: Improve error handling and client connection management in BotDataViewer
- Enhanced the handle_connect, handle_disconnect, handle_subscribe_commands, handle_subscribe_packets, and handle_ping methods to include better error handling and logging.
- Added checks for client_id to prevent issues during connection and disconnection events.
- Implemented database file existence and accessibility checks in the polling loop, with detailed logging for errors.
- Improved handling of database connection errors, including exponential backoff for persistent issues, ensuring more robust database interactions.
2026-01-03 20:57:29 -08:00
agessaman
2cf2fd6ce7 feat: Enhance link extraction and conversion in WeatherService
- Improved the link extraction logic to prioritize HTML links over CAP XML links, ensuring more user-friendly URLs are used.
- Added a new method to convert CAP XML URLs to a more readable API format, accommodating changes in the NWS alerts webpage.
- Enhanced fallback mechanisms for link retrieval to ensure reliable access to alert information.
2026-01-02 16:24:49 -08:00
agessaman
51acebdc1a refactor: Improve async lock handling in InternetStatusCache
- Changed the lock attribute to a private variable and introduced a lazy initialization method for the async lock.
- Updated the CommandManager to use the new _get_lock method, enhancing thread safety and preventing potential RuntimeErrors when the event loop is not running.
2026-01-02 14:42:04 -08:00
agessaman
50724d1fed feat: Enhance asyncio event loop handling across modules
- Introduced a mechanism to utilize the main event loop for scheduling coroutines, preventing deadlocks when the main loop is running.
- Updated the JWT renewal interval to 12 hours, with tokens now valid for 24 hours, improving token management.
- Refactored various async function calls in the MessageScheduler, WeatherService, and PacketCaptureService to ensure consistent event loop usage.
- Improved error handling and logging for scheduled tasks, enhancing robustness and maintainability.
2026-01-02 09:25:31 -08:00