bedrock-portal 0.2.7 → 0.3.1
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/README.md +91 -0
- package/examples/portal.js +8 -0
- package/package.json +1 -1
- package/src/classes/Module.js +4 -1
- package/src/modules/autoFriendAdd.js +31 -15
- package/src/rest.js +7 -2
package/README.md
CHANGED
|
@@ -63,6 +63,10 @@ Automatically adds the account's followers as friends and invites them to the ga
|
|
|
63
63
|
|
|
64
64
|
Options:
|
|
65
65
|
- **inviteOnAdd**: boolean - Automatically invites recently added friends to the game (default: false)
|
|
66
|
+
- **conditionToMeet**: (player: RawPlayer) => boolean - A function that returns a boolean. If the function returns true, followers will be added as a friend and the friends that don't will be removed (default: () => true)
|
|
67
|
+
- **checkInterval**: number - How often to check for friends to add/remove (default: 30000ms)
|
|
68
|
+
- **addInterval**: number - How long to wait between adding friends (default: 2000ms)
|
|
69
|
+
- **removeInterval**: number - How long to wait between removing friends (default: 2000ms)
|
|
66
70
|
|
|
67
71
|
```js
|
|
68
72
|
const { BedrockPortal, Modules } = require('bedrock-portal');
|
|
@@ -75,6 +79,10 @@ portal.use(Modules.autoFriendAdd);
|
|
|
75
79
|
|
|
76
80
|
portal.use(Modules.autoFriendAdd, {
|
|
77
81
|
inviteOnAdd: true,
|
|
82
|
+
conditionToMeet: (player) => player.presenceState === 'Online', // Only add friends that are online and remove friends that are offline
|
|
83
|
+
// checkInterval: 30000, // How often to check for friends to add/remove (optional - defaults to 30000ms)
|
|
84
|
+
// addInterval: 2000, // How long to wait between adding friends (optional - defaults to 2000ms)
|
|
85
|
+
// removeInterval: 2000, // How long to wait between removing friends (optional - defaults to 2000ms)
|
|
78
86
|
});
|
|
79
87
|
```
|
|
80
88
|
|
|
@@ -143,6 +151,12 @@ Emitted when a player is added as a friend. This event is only emitted when the
|
|
|
143
151
|
**Parameters**
|
|
144
152
|
- player - [Player](#player) object
|
|
145
153
|
|
|
154
|
+
### portal.on('friendRemoved', (player) => {})
|
|
155
|
+
Emitted when a player is removed as a friend. This event is only emitted when the `autoFriendAdd` module is enabled.
|
|
156
|
+
|
|
157
|
+
**Parameters**
|
|
158
|
+
- player - [Player](#player) object
|
|
159
|
+
|
|
146
160
|
## Objects
|
|
147
161
|
|
|
148
162
|
### Player
|
|
@@ -258,6 +272,83 @@ Emitted when a player is added as a friend. This event is only emitted when the
|
|
|
258
272
|
}
|
|
259
273
|
```
|
|
260
274
|
|
|
275
|
+
### RawPlayer
|
|
276
|
+
|
|
277
|
+
```ts
|
|
278
|
+
{
|
|
279
|
+
xuid: string;
|
|
280
|
+
isFavorite: boolean;
|
|
281
|
+
isFollowingCaller: boolean;
|
|
282
|
+
isFollowedByCaller: boolean;
|
|
283
|
+
isIdentityShared: boolean;
|
|
284
|
+
addedDateTimeUtc: string;
|
|
285
|
+
displayName: string;
|
|
286
|
+
realName: string;
|
|
287
|
+
displayPicRaw: string;
|
|
288
|
+
showUserAsAvatar: string;
|
|
289
|
+
gamertag: string;
|
|
290
|
+
gamerScore: string;
|
|
291
|
+
modernGamertag: string;
|
|
292
|
+
modernGamertagSuffix: string;
|
|
293
|
+
uniqueModernGamertag: string;
|
|
294
|
+
xboxOneRep: string;
|
|
295
|
+
presenceState: string;
|
|
296
|
+
presenceText: string;
|
|
297
|
+
presenceDevices: null | any[];
|
|
298
|
+
isBroadcasting: boolean;
|
|
299
|
+
isCloaked: null | boolean;
|
|
300
|
+
isQuarantined: boolean;
|
|
301
|
+
isXbox360Gamerpic: boolean;
|
|
302
|
+
lastSeenDateTimeUtc: string;
|
|
303
|
+
suggestion: null;
|
|
304
|
+
recommendation: null;
|
|
305
|
+
search: null;
|
|
306
|
+
titleHistory: null;
|
|
307
|
+
multiplayerSummary: null;
|
|
308
|
+
recentPlayer: null;
|
|
309
|
+
follower: {
|
|
310
|
+
text: string;
|
|
311
|
+
followedDateTime: string;
|
|
312
|
+
};
|
|
313
|
+
preferredColor: {
|
|
314
|
+
primaryColor: string;
|
|
315
|
+
secondaryColor: string;
|
|
316
|
+
tertiaryColor: string;
|
|
317
|
+
};
|
|
318
|
+
presenceDetails: null;
|
|
319
|
+
titlePresence: null;
|
|
320
|
+
titleSummaries: null;
|
|
321
|
+
presenceTitleIds: null;
|
|
322
|
+
detail: {
|
|
323
|
+
accountTier: string;
|
|
324
|
+
bio: string;
|
|
325
|
+
isVerified: boolean;
|
|
326
|
+
location: string;
|
|
327
|
+
tenure: string;
|
|
328
|
+
watermarks: any[];
|
|
329
|
+
blocked: boolean;
|
|
330
|
+
mute: boolean;
|
|
331
|
+
followerCount: number;
|
|
332
|
+
followingCount: number;
|
|
333
|
+
hasGamePass: boolean;
|
|
334
|
+
};
|
|
335
|
+
communityManagerTitles: null;
|
|
336
|
+
socialManager: null;
|
|
337
|
+
broadcast: null;
|
|
338
|
+
avatar: null;
|
|
339
|
+
linkedAccounts: {
|
|
340
|
+
networkName: string;
|
|
341
|
+
displayName: string;
|
|
342
|
+
showOnProfile: boolean;
|
|
343
|
+
isFamilyFriendly: boolean;
|
|
344
|
+
deeplink: null;
|
|
345
|
+
}[];
|
|
346
|
+
colorTheme: string;
|
|
347
|
+
preferredFlag: string;
|
|
348
|
+
preferredPlatforms: string[];
|
|
349
|
+
}
|
|
350
|
+
```
|
|
351
|
+
|
|
261
352
|
|
|
262
353
|
## Debugging
|
|
263
354
|
|
package/examples/portal.js
CHANGED
|
@@ -23,6 +23,10 @@ const main = async () => {
|
|
|
23
23
|
|
|
24
24
|
portal.use(Modules.autoFriendAdd, { // Automatically adds friends to the session
|
|
25
25
|
inviteOnAdd: true,
|
|
26
|
+
conditionToMeet: (player) => player.presenceState === 'Online', // Only add friends that are online and remove friends that are offline
|
|
27
|
+
// checkInterval: 30000, // How often to check for friends to add/remove (optional - defaults to 30000ms)
|
|
28
|
+
addInterval: 2000, // How long to wait between adding friends (optional - defaults to 2000ms)
|
|
29
|
+
removeInterval: 2000, // How long to wait between removing friends (optional - defaults to 2000ms)
|
|
26
30
|
});
|
|
27
31
|
|
|
28
32
|
// Put your event listeners before portal.start() to ensure you don't miss any events
|
|
@@ -51,6 +55,10 @@ const main = async () => {
|
|
|
51
55
|
console.log('Friend Added: ', player);
|
|
52
56
|
});
|
|
53
57
|
|
|
58
|
+
portal.on('friendRemoved', (player) => { // Emits when a friend is removed. Only emitted if autoFriendAdd module is used
|
|
59
|
+
console.log('Friend Removed: ', player);
|
|
60
|
+
});
|
|
61
|
+
|
|
54
62
|
await portal.start(); // Starts the session
|
|
55
63
|
|
|
56
64
|
await portal.invitePlayer('p3'); // gamertag or xuid to invite
|
package/package.json
CHANGED
package/src/classes/Module.js
CHANGED
|
@@ -7,6 +7,10 @@ class AutoFriendAdd extends Module {
|
|
|
7
7
|
super('autoFriendAdd', 'Automatically adds followers as friends');
|
|
8
8
|
this.options = {
|
|
9
9
|
inviteOnAdd: false,
|
|
10
|
+
conditionToMeet: () => true,
|
|
11
|
+
checkInterval: 30000,
|
|
12
|
+
addInterval: 2000,
|
|
13
|
+
removeInterval: 2000,
|
|
10
14
|
};
|
|
11
15
|
}
|
|
12
16
|
|
|
@@ -17,24 +21,12 @@ class AutoFriendAdd extends Module {
|
|
|
17
21
|
|
|
18
22
|
this.debug('Checking for followers to add');
|
|
19
23
|
|
|
20
|
-
const friends = await rest.getXboxFriends()
|
|
21
|
-
.then(people => people.map(e => e.xuid))
|
|
22
|
-
.catch(() => []);
|
|
23
|
-
|
|
24
|
-
this.debug(`Found ${friends.length} friend(s)`);
|
|
25
|
-
|
|
26
24
|
const followers = await rest.getXboxFollowers()
|
|
27
25
|
.catch(() => []);
|
|
28
26
|
|
|
29
27
|
this.debug(`Found ${followers.length} follower(s)`);
|
|
30
28
|
|
|
31
|
-
const needsAdding = followers.filter(res => !
|
|
32
|
-
|
|
33
|
-
if (!needsAdding.length) {
|
|
34
|
-
this.debug('No followers to add');
|
|
35
|
-
await new Promise(resolve => setTimeout(resolve, 30000));
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
29
|
+
const needsAdding = followers.filter(res => !res.isFollowedByCaller && this.options.conditionToMeet(res));
|
|
38
30
|
|
|
39
31
|
this.debug(`Adding ${needsAdding.length} account(s) [${needsAdding.map(res => res.gamertag).join(', ')}]`);
|
|
40
32
|
|
|
@@ -53,14 +45,38 @@ class AutoFriendAdd extends Module {
|
|
|
53
45
|
|
|
54
46
|
this.debug(`Added & invited ${account.gamertag}`);
|
|
55
47
|
|
|
56
|
-
await new Promise(resolve => setTimeout(resolve,
|
|
48
|
+
await new Promise(resolve => setTimeout(resolve, this.options.addInterval));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.debug('Checking for friends to remove');
|
|
52
|
+
|
|
53
|
+
const friends = await rest.getXboxFriends()
|
|
54
|
+
.catch(() => []);
|
|
55
|
+
|
|
56
|
+
this.debug(`Found ${friends.length} friend(s)`);
|
|
57
|
+
|
|
58
|
+
const needsRemoving = friends.filter(res => !res.isFollowingCaller || !this.options.conditionToMeet(res));
|
|
59
|
+
|
|
60
|
+
this.debug(`Removing ${needsRemoving.length} account(s) [${needsRemoving.map(res => res.gamertag).join(', ')}]`);
|
|
61
|
+
|
|
62
|
+
for (const account of needsRemoving) {
|
|
63
|
+
await rest.removeXboxFriend(account.xuid).catch(err => {
|
|
64
|
+
throw Error(`Failed to remove ${account.gamertag}`, { cause: err });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
portal.emit('friendRemoved', Player.fromXboxProfile(account));
|
|
68
|
+
|
|
69
|
+
this.debug(`Removed ${account.gamertag}`);
|
|
70
|
+
|
|
71
|
+
await new Promise(resolve => setTimeout(resolve, this.options.removeInterval));
|
|
57
72
|
}
|
|
73
|
+
|
|
58
74
|
}
|
|
59
75
|
catch (error) {
|
|
60
76
|
this.debug(`Error: ${error.message}`, error);
|
|
61
77
|
}
|
|
62
78
|
|
|
63
|
-
await new Promise(resolve => setTimeout(resolve,
|
|
79
|
+
await new Promise(resolve => setTimeout(resolve, this.options.checkInterval));
|
|
64
80
|
}
|
|
65
81
|
}
|
|
66
82
|
}
|
package/src/rest.js
CHANGED
|
@@ -114,19 +114,24 @@ 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/detail,preferredColor', { contractVersion: 5 }).then(res => res.people.map(e => this.#parseXboxProfile(e)));
|
|
117
|
+
return await this.get('https://peoplehub.xboxlive.com/users/me/people/social/decoration/detail,preferredColor,follower', { 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/detail,preferredColor', { contractVersion: 5 }).then(res => res.people.map(e => this.#parseXboxProfile(e)));
|
|
121
|
+
return await this.get('https://peoplehub.xboxlive.com/users/me/people/followers/decoration/detail,preferredColor,follower', { contractVersion: 5 }).then(res => res.people.map(e => this.#parseXboxProfile(e)));
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
async addXboxFriend(xuid) {
|
|
125
125
|
return await this.put(`https://social.xboxlive.com/users/me/people/xuid(${xuid})`, { contractVersion: 2 });
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
async removeXboxFriend(xuid) {
|
|
129
|
+
return await this.delete(`https://social.xboxlive.com/users/me/people/xuid(${xuid})`, { contractVersion: 2 });
|
|
130
|
+
}
|
|
131
|
+
|
|
128
132
|
#parseXboxProfile(profile) {
|
|
129
133
|
return {
|
|
134
|
+
...profile,
|
|
130
135
|
xuid: profile.xuid,
|
|
131
136
|
avatar: profile.displayPicRaw,
|
|
132
137
|
gamerscore: profile.gamerScore,
|