Improve gym challenge command with location-aware and case-insensitive search

- Updated gym challenge to automatically search in player's current location first
- Made gym search case-insensitive (forest guardian, Forest Guardian, FOREST GUARDIAN all work)
- Added helpful error messages showing available gyms in current location
- Updated gym info command to also prioritize current location and be case-insensitive
- Added get_gym_by_name_in_location() database method for location-specific searches
- Improved user experience by removing need to travel between locations to challenge gyms

Fixes: \!gym challenge forest guardian now works correctly

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
megaproxy 2025-07-14 12:57:36 +01:00
parent 4ccfdd3505
commit c1f82b6c6d
3 changed files with 48 additions and 16 deletions

View file

@ -103,20 +103,24 @@ class GymBattles(BaseModule):
if not player:
return
gym_name = " ".join(args).strip('"')
# Get gym details
gym = await self.database.get_gym_by_name(gym_name)
if not gym:
self.send_message(channel, f"{nickname}: Gym '{gym_name}' not found!")
# Get player's current location first
location = await self.database.get_player_location(player["id"])
if not location:
self.send_message(channel, f"{nickname}: You are not in a valid location! Use !travel to go somewhere first.")
return
# Check if player is in correct location
location = await self.database.get_player_location(player["id"])
if not location or location["id"] != gym["location_id"]:
self.send_message(channel,
f"{nickname}: {gym['name']} gym is located in {gym['location_name']}. "
f"You are currently in {location['name'] if location else 'nowhere'}. Travel there first!")
gym_name = " ".join(args).strip('"')
# Look for gym in player's current location (case-insensitive)
gym = await self.database.get_gym_by_name_in_location(gym_name, location["id"])
if not gym:
# List available gyms in current location for helpful error message
available_gyms = await self.database.get_gyms_in_location(location["id"])
if available_gyms:
gym_list = ", ".join([f'"{g["name"]}"' for g in available_gyms])
self.send_message(channel, f"{nickname}: No gym named '{gym_name}' found in {location['name']}! Available gyms: {gym_list}")
else:
self.send_message(channel, f"{nickname}: No gyms found in {location['name']}! Try traveling to a different location.")
return
# Check if player has active pets
@ -224,8 +228,22 @@ class GymBattles(BaseModule):
self.send_message(channel, f"{nickname}: Specify a gym name! Example: !gym info \"Forest Guardian\"")
return
player = await self.require_player(channel, nickname)
if not player:
return
gym_name = " ".join(args).strip('"')
gym = await self.database.get_gym_by_name(gym_name)
# First try to find gym in player's current location
location = await self.database.get_player_location(player["id"])
gym = None
if location:
gym = await self.database.get_gym_by_name_in_location(gym_name, location["id"])
# If not found in current location, search globally
if not gym:
gym = await self.database.get_gym_by_name(gym_name)
if not gym:
self.send_message(channel, f"{nickname}: Gym '{gym_name}' not found!")