Files
Hippolyzer/addon_examples/transfer_example.py

71 lines
2.7 KiB
Python
Raw Normal View History

2021-04-30 17:30:24 +00:00
"""
Example of how to request a Transfer
"""
from typing import *
from hippolyzer.lib.base.inventory import InventoryModel, InventoryItem
from hippolyzer.lib.base.message.message import Block, Message
from hippolyzer.lib.base.templates import (
2021-04-30 17:30:24 +00:00
AssetType,
EstateAssetType,
TransferRequestParamsSimEstate,
TransferRequestParamsSimInvItem,
TransferSourceType,
XferFilePath,
)
from hippolyzer.lib.proxy.addon_utils import BaseAddon, show_message
from hippolyzer.lib.proxy.commands import handle_command
from hippolyzer.lib.proxy.region import ProxiedRegion
from hippolyzer.lib.proxy.sessions import Session
2021-04-30 17:30:24 +00:00
class TransferExampleAddon(BaseAddon):
@handle_command()
async def get_covenant(self, _session: Session, region: ProxiedRegion):
"""Get the current region's covenent"""
transfer = await region.transfer_manager.request(
source_type=TransferSourceType.SIM_ESTATE,
params=TransferRequestParamsSimEstate(
EstateAssetType=EstateAssetType.COVENANT,
),
)
show_message(transfer.reassemble_chunks().decode("utf8"))
@handle_command()
async def get_first_script(self, session: Session, region: ProxiedRegion):
"""Get the contents of the first script in the selected object"""
# Ask for the object inventory so we can find a script
2021-12-09 05:30:12 +00:00
region.circuit.send(Message(
2021-04-30 17:30:24 +00:00
'RequestTaskInventory',
Block('AgentData', AgentID=session.agent_id, SessionID=session.id),
Block('InventoryData', LocalID=session.selected.object_local),
))
inv_message = await region.message_handler.wait_for(('ReplyTaskInventory',), timeout=5.0)
2021-04-30 17:30:24 +00:00
# Xfer the inventory file and look for a script
xfer = await region.xfer_manager.request(
file_name=inv_message["InventoryData"]["Filename"], file_path=XferFilePath.CACHE)
inv_model = InventoryModel.from_bytes(xfer.reassemble_chunks())
first_script: Optional[InventoryItem] = None
2022-07-09 02:48:23 +00:00
for item in inv_model.all_items:
2021-04-30 17:30:24 +00:00
if item.type == "lsltext":
first_script = item
if not first_script:
show_message("No scripts in object?")
return
# Ask for the actual script contents
transfer = await region.transfer_manager.request(
source_type=TransferSourceType.SIM_INV_ITEM,
params=TransferRequestParamsSimInvItem(
OwnerID=first_script.permissions.owner_id,
TaskID=inv_model.root.node_id,
ItemID=first_script.item_id,
AssetType=AssetType.LSL_TEXT,
),
)
show_message(transfer.reassemble_chunks().decode("utf8"))
addons = [TransferExampleAddon()]