Skip to content

Commit

Permalink
Merge pull request #62 from GreepTheSheep/develop
Browse files Browse the repository at this point in the history
3.0.2
  • Loading branch information
GreepTheSheep authored Nov 25, 2021
2 parents 9f01b8d + ff22e7d commit 21d16c3
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
- 'docs'
tags:
- '*'
paths-ignore:
- 'typings/**'
workflow_dispatch:

permissions: write-all
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/publish-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ jobs:

- name: Deprecate old dev version
if: steps.pre-release.outputs.release == 'true'
run: "npm deprecate trackmania.io@${{ steps.get-version.outputs.version }} 'no longer supported'"
run: "npm deprecate trackmania.io@${{ steps.get-version.outputs.version }} 'no longer supported'"
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}
11 changes: 11 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,22 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Get latest version
id: get-version
if: steps.pre-release.outputs.release == 'true'
run: "echo '::set-output name=version::$(npm view trackmania.io version)'"

- name: Publish on NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

- name: Deprecate old version
if: steps.pre-release.outputs.release == 'true'
run: "npm deprecate trackmania.io@${{ steps.get-version.outputs.version }} 'no longer supported'"
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}

publish-gpr:
name: Publish on Github Packages
runs-on: ubuntu-latest
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">

[![NPM](https://raw.githubusercontent.com/GreepTheSheep/node-trackmania.io/main/docs/graphic/image.svg)](https://tmio.greep.gq/#)
[![Logo](https://raw.githubusercontent.com/GreepTheSheep/node-trackmania.io/main/docs/graphic/image.svg)](https://tmio.greep.gq/#)

[![NPM](https://nodei.co/npm/trackmania.io.png?downloads=true&stars=true)](https://npmjs.org/trackmania.io)

Expand All @@ -16,7 +16,7 @@
[![GitHub Repo stars](https://img.shields.io/github/stars/GreepTheSheep/node-trackmania.io?logo=github&style=flat-square)](https://github.com/GreepTheSheep/node-trackmania.io/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/GreepTheSheep/node-trackmania.io?style=flat-square)](https://github.com/GreepTheSheep/node-trackmania.io/network/members)

[![Unit Test (Push) & Builds](https://github.com/GreepTheSheep/node-trackmania.io/actions/workflows/builds.yml/badge.svg)](https://github.com/GreepTheSheep/node-trackmania.io/actions/workflows/builds.yml)
[![Builds](https://github.com/GreepTheSheep/node-trackmania.io/actions/workflows/build.yml/badge.svg)](https://github.com/GreepTheSheep/node-trackmania.io/actions/workflows/build.yml)

</div>

Expand All @@ -28,7 +28,17 @@

API Keys can be set with the method `Client.setAPIKey("yourname:yourkey");`

If you're still unsure about your use of the API, feel free to DM Miss#8888 with any further questions.
If you're still unsure about your use of the API, feel free to DM Miss on the [Openplanet Discord](https://openplanet.nl/link/discord) with any further questions.

---
## API Keys

API keys for trackmania.io can be retrieved by requesting access to Miss on the [Openplanet Discord](https://openplanet.nl/link/discord)

---
## Documentation

Documentation and examples are available on [this website](https://tmio.greep.gq/#/docs)

---
## Contributing
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.Util.formatTMText(map.name);
const mapName = client.formatTMText(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.Util.formatTMText(map.name);
const mapName = client.formatTMText(map.name);

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

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"name": "trackmania.io",
"version": "3.0.1",
"version": "3.0.2",
"description": "Node.js inplementation of Trackmania Live services (trackmania.io)",
"main": "src/index.js",
"types": "typings/index.d.ts",
"scripts": {
"test": "eslint . && mocha --exit",
"build": "tsc && docgen --source src --custom docs/index.yml --output docs/docs.json",
"dts": "tsc",
"docs": "docgen --source src --custom docs/index.yml --output docs/docs.json"
},
Expand All @@ -24,7 +23,7 @@
"bugs": {
"url": "https://github.com/GreepTheSheep/node-trackmania.io/issues"
},
"homepage": "https://github.com/GreepTheSheep/node-trackmania.io#readme",
"homepage": "https://tmio.greep.gq/",
"dependencies": {
"events": "3.3.0",
"luxon": "^2.1.1",
Expand Down
28 changes: 28 additions & 0 deletions src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,34 @@ class Client extends BaseClient {
} else newTotdChecked = false;
}, 10000);
}

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

// Iterate through the string and check if there are $t,

// First remplace all $T by $t and $Z by $z (for the regex)
resStr = str.replace(/\$T/g, '$t').replace(/\$Z/g, '$z');


// If there is a $t, it will be replaced by the text in uppercase until the $z or the end of the string
while ((res = resStr.match(/\$t(.)*(\$z)|\$t(.)*$/g)) !== null) {
for (let i = 0; i < res.length; i++) {
resStr = resStr.replace(res[i], res[i].toUpperCase());
}
}

// Check if there are two dollar signs in a row, returns one dollar sign
resStr = resStr.replace(/\$\$/gi, '$');

// Then remove all TM codes
return resStr.replace(/\$[<>wnoisgtz]|\$[hl]\[(.)+\]|\$[hl]|\$[0-9a-fA-F]{3}/gi, '');
}
}

module.exports = Client;
Expand Down
4 changes: 1 addition & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module.exports = {

// Entry point for the application.
Client: require("./client/Client"),

Util: require("./util/Util"),
Client: require("./client/Client")
};
2 changes: 1 addition & 1 deletion src/structures/Campaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Campaign {
* @type {string}
*/
get leaderboardId() {
return this._data.leaderboardid;
return this._data.leaderboarduid;
}

/**
Expand Down
28 changes: 0 additions & 28 deletions src/util/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,4 @@ exports.createEnum = (keys) => {
obj[index] = key;
}
return obj;
};

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

// Iterate through the string and check if there are $t,

// First remplace all $T by $t and $Z by $z (for the regex)
resStr = str.replace(/\$T/g, '$t').replace(/\$Z/g, '$z');


// If there is a $t, it will be replaced by the text in uppercase until the $z or the end of the string
while ((res = resStr.match(/\$t(.)*(\$z)|\$t(.)*$/g)) !== null) {
for (let i = 0; i < res.length; i++) {
resStr = resStr.replace(res[i], res[i].toUpperCase());
}
}

// Check if there are two dollar signs in a row, returns one dollar sign
resStr = resStr.replace(/\$\$/gi, '$');

// Then remove all TM codes
return resStr.replace(/\$[<>wnoisgtz]|\$[hl]\[(.)+\]|\$[hl]|\$[0-9a-fA-F]{3}/gi, '');
};
6 changes: 6 additions & 0 deletions typings/client/Client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ declare class Client extends BaseClient {
* @type {EventManager}
*/
events: EventManager;
/**
* Format the string and remove the TM style code on it.
* @param {string} str string to format
* @returns {string}
*/
formatTMText(str: string): string;
}
import BaseClient = require("./BaseClient");
import PlayerManager = require("../managers/PlayerManager");
Expand Down
1 change: 0 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export const Client: typeof import("./client/Client");
export const Util: typeof import("./util/Util");
1 change: 0 additions & 1 deletion typings/util/Util.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function mergeDefault(def: any, given: any): any;
export function createEnum(keys: Array<string>): any;
export function formatTMText(str: string): string;

0 comments on commit 21d16c3

Please sign in to comment.