@caspertech/node-metaverse 0.7.24 → 0.7.25
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/llsd/LLSDNotationParser.spec.js +46 -46
- 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,41 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
import { ExampleBot } from '../ExampleBot';
|
|
3
|
-
import { InstantMessageEvent } from '../../lib/events/InstantMessageEvent';
|
|
4
|
-
import { ChatSourceType } from '../../lib/enums/ChatSourceType';
|
|
5
|
-
import { InstantMessageEventFlags } from '../../lib/enums/InstantMessageEventFlags';
|
|
6
|
-
|
|
7
|
-
class InstantMessages extends ExampleBot
|
|
8
|
-
{
|
|
9
|
-
constructor()
|
|
10
|
-
{
|
|
11
|
-
super();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async onConnected(): Promise<void>
|
|
15
|
-
{
|
|
16
|
-
this.bot.clientEvents.onInstantMessage.subscribe(this.onInstantMessage.bind(this));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async onInstantMessage(event: InstantMessageEvent): Promise<void>
|
|
20
|
-
{
|
|
21
|
-
if (event.source === ChatSourceType.Agent)
|
|
22
|
-
{
|
|
23
|
-
if (!(event.flags & InstantMessageEventFlags.startTyping || event.flags & InstantMessageEventFlags.finishTyping))
|
|
24
|
-
{
|
|
25
|
-
// typeInstantMessage will emulate a human-ish typing speed
|
|
26
|
-
await this.bot.clientCommands.comms.typeInstantMessage(event.from, 'Thanks for the message! This account is a scripted agent (bot), so cannot reply to your query. Sorry!');
|
|
27
|
-
|
|
28
|
-
// sendInstantMessage will send it instantly
|
|
29
|
-
await this.bot.clientCommands.comms.sendInstantMessage(event.from, 'Of course I still love you!');
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
new InstantMessages().run().then(() =>
|
|
36
|
-
{
|
|
37
|
-
|
|
38
|
-
}).catch((err: Error) =>
|
|
39
|
-
{
|
|
40
|
-
console.error(err);
|
|
41
|
-
});
|
|
1
|
+
|
|
2
|
+
import { ExampleBot } from '../ExampleBot';
|
|
3
|
+
import { InstantMessageEvent } from '../../lib/events/InstantMessageEvent';
|
|
4
|
+
import { ChatSourceType } from '../../lib/enums/ChatSourceType';
|
|
5
|
+
import { InstantMessageEventFlags } from '../../lib/enums/InstantMessageEventFlags';
|
|
6
|
+
|
|
7
|
+
class InstantMessages extends ExampleBot
|
|
8
|
+
{
|
|
9
|
+
constructor()
|
|
10
|
+
{
|
|
11
|
+
super();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async onConnected(): Promise<void>
|
|
15
|
+
{
|
|
16
|
+
this.bot.clientEvents.onInstantMessage.subscribe(this.onInstantMessage.bind(this));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async onInstantMessage(event: InstantMessageEvent): Promise<void>
|
|
20
|
+
{
|
|
21
|
+
if (event.source === ChatSourceType.Agent)
|
|
22
|
+
{
|
|
23
|
+
if (!(event.flags & InstantMessageEventFlags.startTyping || event.flags & InstantMessageEventFlags.finishTyping))
|
|
24
|
+
{
|
|
25
|
+
// typeInstantMessage will emulate a human-ish typing speed
|
|
26
|
+
await this.bot.clientCommands.comms.typeInstantMessage(event.from, 'Thanks for the message! This account is a scripted agent (bot), so cannot reply to your query. Sorry!');
|
|
27
|
+
|
|
28
|
+
// sendInstantMessage will send it instantly
|
|
29
|
+
await this.bot.clientCommands.comms.sendInstantMessage(event.from, 'Of course I still love you!');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
new InstantMessages().run().then(() =>
|
|
36
|
+
{
|
|
37
|
+
|
|
38
|
+
}).catch((err: Error) =>
|
|
39
|
+
{
|
|
40
|
+
console.error(err);
|
|
41
|
+
});
|
|
@@ -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
|
+
});
|