Fix parsing for real this time.
This commit is contained in:
@@ -15,6 +15,12 @@ name="$1"
|
|||||||
channelName="$2"
|
channelName="$2"
|
||||||
shift 2
|
shift 2
|
||||||
|
|
||||||
|
# Parse arguments into array to handle subcommands properly
|
||||||
|
# When bot.sh calls this with "$will", it arrives as a single quoted argument
|
||||||
|
# e.g., "set Ferguson North Carolina" comes as one $1, not multiple args
|
||||||
|
# shellcheck disable=SC2206
|
||||||
|
request=($*)
|
||||||
|
|
||||||
# Database file for user locations and cached geocoding
|
# Database file for user locations and cached geocoding
|
||||||
weatherDb="data/weather.db"
|
weatherDb="data/weather.db"
|
||||||
weatherDbLock="${weatherDb}.lock"
|
weatherDbLock="${weatherDb}.lock"
|
||||||
@@ -453,18 +459,20 @@ format_forecast() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Main command logic
|
# Main command logic
|
||||||
subcommand="${1:-}"
|
# Check if first element is a subcommand
|
||||||
|
subcommand="${request[0]:-}"
|
||||||
|
|
||||||
case "$subcommand" in
|
case "$subcommand" in
|
||||||
set)
|
set)
|
||||||
# Set user's location
|
# Set user's location
|
||||||
shift
|
# Remove 'set' from the array and get the rest as location
|
||||||
if [[ $# -eq 0 ]]; then
|
if [[ ${#request[@]} -lt 2 ]]; then
|
||||||
msg "$channelName" "$name: Usage: weather set <location>"
|
msg "$channelName" "$name: Usage: weather set <location>"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
location="$*"
|
# Get everything after 'set' as the location
|
||||||
|
location="${request[*]:1}"
|
||||||
|
|
||||||
# Validate location length
|
# Validate location length
|
||||||
if [[ ${#location} -gt 100 ]]; then
|
if [[ ${#location} -gt 100 ]]; then
|
||||||
@@ -502,7 +510,7 @@ case "$subcommand" in
|
|||||||
# Show weather (default action)
|
# Show weather (default action)
|
||||||
if [[ -n "$subcommand" ]]; then
|
if [[ -n "$subcommand" ]]; then
|
||||||
# Weather for specified location
|
# Weather for specified location
|
||||||
location="$*"
|
location="${request[*]}"
|
||||||
|
|
||||||
# Validate location length
|
# Validate location length
|
||||||
if [[ ${#location} -gt 100 ]]; then
|
if [[ ${#location} -gt 100 ]]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user