@caspertech/node-metaverse 0.7.24 → 0.7.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,178 +1,178 @@
1
- import { Vector3 } from '../lib';
2
- import { LoginResponse } from '../lib/classes/LoginResponse';
3
- import { Bot } from '../lib/Bot';
4
- import { LoginParameters } from '../lib/classes/LoginParameters';
5
- import { BotOptionFlags } from '../lib/enums/BotOptionFlags';
6
-
7
- import * as path from 'path';
8
-
9
- import Signals = NodeJS.Signals;
10
- import Timeout = NodeJS.Timeout;
11
-
12
- export class ExampleBot
13
- {
14
- protected masterAvatar = 'd1cd5b71-6209-4595-9bf0-771bf689ce00';
15
- protected isConnected = false;
16
- protected isConnecting = false;
17
- protected loginParamsJsonFile: string;
18
- protected loginResponse?: LoginResponse;
19
- protected bot: Bot;
20
- private reconnectTimer?: Timeout;
21
- protected loginParameters: LoginParameters;
22
-
23
- protected stayRegion?: string;
24
- protected stayPosition?: Vector3;
25
- protected firstName?: string;
26
- protected lastName?: string;
27
-
28
- constructor()
29
- {
30
- this.loginParamsJsonFile = path.join(__dirname, '..', '..', 'examples', 'loginParameters.json');
31
- this.loginParameters = require(this.loginParamsJsonFile);
32
- this.firstName = this.loginParameters.firstName;
33
- this.lastName = this.loginParameters.lastName;
34
-
35
- // If you don't intend to use the object store (i.e you have no interest in inworld objects, textures, etc,
36
- // using nmv.BotOptionFlags.LiteObjectStore will drastically reduce the footprint and CPU usage.
37
- //
38
- // The full object store has a full searchable rtree index, the lite does not.
39
- //
40
- // For the minimum footprint, use :
41
- //
42
- // const options = nmv.BotOptionFlags.LiteObjectStore | nmv.BotOptionFlags.StoreMyAttachmentsOnly;
43
-
44
- const options = BotOptionFlags.None;
45
-
46
- this.bot = new Bot(this.loginParameters, options);
47
- }
48
-
49
- public async run(): Promise<void>
50
- {
51
- const exitHandler = async(options: { exit?: boolean }, err: Error | number | Signals) =>
52
- {
53
- if (err && err instanceof Error)
54
- {
55
- console.log(err.stack);
56
- }
57
- if (this.isConnected)
58
- {
59
- console.log('Disconnecting');
60
- try
61
- {
62
- await this.bot.close();
63
- }
64
- catch (error)
65
- {
66
- console.error('Error when closing client:');
67
- console.error(error);
68
- }
69
- process.exit();
70
- return;
71
- }
72
- if (options.exit)
73
- {
74
- process.exit();
75
- }
76
- }
77
-
78
-
79
-
80
- // Do something when app is closing
81
- process.on('exit', exitHandler.bind(this, {}));
82
-
83
- // Catches ctrl+c event
84
- process.on('SIGINT', exitHandler.bind(this, { exit: true }));
85
-
86
- // Catches "kill pid"
87
- process.on('SIGUSR1', exitHandler.bind(this, { exit: true }));
88
- process.on('SIGUSR2', exitHandler.bind(this, { exit: true }));
89
-
90
- // Catches uncaught exceptions
91
- process.on('uncaughtException', exitHandler.bind(this, { exit: true }));
92
-
93
- // This will tell the bot to keep trying to teleport back to the 'stay' location.
94
- // You can specify a region and position, such as:
95
- // bot.stayPut(true, 'Izanagi', new nmv.Vector3([128, 128, 21]));
96
- // Note that the 'stay' location will be updated if you request or accept a lure (a teleport).
97
- // If no region is specified, it will be set to the region you log in to.
98
- this.bot.stayPut(true, this.stayRegion, this.stayPosition);
99
-
100
- await this.login();
101
- }
102
-
103
- protected async onConnected(): Promise<void>
104
- {
105
-
106
- }
107
-
108
- protected async login(): Promise<void>
109
- {
110
- if (this.isConnecting)
111
- {
112
- return;
113
- }
114
- this.isConnecting = true;
115
- try
116
- {
117
- if (this.reconnectTimer !== undefined)
118
- {
119
- clearInterval(this.reconnectTimer);
120
- }
121
- this.reconnectTimer = setInterval(this.reconnectCheck.bind(this), 60000);
122
-
123
- console.log('Logging in..');
124
- this.loginResponse = await this.bot.login();
125
-
126
- console.log('Login complete');
127
-
128
- // Establish circuit with region
129
- await this.bot.connectToSim();
130
-
131
- console.log('Waiting for event queue');
132
- await this.bot.waitForEventQueue();
133
-
134
- this.isConnected = true;
135
- }
136
- finally
137
- {
138
- this.isConnecting = false;
139
- }
140
- return this.connected();
141
- }
142
-
143
- private async reconnectCheck(): Promise<void>
144
- {
145
- if (!this.isConnected)
146
- {
147
- await this.login();
148
- }
149
- }
150
-
151
- private async connected(): Promise<void>
152
- {
153
- this.bot.clientEvents.onDisconnected.subscribe((event) =>
154
- {
155
- if (event.requested)
156
- {
157
- if (this.reconnectTimer !== undefined)
158
- {
159
- clearInterval(this.reconnectTimer);
160
- }
161
- }
162
- this.isConnected = false;
163
- console.log('Disconnected from simulator: ' + event.message);
164
- });
165
- await this.onConnected();
166
- }
167
-
168
- // @ts-ignore
169
- private async close(): Promise<void>
170
- {
171
- if (this.reconnectTimer !== undefined)
172
- {
173
- clearInterval(this.reconnectTimer);
174
- this.reconnectTimer = undefined;
175
- }
176
- return this.bot.close();
177
- }
178
- }
1
+ import { Vector3 } from '../lib';
2
+ import { LoginResponse } from '../lib/classes/LoginResponse';
3
+ import { Bot } from '../lib/Bot';
4
+ import { LoginParameters } from '../lib/classes/LoginParameters';
5
+ import { BotOptionFlags } from '../lib/enums/BotOptionFlags';
6
+
7
+ import * as path from 'path';
8
+
9
+ import Signals = NodeJS.Signals;
10
+ import Timeout = NodeJS.Timeout;
11
+
12
+ export class ExampleBot
13
+ {
14
+ protected masterAvatar = 'd1cd5b71-6209-4595-9bf0-771bf689ce00';
15
+ protected isConnected = false;
16
+ protected isConnecting = false;
17
+ protected loginParamsJsonFile: string;
18
+ protected loginResponse?: LoginResponse;
19
+ protected bot: Bot;
20
+ private reconnectTimer?: Timeout;
21
+ protected loginParameters: LoginParameters;
22
+
23
+ protected stayRegion?: string;
24
+ protected stayPosition?: Vector3;
25
+ protected firstName?: string;
26
+ protected lastName?: string;
27
+
28
+ constructor()
29
+ {
30
+ this.loginParamsJsonFile = path.join(__dirname, '..', '..', 'examples', 'loginParameters.json');
31
+ this.loginParameters = require(this.loginParamsJsonFile);
32
+ this.firstName = this.loginParameters.firstName;
33
+ this.lastName = this.loginParameters.lastName;
34
+
35
+ // If you don't intend to use the object store (i.e you have no interest in inworld objects, textures, etc,
36
+ // using nmv.BotOptionFlags.LiteObjectStore will drastically reduce the footprint and CPU usage.
37
+ //
38
+ // The full object store has a full searchable rtree index, the lite does not.
39
+ //
40
+ // For the minimum footprint, use :
41
+ //
42
+ // const options = nmv.BotOptionFlags.LiteObjectStore | nmv.BotOptionFlags.StoreMyAttachmentsOnly;
43
+
44
+ const options = BotOptionFlags.None;
45
+
46
+ this.bot = new Bot(this.loginParameters, options);
47
+ }
48
+
49
+ public async run(): Promise<void>
50
+ {
51
+ const exitHandler = async(options: { exit?: boolean }, err: Error | number | Signals) =>
52
+ {
53
+ if (err && err instanceof Error)
54
+ {
55
+ console.log(err.stack);
56
+ }
57
+ if (this.isConnected)
58
+ {
59
+ console.log('Disconnecting');
60
+ try
61
+ {
62
+ await this.bot.close();
63
+ }
64
+ catch (error)
65
+ {
66
+ console.error('Error when closing client:');
67
+ console.error(error);
68
+ }
69
+ process.exit();
70
+ return;
71
+ }
72
+ if (options.exit)
73
+ {
74
+ process.exit();
75
+ }
76
+ }
77
+
78
+
79
+
80
+ // Do something when app is closing
81
+ process.on('exit', exitHandler.bind(this, {}));
82
+
83
+ // Catches ctrl+c event
84
+ process.on('SIGINT', exitHandler.bind(this, { exit: true }));
85
+
86
+ // Catches "kill pid"
87
+ process.on('SIGUSR1', exitHandler.bind(this, { exit: true }));
88
+ process.on('SIGUSR2', exitHandler.bind(this, { exit: true }));
89
+
90
+ // Catches uncaught exceptions
91
+ process.on('uncaughtException', exitHandler.bind(this, { exit: true }));
92
+
93
+ // This will tell the bot to keep trying to teleport back to the 'stay' location.
94
+ // You can specify a region and position, such as:
95
+ // bot.stayPut(true, 'Izanagi', new nmv.Vector3([128, 128, 21]));
96
+ // Note that the 'stay' location will be updated if you request or accept a lure (a teleport).
97
+ // If no region is specified, it will be set to the region you log in to.
98
+ this.bot.stayPut(true, this.stayRegion, this.stayPosition);
99
+
100
+ await this.login();
101
+ }
102
+
103
+ protected async onConnected(): Promise<void>
104
+ {
105
+
106
+ }
107
+
108
+ protected async login(): Promise<void>
109
+ {
110
+ if (this.isConnecting)
111
+ {
112
+ return;
113
+ }
114
+ this.isConnecting = true;
115
+ try
116
+ {
117
+ if (this.reconnectTimer !== undefined)
118
+ {
119
+ clearInterval(this.reconnectTimer);
120
+ }
121
+ this.reconnectTimer = setInterval(this.reconnectCheck.bind(this), 60000);
122
+
123
+ console.log('Logging in..');
124
+ this.loginResponse = await this.bot.login();
125
+
126
+ console.log('Login complete');
127
+
128
+ // Establish circuit with region
129
+ await this.bot.connectToSim();
130
+
131
+ console.log('Waiting for event queue');
132
+ await this.bot.waitForEventQueue();
133
+
134
+ this.isConnected = true;
135
+ }
136
+ finally
137
+ {
138
+ this.isConnecting = false;
139
+ }
140
+ return this.connected();
141
+ }
142
+
143
+ private async reconnectCheck(): Promise<void>
144
+ {
145
+ if (!this.isConnected)
146
+ {
147
+ await this.login();
148
+ }
149
+ }
150
+
151
+ private async connected(): Promise<void>
152
+ {
153
+ this.bot.clientEvents.onDisconnected.subscribe((event) =>
154
+ {
155
+ if (event.requested)
156
+ {
157
+ if (this.reconnectTimer !== undefined)
158
+ {
159
+ clearInterval(this.reconnectTimer);
160
+ }
161
+ }
162
+ this.isConnected = false;
163
+ console.log('Disconnected from simulator: ' + event.message);
164
+ });
165
+ await this.onConnected();
166
+ }
167
+
168
+ // @ts-ignore
169
+ private async close(): Promise<void>
170
+ {
171
+ if (this.reconnectTimer !== undefined)
172
+ {
173
+ clearInterval(this.reconnectTimer);
174
+ this.reconnectTimer = undefined;
175
+ }
176
+ return this.bot.close();
177
+ }
178
+ }
@@ -1,67 +1,67 @@
1
- import { ExampleBot } from '../ExampleBot';
2
- import { FriendRequestEvent } from '../../lib/events/FriendRequestEvent';
3
- import { FriendResponseEvent } from '../../lib/events/FriendResponseEvent';
4
-
5
- class Friends extends ExampleBot
6
- {
7
- async onConnected(): Promise<void>
8
- {
9
- this.bot.clientEvents.onFriendRequest.subscribe(this.onFriendRequest.bind(this));
10
- this.bot.clientEvents.onFriendResponse.subscribe(this.onFriendResponse.bind(this));
11
-
12
- this.bot.clientCommands.friends.sendFriendRequest(this.masterAvatar, 'Be friends with me?').then(() =>
13
- {
14
-
15
- });
16
-
17
- try
18
- {
19
- // Get map location of the master avatar. Will fail if you don't have map rights
20
- const regionLocation = await this.bot.clientCommands.friends.getFriendMapLocation(this.masterAvatar);
21
- console.log('Master is in ' + regionLocation.regionName + ' at <' + regionLocation.localX + ', ' + regionLocation.localY + '> and there are ' + regionLocation.avatars.length + ' other avatars there too! You stalker!');
22
- }
23
- catch (error)
24
- {
25
- console.log('Map location request failed. The bot probably does not have map rights on the master avatar, or they are offline.');
26
- }
27
- }
28
-
29
- async onFriendRequest(event: FriendRequestEvent): Promise<void>
30
- {
31
- if (event.from.toString() === this.masterAvatar)
32
- {
33
- console.log('Accepting friend request from ' + event.fromName);
34
- this.bot.clientCommands.friends.acceptFriendRequest(event).then(() =>
35
- {
36
- });
37
- }
38
- else
39
- {
40
- console.log('Rejecting friend request from ' + event.fromName);
41
- this.bot.clientCommands.friends.rejectFriendRequest(event).then(() =>
42
- {
43
- });
44
- }
45
- }
46
-
47
- async onFriendResponse(response: FriendResponseEvent): Promise<void>
48
- {
49
- if (response.accepted)
50
- {
51
- console.log(response.fromName + ' accepted your friend request');
52
- }
53
- else
54
- {
55
- console.log(response.fromName + ' declined your friend request');
56
- }
57
- }
58
-
59
- }
60
-
61
- new Friends().run().then(() =>
62
- {
63
-
64
- }).catch((err) =>
65
- {
66
- console.error(err);
67
- });
1
+ import { ExampleBot } from '../ExampleBot';
2
+ import { FriendRequestEvent } from '../../lib/events/FriendRequestEvent';
3
+ import { FriendResponseEvent } from '../../lib/events/FriendResponseEvent';
4
+
5
+ class Friends extends ExampleBot
6
+ {
7
+ async onConnected(): Promise<void>
8
+ {
9
+ this.bot.clientEvents.onFriendRequest.subscribe(this.onFriendRequest.bind(this));
10
+ this.bot.clientEvents.onFriendResponse.subscribe(this.onFriendResponse.bind(this));
11
+
12
+ this.bot.clientCommands.friends.sendFriendRequest(this.masterAvatar, 'Be friends with me?').then(() =>
13
+ {
14
+
15
+ });
16
+
17
+ try
18
+ {
19
+ // Get map location of the master avatar. Will fail if you don't have map rights
20
+ const regionLocation = await this.bot.clientCommands.friends.getFriendMapLocation(this.masterAvatar);
21
+ console.log('Master is in ' + regionLocation.regionName + ' at <' + regionLocation.localX + ', ' + regionLocation.localY + '> and there are ' + regionLocation.avatars.length + ' other avatars there too! You stalker!');
22
+ }
23
+ catch (error)
24
+ {
25
+ console.log('Map location request failed. The bot probably does not have map rights on the master avatar, or they are offline.');
26
+ }
27
+ }
28
+
29
+ async onFriendRequest(event: FriendRequestEvent): Promise<void>
30
+ {
31
+ if (event.from.toString() === this.masterAvatar)
32
+ {
33
+ console.log('Accepting friend request from ' + event.fromName);
34
+ this.bot.clientCommands.friends.acceptFriendRequest(event).then(() =>
35
+ {
36
+ });
37
+ }
38
+ else
39
+ {
40
+ console.log('Rejecting friend request from ' + event.fromName);
41
+ this.bot.clientCommands.friends.rejectFriendRequest(event).then(() =>
42
+ {
43
+ });
44
+ }
45
+ }
46
+
47
+ async onFriendResponse(response: FriendResponseEvent): Promise<void>
48
+ {
49
+ if (response.accepted)
50
+ {
51
+ console.log(response.fromName + ' accepted your friend request');
52
+ }
53
+ else
54
+ {
55
+ console.log(response.fromName + ' declined your friend request');
56
+ }
57
+ }
58
+
59
+ }
60
+
61
+ new Friends().run().then(() =>
62
+ {
63
+
64
+ }).catch((err) =>
65
+ {
66
+ console.error(err);
67
+ });
@@ -1,50 +1,50 @@
1
- import { ExampleBot } from '../ExampleBot';
2
-
3
- class Name2Key extends ExampleBot
4
- {
5
- async onConnected(): Promise<void>
6
- {
7
- const test1 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp');
8
- if (test1.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test1.avatarName === 'CasperHelp Resident')
9
- {
10
- console.log('Test 1 passed');
11
- }
12
- const test2 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp resident');
13
- if (test2.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test2.avatarName === 'CasperHelp Resident')
14
- {
15
- console.log('Test 2 passed');
16
- }
17
-
18
- const test3 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp.resident');
19
- if (test3.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test3.avatarName === 'CasperHelp Resident')
20
- {
21
- console.log('Test 3 passed');
22
- }
23
-
24
- const test4 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp', false);
25
- if (test4.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test4.avatarName === 'CasperHelp Resident')
26
- {
27
- console.log('Test 4 passed');
28
- }
29
-
30
- const test5 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp resident', false);
31
- if (test5.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test5.avatarName === 'CasperHelp Resident')
32
- {
33
- console.log('Test 5 passed');
34
- }
35
-
36
- const test6 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp.resident', false);
37
- if (test6.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test6.avatarName === 'CasperHelp Resident')
38
- {
39
- console.log('Test 6 passed');
40
- }
41
- }
42
- }
43
-
44
- new Name2Key().run().then(() =>
45
- {
46
-
47
- }).catch((err) =>
48
- {
49
- console.error(err);
50
- });
1
+ import { ExampleBot } from '../ExampleBot';
2
+
3
+ class Name2Key extends ExampleBot
4
+ {
5
+ async onConnected(): Promise<void>
6
+ {
7
+ const test1 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp');
8
+ if (test1.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test1.avatarName === 'CasperHelp Resident')
9
+ {
10
+ console.log('Test 1 passed');
11
+ }
12
+ const test2 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp resident');
13
+ if (test2.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test2.avatarName === 'CasperHelp Resident')
14
+ {
15
+ console.log('Test 2 passed');
16
+ }
17
+
18
+ const test3 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp.resident');
19
+ if (test3.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test3.avatarName === 'CasperHelp Resident')
20
+ {
21
+ console.log('Test 3 passed');
22
+ }
23
+
24
+ const test4 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp', false);
25
+ if (test4.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test4.avatarName === 'CasperHelp Resident')
26
+ {
27
+ console.log('Test 4 passed');
28
+ }
29
+
30
+ const test5 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp resident', false);
31
+ if (test5.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test5.avatarName === 'CasperHelp Resident')
32
+ {
33
+ console.log('Test 5 passed');
34
+ }
35
+
36
+ const test6 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp.resident', false);
37
+ if (test6.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test6.avatarName === 'CasperHelp Resident')
38
+ {
39
+ console.log('Test 6 passed');
40
+ }
41
+ }
42
+ }
43
+
44
+ new Name2Key().run().then(() =>
45
+ {
46
+
47
+ }).catch((err) =>
48
+ {
49
+ console.error(err);
50
+ });