UNPKG

@ariusii/intersect.ts

Version:

The Intersect Engine API Client Library based on TS.

218 lines 7.8 kB
/** * This is the Players Class, it contains all the methods to handle the Players. * Those actions do not require any Query Role. * @class Players * @link https://docs.freemmorpgmaker.com/en-US/api/v1/endpoints/players.html * @author AriusII */ export class Players { _url; _token; constructor(_url, _token) { this._url = _url; this._token = _token; } async playersList(page, pageSize, limit) { const res = await fetch(`${this._url}/api/v1/players?page=${page || 0}&pageSize=${pageSize || 5}&limit=${limit || (pageSize || 5)}`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` } }); return await res.json(); } async playerRank(page, pageSize, limit, sort) { const res = await fetch(`${this._url}/api/v1/players/rank?page=${page || 0}&pageSize=${pageSize || 5}&limit=${limit || (pageSize || 5)}&sortDirection=${sort || 'Descending'}`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` } }); return await res.json(); } async playersOnline(page, count) { const res = await fetch(`${this._url}/api/v1/players/online`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` }, body: JSON.stringify({ page: page || 0, count: count || 5 }) }); return await res.json(); } async playerOnlineCount() { const res = await fetch(`${this._url}/api/v1/players/online/count`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` } }); return await res.json(); } async playerLookup(player) { const res = await fetch(`${this._url}/api/v1/players/${player}`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` } }); return await res.json(); } async playerVariables(player) { const res = await fetch(`${this._url}/api/v1/players/${player}/variables`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` } }); return await res.json(); } async playerVariable(player, variable) { const res = await fetch(`${this._url}/api/v1/players/${player}/variables/${variable}`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` } }); return await res.json(); } async getPlayerVariableValue(player, variable) { const res = await fetch(`${this._url}/api/v1/players/${player}/variables/${variable}/value`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` } }); return await res.json(); } async setPlayerVariableValue(player, variable, value) { const res = await fetch(`${this._url}/api/v1/players/${player}/variables/${variable}/value`, { method: 'PUT', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` }, body: JSON.stringify({ value: value }) }); return await res.json(); } async getPlayerItems(player) { const res = await fetch(`${this._url}/api/v1/players/${player}/items`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` } }); return await res.json(); } async getPlayerInventoryItems(player) { const res = await fetch(`${this._url}/api/v1/players/${player}/items/inventory`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` } }); return await res.json(); } async getPlayerBankItems(player) { const res = await fetch(`${this._url}/api/v1/players/${player}/items/bank`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` } }); return await res.json(); } async getPlayerBag(bag) { const res = await fetch(`${this._url}/api/v1/players/bag/${bag}`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` } }); return await res.json(); } async givePlayerItem(player, item, amount, bankoverflow) { const res = await fetch(`${this._url}/api/v1/players/${player}/items/give`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` }, body: JSON.stringify({ itemid: item, quantity: amount, bankoverflow: bankoverflow }) }); return await res.json(); } async takePlayerItem(player, item, amount) { const res = await fetch(`${this._url}/api/v1/players/${player}/items/take`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` }, body: JSON.stringify({ itemid: item, quantity: amount }) }); return await res.json(); } async getPlayerSpells(player) { const res = await fetch(`${this._url}/api/v1/players/${player}/spells`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` } }); return await res.json(); } async givePlayerSpell(player, spell) { const res = await fetch(`${this._url}/api/v1/players/${player}/spells/teach`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` }, body: JSON.stringify({ spellid: spell }) }); return await res.json(); } async takePlayerSpell(player, spell) { const res = await fetch(`${this._url}/api/v1/players/${player}/spells/forget`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this._token}` }, body: JSON.stringify({ spellid: spell }) }); return await res.json(); } } //# sourceMappingURL=players.js.map