@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,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
+ });
@@ -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
+ });