diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 80804dc..4588336 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -9,7 +9,8 @@ "Bash(cat:*)", "Bash(pip3 install:*)", "Bash(apt list:*)", - "Bash(curl:*)" + "Bash(curl:*)", + "Bash(git commit:*)" ], "deny": [] } diff --git a/modules/gym_battles.py b/modules/gym_battles.py index 82f430d..a4c05f6 100644 --- a/modules/gym_battles.py +++ b/modules/gym_battles.py @@ -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!") diff --git a/src/database.py b/src/database.py index 9806363..03c3fbe 100644 --- a/src/database.py +++ b/src/database.py @@ -770,18 +770,31 @@ class Database: return [dict(row) for row in rows] async def get_gym_by_name(self, gym_name: str) -> Optional[Dict]: - """Get gym details by name""" + """Get gym details by name (case-insensitive)""" async with aiosqlite.connect(self.db_path) as db: db.row_factory = aiosqlite.Row cursor = await db.execute(""" SELECT g.*, l.name as location_name FROM gyms g JOIN locations l ON g.location_id = l.id - WHERE g.name = ? + WHERE LOWER(g.name) = LOWER(?) """, (gym_name,)) row = await cursor.fetchone() return dict(row) if row else None + async def get_gym_by_name_in_location(self, gym_name: str, location_id: int) -> Optional[Dict]: + """Get gym details by name in a specific location (case-insensitive)""" + async with aiosqlite.connect(self.db_path) as db: + db.row_factory = aiosqlite.Row + cursor = await db.execute(""" + SELECT g.*, l.name as location_name + FROM gyms g + JOIN locations l ON g.location_id = l.id + WHERE g.location_id = ? AND LOWER(g.name) = LOWER(?) + """, (location_id, gym_name)) + row = await cursor.fetchone() + return dict(row) if row else None + async def get_gym_team(self, gym_id: int, difficulty_multiplier: float = 1.0) -> List[Dict]: """Get gym team with difficulty scaling applied""" async with aiosqlite.connect(self.db_path) as db: