Petbot/modules/inventory.py
megaproxy 61463267c8 Redirect inventory commands to web interface with jump points
- Updated \!inventory, \!inv, and \!items commands to redirect to player profile
- Added #inventory jump point for direct section navigation
- Improved user experience with web-based inventory management
- Enhanced UX with helpful explanatory messages

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-15 16:57:27 +01:00

108 lines
No EOL
4.7 KiB
Python

#!/usr/bin/env python3
"""Inventory management module for PetBot"""
from .base_module import BaseModule
class Inventory(BaseModule):
"""Handles inventory, item usage, and item management commands"""
def get_commands(self):
return ["inventory", "inv", "items", "use", "item"]
async def handle_command(self, channel, nickname, command, args):
if command in ["inventory", "inv", "items"]:
await self.cmd_inventory(channel, nickname)
elif command in ["use", "item"]:
await self.cmd_use_item(channel, nickname, args)
async def cmd_inventory(self, channel, nickname):
"""Redirect player to their web profile for inventory management"""
player = await self.require_player(channel, nickname)
if not player:
return
# Redirect to web interface for better inventory management
self.send_message(channel, f"🎒 {nickname}: View your complete inventory at: http://petz.rdx4.com/player/{nickname}#inventory")
self.send_message(channel, f"💡 The web interface shows detailed item information, categories, and usage options!")
async def cmd_use_item(self, channel, nickname, args):
"""Use an item from inventory"""
if not args:
self.send_message(channel, f"{nickname}: Specify an item to use! Example: !use Small Potion")
return
player = await self.require_player(channel, nickname)
if not player:
return
item_name = " ".join(self.normalize_input(args))
result = await self.database.use_item(player["id"], item_name)
if not result["success"]:
self.send_message(channel, f"{nickname}: {result['error']}")
return
item = result["item"]
effect = result["effect"]
effect_value = result["effect_value"]
# Handle different item effects
if effect == "heal":
# Find active pet to heal
active_pets = await self.database.get_active_pets(player["id"])
if not active_pets:
self.send_message(channel, f"{nickname}: You need an active pet to use healing items!")
return
# Heal the first active pet (can be expanded to choose specific pet)
pet = active_pets[0]
old_hp = pet["hp"]
new_hp = min(pet["max_hp"], pet["hp"] + effect_value)
healed_amount = new_hp - old_hp
# Update pet HP in database
await self.database.update_pet_hp(pet["id"], new_hp)
self.send_message(channel,
f"💊 {nickname}: Used {item['name']} on {pet['nickname'] or pet['species_name']}! "
f"Restored {healed_amount} HP ({old_hp}{new_hp}/{pet['max_hp']})")
elif effect == "full_heal":
active_pets = await self.database.get_active_pets(player["id"])
if not active_pets:
self.send_message(channel, f"{nickname}: You need an active pet to use healing items!")
return
pet = active_pets[0]
old_hp = pet["hp"]
healed_amount = pet["max_hp"] - old_hp
await self.database.update_pet_hp(pet["id"], pet["max_hp"])
self.send_message(channel,
f"{nickname}: Used {item['name']} on {pet['nickname'] or pet['species_name']}! "
f"Fully restored HP! ({old_hp}{pet['max_hp']}/{pet['max_hp']})")
elif effect == "attack_boost":
self.send_message(channel,
f"⚔️ {nickname}: Used {item['name']}! Your next battle will have +{effect_value}% attack damage!")
elif effect == "defense_boost":
self.send_message(channel,
f"🛡️ {nickname}: Used {item['name']}! Your next battle will have +{effect_value}% damage reduction!")
elif effect == "speed_boost":
self.send_message(channel,
f"💨 {nickname}: Used {item['name']}! You'll move first in your next battle!")
elif effect == "lucky_boost":
self.send_message(channel,
f"🍀 {nickname}: Used {item['name']}! Rare pet encounter rate increased by {effect_value}% for 1 hour!")
elif effect == "none":
self.send_message(channel,
f"📦 {nickname}: Used {item['name']}! This item has no immediate effect but may be useful later.")
else:
self.send_message(channel,
f"{nickname}: Used {item['name']}! {item['description']}")