2023-12-13 19:19:14 +00:00
|
|
|
"""
|
|
|
|
|
A simple client that just says hello to people
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import asyncio
|
2024-01-04 21:45:54 +00:00
|
|
|
import pprint
|
2023-12-13 19:19:14 +00:00
|
|
|
from contextlib import aclosing
|
|
|
|
|
import os
|
|
|
|
|
|
2023-12-13 20:42:21 +00:00
|
|
|
from hippolyzer.lib.base.message.message import Message
|
2023-12-13 19:19:14 +00:00
|
|
|
from hippolyzer.lib.base.templates import ChatType, ChatSourceType
|
|
|
|
|
from hippolyzer.lib.client.hippo_client import HippoClient
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def amain():
|
|
|
|
|
client = HippoClient()
|
|
|
|
|
|
|
|
|
|
async def _respond_to_chat(message: Message):
|
|
|
|
|
if message["ChatData"]["SourceID"] == client.session.agent_id:
|
|
|
|
|
return
|
|
|
|
|
if message["ChatData"]["SourceType"] != ChatSourceType.AGENT:
|
|
|
|
|
return
|
2023-12-31 15:52:15 +00:00
|
|
|
if "hello" not in message["ChatData"]["Message"].lower():
|
2023-12-13 19:19:14 +00:00
|
|
|
return
|
2023-12-13 20:42:21 +00:00
|
|
|
await client.send_chat(f'Hello {message["ChatData"]["FromName"]}!', chat_type=ChatType.SHOUT)
|
2023-12-13 19:19:14 +00:00
|
|
|
|
|
|
|
|
async with aclosing(client):
|
|
|
|
|
await client.login(
|
|
|
|
|
username=os.environ["HIPPO_USERNAME"],
|
|
|
|
|
password=os.environ["HIPPO_PASSWORD"],
|
2023-12-19 04:24:17 +00:00
|
|
|
start_location=os.environ.get("HIPPO_START_LOCATION", "last"),
|
2023-12-13 19:19:14 +00:00
|
|
|
)
|
|
|
|
|
print("I'm here")
|
2024-01-04 21:45:54 +00:00
|
|
|
|
|
|
|
|
# Wait until we have details about parcels and print them
|
|
|
|
|
await client.main_region.parcel_manager.parcels_downloaded.wait()
|
|
|
|
|
pprint.pprint(client.main_region.parcel_manager.parcels)
|
|
|
|
|
|
2023-12-13 20:42:21 +00:00
|
|
|
await client.send_chat("Hello World!", chat_type=ChatType.SHOUT)
|
2023-12-13 19:19:14 +00:00
|
|
|
client.session.message_handler.subscribe("ChatFromSimulator", _respond_to_chat)
|
2023-12-14 02:19:11 +00:00
|
|
|
# Example of how to work with caps
|
2023-12-20 00:58:12 +00:00
|
|
|
async with client.main_caps_client.get("SimulatorFeatures") as features_resp:
|
2023-12-14 02:19:11 +00:00
|
|
|
print("Features:", await features_resp.read_llsd())
|
|
|
|
|
|
2023-12-13 19:19:14 +00:00
|
|
|
while True:
|
|
|
|
|
try:
|
|
|
|
|
await asyncio.sleep(0.001)
|
|
|
|
|
except (KeyboardInterrupt, asyncio.CancelledError):
|
2023-12-13 20:42:21 +00:00
|
|
|
await client.send_chat("Goodbye World!", chat_type=ChatType.SHOUT)
|
2023-12-13 19:19:14 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
asyncio.run(amain())
|