fortnite-basic-api
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -22,9 +22,11 @@ /* eslint-disable no-console */ | ||
// Setup communicator events | ||
communicator.events.on('session:started', () => { | ||
communicator.events.on('session:started', async () => { | ||
console.log('XMPP Client is fully connected'); | ||
communicator.friendship.addFriend('iXyles'); // example of how to add a friend | ||
console.log('Add friend: ', await communicator.friendship.addFriend('iXyles')); // example of how to add a friend | ||
}); | ||
communicator.events.on('friend:request', async (friendrequest) => { | ||
if (FriendStatus.INCOMING) console.log(await friendrequest.accept()); | ||
if (friendrequest.friendStatus === FriendStatus.INCOMING) { | ||
console.log(friendrequest, await friendrequest.accept()); | ||
} | ||
}); | ||
@@ -36,2 +38,6 @@ | ||
communicator.events.on('friend:reject', async (friend) => { | ||
console.log(`You got rejected the friend request by: ${friend.accountId}`); | ||
}); | ||
communicator.events.on('friend:removed', async (friend) => { | ||
@@ -51,3 +57,3 @@ console.log(`You're now unfriended with: ${friend.accountId}`); | ||
console.log(await friend.getStatus()); | ||
console.log(friend.sendMessage('Send something back')); | ||
console.log('message', await friend.sendMessage('Send something back')); | ||
}); | ||
@@ -54,0 +60,0 @@ |
{ | ||
"name": "fortnite-basic-api", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "basic fortnite api and other things, supporting both v1 and v2, using request-promises, xmpp support", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -12,3 +12,3 @@ # fortnite-basic-api | ||
# fortnite-basic-api | ||
# BREAKING CHANGE | ||
V1.3.0 Changed location of where you find "lookup, stats, authenticator" data, check index.js in Client to see more regarding it. | ||
@@ -15,0 +15,0 @@ |
@@ -30,3 +30,3 @@ const Endpoints = require('../../resources/Endpoints'); | ||
async lookupByUsername(username) { | ||
const check = await this.client.checkToken(); | ||
const check = await this.client.authenticator.checkToken(); | ||
if (!check.tokenValid) return check; | ||
@@ -47,3 +47,3 @@ | ||
async lookupByUserId(accountId) { | ||
const check = await this.client.checkToken(); | ||
const check = await this.client.authenticator.checkToken(); | ||
if (!check.tokenValid) return check; | ||
@@ -64,3 +64,3 @@ | ||
async lookupByUserIds(accountIds) { | ||
const check = await this.client.checkToken(); | ||
const check = await this.client.authenticator.checkToken(); | ||
if (!check.tokenValid) return check; | ||
@@ -67,0 +67,0 @@ |
@@ -16,6 +16,6 @@ const Endpoints = require('../../resources/Endpoints'); | ||
async getV1Stats(user) { | ||
const check = await this.client.checkToken(); | ||
const check = await this.client.authenticator.checkToken(); | ||
if (!check.tokenValid) return check; | ||
const account = await this.client.accountLookup(user); | ||
const account = await this.client.lookup.accountLookup(user); | ||
if (account.error || !account.id) return { error: account.error || 'Cannot retrieve stats since the input account does not exist' }; | ||
@@ -44,6 +44,6 @@ | ||
async getV2Stats(user) { | ||
const check = await this.client.checkToken(); | ||
const check = await this.client.authenticator.checkToken(); | ||
if (!check.tokenValid) return check; | ||
const account = await this.client.accountLookup(user); | ||
const account = await this.client.lookup.accountLookup(user); | ||
if (account.error || !account.id) return { error: account.error || 'Cannot retrieve stats since the input account does not exist' }; | ||
@@ -50,0 +50,0 @@ |
@@ -204,8 +204,20 @@ /* eslint-disable no-nested-ternary */ | ||
accountId: data.to, | ||
friendStatus: FriendStatus.REMOVED, | ||
friendStatus: data.reason === 'ABORTED' | ||
? FriendStatus.ABORTED | ||
: data.reason === 'REJECTED' | ||
? FriendStatus.REJECTED | ||
: FriendStatus.REMOVED, | ||
}); | ||
this.emit(data.reason === 'ABORTED' ? 'friend:abort' : 'friend:removed', friend); | ||
this.emit(data.reason === 'ABORTED' ? `friend#${friend.accountId}:abort` : `friend#${friend.accountId}:removed`, friend); | ||
this.emit(friend.friendStatus === 'ABORTED' | ||
? 'friend:abort' | ||
: friend.friendStatus === 'REJECTED' | ||
? 'friend:reject' | ||
: 'friend:removed', friend); | ||
this.emit(friend.friendStatus === 'ABORTED' | ||
? `friend#${friend.accountId}:abort` | ||
: friend.friendStatus === 'REJECTED' | ||
? `friend#${friend.accountId}:reject` | ||
: `friend#${friend.accountId}:removed`, friend); | ||
} | ||
}; |
@@ -17,2 +17,23 @@ const Status = require('./Status.js'); | ||
/** | ||
* Fetch data about user and update Friend | ||
*/ | ||
async fetch() { | ||
const data = await this.communicator.client.lookup.accountLookup(this.accountId); | ||
if (data) this.update(data); | ||
} | ||
/** | ||
* Update the friend user data | ||
* @param {object) data of the user to update | ||
*/ | ||
update(data) { | ||
if (!data.displayName) { | ||
Object.keys(data.externalAuths).forEach((key) => { | ||
this.displayName = `[${key}]${data.externalAuths[key].externalDisplayName}`; | ||
}); | ||
} else this.displayName = data.displayName || 'UNKNOWN'; | ||
this.externalAuths = data.externalAuths; | ||
} | ||
/** | ||
* Request and get the user presence and status | ||
@@ -19,0 +40,0 @@ * @param {string} type - What data to return to the caller |
const Endpoints = require('../../../resources/Endpoints'); | ||
const Utils = require('../../Utils.js'); | ||
const Friend = require('./Friend'); | ||
module.exports = class Friendship { | ||
@@ -12,5 +14,8 @@ constructor(communicator) { | ||
* Accept or add a user with ID | ||
* @param {string} id - GUID of the user to add | ||
* @param {string} id - User ID or name to add | ||
*/ | ||
async addFriend(id) { | ||
async addFriend(user) { | ||
const { id } = await this.client.lookup.accountLookup(user); | ||
if (!id) return false; | ||
const result = await this.client.requester.sendPost( | ||
@@ -21,3 +26,3 @@ `${Endpoints.FRIENDS}/${this.client.authenticator.accountId}/${id}`, | ||
return result === 'undefined' || (result && result.error === 'undefined'); | ||
return result === undefined; | ||
} | ||
@@ -27,5 +32,8 @@ | ||
* Remove a friend with ID | ||
* @param {string} id - GUID of the user to remove | ||
* @param {string} id - User ID or name to add | ||
*/ | ||
async removeFriend(id) { | ||
async removeFriend(user) { | ||
const { id } = await this.client.lookup.accountLookup(user); | ||
if (!id) return false; | ||
const result = await this.client.requester.sendDelete( | ||
@@ -36,3 +44,3 @@ `${Endpoints.FRIENDS}/${this.client.authenticator.accountId}/${id}`, | ||
return result === 'undefined' || (result && result.error === 'undefined'); | ||
return result === undefined; | ||
} | ||
@@ -45,4 +53,6 @@ | ||
*/ | ||
sendMessage(to, message) { | ||
const user = typeof to === 'string' ? Utils.makeJID(to) : to; | ||
async sendMessage(to, message) { | ||
const id = typeof to === 'string' ? (await this.client.lookup.accountLookup(to)).id : to; | ||
if (!id) return false; | ||
const user = typeof to === 'string' ? Utils.makeJID(id) : id; | ||
this.communicator.stream.sendMessage({ | ||
@@ -53,3 +63,4 @@ to: user, | ||
}); | ||
return true; | ||
} | ||
}; |
@@ -10,3 +10,4 @@ module.exports = Object.freeze({ | ||
REJECTED: 'REJECTED', | ||
ABORTED: 'ABORTED', | ||
}); |
@@ -10,2 +10,4 @@ const { createClient } = require('stanza'); | ||
constructor(client, args = {}) { | ||
this.client = client; | ||
this.events = new CommunicatorEvents(this); | ||
@@ -16,3 +18,2 @@ this.friendship = new Friendship(this); | ||
this.uuid = Utils.generateUUID(); | ||
this.client = client; | ||
this.resource = `V2:Fortnite:WIN::${this.uuid}`; | ||
@@ -19,0 +20,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
60801
1435
0