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.
This commit is contained in:
agessaman
2026-03-21 10:56:24 -07:00
parent 5020120273
commit 022053a674
3 changed files with 63 additions and 8 deletions
+5
View File
@@ -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
@@ -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 2GWX_MULTIDAY_MAX_DAYS
forecast_type = "default"
+28 -4
View File
@@ -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