-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from GreepTheSheep/develop
3.0.6
- Loading branch information
Showing
14 changed files
with
687 additions
and
287 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
[ | ||
{ | ||
"name": "Flamingo", | ||
"img": "https://trackmania.io/img/clans/flamingo.png" | ||
}, | ||
{ | ||
"name": "Pig", | ||
"img": "https://trackmania.io/img/clans/pig.png" | ||
}, | ||
{ | ||
"name": "Clown Fish", | ||
"img": "https://trackmania.io/img/clans/clown_fish.png" | ||
}, | ||
{ | ||
"name": "Fox", | ||
"img": "https://trackmania.io/img/clans/fox.png" | ||
}, | ||
{ | ||
"name": "Octopus", | ||
"img": "https://trackmania.io/img/clans/octopus.png" | ||
}, | ||
{ | ||
"name": "Butterfly", | ||
"img": "https://trackmania.io/img/clans/butterfly.png" | ||
}, | ||
{ | ||
"name": "Crocodile", | ||
"img": "https://trackmania.io/img/clans/crocodile.png" | ||
}, | ||
{ | ||
"name": "Grasshopper", | ||
"img": "https://trackmania.io/img/clans/grasshopper.png" | ||
}, | ||
{ | ||
"name": "Ladybug", | ||
"img": "https://trackmania.io/img/clans/ladybug.png" | ||
}, | ||
{ | ||
"name": "Macaw Parrot", | ||
"img": "https://trackmania.io/img/clans/macaw_parrot.png" | ||
}, | ||
{ | ||
"name": "Giraffe", | ||
"img": "https://trackmania.io/img/clans/giraffe.png" | ||
}, | ||
{ | ||
"name": "Bee", | ||
"img": "https://trackmania.io/img/clans/bee.png" | ||
}, | ||
{ | ||
"name": "Dolphin", | ||
"img": "https://trackmania.io/img/clans/dolphin.png" | ||
}, | ||
{ | ||
"name": "Peafowl", | ||
"img": "https://trackmania.io/img/clans/peafowl.png" | ||
}, | ||
{ | ||
"name": "Kangaroo", | ||
"img": "https://trackmania.io/img/clans/kangaroo.png" | ||
}, | ||
{ | ||
"name": "Monkey", | ||
"img": "https://trackmania.io/img/clans/monkey.png" | ||
}, | ||
{ | ||
"name": "Panda", | ||
"img": "https://trackmania.io/img/clans/panda.png" | ||
}, | ||
{ | ||
"name": "Zebra", | ||
"img": "https://trackmania.io/img/clans/zebra.png" | ||
}, | ||
{ | ||
"name": "Rabbit", | ||
"img": "https://trackmania.io/img/clans/rabbit.png" | ||
}, | ||
{ | ||
"name": "Polar Bear", | ||
"img": "https://trackmania.io/img/clans/polar_bear.png" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
const ReqUtil = require('../util/ReqUtil'); | ||
const CacheManager = require('./CacheManager'); | ||
const {MMTypes, MatchmakingGroup, MatchStatus} = require('../util/Constants'); // eslint-disable-line no-unused-vars | ||
const Match = require('../structures/Match'); | ||
const Client = require('../client/Client'); // eslint-disable-line no-unused-vars | ||
|
||
/** | ||
* Represents the matches manager (3v3 or Royal matches). | ||
*/ | ||
class MatchesManager{ | ||
constructor(client){ | ||
/** | ||
* The client instance. | ||
* @type {Client} | ||
* @readonly | ||
*/ | ||
this.client = client; | ||
|
||
/** | ||
* The cache manager | ||
* @type {CacheManager} | ||
* @private | ||
*/ | ||
this._cache = new CacheManager(this.client, this, Match); | ||
} | ||
|
||
/** | ||
* Get a list of the matches | ||
* @param {MatchmakingGroup} [group='3v3'] The group to get the matches from | ||
* @param {number} [page=0] The page to get | ||
* @param {Boolean} [cache=this.client.options.cache.enabled] Whether to cache the matches or not | ||
* @returns {Promise<Array<MatchResult>>} | ||
*/ | ||
async list(group = 2, page = 0, cache = this.client.options.cache.enabled){ | ||
if (typeof group == 'string') group = MMTypes[group]; | ||
const matches = this.client.options.api.paths.tmio.tabs.matches; | ||
const res = await this.client._apiReq(`${new ReqUtil(this.client).tmioAPIURL}/${matches}/${group}/${page}`); | ||
const array = []; | ||
if (res.matches.length > 0) { | ||
for (let i = 0; i < res.matches.length; i++) { | ||
let match = new MatchResult(this.client, res.matches[i]); | ||
if (cache) { | ||
res.matches[i]._cachedTimestamp = Date.now(); | ||
this._cache.set(res.id, match); | ||
} | ||
array.push(match); | ||
} | ||
} | ||
return array; | ||
} | ||
|
||
/** | ||
* Fetches a Trackmania Match and returns its data. | ||
* @param {string} liveID The live ID of the match (should start with 'LID-MTCH') | ||
* @param {boolean} [cache=this.client.options.cache.enabled] Whether to get the news from cache or not | ||
* @returns {Promise<Match>} The Match | ||
*/ | ||
async get(liveID, cache = this.client.options.cache.enabled){ | ||
if (cache && this._cache.has(liveID)) { | ||
return this._cache.get(liveID); | ||
} else { | ||
return await this._fetch(liveID, cache); | ||
} | ||
} | ||
|
||
/** | ||
* Fetches a Match and returns its data | ||
* @param {string} liveID Thelive ID of the match (should start with 'LID-MTCH') | ||
* @param {boolean} [cache=this.client.options.cache.enabled] Whether to cache the news or not | ||
* @returns {Promise<Match>} The splashscreen | ||
* @private | ||
*/ | ||
async _fetch(liveID, cache = this.client.options.cache.enabled){ | ||
if (!liveID.startsWith("LID-MTCH")) throw "The live ID must start with 'LID-MTCH'"; | ||
const match = this.client.options.api.paths.tmio.tabs.match; | ||
const res = await this.client._apiReq(`${new ReqUtil(this.client).tmioAPIURL}/${match}/${liveID}`); | ||
|
||
const theMatch = new Match(this.client, res); | ||
if (cache) { | ||
res._cachedTimestamp = Date.now(); | ||
this._cache.set(res.lid, theMatch); | ||
} | ||
return theMatch; | ||
} | ||
} | ||
|
||
/** | ||
* The result of a Match from the list. It is completely different from the {@link Match} object. | ||
*/ | ||
class MatchResult { | ||
constructor(client, data){ | ||
/** | ||
* The client instance. | ||
* @type {Client} | ||
*/ | ||
this.client = client; | ||
|
||
/** | ||
* The match ID | ||
* @type {number} | ||
*/ | ||
this.id = data.id; | ||
|
||
/** | ||
* The match Live ID | ||
* @type {string} | ||
*/ | ||
this.liveID = data.lid; | ||
|
||
/** | ||
* The match start date | ||
* @type {Date} | ||
*/ | ||
this.startDate = new Date(data.starttime); | ||
|
||
/** | ||
* The status of the match | ||
* @type {MatchStatus} | ||
*/ | ||
this.status = data.status; | ||
} | ||
|
||
/** | ||
* Get the match | ||
* @param {boolean} [cache=this.client.options.cache.enabled] Whether to cache the match or not | ||
*/ | ||
async match(cache = this.client.options.cache.enabled){ | ||
return this.client.matches.get(this.liveID, cache); | ||
} | ||
} | ||
|
||
module.exports = MatchesManager; |
Oops, something went wrong.