bedrock-portal 0.2.6 → 0.2.7
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/examples/portal.js +7 -3
- package/package.json +1 -1
- package/src/classes/Player.js +3 -3
- package/src/common/constants.js +1 -1
- package/src/index.js +14 -6
- package/src/modules/autoFriendAdd.js +4 -0
- package/src/rest.js +2 -2
package/examples/portal.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-multi-spaces */
|
|
2
|
+
// process.env.DEBUG = 'bedrock-portal*';
|
|
3
|
+
|
|
2
4
|
const { BedrockPortal, Modules, Joinability } = require('bedrock-portal');
|
|
3
5
|
const { Authflow, Titles } = require('prismarine-auth');
|
|
4
6
|
|
|
@@ -23,9 +25,7 @@ const main = async () => {
|
|
|
23
25
|
inviteOnAdd: true,
|
|
24
26
|
});
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
await portal.invitePlayer('p3'); // gamertag or xuid to invite
|
|
28
|
+
// Put your event listeners before portal.start() to ensure you don't miss any events
|
|
29
29
|
|
|
30
30
|
portal.on('rtaEvent', (event) => { // Emits when an RTA event is received
|
|
31
31
|
console.log('RTA Event: ', event);
|
|
@@ -51,6 +51,10 @@ const main = async () => {
|
|
|
51
51
|
console.log('Friend Added: ', player);
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
+
await portal.start(); // Starts the session
|
|
55
|
+
|
|
56
|
+
await portal.invitePlayer('p3'); // gamertag or xuid to invite
|
|
57
|
+
|
|
54
58
|
};
|
|
55
59
|
|
|
56
60
|
main();
|
package/package.json
CHANGED
package/src/classes/Player.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
class Player {
|
|
2
|
-
constructor(profileData
|
|
2
|
+
constructor(profileData, sessionData) {
|
|
3
3
|
this.profile = {};
|
|
4
4
|
this.session = {};
|
|
5
|
-
this.setXboxProfile(profileData);
|
|
6
|
-
this.setSessionMember(sessionData);
|
|
5
|
+
if (profileData) this.setXboxProfile(profileData);
|
|
6
|
+
if (sessionData) this.setSessionMember(sessionData);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
static fromSessionMember(data) {
|
package/src/common/constants.js
CHANGED
package/src/index.js
CHANGED
|
@@ -94,7 +94,11 @@ module.exports = class BedrockPortal extends EventEmitter {
|
|
|
94
94
|
async invitePlayer(identifier) {
|
|
95
95
|
debug(`Inviting player, identifier: ${identifier}`);
|
|
96
96
|
|
|
97
|
-
const profile = await this.#rest.getXboxProfile(identifier)
|
|
97
|
+
const profile = await this.#rest.getXboxProfile(identifier)
|
|
98
|
+
.catch(() => { throw new Error(`Failed to get profile for identifier: ${identifier}`); });
|
|
99
|
+
|
|
100
|
+
debug(`Inviting player, Got profile, xuid: ${profile.xuid}`);
|
|
101
|
+
|
|
98
102
|
const invitePayload = {
|
|
99
103
|
invitedXuid: String(profile.xuid),
|
|
100
104
|
inviteAttributes: { titleId: SessionConfig.MinecraftTitleID },
|
|
@@ -220,11 +224,15 @@ module.exports = class BedrockPortal extends EventEmitter {
|
|
|
220
224
|
});
|
|
221
225
|
|
|
222
226
|
if (this.modules) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
.
|
|
226
|
-
|
|
227
|
-
|
|
227
|
+
Object.values(this.modules).forEach(async mod => {
|
|
228
|
+
try {
|
|
229
|
+
mod.run(this, { rest: this.#rest, rta: this.#rta });
|
|
230
|
+
debug(`Module ${mod.name} has run`);
|
|
231
|
+
}
|
|
232
|
+
catch (e) {
|
|
233
|
+
debug(`Module ${mod.name} failed to run`, e);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
228
236
|
}
|
|
229
237
|
|
|
230
238
|
}
|
|
@@ -21,9 +21,13 @@ class AutoFriendAdd extends Module {
|
|
|
21
21
|
.then(people => people.map(e => e.xuid))
|
|
22
22
|
.catch(() => []);
|
|
23
23
|
|
|
24
|
+
this.debug(`Found ${friends.length} friend(s)`);
|
|
25
|
+
|
|
24
26
|
const followers = await rest.getXboxFollowers()
|
|
25
27
|
.catch(() => []);
|
|
26
28
|
|
|
29
|
+
this.debug(`Found ${followers.length} follower(s)`);
|
|
30
|
+
|
|
27
31
|
const needsAdding = followers.filter(res => !friends.includes(res.xuid));
|
|
28
32
|
|
|
29
33
|
if (!needsAdding.length) {
|
package/src/rest.js
CHANGED
|
@@ -114,11 +114,11 @@ module.exports = class Rest {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
async getXboxFriends() {
|
|
117
|
-
return await this.get('https://peoplehub.xboxlive.com/users/me/people/social/decoration/
|
|
117
|
+
return await this.get('https://peoplehub.xboxlive.com/users/me/people/social/decoration/detail,preferredColor', { contractVersion: 5 }).then(res => res.people.map(e => this.#parseXboxProfile(e)));
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
async getXboxFollowers() {
|
|
121
|
-
return await this.get('https://peoplehub.xboxlive.com/users/me/people/followers/decoration/
|
|
121
|
+
return await this.get('https://peoplehub.xboxlive.com/users/me/people/followers/decoration/detail,preferredColor', { contractVersion: 5 }).then(res => res.people.map(e => this.#parseXboxProfile(e)));
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
async addXboxFriend(xuid) {
|