From 022053a674bdd7ed03e0aa66fc74995e2a1b3d6f Mon Sep 17 00:00:00 2001 From: agessaman Date: Sat, 21 Mar 2026 10:56:24 -0700 Subject: [PATCH] Implement bot location fallback in weather commands when no location is provided - Added a new configuration option `use_bot_location_when_no_location` to allow the use of bot's configured coordinates if no companion location is available. - Updated `wx_command.py` and `wx_international.py` to utilize the new configuration, enhancing the user experience by providing a fallback mechanism for location-based commands. - Improved logging to reflect the usage of bot coordinates and handle cases where bot location is not set. --- config.ini.example | 5 +++ .../commands/alternatives/wx_international.py | 34 ++++++++++++++++--- modules/commands/wx_command.py | 32 ++++++++++++++--- 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/config.ini.example b/config.ini.example index 1c38f12..e20f404 100644 --- a/config.ini.example +++ b/config.ini.example @@ -534,6 +534,11 @@ default_state = WA # Use 2-letter country code (e.g., US, CA, GB, AU) default_country = US +# When true, a bare "wx" or "gwx" (no location) uses bot_latitude/bot_longitude from [Bot] +# if there is no default WXSIM source and no companion location in the database. +# Default: false (show usage instead) +use_bot_location_when_no_location = false + # Temperature unit for weather display # Options: fahrenheit, celsius # Default: fahrenheit diff --git a/modules/commands/alternatives/wx_international.py b/modules/commands/alternatives/wx_international.py index c4dc090..fe02312 100644 --- a/modules/commands/alternatives/wx_international.py +++ b/modules/commands/alternatives/wx_international.py @@ -390,10 +390,36 @@ class GlobalWxCommand(BaseCommand): parts = [parts[0], location_str] self.logger.info(f"Using companion coordinates: {location_str}") else: - # No companion location available, show usage - self.logger.debug("No companion location found, showing usage") - await self.send_response(message, self.translate('commands.gwx.usage')) - return True + # No companion location: optionally use bot's configured coordinates + use_bot = self.get_config_value( + 'Wx_Command', + 'use_bot_location_when_no_location', + fallback=False, + value_type='bool', + ) + bot_loc = self._get_bot_location() if use_bot else None + if bot_loc: + location_str = self._coordinates_to_location_string(bot_loc[0], bot_loc[1]) + if location_str: + parts = [parts[0], location_str] + self.logger.info( + f"Using bot location (no args): {location_str} " + f"({bot_loc[0]}, {bot_loc[1]})" + ) + else: + location_str = f"{bot_loc[0]},{bot_loc[1]}" + parts = [parts[0], location_str] + self.logger.info(f"Using bot coordinates (no args): {location_str}") + else: + if use_bot: + self.logger.debug( + "use_bot_location_when_no_location enabled but bot_latitude/bot_longitude " + "not set; showing usage" + ) + else: + self.logger.debug("No companion location found, showing usage") + await self.send_response(message, self.translate('commands.gwx.usage')) + return True # Check for forecast type options: "tomorrow", Nd (7d, 10d), or plain digit days 2–GWX_MULTIDAY_MAX_DAYS forecast_type = "default" diff --git a/modules/commands/wx_command.py b/modules/commands/wx_command.py index 6c08fa0..fc933a5 100644 --- a/modules/commands/wx_command.py +++ b/modules/commands/wx_command.py @@ -472,10 +472,34 @@ class WxCommand(BaseCommand): else: self.logger.info(f"Using companion coordinates: {location_str}") else: - # No companion location available, show usage - self.logger.debug("No companion location found, showing usage") - await self.send_response(message, self.translate('commands.wx.usage')) - return True + # No companion location: optionally use bot's configured coordinates + use_bot = self.get_config_value( + 'Wx_Command', + 'use_bot_location_when_no_location', + fallback=False, + value_type='bool', + ) + bot_loc = self._get_bot_location() if use_bot else None + if bot_loc: + location_str = f"{bot_loc[0]},{bot_loc[1]}" + parts = [parts[0], location_str] + display_name = self._coordinates_to_location_string(bot_loc[0], bot_loc[1]) + if display_name: + self.logger.info( + f"Using bot location (no args): {display_name} ({bot_loc[0]}, {bot_loc[1]})" + ) + else: + self.logger.info(f"Using bot coordinates (no args): {location_str}") + else: + if use_bot: + self.logger.debug( + "use_bot_location_when_no_location enabled but bot_latitude/bot_longitude " + "not set; showing usage" + ) + else: + self.logger.debug("No companion location found, showing usage") + await self.send_response(message, self.translate('commands.wx.usage')) + return True # Check for "alerts" keyword first (special handling) show_full_alerts = False