Skip to content

Commit

Permalink
Merge pull request #115 from GreepTheSheep/develop
Browse files Browse the repository at this point in the history
v3.2.0
  • Loading branch information
GreepTheSheep authored Jun 21, 2022
2 parents 4ec81fd + f8f251a commit 4857548
Show file tree
Hide file tree
Showing 13 changed files with 376 additions and 76 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ If you're still unsure about your use of the API, feel free to DM Miss on the [O
---
## API Keys

API keys for trackmania.io can be retrieved by requesting access to Miss on the [Openplanet Discord](https://openplanet.nl/link/discord)
API keys for trackmania.io are not mandatory, but can be used to increase the rate limit. These are not given out frequently, and as such are issued only on request. For more information, contact Miss on the [Openplanet Discord](https://openplanet.nl/link/discord).

---
## Documentation
Expand Down
2 changes: 1 addition & 1 deletion examples/totd.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ client.totd.get(new Date()).then(async totd=>{
author = await map.author();

// Map names aren't formatted by default (color codes for example), so we need to format them
const mapName = client.formatTMText(map.name);
const mapName = client.stripFormat(map.name);

console.log("Today's TOTD is called", mapName, "and it was created by", author.name);
});
Expand Down
2 changes: 1 addition & 1 deletion examples/totdEvent.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ client.on('totd', async totd=>{
const map = await totd.map();

// Map names aren't formatted by default (color codes for example), so we need to format them
const mapName = client.formatTMText(map.name);
const mapName = client.stripFormat(map.name);

console.log('New Track Of The Day:', mapName);
});
Expand Down
46 changes: 23 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trackmania.io",
"version": "3.1.1",
"version": "3.2.0",
"description": "Node.js inplementation of Trackmania Live services (trackmania.io)",
"main": "src/index.js",
"types": "typings/index.d.ts",
Expand All @@ -25,14 +25,14 @@
},
"homepage": "https://tmio.greep.gq/",
"dependencies": {
"luxon": "^2.3.2",
"luxon": "^2.4.0",
"node-fetch": "2.6.7"
},
"devDependencies": {
"@discordjs/docgen": "0.11.1",
"dotenv": "16.0.0",
"dotenv": "16.0.1",
"eslint": "7.31.0",
"mocha": "10.0.0",
"typescript": "4.6.4"
"typescript": "4.7.4"
}
}
19 changes: 14 additions & 5 deletions src/client/Client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const {DateTime} = require('luxon');
const BaseClient = require('./BaseClient');
const { deprecate } = require('util');

const defaultOptions = require('../util/defaultOptions'); // eslint-disable-line no-unused-vars
const TOTD = require('../structures/TOTD'); // eslint-disable-line no-unused-vars
Expand Down Expand Up @@ -99,12 +100,11 @@ class Client extends BaseClient {
let newTotdChecked = false;
setInterval(async ()=>{
const date = DateTime.local().setZone("Europe/Paris");
if (date.hour === 19 && date.minute === 1 && !newTotdChecked){
if (date.hour === 19 && !newTotdChecked){
let totd = await this.totd.get(date.toJSDate());
if (totd.monthDay === date.day) {
/**
* Emitted when a new Track Of The Day is out on Trackmania.io.
* <info>This event is mostly emitted one minute after the release (at 19h01 CE(S)T)</info>
* @event Client#totd
* @param {TOTD} totd The Track of The Day
*/
Expand All @@ -113,18 +113,27 @@ class Client extends BaseClient {
// this prevent emitting this event a second time in the same day
newTotdChecked = true;
}
} else {
if (date.hour !== 19 && date.minute !== 1) newTotdChecked = false;
}
}, 10000);
if (date.hour !== 19) newTotdChecked = false;
}, 30000);
}

/**
* Format the string and remove the TM style code on it.
* @param {string} str string to format
* @returns {string}
* @deprecated use {@link Client#stripFormat} instead
*/
formatTMText(str){
return deprecate(this.stripFormat, 'Client#formatTMText is deprecated, use Client#stripFormat instead')(str);
}

/**
* Format the string and remove the TM style code on it.
* @param {string} str string to format
* @returns {string}
*/
stripFormat(str){
let res, resStr;

// Iterate through the string and check if there are $t,
Expand Down
20 changes: 10 additions & 10 deletions src/managers/PlayerManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PlayerManager {

/**
* The cache manager
* @type {CacheManager}
* @type {CacheManager}
* @private
*/
this._cache = new CacheManager(this.client, this, Player);
Expand All @@ -40,9 +40,9 @@ class PlayerManager {
var byte = String.fromCharCode(dec);
bytes += byte;
}

return btoa(bytes)
.replace(/\\+/g, '-')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=/g, '');
}
Expand All @@ -54,12 +54,12 @@ class PlayerManager {
*/
toAccountId(login){
if (login.length != 22) return null;

var bytes = atob(login
.replace(/-/g, '+')
.replace(/_/g, '/')
);

var ret = '';
for (var i = 0; i < bytes.length; i++) {
if (i == 4 || i == 6 || i == 8 || i == 10) {
Expand Down Expand Up @@ -144,7 +144,7 @@ class PlayerManager {
res = await this.client._apiReq(`${new ReqUtil(this.client).tmioAPIURL}/${top}/${typeId}/${page}`);

if (res.error) throw res.error;

const topsArray = res.ranks.map(playerTop=> new PlayerTopMatchmaking(this.client, typeId, playerTop));
return topsArray;
}
Expand All @@ -155,7 +155,7 @@ class PlayerManager {
* @param {boolean} [cache=this.client.options.cache.enabled] Whether to get the player from cache or not
* @returns {Promise<Player>} The player
* @example
* // Get a player
* // Get a player
* client.players.get('26d9a7de-4067-4926-9d93-2fe62cd869fc').then(player => {
* console.log(player.name);
* });
Expand All @@ -167,7 +167,7 @@ class PlayerManager {
return await this._fetch(accountId, cache);
}
}

/**
* Fetches a player and returns its data
* @param {string} accountId The account ID or its tm.io vanity name
Expand All @@ -178,11 +178,11 @@ class PlayerManager {
async _fetch(accountId, cache = this.client.options.cache.enabled){
const player = this.client.options.api.paths.tmio.tabs.player,
res = await this.client._apiReq(`${new ReqUtil(this.client).tmioAPIURL}/${player}/${accountId}`);

const thePlayer = new Player(this.client, res);
if (cache) {
res._cachedTimestamp = Date.now();

this._cache.set(res.accountid, thePlayer);

// Adds also the player by its vanity name in the cache
Expand Down
Loading

0 comments on commit 4857548

Please sign in to comment.