@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,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
|
+
});
|
package/examples/Groups/Group.ts
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import { ExampleBot } from '../ExampleBot';
|
|
2
|
-
import { UUID } from '../../lib/classes/UUID';
|
|
3
|
-
import { GroupNoticeEvent } from '../../lib/events/GroupNoticeEvent';
|
|
4
|
-
|
|
5
|
-
class Group extends ExampleBot
|
|
6
|
-
{
|
|
7
|
-
async onConnected(): Promise<void>
|
|
8
|
-
{
|
|
9
|
-
this.bot.clientEvents.onGroupNotice.subscribe(this.onGroupNotice.bind(this));
|
|
10
|
-
|
|
11
|
-
// Group invite example
|
|
12
|
-
// Just omit the role parameter for "everyone" role
|
|
13
|
-
//
|
|
14
|
-
// bot.clientCommands.group.sendGroupInvite("c6424e05-6e2c-fb03-220b-ca7904d11e04", "d1cd5b71-6209-4595-9bf0-771bf689ce00");
|
|
15
|
-
|
|
16
|
-
// Advanced group invite example
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
const userToInvite = new UUID('d1cd5b71-6209-4595-9bf0-771bf689ce00');
|
|
20
|
-
const groupID = new UUID('4b35083d-b51a-a148-c400-6f1038a5589e');
|
|
21
|
-
|
|
22
|
-
// Retrieve group roles
|
|
23
|
-
const roles = await this.bot.clientCommands.group.getGroupRoles(groupID);
|
|
24
|
-
|
|
25
|
-
for (const role of roles)
|
|
26
|
-
{
|
|
27
|
-
if (role.Name === 'Officers')
|
|
28
|
-
{
|
|
29
|
-
// IMPORTANT: IN PRODUCTION, IT IS HIGHLY RECOMMENDED TO CACHE THIS LIST.
|
|
30
|
-
//
|
|
31
|
-
try
|
|
32
|
-
{
|
|
33
|
-
const members = await this.bot.clientCommands.group.getMemberList(groupID);
|
|
34
|
-
let found = true;
|
|
35
|
-
for (const member of members)
|
|
36
|
-
{
|
|
37
|
-
if (member.AgentID.toString() === userToInvite.toString())
|
|
38
|
-
{
|
|
39
|
-
found = true;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (found)
|
|
43
|
-
{
|
|
44
|
-
console.log('User already in group, skipping invite');
|
|
45
|
-
}
|
|
46
|
-
else
|
|
47
|
-
{
|
|
48
|
-
this.bot.clientCommands.group.sendGroupInvite(groupID, userToInvite, role.RoleID).then(() =>
|
|
49
|
-
{
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
catch (error)
|
|
54
|
-
{
|
|
55
|
-
console.error('Error retrieving member list for group invite');
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Get group member list
|
|
61
|
-
try
|
|
62
|
-
{
|
|
63
|
-
const memberList = await this.bot.clientCommands.group.getMemberList(groupID);
|
|
64
|
-
console.log(memberList.length + ' members in member list');
|
|
65
|
-
}
|
|
66
|
-
catch (error)
|
|
67
|
-
{
|
|
68
|
-
// Probably access denied
|
|
69
|
-
console.error(error);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Get group ban list
|
|
73
|
-
try
|
|
74
|
-
{
|
|
75
|
-
const banList = await this.bot.clientCommands.group.getBanList(groupID);
|
|
76
|
-
console.log(banList.length + ' members in ban list');
|
|
77
|
-
}
|
|
78
|
-
catch (error)
|
|
79
|
-
{
|
|
80
|
-
// Probably access denied
|
|
81
|
-
console.error(error);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async onGroupNotice(event: GroupNoticeEvent): Promise<void>
|
|
86
|
-
{
|
|
87
|
-
// Get group name
|
|
88
|
-
const groupProfile = await this.bot.clientCommands.group.getGroupProfile(event.groupID);
|
|
89
|
-
|
|
90
|
-
console.log('Group notice from ' + event.fromName + ' (' + event.from + '), from group ' + groupProfile.Name + ' (' + event.groupID + ')');
|
|
91
|
-
console.log('Subject: ' + event.subject);
|
|
92
|
-
console.log('Message: ' + event.message);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
new Group().run().then(() =>
|
|
97
|
-
{
|
|
98
|
-
|
|
99
|
-
}).catch((err: Error) =>
|
|
100
|
-
{
|
|
101
|
-
console.error(err);
|
|
102
|
-
});
|
|
1
|
+
import { ExampleBot } from '../ExampleBot';
|
|
2
|
+
import { UUID } from '../../lib/classes/UUID';
|
|
3
|
+
import { GroupNoticeEvent } from '../../lib/events/GroupNoticeEvent';
|
|
4
|
+
|
|
5
|
+
class Group extends ExampleBot
|
|
6
|
+
{
|
|
7
|
+
async onConnected(): Promise<void>
|
|
8
|
+
{
|
|
9
|
+
this.bot.clientEvents.onGroupNotice.subscribe(this.onGroupNotice.bind(this));
|
|
10
|
+
|
|
11
|
+
// Group invite example
|
|
12
|
+
// Just omit the role parameter for "everyone" role
|
|
13
|
+
//
|
|
14
|
+
// bot.clientCommands.group.sendGroupInvite("c6424e05-6e2c-fb03-220b-ca7904d11e04", "d1cd5b71-6209-4595-9bf0-771bf689ce00");
|
|
15
|
+
|
|
16
|
+
// Advanced group invite example
|
|
17
|
+
//
|
|
18
|
+
|
|
19
|
+
const userToInvite = new UUID('d1cd5b71-6209-4595-9bf0-771bf689ce00');
|
|
20
|
+
const groupID = new UUID('4b35083d-b51a-a148-c400-6f1038a5589e');
|
|
21
|
+
|
|
22
|
+
// Retrieve group roles
|
|
23
|
+
const roles = await this.bot.clientCommands.group.getGroupRoles(groupID);
|
|
24
|
+
|
|
25
|
+
for (const role of roles)
|
|
26
|
+
{
|
|
27
|
+
if (role.Name === 'Officers')
|
|
28
|
+
{
|
|
29
|
+
// IMPORTANT: IN PRODUCTION, IT IS HIGHLY RECOMMENDED TO CACHE THIS LIST.
|
|
30
|
+
//
|
|
31
|
+
try
|
|
32
|
+
{
|
|
33
|
+
const members = await this.bot.clientCommands.group.getMemberList(groupID);
|
|
34
|
+
let found = true;
|
|
35
|
+
for (const member of members)
|
|
36
|
+
{
|
|
37
|
+
if (member.AgentID.toString() === userToInvite.toString())
|
|
38
|
+
{
|
|
39
|
+
found = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (found)
|
|
43
|
+
{
|
|
44
|
+
console.log('User already in group, skipping invite');
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
{
|
|
48
|
+
this.bot.clientCommands.group.sendGroupInvite(groupID, userToInvite, role.RoleID).then(() =>
|
|
49
|
+
{
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (error)
|
|
54
|
+
{
|
|
55
|
+
console.error('Error retrieving member list for group invite');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Get group member list
|
|
61
|
+
try
|
|
62
|
+
{
|
|
63
|
+
const memberList = await this.bot.clientCommands.group.getMemberList(groupID);
|
|
64
|
+
console.log(memberList.length + ' members in member list');
|
|
65
|
+
}
|
|
66
|
+
catch (error)
|
|
67
|
+
{
|
|
68
|
+
// Probably access denied
|
|
69
|
+
console.error(error);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Get group ban list
|
|
73
|
+
try
|
|
74
|
+
{
|
|
75
|
+
const banList = await this.bot.clientCommands.group.getBanList(groupID);
|
|
76
|
+
console.log(banList.length + ' members in ban list');
|
|
77
|
+
}
|
|
78
|
+
catch (error)
|
|
79
|
+
{
|
|
80
|
+
// Probably access denied
|
|
81
|
+
console.error(error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async onGroupNotice(event: GroupNoticeEvent): Promise<void>
|
|
86
|
+
{
|
|
87
|
+
// Get group name
|
|
88
|
+
const groupProfile = await this.bot.clientCommands.group.getGroupProfile(event.groupID);
|
|
89
|
+
|
|
90
|
+
console.log('Group notice from ' + event.fromName + ' (' + event.from + '), from group ' + groupProfile.Name + ' (' + event.groupID + ')');
|
|
91
|
+
console.log('Subject: ' + event.subject);
|
|
92
|
+
console.log('Message: ' + event.message);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
new Group().run().then(() =>
|
|
97
|
+
{
|
|
98
|
+
|
|
99
|
+
}).catch((err: Error) =>
|
|
100
|
+
{
|
|
101
|
+
console.error(err);
|
|
102
|
+
});
|
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
import { GroupChatSessionJoinEvent, GroupChatEvent, UUID } from '../../lib';
|
|
2
|
-
import { GroupChatClosedEvent } from '../../lib/events/GroupChatClosedEvent';
|
|
3
|
-
import { ExampleBot } from '../ExampleBot';
|
|
4
|
-
|
|
5
|
-
class GroupChat extends ExampleBot
|
|
6
|
-
{
|
|
7
|
-
private pings: {
|
|
8
|
-
[key: string]: number
|
|
9
|
-
} = {};
|
|
10
|
-
|
|
11
|
-
async onConnected(): Promise<void>
|
|
12
|
-
{
|
|
13
|
-
const groupID = new UUID('4b35083d-b51a-a148-c400-6f1038a5589e');
|
|
14
|
-
|
|
15
|
-
this.bot.clientEvents.onGroupChat.subscribe(this.onGroupChat.bind(this));
|
|
16
|
-
|
|
17
|
-
// Start a group chat session - equivalent to opening a group chat but not sending a message
|
|
18
|
-
await this.bot.clientCommands.comms.startGroupChatSession(groupID, '');
|
|
19
|
-
|
|
20
|
-
const badGuyID = new UUID('1481561a-9113-46f8-9c02-9ac1bf005de7');
|
|
21
|
-
await this.bot.clientCommands.comms.moderateGroupChat(groupID, badGuyID, true, true);
|
|
22
|
-
|
|
23
|
-
// Now, the group mute stuff is often pretty useless because an avatar can just leave the session and re-join.
|
|
24
|
-
// Let's enforce it a little better.
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
const groupChatSubscriber = this.bot.clientEvents.onGroupChatAgentListUpdate.subscribe((event) =>
|
|
27
|
-
{
|
|
28
|
-
if (event.groupID.equals(groupID) && event.agentID.equals(badGuyID) && event.entered)
|
|
29
|
-
{
|
|
30
|
-
this.bot.clientCommands.comms.moderateGroupChat(groupID, badGuyID, true, true).then(() =>
|
|
31
|
-
{
|
|
32
|
-
console.log('Re-enforced mute on ' + badGuyID.toString());
|
|
33
|
-
}).catch((err) =>
|
|
34
|
-
{
|
|
35
|
-
console.error(err);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
this.bot.clientEvents.onGroupChatSessionJoin.subscribe((event: GroupChatSessionJoinEvent) =>
|
|
41
|
-
{
|
|
42
|
-
if (event.success)
|
|
43
|
-
{
|
|
44
|
-
console.log('We have joined a chat session! Group ID: ' + event.sessionID);
|
|
45
|
-
}
|
|
46
|
-
else
|
|
47
|
-
{
|
|
48
|
-
console.log('We have FAILED to join a chat session! Group ID: ' + event.sessionID);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
this.bot.clientEvents.onGroupChatClosed.subscribe((event: GroupChatClosedEvent) =>
|
|
53
|
-
{
|
|
54
|
-
console.log('Group chat session closed! Group ID: ' + event.groupID.toString());
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// Actually, maybe we want to ban the chump.
|
|
58
|
-
await this.bot.clientCommands.group.banMembers(groupID, [badGuyID]);
|
|
59
|
-
await this.bot.clientCommands.group.ejectFromGroup(groupID, badGuyID);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async onGroupChat(event: GroupChatEvent): Promise<void>
|
|
63
|
-
{
|
|
64
|
-
console.log('Group chat: ' + event.fromName + ': ' + event.message);
|
|
65
|
-
if (event.message === '!ping')
|
|
66
|
-
{
|
|
67
|
-
const ping = UUID.random().toString();
|
|
68
|
-
this.pings[ping] = Math.floor(new Date().getTime());
|
|
69
|
-
try
|
|
70
|
-
{
|
|
71
|
-
const memberCount = await this.bot.clientCommands.comms.sendGroupMessage(event.groupID, 'ping ' + ping);
|
|
72
|
-
console.log('Group message sent to ' + memberCount + ' members');
|
|
73
|
-
}
|
|
74
|
-
catch (error)
|
|
75
|
-
{
|
|
76
|
-
console.error('Failed to send group message:');
|
|
77
|
-
console.error(error);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else if (event.message === '!rejoin')
|
|
81
|
-
{
|
|
82
|
-
console.log('Leaving the session..');
|
|
83
|
-
await this.bot.clientCommands.comms.endGroupChatSession(event.groupID);
|
|
84
|
-
console.log('Session terminated');
|
|
85
|
-
console.log('Rejoining session');
|
|
86
|
-
await this.bot.clientCommands.comms.startGroupChatSession(event.groupID, '');
|
|
87
|
-
await this.bot.clientCommands.comms.sendGroupMessage(event.groupID, 'I am back!');
|
|
88
|
-
}
|
|
89
|
-
else if (event.from.toString() === this.bot.agentID().toString())
|
|
90
|
-
{
|
|
91
|
-
if (event.message.substring(0, 5) === 'ping ')
|
|
92
|
-
{
|
|
93
|
-
const pingID = event.message.substring(5);
|
|
94
|
-
if (this.pings[pingID])
|
|
95
|
-
{
|
|
96
|
-
const time = (new Date().getTime()) - this.pings[pingID];
|
|
97
|
-
delete this.pings[pingID];
|
|
98
|
-
await this.bot.clientCommands.comms.sendGroupMessage(event.groupID, 'Chat lag: ' + time + 'ms');
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
new GroupChat().run().then(() =>
|
|
107
|
-
{
|
|
108
|
-
|
|
109
|
-
}).catch((err: Error) =>
|
|
110
|
-
{
|
|
111
|
-
console.error(err)
|
|
112
|
-
});
|
|
1
|
+
import { GroupChatSessionJoinEvent, GroupChatEvent, UUID } from '../../lib';
|
|
2
|
+
import { GroupChatClosedEvent } from '../../lib/events/GroupChatClosedEvent';
|
|
3
|
+
import { ExampleBot } from '../ExampleBot';
|
|
4
|
+
|
|
5
|
+
class GroupChat extends ExampleBot
|
|
6
|
+
{
|
|
7
|
+
private pings: {
|
|
8
|
+
[key: string]: number
|
|
9
|
+
} = {};
|
|
10
|
+
|
|
11
|
+
async onConnected(): Promise<void>
|
|
12
|
+
{
|
|
13
|
+
const groupID = new UUID('4b35083d-b51a-a148-c400-6f1038a5589e');
|
|
14
|
+
|
|
15
|
+
this.bot.clientEvents.onGroupChat.subscribe(this.onGroupChat.bind(this));
|
|
16
|
+
|
|
17
|
+
// Start a group chat session - equivalent to opening a group chat but not sending a message
|
|
18
|
+
await this.bot.clientCommands.comms.startGroupChatSession(groupID, '');
|
|
19
|
+
|
|
20
|
+
const badGuyID = new UUID('1481561a-9113-46f8-9c02-9ac1bf005de7');
|
|
21
|
+
await this.bot.clientCommands.comms.moderateGroupChat(groupID, badGuyID, true, true);
|
|
22
|
+
|
|
23
|
+
// Now, the group mute stuff is often pretty useless because an avatar can just leave the session and re-join.
|
|
24
|
+
// Let's enforce it a little better.
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
const groupChatSubscriber = this.bot.clientEvents.onGroupChatAgentListUpdate.subscribe((event) =>
|
|
27
|
+
{
|
|
28
|
+
if (event.groupID.equals(groupID) && event.agentID.equals(badGuyID) && event.entered)
|
|
29
|
+
{
|
|
30
|
+
this.bot.clientCommands.comms.moderateGroupChat(groupID, badGuyID, true, true).then(() =>
|
|
31
|
+
{
|
|
32
|
+
console.log('Re-enforced mute on ' + badGuyID.toString());
|
|
33
|
+
}).catch((err) =>
|
|
34
|
+
{
|
|
35
|
+
console.error(err);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
this.bot.clientEvents.onGroupChatSessionJoin.subscribe((event: GroupChatSessionJoinEvent) =>
|
|
41
|
+
{
|
|
42
|
+
if (event.success)
|
|
43
|
+
{
|
|
44
|
+
console.log('We have joined a chat session! Group ID: ' + event.sessionID);
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
{
|
|
48
|
+
console.log('We have FAILED to join a chat session! Group ID: ' + event.sessionID);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
this.bot.clientEvents.onGroupChatClosed.subscribe((event: GroupChatClosedEvent) =>
|
|
53
|
+
{
|
|
54
|
+
console.log('Group chat session closed! Group ID: ' + event.groupID.toString());
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Actually, maybe we want to ban the chump.
|
|
58
|
+
await this.bot.clientCommands.group.banMembers(groupID, [badGuyID]);
|
|
59
|
+
await this.bot.clientCommands.group.ejectFromGroup(groupID, badGuyID);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async onGroupChat(event: GroupChatEvent): Promise<void>
|
|
63
|
+
{
|
|
64
|
+
console.log('Group chat: ' + event.fromName + ': ' + event.message);
|
|
65
|
+
if (event.message === '!ping')
|
|
66
|
+
{
|
|
67
|
+
const ping = UUID.random().toString();
|
|
68
|
+
this.pings[ping] = Math.floor(new Date().getTime());
|
|
69
|
+
try
|
|
70
|
+
{
|
|
71
|
+
const memberCount = await this.bot.clientCommands.comms.sendGroupMessage(event.groupID, 'ping ' + ping);
|
|
72
|
+
console.log('Group message sent to ' + memberCount + ' members');
|
|
73
|
+
}
|
|
74
|
+
catch (error)
|
|
75
|
+
{
|
|
76
|
+
console.error('Failed to send group message:');
|
|
77
|
+
console.error(error);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else if (event.message === '!rejoin')
|
|
81
|
+
{
|
|
82
|
+
console.log('Leaving the session..');
|
|
83
|
+
await this.bot.clientCommands.comms.endGroupChatSession(event.groupID);
|
|
84
|
+
console.log('Session terminated');
|
|
85
|
+
console.log('Rejoining session');
|
|
86
|
+
await this.bot.clientCommands.comms.startGroupChatSession(event.groupID, '');
|
|
87
|
+
await this.bot.clientCommands.comms.sendGroupMessage(event.groupID, 'I am back!');
|
|
88
|
+
}
|
|
89
|
+
else if (event.from.toString() === this.bot.agentID().toString())
|
|
90
|
+
{
|
|
91
|
+
if (event.message.substring(0, 5) === 'ping ')
|
|
92
|
+
{
|
|
93
|
+
const pingID = event.message.substring(5);
|
|
94
|
+
if (this.pings[pingID])
|
|
95
|
+
{
|
|
96
|
+
const time = (new Date().getTime()) - this.pings[pingID];
|
|
97
|
+
delete this.pings[pingID];
|
|
98
|
+
await this.bot.clientCommands.comms.sendGroupMessage(event.groupID, 'Chat lag: ' + time + 'ms');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
new GroupChat().run().then(() =>
|
|
107
|
+
{
|
|
108
|
+
|
|
109
|
+
}).catch((err: Error) =>
|
|
110
|
+
{
|
|
111
|
+
console.error(err)
|
|
112
|
+
});
|