@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.
- package/.editorconfig +817 -817
- package/.eslintrc +224 -224
- package/IdeaCodeStyle.xml +68 -68
- package/LICENSE +21 -21
- package/README.md +78 -78
- package/dist/keepme.txt +0 -0
- package/dist/lib/classes/ParticleSystem.js +0 -1
- package/dist/lib/classes/ParticleSystem.js.map +1 -1
- package/dist/lib/classes/llsd/LLSDNotationParser.spec.js +46 -46
- package/dist/lib/classes/public/GameObject.d.ts +2 -2
- package/dist/lib/classes/public/GameObject.js +10 -10
- package/dist/lib/classes/public/GameObject.js.map +1 -1
- package/examples/Camera/Camera.ts +24 -24
- package/examples/ExampleBot.ts +178 -178
- package/examples/Friends/Friends.ts +67 -67
- package/examples/Grid/Name2Key.ts +50 -50
- package/examples/Groups/Group.ts +102 -102
- package/examples/Groups/GroupChat.ts +112 -112
- package/examples/InstantMessages/InstantMessages.ts +41 -41
- package/examples/Inventory/Inventory.ts +175 -175
- package/examples/MFA/MFA.ts +55 -55
- package/examples/Money/Money.ts +63 -63
- package/examples/Objects/TaskInventory.ts +35 -35
- package/examples/Region/Agents.ts +81 -81
- package/examples/Region/Estate.ts +34 -34
- package/examples/Region/Parcels.ts +31 -31
- package/examples/Region/Region.ts +23 -23
- package/examples/Teleports/Teleports.ts +60 -60
- package/package.json +71 -71
|
@@ -1,175 +1,175 @@
|
|
|
1
|
-
import { ExampleBot } from '../ExampleBot';
|
|
2
|
-
import { InventoryFolder } from '../../lib/classes/InventoryFolder';
|
|
3
|
-
import { FolderType } from '../../lib/enums/FolderType';
|
|
4
|
-
import { InventoryItem } from '../../lib/classes/InventoryItem';
|
|
5
|
-
import { LLLindenText } from '../../lib/classes/LLLindenText';
|
|
6
|
-
import { AssetType } from '../../lib/enums/AssetType';
|
|
7
|
-
import { InventoryType } from '../../lib/enums/InventoryType';
|
|
8
|
-
import { PermissionMask } from '../../lib/enums/PermissionMask';
|
|
9
|
-
import { InventoryResponseEvent } from '../../lib/events/InventoryResponseEvent';
|
|
10
|
-
import { InventoryOfferedEvent } from '../../lib/events/InventoryOfferedEvent';
|
|
11
|
-
import { UUID } from '../../lib';
|
|
12
|
-
|
|
13
|
-
class Inventory extends ExampleBot
|
|
14
|
-
{
|
|
15
|
-
async onConnected(): Promise<void>
|
|
16
|
-
{
|
|
17
|
-
this.bot.clientEvents.onInventoryOffered.subscribe(this.onInventoryOffered.bind(this));
|
|
18
|
-
this.bot.clientEvents.onInventoryResponse.subscribe(this.onInventoryResponse.bind(this));
|
|
19
|
-
|
|
20
|
-
// Get the root inventory folder
|
|
21
|
-
const rootFolder = this.bot.clientCommands.inventory.getInventoryRoot();
|
|
22
|
-
|
|
23
|
-
// Populate the root folder
|
|
24
|
-
await rootFolder.populate(false);
|
|
25
|
-
|
|
26
|
-
const exampleFolderName = 'node-metaverse example';
|
|
27
|
-
const exampleNotecardName = 'Example Notecard';
|
|
28
|
-
const exampleScriptName = 'Example script';
|
|
29
|
-
|
|
30
|
-
let exampleFolder: InventoryFolder | undefined = undefined;
|
|
31
|
-
for (const childFolder of rootFolder.folders)
|
|
32
|
-
{
|
|
33
|
-
if (childFolder.name === exampleFolderName)
|
|
34
|
-
{
|
|
35
|
-
exampleFolder = childFolder;
|
|
36
|
-
await exampleFolder.populate(false);
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Our folder doesnt' seem to exist, so create it
|
|
42
|
-
if (exampleFolder === undefined)
|
|
43
|
-
{
|
|
44
|
-
exampleFolder = await rootFolder.createFolder(exampleFolderName, FolderType.None);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// See if we've already made our test notecard to avoid clutter..
|
|
48
|
-
let exampleNotecard: InventoryItem | undefined = undefined;
|
|
49
|
-
for (const childItem of exampleFolder.items)
|
|
50
|
-
{
|
|
51
|
-
if (childItem.name === exampleNotecardName)
|
|
52
|
-
{
|
|
53
|
-
exampleNotecard = childItem;
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Create the notecard
|
|
59
|
-
if (exampleNotecard === undefined)
|
|
60
|
-
{
|
|
61
|
-
const notecard = new LLLindenText();
|
|
62
|
-
notecard.body = 'This is a notecard I made all by myself at ' + new Date().toString();
|
|
63
|
-
exampleNotecard = await exampleFolder.uploadAsset(AssetType.Notecard, InventoryType.Notecard, notecard.toAsset(), exampleNotecardName, 'This is an example notecard');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Set notecard to transfer only
|
|
67
|
-
exampleNotecard.permissions.nextOwnerMask = PermissionMask.Transfer | PermissionMask.Modify;
|
|
68
|
-
await exampleNotecard.update();
|
|
69
|
-
|
|
70
|
-
// Make a copy of the notecard
|
|
71
|
-
const copy = await exampleNotecard.copyTo(exampleFolder, exampleNotecard.name + ' - The comeback ' + UUID.random().toString().substring(0, 8));
|
|
72
|
-
|
|
73
|
-
// Delete the copy
|
|
74
|
-
await copy.delete();
|
|
75
|
-
|
|
76
|
-
// Let's set some perms
|
|
77
|
-
const copyOnly = await exampleNotecard.copyTo(exampleFolder, exampleNotecard.name + ' - Copy Only ' + UUID.random().toString().substring(0, 8));
|
|
78
|
-
copyOnly.permissions.nextOwnerMask = PermissionMask.Copy;
|
|
79
|
-
await copyOnly.update();
|
|
80
|
-
|
|
81
|
-
const modOnly = await exampleNotecard.copyTo(exampleFolder, exampleNotecard.name + ' - Mod Only ' + UUID.random().toString().substring(0, 8));
|
|
82
|
-
modOnly.permissions.nextOwnerMask = PermissionMask.Modify;
|
|
83
|
-
await modOnly.update();
|
|
84
|
-
|
|
85
|
-
const transOnly = await exampleNotecard.copyTo(exampleFolder, exampleNotecard.name + ' - Trans Only ' + UUID.random().toString().substring(0, 8));
|
|
86
|
-
transOnly.permissions.nextOwnerMask = PermissionMask.Transfer;
|
|
87
|
-
await transOnly.update();
|
|
88
|
-
|
|
89
|
-
let exampleScript = exampleFolder.items.find(f => f.name === exampleScriptName);
|
|
90
|
-
if (exampleScript === undefined)
|
|
91
|
-
{
|
|
92
|
-
exampleScript = await exampleFolder.uploadAsset(
|
|
93
|
-
AssetType.LSLText,
|
|
94
|
-
InventoryType.LSL,
|
|
95
|
-
Buffer.from(
|
|
96
|
-
'default { touch_start(integer total_number) { llSay(0, "Hello, world!"); } } '
|
|
97
|
-
, 'utf-8'
|
|
98
|
-
),
|
|
99
|
-
'Script',
|
|
100
|
-
''
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Give the notecard to our owner
|
|
105
|
-
await this.bot.clientCommands.comms.giveInventory(this.masterAvatar, exampleNotecard);
|
|
106
|
-
|
|
107
|
-
// Enumerate library
|
|
108
|
-
const folders = this.bot.clientCommands.inventory.getLibraryRoot().getChildFolders();
|
|
109
|
-
for (const folder of folders)
|
|
110
|
-
{
|
|
111
|
-
await this.iterateFolder(folder, '[ROOT]');
|
|
112
|
-
}
|
|
113
|
-
console.log('Done iterating through library');
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async onInventoryResponse(response: InventoryResponseEvent): Promise<void>
|
|
117
|
-
{
|
|
118
|
-
if (response.accepted)
|
|
119
|
-
{
|
|
120
|
-
console.log(response.fromName + ' accepted your inventory offer');
|
|
121
|
-
}
|
|
122
|
-
else
|
|
123
|
-
{
|
|
124
|
-
console.log(response.fromName + ' declined your inventory offer');
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async iterateFolder(folder: InventoryFolder, prefix: string): Promise<void>
|
|
129
|
-
{
|
|
130
|
-
console.log(prefix + ' [' + folder.name + ']');
|
|
131
|
-
await folder.populate(false);
|
|
132
|
-
|
|
133
|
-
for (const subFolder of folder.folders)
|
|
134
|
-
{
|
|
135
|
-
await this.iterateFolder(subFolder, prefix + ' [' + folder.name + ']');
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
for (const item of folder.items)
|
|
139
|
-
{
|
|
140
|
-
console.log(prefix + ' [' + folder.name + ']' + ': ' + item.name);
|
|
141
|
-
|
|
142
|
-
if (item.name === 'anim SMOOTH')
|
|
143
|
-
{
|
|
144
|
-
// Send this to our master av
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
async onInventoryOffered(event: InventoryOfferedEvent): Promise<void>
|
|
151
|
-
{
|
|
152
|
-
if (event.from.toString() === this.masterAvatar)
|
|
153
|
-
{
|
|
154
|
-
console.log('Accepting inventory offer from ' + event.fromName);
|
|
155
|
-
this.bot.clientCommands.inventory.acceptInventoryOffer(event).then(() =>
|
|
156
|
-
{
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
else
|
|
160
|
-
{
|
|
161
|
-
console.log('Rejecting inventory offer from ' + event.fromName);
|
|
162
|
-
this.bot.clientCommands.inventory.rejectInventoryOffer(event).then(() =>
|
|
163
|
-
{
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
new Inventory().run().then(() =>
|
|
170
|
-
{
|
|
171
|
-
|
|
172
|
-
}).catch((err) =>
|
|
173
|
-
{
|
|
174
|
-
console.error(err);
|
|
175
|
-
});
|
|
1
|
+
import { ExampleBot } from '../ExampleBot';
|
|
2
|
+
import { InventoryFolder } from '../../lib/classes/InventoryFolder';
|
|
3
|
+
import { FolderType } from '../../lib/enums/FolderType';
|
|
4
|
+
import { InventoryItem } from '../../lib/classes/InventoryItem';
|
|
5
|
+
import { LLLindenText } from '../../lib/classes/LLLindenText';
|
|
6
|
+
import { AssetType } from '../../lib/enums/AssetType';
|
|
7
|
+
import { InventoryType } from '../../lib/enums/InventoryType';
|
|
8
|
+
import { PermissionMask } from '../../lib/enums/PermissionMask';
|
|
9
|
+
import { InventoryResponseEvent } from '../../lib/events/InventoryResponseEvent';
|
|
10
|
+
import { InventoryOfferedEvent } from '../../lib/events/InventoryOfferedEvent';
|
|
11
|
+
import { UUID } from '../../lib';
|
|
12
|
+
|
|
13
|
+
class Inventory extends ExampleBot
|
|
14
|
+
{
|
|
15
|
+
async onConnected(): Promise<void>
|
|
16
|
+
{
|
|
17
|
+
this.bot.clientEvents.onInventoryOffered.subscribe(this.onInventoryOffered.bind(this));
|
|
18
|
+
this.bot.clientEvents.onInventoryResponse.subscribe(this.onInventoryResponse.bind(this));
|
|
19
|
+
|
|
20
|
+
// Get the root inventory folder
|
|
21
|
+
const rootFolder = this.bot.clientCommands.inventory.getInventoryRoot();
|
|
22
|
+
|
|
23
|
+
// Populate the root folder
|
|
24
|
+
await rootFolder.populate(false);
|
|
25
|
+
|
|
26
|
+
const exampleFolderName = 'node-metaverse example';
|
|
27
|
+
const exampleNotecardName = 'Example Notecard';
|
|
28
|
+
const exampleScriptName = 'Example script';
|
|
29
|
+
|
|
30
|
+
let exampleFolder: InventoryFolder | undefined = undefined;
|
|
31
|
+
for (const childFolder of rootFolder.folders)
|
|
32
|
+
{
|
|
33
|
+
if (childFolder.name === exampleFolderName)
|
|
34
|
+
{
|
|
35
|
+
exampleFolder = childFolder;
|
|
36
|
+
await exampleFolder.populate(false);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Our folder doesnt' seem to exist, so create it
|
|
42
|
+
if (exampleFolder === undefined)
|
|
43
|
+
{
|
|
44
|
+
exampleFolder = await rootFolder.createFolder(exampleFolderName, FolderType.None);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// See if we've already made our test notecard to avoid clutter..
|
|
48
|
+
let exampleNotecard: InventoryItem | undefined = undefined;
|
|
49
|
+
for (const childItem of exampleFolder.items)
|
|
50
|
+
{
|
|
51
|
+
if (childItem.name === exampleNotecardName)
|
|
52
|
+
{
|
|
53
|
+
exampleNotecard = childItem;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Create the notecard
|
|
59
|
+
if (exampleNotecard === undefined)
|
|
60
|
+
{
|
|
61
|
+
const notecard = new LLLindenText();
|
|
62
|
+
notecard.body = 'This is a notecard I made all by myself at ' + new Date().toString();
|
|
63
|
+
exampleNotecard = await exampleFolder.uploadAsset(AssetType.Notecard, InventoryType.Notecard, notecard.toAsset(), exampleNotecardName, 'This is an example notecard');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Set notecard to transfer only
|
|
67
|
+
exampleNotecard.permissions.nextOwnerMask = PermissionMask.Transfer | PermissionMask.Modify;
|
|
68
|
+
await exampleNotecard.update();
|
|
69
|
+
|
|
70
|
+
// Make a copy of the notecard
|
|
71
|
+
const copy = await exampleNotecard.copyTo(exampleFolder, exampleNotecard.name + ' - The comeback ' + UUID.random().toString().substring(0, 8));
|
|
72
|
+
|
|
73
|
+
// Delete the copy
|
|
74
|
+
await copy.delete();
|
|
75
|
+
|
|
76
|
+
// Let's set some perms
|
|
77
|
+
const copyOnly = await exampleNotecard.copyTo(exampleFolder, exampleNotecard.name + ' - Copy Only ' + UUID.random().toString().substring(0, 8));
|
|
78
|
+
copyOnly.permissions.nextOwnerMask = PermissionMask.Copy;
|
|
79
|
+
await copyOnly.update();
|
|
80
|
+
|
|
81
|
+
const modOnly = await exampleNotecard.copyTo(exampleFolder, exampleNotecard.name + ' - Mod Only ' + UUID.random().toString().substring(0, 8));
|
|
82
|
+
modOnly.permissions.nextOwnerMask = PermissionMask.Modify;
|
|
83
|
+
await modOnly.update();
|
|
84
|
+
|
|
85
|
+
const transOnly = await exampleNotecard.copyTo(exampleFolder, exampleNotecard.name + ' - Trans Only ' + UUID.random().toString().substring(0, 8));
|
|
86
|
+
transOnly.permissions.nextOwnerMask = PermissionMask.Transfer;
|
|
87
|
+
await transOnly.update();
|
|
88
|
+
|
|
89
|
+
let exampleScript = exampleFolder.items.find(f => f.name === exampleScriptName);
|
|
90
|
+
if (exampleScript === undefined)
|
|
91
|
+
{
|
|
92
|
+
exampleScript = await exampleFolder.uploadAsset(
|
|
93
|
+
AssetType.LSLText,
|
|
94
|
+
InventoryType.LSL,
|
|
95
|
+
Buffer.from(
|
|
96
|
+
'default { touch_start(integer total_number) { llSay(0, "Hello, world!"); } } '
|
|
97
|
+
, 'utf-8'
|
|
98
|
+
),
|
|
99
|
+
'Script',
|
|
100
|
+
''
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Give the notecard to our owner
|
|
105
|
+
await this.bot.clientCommands.comms.giveInventory(this.masterAvatar, exampleNotecard);
|
|
106
|
+
|
|
107
|
+
// Enumerate library
|
|
108
|
+
const folders = this.bot.clientCommands.inventory.getLibraryRoot().getChildFolders();
|
|
109
|
+
for (const folder of folders)
|
|
110
|
+
{
|
|
111
|
+
await this.iterateFolder(folder, '[ROOT]');
|
|
112
|
+
}
|
|
113
|
+
console.log('Done iterating through library');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async onInventoryResponse(response: InventoryResponseEvent): Promise<void>
|
|
117
|
+
{
|
|
118
|
+
if (response.accepted)
|
|
119
|
+
{
|
|
120
|
+
console.log(response.fromName + ' accepted your inventory offer');
|
|
121
|
+
}
|
|
122
|
+
else
|
|
123
|
+
{
|
|
124
|
+
console.log(response.fromName + ' declined your inventory offer');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async iterateFolder(folder: InventoryFolder, prefix: string): Promise<void>
|
|
129
|
+
{
|
|
130
|
+
console.log(prefix + ' [' + folder.name + ']');
|
|
131
|
+
await folder.populate(false);
|
|
132
|
+
|
|
133
|
+
for (const subFolder of folder.folders)
|
|
134
|
+
{
|
|
135
|
+
await this.iterateFolder(subFolder, prefix + ' [' + folder.name + ']');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
for (const item of folder.items)
|
|
139
|
+
{
|
|
140
|
+
console.log(prefix + ' [' + folder.name + ']' + ': ' + item.name);
|
|
141
|
+
|
|
142
|
+
if (item.name === 'anim SMOOTH')
|
|
143
|
+
{
|
|
144
|
+
// Send this to our master av
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async onInventoryOffered(event: InventoryOfferedEvent): Promise<void>
|
|
151
|
+
{
|
|
152
|
+
if (event.from.toString() === this.masterAvatar)
|
|
153
|
+
{
|
|
154
|
+
console.log('Accepting inventory offer from ' + event.fromName);
|
|
155
|
+
this.bot.clientCommands.inventory.acceptInventoryOffer(event).then(() =>
|
|
156
|
+
{
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
else
|
|
160
|
+
{
|
|
161
|
+
console.log('Rejecting inventory offer from ' + event.fromName);
|
|
162
|
+
this.bot.clientCommands.inventory.rejectInventoryOffer(event).then(() =>
|
|
163
|
+
{
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
new Inventory().run().then(() =>
|
|
170
|
+
{
|
|
171
|
+
|
|
172
|
+
}).catch((err) =>
|
|
173
|
+
{
|
|
174
|
+
console.error(err);
|
|
175
|
+
});
|
package/examples/MFA/MFA.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import { Logger } from '../../lib/classes/Logger';
|
|
2
|
-
import { LoginError } from '../../lib/classes/LoginError';
|
|
3
|
-
import { ExampleBot } from '../ExampleBot';
|
|
4
|
-
import * as readline from 'readline';
|
|
5
|
-
import * as fs from 'fs';
|
|
6
|
-
|
|
7
|
-
class MFA extends ExampleBot
|
|
8
|
-
{
|
|
9
|
-
public async login(): Promise<void>
|
|
10
|
-
{
|
|
11
|
-
try
|
|
12
|
-
{
|
|
13
|
-
await super.login();
|
|
14
|
-
}
|
|
15
|
-
catch (e: unknown)
|
|
16
|
-
{
|
|
17
|
-
if (e instanceof LoginError)
|
|
18
|
-
{
|
|
19
|
-
if (e.reason === 'mfa_challenge')
|
|
20
|
-
{
|
|
21
|
-
const rl = readline.createInterface({
|
|
22
|
-
input: process.stdin,
|
|
23
|
-
output: process.stdout
|
|
24
|
-
});
|
|
25
|
-
rl.question('Please enter authenticator code for ' + String(this.firstName) + ' ' + String(this.lastName) + '\n# ', (code) =>
|
|
26
|
-
{
|
|
27
|
-
this.bot.loginParameters.token = code;
|
|
28
|
-
void this.login();
|
|
29
|
-
});
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
Logger.Error(e);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public async onConnected(): Promise<void>
|
|
38
|
-
{
|
|
39
|
-
if (this.loginResponse && this.loginResponse.mfaHash)
|
|
40
|
-
{
|
|
41
|
-
// Store MFA hash in our login credentials for next time
|
|
42
|
-
this.loginParameters.mfa_hash = this.loginResponse.mfaHash;
|
|
43
|
-
delete this.loginParameters.token;
|
|
44
|
-
await fs.promises.writeFile(this.loginParamsJsonFile, JSON.stringify(this.loginParameters, null, 4));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
new MFA().run().then(() =>
|
|
50
|
-
{
|
|
51
|
-
|
|
52
|
-
}).catch((err) =>
|
|
53
|
-
{
|
|
54
|
-
console.error(err);
|
|
55
|
-
});
|
|
1
|
+
import { Logger } from '../../lib/classes/Logger';
|
|
2
|
+
import { LoginError } from '../../lib/classes/LoginError';
|
|
3
|
+
import { ExampleBot } from '../ExampleBot';
|
|
4
|
+
import * as readline from 'readline';
|
|
5
|
+
import * as fs from 'fs';
|
|
6
|
+
|
|
7
|
+
class MFA extends ExampleBot
|
|
8
|
+
{
|
|
9
|
+
public async login(): Promise<void>
|
|
10
|
+
{
|
|
11
|
+
try
|
|
12
|
+
{
|
|
13
|
+
await super.login();
|
|
14
|
+
}
|
|
15
|
+
catch (e: unknown)
|
|
16
|
+
{
|
|
17
|
+
if (e instanceof LoginError)
|
|
18
|
+
{
|
|
19
|
+
if (e.reason === 'mfa_challenge')
|
|
20
|
+
{
|
|
21
|
+
const rl = readline.createInterface({
|
|
22
|
+
input: process.stdin,
|
|
23
|
+
output: process.stdout
|
|
24
|
+
});
|
|
25
|
+
rl.question('Please enter authenticator code for ' + String(this.firstName) + ' ' + String(this.lastName) + '\n# ', (code) =>
|
|
26
|
+
{
|
|
27
|
+
this.bot.loginParameters.token = code;
|
|
28
|
+
void this.login();
|
|
29
|
+
});
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
Logger.Error(e);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public async onConnected(): Promise<void>
|
|
38
|
+
{
|
|
39
|
+
if (this.loginResponse && this.loginResponse.mfaHash)
|
|
40
|
+
{
|
|
41
|
+
// Store MFA hash in our login credentials for next time
|
|
42
|
+
this.loginParameters.mfa_hash = this.loginResponse.mfaHash;
|
|
43
|
+
delete this.loginParameters.token;
|
|
44
|
+
await fs.promises.writeFile(this.loginParamsJsonFile, JSON.stringify(this.loginParameters, null, 4));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
new MFA().run().then(() =>
|
|
50
|
+
{
|
|
51
|
+
|
|
52
|
+
}).catch((err) =>
|
|
53
|
+
{
|
|
54
|
+
console.error(err);
|
|
55
|
+
});
|
package/examples/Money/Money.ts
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import { ExampleBot } from '../ExampleBot';
|
|
2
|
-
import { BalanceUpdatedEvent } from '../../lib/events/BalanceUpdatedEvent';
|
|
3
|
-
import { AvatarQueryResult } from '../../lib/classes/public/AvatarQueryResult';
|
|
4
|
-
import { MoneyTransactionType } from '../../lib/enums/MoneyTransactionType';
|
|
5
|
-
|
|
6
|
-
class Money extends ExampleBot
|
|
7
|
-
{
|
|
8
|
-
private balance = 0;
|
|
9
|
-
|
|
10
|
-
async onConnected(): Promise<void>
|
|
11
|
-
{
|
|
12
|
-
this.bot.clientEvents.onBalanceUpdated.subscribe(this.onBalanceUpdated.bind(this));
|
|
13
|
-
try
|
|
14
|
-
{
|
|
15
|
-
this.balance = await this.bot.clientCommands.grid.getBalance();
|
|
16
|
-
console.log('Balance is L$' + this.balance);
|
|
17
|
-
await this.bot.clientCommands.grid.payAvatar('d1cd5b71-6209-4595-9bf0-771bf689ce00', 1, 'This is a gift for being so awesome!');
|
|
18
|
-
console.log('Payment success');
|
|
19
|
-
}
|
|
20
|
-
catch (error)
|
|
21
|
-
{
|
|
22
|
-
console.log('Payment failed');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async onBalanceUpdated(evt: BalanceUpdatedEvent): Promise<void>
|
|
27
|
-
{
|
|
28
|
-
this.balance = evt.balance;
|
|
29
|
-
if (evt.transaction.from.equals(this.bot.agentID()))
|
|
30
|
-
{
|
|
31
|
-
if (evt.transaction.toGroup)
|
|
32
|
-
{
|
|
33
|
-
console.log('You paid a group L$' + evt.transaction.amount);
|
|
34
|
-
}
|
|
35
|
-
else
|
|
36
|
-
{
|
|
37
|
-
const result = await this.bot.clientCommands.grid.avatarKey2Name(evt.transaction.to) as AvatarQueryResult;
|
|
38
|
-
console.log('You paid L$' + evt.transaction.amount + ' to ' + result.getName() + ' "' + evt.transaction.description + '" (' + MoneyTransactionType[evt.transaction.type] + ')');
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
else
|
|
42
|
-
{
|
|
43
|
-
if (evt.transaction.fromGroup)
|
|
44
|
-
{
|
|
45
|
-
console.log('A group paid you L$' + evt.transaction.amount);
|
|
46
|
-
}
|
|
47
|
-
else
|
|
48
|
-
{
|
|
49
|
-
const result = await this.bot.clientCommands.grid.avatarKey2Name(evt.transaction.from) as AvatarQueryResult;
|
|
50
|
-
console.log(result.getName() + ' paid you L$' + evt.transaction.amount + ' "' + evt.transaction.description + '" (' + MoneyTransactionType[evt.transaction.type] + ')');
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
console.log('Balance updated (New balance L$' + evt.balance + ')');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
new Money().run().then(() =>
|
|
58
|
-
{
|
|
59
|
-
|
|
60
|
-
}).catch((err) =>
|
|
61
|
-
{
|
|
62
|
-
console.error(err);
|
|
63
|
-
});
|
|
1
|
+
import { ExampleBot } from '../ExampleBot';
|
|
2
|
+
import { BalanceUpdatedEvent } from '../../lib/events/BalanceUpdatedEvent';
|
|
3
|
+
import { AvatarQueryResult } from '../../lib/classes/public/AvatarQueryResult';
|
|
4
|
+
import { MoneyTransactionType } from '../../lib/enums/MoneyTransactionType';
|
|
5
|
+
|
|
6
|
+
class Money extends ExampleBot
|
|
7
|
+
{
|
|
8
|
+
private balance = 0;
|
|
9
|
+
|
|
10
|
+
async onConnected(): Promise<void>
|
|
11
|
+
{
|
|
12
|
+
this.bot.clientEvents.onBalanceUpdated.subscribe(this.onBalanceUpdated.bind(this));
|
|
13
|
+
try
|
|
14
|
+
{
|
|
15
|
+
this.balance = await this.bot.clientCommands.grid.getBalance();
|
|
16
|
+
console.log('Balance is L$' + this.balance);
|
|
17
|
+
await this.bot.clientCommands.grid.payAvatar('d1cd5b71-6209-4595-9bf0-771bf689ce00', 1, 'This is a gift for being so awesome!');
|
|
18
|
+
console.log('Payment success');
|
|
19
|
+
}
|
|
20
|
+
catch (error)
|
|
21
|
+
{
|
|
22
|
+
console.log('Payment failed');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async onBalanceUpdated(evt: BalanceUpdatedEvent): Promise<void>
|
|
27
|
+
{
|
|
28
|
+
this.balance = evt.balance;
|
|
29
|
+
if (evt.transaction.from.equals(this.bot.agentID()))
|
|
30
|
+
{
|
|
31
|
+
if (evt.transaction.toGroup)
|
|
32
|
+
{
|
|
33
|
+
console.log('You paid a group L$' + evt.transaction.amount);
|
|
34
|
+
}
|
|
35
|
+
else
|
|
36
|
+
{
|
|
37
|
+
const result = await this.bot.clientCommands.grid.avatarKey2Name(evt.transaction.to) as AvatarQueryResult;
|
|
38
|
+
console.log('You paid L$' + evt.transaction.amount + ' to ' + result.getName() + ' "' + evt.transaction.description + '" (' + MoneyTransactionType[evt.transaction.type] + ')');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else
|
|
42
|
+
{
|
|
43
|
+
if (evt.transaction.fromGroup)
|
|
44
|
+
{
|
|
45
|
+
console.log('A group paid you L$' + evt.transaction.amount);
|
|
46
|
+
}
|
|
47
|
+
else
|
|
48
|
+
{
|
|
49
|
+
const result = await this.bot.clientCommands.grid.avatarKey2Name(evt.transaction.from) as AvatarQueryResult;
|
|
50
|
+
console.log(result.getName() + ' paid you L$' + evt.transaction.amount + ' "' + evt.transaction.description + '" (' + MoneyTransactionType[evt.transaction.type] + ')');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
console.log('Balance updated (New balance L$' + evt.balance + ')');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
new Money().run().then(() =>
|
|
58
|
+
{
|
|
59
|
+
|
|
60
|
+
}).catch((err) =>
|
|
61
|
+
{
|
|
62
|
+
console.error(err);
|
|
63
|
+
});
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { ExampleBot } from '../ExampleBot';
|
|
2
|
-
import { GameObject, Utils } from '../../lib';
|
|
3
|
-
|
|
4
|
-
class TaskInventory extends ExampleBot
|
|
5
|
-
{
|
|
6
|
-
async onConnected(): Promise<void>
|
|
7
|
-
{
|
|
8
|
-
let attachments: GameObject[] = [];
|
|
9
|
-
while(!attachments.length)
|
|
10
|
-
{
|
|
11
|
-
await Utils.sleep(1000);
|
|
12
|
-
attachments = this.bot.currentRegion.objects.getObjectsByParent(this.bot.agent.localID);
|
|
13
|
-
}
|
|
14
|
-
console.log('Got ' + attachments.length + ' attachments');
|
|
15
|
-
|
|
16
|
-
for(const obj of attachments)
|
|
17
|
-
{
|
|
18
|
-
await obj.updateInventory();
|
|
19
|
-
for(const task of obj.inventory)
|
|
20
|
-
{
|
|
21
|
-
console.log('Found task inventory item ' + task.name);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
console.log('Finished!');
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
new TaskInventory().run().then(() =>
|
|
30
|
-
{
|
|
31
|
-
|
|
32
|
-
}).catch((err) =>
|
|
33
|
-
{
|
|
34
|
-
console.error(err);
|
|
35
|
-
});
|
|
1
|
+
import { ExampleBot } from '../ExampleBot';
|
|
2
|
+
import { GameObject, Utils } from '../../lib';
|
|
3
|
+
|
|
4
|
+
class TaskInventory extends ExampleBot
|
|
5
|
+
{
|
|
6
|
+
async onConnected(): Promise<void>
|
|
7
|
+
{
|
|
8
|
+
let attachments: GameObject[] = [];
|
|
9
|
+
while(!attachments.length)
|
|
10
|
+
{
|
|
11
|
+
await Utils.sleep(1000);
|
|
12
|
+
attachments = this.bot.currentRegion.objects.getObjectsByParent(this.bot.agent.localID);
|
|
13
|
+
}
|
|
14
|
+
console.log('Got ' + attachments.length + ' attachments');
|
|
15
|
+
|
|
16
|
+
for(const obj of attachments)
|
|
17
|
+
{
|
|
18
|
+
await obj.updateInventory();
|
|
19
|
+
for(const task of obj.inventory)
|
|
20
|
+
{
|
|
21
|
+
console.log('Found task inventory item ' + task.name);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
console.log('Finished!');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
new TaskInventory().run().then(() =>
|
|
30
|
+
{
|
|
31
|
+
|
|
32
|
+
}).catch((err) =>
|
|
33
|
+
{
|
|
34
|
+
console.error(err);
|
|
35
|
+
});
|