Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
anjo0803 committed May 11, 2024
1 parent 425be0d commit 4111ebc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const dump = require('./requests/dump');
*/
function setAgent(agent) {
if (typeof agent === 'string') NSRequest.useragent = agent;
return this;
return exports;
}

/**
Expand All @@ -115,7 +115,7 @@ function setAgent(agent) {
*/
function setUseRateLimit(state) {
if (typeof state === 'boolean') NSRequest.useRateLimit = state;
return this;
return exports;
}

/**
Expand All @@ -130,7 +130,7 @@ function setUseRateLimit(state) {
function setUseVersion(version) {
if (typeof version === 'number' || version === null)
DataRequest.version = version;
return this;
return exports;
}

/**
Expand All @@ -141,7 +141,7 @@ function setUseVersion(version) {
*/
function setTGClientKey(key) {
if(typeof key === 'string') TGRequest.client = key;
return this;
return exports;
}

/**
Expand All @@ -151,7 +151,7 @@ function setTGClientKey(key) {
*/
function setDumpDirectory(path) {
DumpRequest.setDirectory(path);
return this;
return exports;
}

/**
Expand All @@ -162,6 +162,7 @@ function setDumpDirectory(path) {
*/
function setDumpNameNation(fileNamer) {
if(typeof fileNamer === 'function') NationDumpRequest.filename = fileNamer;
return exports;
}

/**
Expand All @@ -172,6 +173,7 @@ function setDumpNameNation(fileNamer) {
*/
function setDumpNameRegion(fileNamer) {
if(typeof fileNamer === 'function') RegionDumpRequest.filename = fileNamer;
return exports;
}

/**
Expand All @@ -182,6 +184,7 @@ function setDumpNameRegion(fileNamer) {
*/
function setDumpNameCard(fileNamer) {
if(typeof fileNamer === 'function') CardDumpRequest.filename = fileNamer;
return exports;
}

exports.setAgent = setAgent;
Expand Down
10 changes: 10 additions & 0 deletions src/requests/ratelimit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,51 @@ const http = require('node:http');
* Number of milliseconds treated as one time window by the NS API.
* @type {number}
* @default 30000
* @ignore
*/
let period = 30000

/**
* Total number of requests that may be made within one time window.
* @type {number}
* @default 49
* @ignore
*/
let amount = 49 // Leave space for one TG request

/**
* Number of requests sent to the API in the current time window.
* @type {number}
* @ignore
*/
let sent = 0

/**
* Number of requests currently waiting for the active time window to expire.
* @type {number}
* @ignore
*/
let queued = 0

/**
* Timestamp of when the active time window expires.
* @type {number}
* @ignore
*/
let expires = 0

/**
* Number of milliseconds to add to time window calculations as safety buffer.
* @type {number}
* @default 200
* @ignore
*/
const buffer = 200

/**
* Timestamp of when a new time window starts, as stated by the API.
* @type {number}
* @ignore
*/
let retry = 0

Expand Down Expand Up @@ -145,6 +152,7 @@ async function enforce() {
* recruitment telegram is to be sent next.
* @type {number}
* @default 180000
* @ignore
*/
let recruitment = 180000

Expand All @@ -153,12 +161,14 @@ let recruitment = 180000
* non-recruitment telegram is to be sent next.
* @type {number}
* @default 30000
* @ignore
*/
let standard = 30000

/**
* Timestamp of when the last telegram was sent.
* @type {number}
* @ignore
*/
let last = 0

Expand Down

0 comments on commit 4111ebc

Please sign in to comment.