@@ -50,25 +50,32 @@ The `DpsnPlugin` is designed to be used within the Virtuals Protocol Game SDK fr
5050
5151``` python
5252# Import the pre-instantiated plugin (recommended)
53- from plugins.dpsn.dpsn_plugin_gamesdk.dpsn_plugin import plugin
53+ from plugins.dpsn.dpsn_plugin_gamesdk.dpsn_plugin import DpsnPlugin
54+ load_dotenv()
55+
56+ dpsn_plugin= DpsnPlugin(
57+ dpsn_url = os.getenv(" DPSN_URL" ),
58+ pvt_key = os.getenv(" PVT_KEY" )
59+ )
60+
5461# Define a simple message handler
5562def handle_message (message_data ):
5663 topic = message_data.get(' topic' , ' unknown' )
5764 payload = message_data.get(' payload' , {})
5865 print (f " Message on { topic} : { payload} " )
5966
6067# Register the message handler
61- plugin .set_message_callback(handle_message)
68+ dpsn_plugin .set_message_callback(handle_message)
6269
6370# Subscribe to a topic
64- status, message, details = plugin .subscribe(
71+ status, message, details = dpsn_plugin .subscribe(
6572 topic = " 0xe14768a6d8798e4390ec4cb8a4c991202c2115a5cd7a6c0a7ababcaf93b4d2d4/BTCUSDT/ticker"
6673)
6774print (f " Subscription status: { status} , Message: { message} " )
6875
6976# Later when done:
70- # plugin .unsubscribe(topic="0xe14768a6d8798e4390ec4cb8a4c991202c2115a5cd7a6c0a7ababcaf93b4d2d4/BTCUSDT/ticker")
71- # plugin .shutdown()
77+ dpsn_plugin .unsubscribe(topic = " 0xe14768a6d8798e4390ec4cb8a4c991202c2115a5cd7a6c0a7ababcaf93b4d2d4/BTCUSDT/ticker" )
78+ dpsn_plugin .shutdown()
7279
7380```
7481
@@ -79,8 +86,14 @@ The Game Agent interacts with the plugin by executing tasks that map to the plug
7986``` python
8087from game_sdk.game.agent import Agent, WorkerConfig
8188from game_sdk.game.custom_types import FunctionResult
82- from dpsn_plugin_gamesdk.dpsn_plugin import plugin
89+ from dpsn_plugin_gamesdk.dpsn_plugin import DpsnPlugin
90+
91+ load_dotenv()
8392
93+ dpsn_plugin= DpsnPlugin(
94+ dpsn_url = os.getenv(" DPSN_URL" ),
95+ pvt_key = os.getenv(" PVT_KEY" )
96+ )
8497# --- Add Message Handler ---
8598def handle_incoming_message (message_data : dict ):
8699 """ Callback function to process messages received via the plugin."""
@@ -102,7 +115,7 @@ def handle_incoming_message(message_data: dict):
102115 print (f " Error in message handler: { e} " )
103116
104117# Set the callback in the plugin instance *before* running the agent
105- plugin .set_message_callback(handle_incoming_message)
118+ dpsn_plugin .set_message_callback(handle_incoming_message)
106119
107120def get_agent_state_fn (function_result : FunctionResult, current_state : dict ) -> dict :
108121 """ Update state based on the function results"""
@@ -134,9 +147,9 @@ subscription_worker = WorkerConfig(
134147 worker_description = " Worker specialized in managing DPSN topic subscriptions, unsubscriptions, message handling, and shutdown." ,
135148 get_state_fn = get_worker_state,
136149 action_space = [
137- plugin .get_function(" subscribe" ),
138- plugin .get_function(" unsubscribe" ),
139- plugin .get_function(" shutdown" )
150+ dpsn_plugin .get_function(" subscribe" ),
151+ dpsn_plugin .get_function(" unsubscribe" ),
152+ dpsn_plugin .get_function(" shutdown" )
140153 ],
141154)
142155
@@ -188,6 +201,4 @@ The plugin exposes the following functions intended to be called via the Game Ag
188201
189202
190203
191- > In case of any queries regarding DPSN, please reach out to the team on [ Telegram] ( https://t.me/dpsn_dev ) 📥.
192-
193-
204+ > In case of any queries regarding DPSN, please reach out to the team on [ Telegram] ( https://t.me/dpsn_dev ) 📥.
0 commit comments