warframe-nexus-query 1.6.16 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +10 -9
- package/index.js +27 -56
- package/lib/AttachmentCreator.js +28 -109
- package/lib/Settings.js +2 -21
- package/lib/market/v1/MarketFetcher.js +32 -23
- package/lib/market/v1/summary.js +12 -12
- package/lib/promiseTimeout.js +1 -4
- package/package.json +33 -41
- package/lib/nexus/base/Component.js +0 -39
- package/lib/nexus/base/Item.js +0 -56
- package/lib/nexus/v2/NexusFetcher.js +0 -56
- package/lib/nexus/v2/component.js +0 -84
- package/lib/nexus/v2/item.js +0 -34
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://discord.gg/jGZxH9f)
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
A node project for allowing simple
|
|
7
|
+
A node project for allowing simple summary of the [Warframe.Market](https://warframe.market) pricing API.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
```
|
|
@@ -13,17 +13,18 @@ npm install --save warframe-nexus-query
|
|
|
13
13
|
|
|
14
14
|
## Usage
|
|
15
15
|
|
|
16
|
-
Require
|
|
17
|
-
|
|
18
|
-
`warframe-nexus-query` | `index.js`
|
|
19
|
-
`warframe-nexus-query` | `index.js`
|
|
16
|
+
| Require | Module File | Accessor | Description | parameters |
|
|
17
|
+
|------------------------|-------------|--------------------------|---------------------------------------------------------|---------------------|
|
|
18
|
+
| `warframe-nexus-query` | `index.js` | `.priceCheckQueryString` | Get Query result string | `query`, `callback` |
|
|
19
|
+
| `warframe-nexus-query` | `index.js` | `.priceCheckQuery` | Get Query result objects, has more parameters available | `query`, `callback` |
|
|
20
20
|
|
|
21
21
|
## Environment variables
|
|
22
22
|
|
|
23
|
-
Variable
|
|
24
|
-
|
|
25
|
-
`NEXUSSTATS_MAX_CACHED_TIME` | `600000`
|
|
26
|
-
`NEXUSSTATS_URL_OVERRIDE`
|
|
23
|
+
| Variable | example | default |
|
|
24
|
+
|------------------------------|---------------------------------|-------------------------------|
|
|
25
|
+
| `NEXUSSTATS_MAX_CACHED_TIME` | `600000` | `30000` |
|
|
26
|
+
| `NEXUSSTATS_URL_OVERRIDE` | `'https://nexus-stats.com/api'` | `https://nexus-stats.com/api` |
|
|
27
|
+
|
|
27
28
|
|
|
28
29
|
## Objects
|
|
29
30
|
|
package/index.js
CHANGED
|
@@ -6,43 +6,24 @@ const fss = require('fs');
|
|
|
6
6
|
const path = require('path');
|
|
7
7
|
|
|
8
8
|
const promiseTimeout = require('./lib/promiseTimeout');
|
|
9
|
-
const Settings = require('./lib/Settings
|
|
10
|
-
const Creator = require('./lib/AttachmentCreator
|
|
11
|
-
const MarketFetcher = require('./lib/market/v1/MarketFetcher
|
|
12
|
-
const NexusFetcher = require('./lib/nexus/v2/NexusFetcher');
|
|
9
|
+
const Settings = require('./lib/Settings');
|
|
10
|
+
const Creator = require('./lib/AttachmentCreator');
|
|
11
|
+
const MarketFetcher = require('./lib/market/v1/MarketFetcher');
|
|
13
12
|
|
|
14
13
|
if (!global.__basedir) {
|
|
15
14
|
global.__basedir = __dirname;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
/**
|
|
19
|
-
* Represents a queryable datastore of information derived from `https://nexus-stats.com/api`
|
|
20
|
-
*/
|
|
21
17
|
module.exports = class PriceCheckQuerier {
|
|
22
18
|
/**
|
|
23
19
|
* Creates an instance representing a WarframeNexusStats data object
|
|
24
20
|
* @constructor
|
|
25
21
|
*/
|
|
26
|
-
constructor({
|
|
27
|
-
logger = console,
|
|
28
|
-
nexusApi = undefined,
|
|
29
|
-
marketCache = undefined,
|
|
30
|
-
skipNexus = false,
|
|
31
|
-
skipMarket = false,
|
|
32
|
-
}) {
|
|
22
|
+
constructor({ logger = console, marketCache = undefined, skipMarket = false }) {
|
|
33
23
|
this.settings = new Settings();
|
|
34
24
|
this.logger = logger;
|
|
35
|
-
this.skipNexus = skipNexus;
|
|
36
25
|
this.skipMarket = skipMarket;
|
|
37
26
|
|
|
38
|
-
if (!skipNexus) {
|
|
39
|
-
try {
|
|
40
|
-
this.nexusFetcher = new NexusFetcher({ settings: this.settings, nexusApi, logger });
|
|
41
|
-
} catch (e) {
|
|
42
|
-
this.logger.error(`couldn't set up nexus fetcher: ${e.message}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
27
|
if (!skipMarket) {
|
|
47
28
|
try {
|
|
48
29
|
/**
|
|
@@ -51,7 +32,7 @@ module.exports = class PriceCheckQuerier {
|
|
|
51
32
|
*/
|
|
52
33
|
this.marketFetcher = new MarketFetcher({ logger, settings: this.settings, marketCache });
|
|
53
34
|
} catch (e) {
|
|
54
|
-
this.logger.error(`couldn't set up market fetcher: ${e.message}`);
|
|
35
|
+
/* istanbul ignore next */ this.logger.error(`couldn't set up market fetcher: ${e.message}`);
|
|
55
36
|
}
|
|
56
37
|
}
|
|
57
38
|
|
|
@@ -69,41 +50,28 @@ module.exports = class PriceCheckQuerier {
|
|
|
69
50
|
* @returns {Promise<Array<NexusItem>>} a Promise of an array of Item objects
|
|
70
51
|
*/
|
|
71
52
|
async priceCheckQuery(query, platform = 'pc') {
|
|
72
|
-
this.logger.info(`state:\n\
|
|
53
|
+
this.logger.info(`state:\n\tskipMarket: ${this.skipMarket}\n\tquery: ${query}\n\tplatform: ${platform}`);
|
|
73
54
|
if (!query) {
|
|
74
55
|
throw new Error('This funtcion requires a query to be provided');
|
|
75
56
|
}
|
|
76
57
|
// eslint-disable-next-line no-param-reassign
|
|
77
58
|
platform = this.settings.lookupAlias(platform.toLowerCase());
|
|
78
59
|
|
|
79
|
-
let nexusResults;
|
|
80
60
|
let successfulQuery;
|
|
81
61
|
let attachments = [];
|
|
82
|
-
if (!this.skipNexus) {
|
|
83
|
-
this.logger.info(`querying nexus for ${query} on ${platform}`);
|
|
84
|
-
if (platform !== 'switch') {
|
|
85
|
-
try {
|
|
86
|
-
const nexusPromise = this.nexusFetcher.queryNexus(query, platform);
|
|
87
|
-
nexusResults = await promiseTimeout(this.settings.timeouts.nexus, nexusPromise);
|
|
88
|
-
({ successfulQuery, attachments } = nexusResults);
|
|
89
|
-
} catch (e) {
|
|
90
|
-
this.logger.error(`Couldn't process ${query} on nexus-hub... time out.`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
this.logger.info('skipNexus');
|
|
95
|
-
}
|
|
96
62
|
|
|
63
|
+
/* istanbul ignore else */
|
|
97
64
|
if (this.marketFetcher && !this.skipMarket) {
|
|
98
65
|
this.logger.info(`querying market for ${query} on ${platform}`);
|
|
99
66
|
try {
|
|
100
67
|
const marketPromise = this.marketFetcher.queryMarket(query, {
|
|
101
|
-
successfulQuery,
|
|
68
|
+
successfulQuery,
|
|
69
|
+
platform: this.settings.lookupAlias(platform, true),
|
|
102
70
|
});
|
|
103
71
|
const marketResults = await promiseTimeout(this.settings.timeouts.market, marketPromise);
|
|
104
72
|
attachments = [...attachments, ...marketResults];
|
|
105
73
|
} catch (e) {
|
|
106
|
-
this.logger.error(`Couldn't process ${query} on warframe.market... time out.`);
|
|
74
|
+
/* istanbul ignore next */ this.logger.error(`Couldn't process ${query} on warframe.market... time out.`);
|
|
107
75
|
}
|
|
108
76
|
} else {
|
|
109
77
|
this.logger.info('No market fetcher, skipping market');
|
|
@@ -120,15 +88,13 @@ module.exports = class PriceCheckQuerier {
|
|
|
120
88
|
* @returns {Promise<string>} a Promise of a string containing the results of the query
|
|
121
89
|
*/
|
|
122
90
|
async priceCheckQueryString(query, priorResults, platform = 'pc') {
|
|
123
|
-
const components = priorResults || await this.priceCheckQuery(query, platform);
|
|
91
|
+
const components = priorResults || (await this.priceCheckQuery(query, platform));
|
|
124
92
|
const tokens = [`[${platform.toUpperCase()}] ${query}`];
|
|
125
93
|
components.slice(0, 4).forEach((component) => {
|
|
126
94
|
tokens.push(`${md.lineEnd}${component.toString()}`);
|
|
127
95
|
});
|
|
128
96
|
let componentsToReturnString = `${md.codeMulti}${tokens.join()}${md.blockEnd}`;
|
|
129
|
-
componentsToReturnString = components.length > 0
|
|
130
|
-
? componentsToReturnString
|
|
131
|
-
: this.settings.defaultString;
|
|
97
|
+
componentsToReturnString = components.length > 0 ? componentsToReturnString : this.settings.defaultString;
|
|
132
98
|
return componentsToReturnString;
|
|
133
99
|
}
|
|
134
100
|
|
|
@@ -137,10 +103,10 @@ module.exports = class PriceCheckQuerier {
|
|
|
137
103
|
* @param {string} query Query to search the nexus-stats database against
|
|
138
104
|
* @param {Object[]} priorResults results provided from a prior search
|
|
139
105
|
* @param {string} platform Platform to query price data for. One of 'pc', 'ps4', 'xb1'
|
|
140
|
-
* @returns {Array<Object
|
|
106
|
+
* @returns {Promise<Array<Object>>} a Promise of an array of attachment objects
|
|
141
107
|
*/
|
|
142
108
|
async priceCheckQueryAttachment(query, priorResults, platform = 'pc') {
|
|
143
|
-
const components = priorResults || await this.priceCheckQuery(query, platform);
|
|
109
|
+
const components = priorResults || (await this.priceCheckQuery(query, platform));
|
|
144
110
|
const realPlatform = this.settings.lookupAlias(platform);
|
|
145
111
|
|
|
146
112
|
const attachment = this.creator.attachmentFromComponents(components, query, realPlatform);
|
|
@@ -151,6 +117,7 @@ module.exports = class PriceCheckQuerier {
|
|
|
151
117
|
* Stop updating caches
|
|
152
118
|
*/
|
|
153
119
|
async stopUpdating() {
|
|
120
|
+
/* istanbul ignore else */
|
|
154
121
|
if (!this.skipMarket && this.marketFetcher.marketCache) {
|
|
155
122
|
this.marketFetcher.marketCache.stop();
|
|
156
123
|
} else {
|
|
@@ -160,14 +127,18 @@ module.exports = class PriceCheckQuerier {
|
|
|
160
127
|
if (fss.existsSync(`${global.__basedir}/tmp`)) {
|
|
161
128
|
const files = await fs.readdir(`${global.__basedir}/tmp`);
|
|
162
129
|
let allSuccess = true;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
130
|
+
await Promise.all(
|
|
131
|
+
files.map(
|
|
132
|
+
/* istanbul ignore next */ async (file) => {
|
|
133
|
+
try {
|
|
134
|
+
await fs.unlink(path.join(global.__basedir, 'tmp', file));
|
|
135
|
+
} catch (e) {
|
|
136
|
+
allSuccess = false;
|
|
137
|
+
this.logger.debug(`Couldn't delete ${file}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
);
|
|
171
142
|
|
|
172
143
|
if (allSuccess) {
|
|
173
144
|
await fs.rmdir(`${global.__basedir}/tmp`);
|
package/lib/AttachmentCreator.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
/* eslint-disable class-methods-use-this, no-param-reassign */
|
|
4
|
-
|
|
5
4
|
const n = require('numeral');
|
|
6
|
-
|
|
7
|
-
const NexusComponent = require('./nexus/base/Component'); // eslint-disable-line no-unused-vars
|
|
8
5
|
const MarketComponent = require('./market/v1/summary'); // eslint-disable-line no-unused-vars
|
|
9
6
|
|
|
10
7
|
const numerFmt = '0,0';
|
|
11
|
-
|
|
12
8
|
const wfcdLogo = 'https://warframestat.us/wfcd_logo_color.png';
|
|
13
9
|
|
|
14
10
|
const noResultAttachment = {
|
|
@@ -54,92 +50,40 @@ function safeRange(value1, value2) {
|
|
|
54
50
|
return value1 ? `${Number.parseInt(value1, 10)}p - ${Number.parseInt(value2, 10)}p` : 'No Data';
|
|
55
51
|
}
|
|
56
52
|
|
|
57
|
-
/**
|
|
58
|
-
* Safely truncate the percentage value to a readable length
|
|
59
|
-
* @param {number|undefined} value percentage value
|
|
60
|
-
* @returns {string} readable percentage value (no suffix)
|
|
61
|
-
*/
|
|
62
|
-
function truncPercentage(value) {
|
|
63
|
-
return String((parseFloat(value || 0) * 100).toFixed(2));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
53
|
/**
|
|
67
54
|
* Build a field from provided nexus & market components
|
|
68
|
-
* @param {NexusComponent} nComponent nexus component
|
|
69
55
|
* @param {MarketComponent} mComponent market component
|
|
70
|
-
* @param {number} mCount count of total market components
|
|
71
56
|
* @returns {Object} built field
|
|
72
57
|
*/
|
|
73
|
-
function fieldValue(
|
|
74
|
-
let nMedian;
|
|
75
|
-
let nRange;
|
|
76
|
-
let snD;
|
|
77
|
-
|
|
58
|
+
function fieldValue(mComponent) {
|
|
78
59
|
let mMedian;
|
|
79
60
|
let mRange;
|
|
80
61
|
|
|
81
|
-
if (nComponent) {
|
|
82
|
-
// console.log(`Building nexus component.... ${nComponent.name} : ${nComponent.prices.median}`);
|
|
83
|
-
nMedian = safeValue(nComponent.prices.median);
|
|
84
|
-
nRange = safeRange(nComponent.prices.minimum, nComponent.prices.maximum);
|
|
85
|
-
snD = `Supply: **${nComponent.supply.count}** units (${truncPercentage(nComponent.supply.percentage)}%) `
|
|
86
|
-
+ `- Demand: **${nComponent.demand.count}** units (${truncPercentage(nComponent.demand.percentage)}%)\n\u200B`;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
62
|
if (mComponent) {
|
|
90
63
|
mMedian = safeValue(mComponent.prices.soldPrice);
|
|
91
|
-
mRange = safeRange(
|
|
92
|
-
mComponent.prices.minimum,
|
|
93
|
-
mComponent.prices.maximum,
|
|
94
|
-
);
|
|
64
|
+
mRange = safeRange(mComponent.prices.minimum, mComponent.prices.maximum);
|
|
95
65
|
}
|
|
96
66
|
|
|
97
|
-
if (nComponent && mComponent) {
|
|
98
|
-
return {
|
|
99
|
-
name: `${mCount.length < 2 ? '_ _' : mComponent.name.replace(nComponent.title, '').trim()}${nComponent.ducats ? ` - ${nComponent.ducats} ducats` : ''}`,
|
|
100
|
-
value: '```haskell\n'
|
|
101
|
-
+ `${'Source'.padEnd(6, ' ')} | ${'Nexus'.padEnd(13, ' ')}| Market\n`
|
|
102
|
-
+ `${'Median'.padEnd(6, ' ')} | ${nMedian.padEnd(13, ' ')}| ${mMedian}\n`
|
|
103
|
-
+ `${'Range'.padEnd(6, ' ')} | ${nRange.padEnd(13, ' ')}| ${mRange}\n\n`
|
|
104
|
-
+ `Trade Tax: ${n(mComponent.tradingTax).format(numerFmt)}cr`
|
|
105
|
-
+ `\`\`\`\n${snD}`,
|
|
106
|
-
inline: false,
|
|
107
|
-
};
|
|
108
|
-
} if (nComponent) {
|
|
109
|
-
return {
|
|
110
|
-
name: `${nComponent.name.trim()}${nComponent.ducats ? ` - ${nComponent.ducats} ducats` : ''}`,
|
|
111
|
-
value: `${'```haskell\n'
|
|
112
|
-
+ `${'Source'.padEnd(6, ' ')} | Nexus\n`
|
|
113
|
-
+ `${'Median'.padEnd(6, ' ')} | ${nMedian}\n`
|
|
114
|
-
+ `${'Range'.padEnd(6, ' ')} | ${nRange}\n`
|
|
115
|
-
+ '```\n'}${
|
|
116
|
-
snD}`,
|
|
117
|
-
inline: false,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
67
|
return {
|
|
121
68
|
name: mComponent.name.trim(),
|
|
122
|
-
value:
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
69
|
+
value:
|
|
70
|
+
'```haskell\n' +
|
|
71
|
+
`${'Value'.padEnd(6, ' ')} | Market\n` +
|
|
72
|
+
`${'Median'.padEnd(6, ' ')} | ${mMedian}\n` +
|
|
73
|
+
`${'Range'.padEnd(6, ' ')} | ${mRange}\n` +
|
|
74
|
+
'```\n' +
|
|
75
|
+
`Trade Tax: ${n(mComponent.tradingTax).format(numerFmt)}cr\n`,
|
|
128
76
|
inline: false,
|
|
129
77
|
};
|
|
130
78
|
}
|
|
131
79
|
|
|
132
80
|
/**
|
|
133
|
-
*
|
|
81
|
+
* Create the attachment itself
|
|
134
82
|
*/
|
|
135
83
|
class AttachmentCreator {
|
|
136
|
-
constructor(logger = console) {
|
|
137
|
-
this.logger = logger;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
84
|
/**
|
|
141
85
|
* Build an attachment from the provided components
|
|
142
|
-
* @param {Array
|
|
86
|
+
* @param {Array<MarketComponent>} components -
|
|
143
87
|
* collected array of components with market data
|
|
144
88
|
* @param {string} query Search query that these components match
|
|
145
89
|
* @param {string} [platform='pc'] Platform for the request, defaults to 'pc'
|
|
@@ -148,50 +92,23 @@ class AttachmentCreator {
|
|
|
148
92
|
attachmentFromComponents(components, query, platform = 'pc') {
|
|
149
93
|
if (!components || !components.length || !Array.isArray(components)) return noResultAttachment;
|
|
150
94
|
|
|
151
|
-
const attachment =
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
.filter((component) => component && component.type === 'market-v1'
|
|
156
|
-
&& typeof component.prices.soldPrice !== 'undefined');
|
|
157
|
-
|
|
158
|
-
if (nexusComponents.length > 0) {
|
|
159
|
-
nexusComponents.forEach((nexusComponent) => {
|
|
160
|
-
attachment.title = `[${platform.toUpperCase()}] ${nexusComponent.title}`;
|
|
161
|
-
|
|
162
|
-
nexusComponent.components.forEach((component) => {
|
|
163
|
-
attachment.thumbnail.url = nexusComponent.thumbnail;
|
|
164
|
-
|
|
165
|
-
const marketMatch = marketComponents.find((mk) => mk.prices && mk.prices.soldPrice
|
|
166
|
-
&& mk.name.toLowerCase().includes(component.name.toLowerCase()));
|
|
167
|
-
|
|
168
|
-
component.title = nexusComponent.title;
|
|
169
|
-
attachment.fields.push(fieldValue(component, marketMatch, marketComponents.length));
|
|
95
|
+
const attachment = { ...baseAttachment };
|
|
96
|
+
const marketComponents = components.filter(
|
|
97
|
+
(component) => component && component.type === 'market-v1' && typeof component.prices.soldPrice !== 'undefined'
|
|
98
|
+
);
|
|
170
99
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
100
|
+
/* istanbul ignore else */
|
|
101
|
+
if (marketComponents.length > 0) {
|
|
102
|
+
marketComponents.forEach((marketComponent, index) => {
|
|
103
|
+
if (!index) {
|
|
104
|
+
attachment.color = parseInt(marketComponent.color, 16);
|
|
105
|
+
attachment.title = `[${platform.toUpperCase()}] ${marketComponent.name.replace(/\sset/i, '')}`;
|
|
106
|
+
attachment.url = marketComponent.url;
|
|
107
|
+
attachment.thumbnail.url = marketComponent.thumbnail;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
attachment.fields.push(fieldValue(marketComponent));
|
|
181
111
|
});
|
|
182
|
-
} else if (marketComponents.length > 0) {
|
|
183
|
-
const mCLen = marketComponents.length;
|
|
184
|
-
marketComponents
|
|
185
|
-
.forEach((marketComponent, index) => {
|
|
186
|
-
if (!index) {
|
|
187
|
-
attachment.color = parseInt(marketComponent.color, 16);
|
|
188
|
-
attachment.title = `[${platform.toUpperCase()}] ${marketComponent.name.replace(/\sset/i, '')}`;
|
|
189
|
-
attachment.url = marketComponent.url;
|
|
190
|
-
attachment.thumbnail.url = marketComponent.thumbnail;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
attachment.fields.push(fieldValue(undefined, marketComponent, mCLen));
|
|
194
|
-
});
|
|
195
112
|
|
|
196
113
|
attachment.footer = {
|
|
197
114
|
icon_url: wfcdLogo,
|
|
@@ -200,9 +117,11 @@ class AttachmentCreator {
|
|
|
200
117
|
} else {
|
|
201
118
|
return noResultAttachment;
|
|
202
119
|
}
|
|
120
|
+
/* istanbul ignore else */
|
|
203
121
|
if (attachment.fields.length) {
|
|
204
122
|
return attachment;
|
|
205
123
|
}
|
|
124
|
+
/* istanbul ignore next */
|
|
206
125
|
return noResultAttachment;
|
|
207
126
|
}
|
|
208
127
|
}
|
package/lib/Settings.js
CHANGED
|
@@ -4,31 +4,15 @@
|
|
|
4
4
|
* Settings storage for nexus query
|
|
5
5
|
* @type {Settings}
|
|
6
6
|
* @property {number} maxCacheLength - maximum length to store cached data
|
|
7
|
-
* @property {string} nexusKey - User Key for Nexus-Stats
|
|
8
|
-
* @property {string} nexusSecret - User Secret for Nexus-Stats
|
|
9
|
-
* @property {string} nexusHubSecret - User Secret for NexusHub
|
|
10
|
-
* @property {string} nexusHubKey - User Key for NexusHub
|
|
11
7
|
* @property {Object} urls - URL list for nexus stats
|
|
12
8
|
*/
|
|
13
9
|
class Settings {
|
|
14
10
|
constructor() {
|
|
15
|
-
this.maxCacheLength = process.env.NEXUSSTATS_MAX_CACHED_TIME || 60000;
|
|
16
|
-
this.nexusKey = process.env.NEXUSSTATS_USER_KEY || undefined;
|
|
17
|
-
this.nexusSecret = process.env.NEXUSSTATS_USER_SECRET || undefined;
|
|
18
|
-
|
|
19
|
-
this.nexusHubSecret = process.env.NEXUSHUB_USER_SECRET || undefined;
|
|
20
|
-
this.neuxsHubUser = process.env.NEXUSHUB_USER_KEY || undefined;
|
|
21
|
-
|
|
22
11
|
this.urls = {
|
|
23
|
-
nexus: process.env.NEXUSSTATS_URL_OVERRIDE || 'https://api.nexushub.co/warframe/v1/items',
|
|
24
|
-
nexusWeb: process.env.NEXUSSTATS_WEB_OVERRIDE || 'https://nexushub.co',
|
|
25
|
-
nexusApi: process.env.NEXUS_API_OVERRIDE || 'https://api.nexushub.co',
|
|
26
|
-
nexusAuth: process.env.NEXUS_AUTH_OVERRIDE || 'https://auth.nexus-stats.com',
|
|
27
12
|
market: process.env.MARKET_URL_OVERRIDE || 'https://api.warframe.market/v1/items',
|
|
28
13
|
marketAssets: process.env.MARKET_ASSETS_URL_OVERRIDE || 'https://warframe.market/static/assets/',
|
|
29
14
|
};
|
|
30
15
|
|
|
31
|
-
|
|
32
16
|
this.platforms = {
|
|
33
17
|
pc: 'pc',
|
|
34
18
|
ps4: 'ps4',
|
|
@@ -53,8 +37,7 @@ class Settings {
|
|
|
53
37
|
};
|
|
54
38
|
|
|
55
39
|
this.timeouts = {
|
|
56
|
-
|
|
57
|
-
market: process.env.MARKET_TIMEOUT || 3000,
|
|
40
|
+
market: process.env.MARKET_TIMEOUT || /* istanbul ignore next */ 3000,
|
|
58
41
|
};
|
|
59
42
|
|
|
60
43
|
this.defaultString = 'Operator, there is no such item pricecheck available.';
|
|
@@ -67,9 +50,7 @@ class Settings {
|
|
|
67
50
|
* @returns {string} Real platform identifier
|
|
68
51
|
*/
|
|
69
52
|
lookupAlias(platformAlias, market = false) {
|
|
70
|
-
return market
|
|
71
|
-
? this.platforms.market[platformAlias.toLowerCase()]
|
|
72
|
-
: this.platforms[platformAlias.toLowerCase()];
|
|
53
|
+
return market ? this.platforms.market[platformAlias.toLowerCase()] : this.platforms[platformAlias.toLowerCase()];
|
|
73
54
|
}
|
|
74
55
|
}
|
|
75
56
|
|
|
@@ -8,16 +8,24 @@ const fs = require('fs').promises;
|
|
|
8
8
|
|
|
9
9
|
const fetch = require('node-fetch');
|
|
10
10
|
|
|
11
|
-
const MarketSummary = require('./summary
|
|
11
|
+
const MarketSummary = require('./summary');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {Object} MappedPrice
|
|
15
|
+
* @property {string} volume
|
|
16
|
+
* @property {string} median
|
|
17
|
+
* @property {string} max_price
|
|
18
|
+
* @property {string} min_price
|
|
19
|
+
* @property {string} datetime ts formatted date string
|
|
20
|
+
*/
|
|
12
21
|
|
|
13
22
|
class MarketFetcher {
|
|
14
23
|
constructor({ logger = console, settings, marketCache }) {
|
|
15
24
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.marketCache = marketCache
|
|
20
|
-
|| new JSONCache(settings.urls.market, settings.maxCacheLength, { logger });
|
|
25
|
+
* The json cache stpromg data from warframe.market
|
|
26
|
+
* @type {JSONCache}
|
|
27
|
+
*/
|
|
28
|
+
this.marketCache = marketCache || new JSONCache(settings.urls.market, settings.maxCacheLength, { logger });
|
|
21
29
|
|
|
22
30
|
this.settings = settings;
|
|
23
31
|
this.urls = {
|
|
@@ -37,8 +45,12 @@ class MarketFetcher {
|
|
|
37
45
|
platform: platform.toLowerCase(),
|
|
38
46
|
},
|
|
39
47
|
};
|
|
40
|
-
const data = await fetch(`${this.urls.market}${this.urls.marketBasePath}${urlName}/statistics`, reqOpts)
|
|
41
|
-
|
|
48
|
+
const data = await fetch(`${this.urls.market}${this.urls.marketBasePath}${urlName}/statistics`, reqOpts).then((d) =>
|
|
49
|
+
d.json()
|
|
50
|
+
);
|
|
51
|
+
/**
|
|
52
|
+
* @type {MappedPrice[]}
|
|
53
|
+
*/
|
|
42
54
|
const stats = data.payload.statistics_live['48hours'];
|
|
43
55
|
|
|
44
56
|
// Descending sort
|
|
@@ -48,17 +60,17 @@ class MarketFetcher {
|
|
|
48
60
|
if (tsA === tsB) return 0;
|
|
49
61
|
if (tsA < tsB) return -1;
|
|
50
62
|
if (tsA > tsB) return 1;
|
|
63
|
+
/* istanbul ignore next */
|
|
51
64
|
return 0;
|
|
52
65
|
});
|
|
53
66
|
|
|
54
67
|
const deepData = stats[0];
|
|
55
|
-
|
|
56
|
-
soldCount: deepData ? Number.parseInt(deepData.volume, 10) :
|
|
57
|
-
soldPrice: deepData ? Number.parseInt(deepData.median, 10) :
|
|
58
|
-
maximum: deepData ? Number.parseInt(deepData.max_price, 10) :
|
|
59
|
-
minimum: deepData ? Number.parseInt(deepData.min_price, 10) :
|
|
68
|
+
return {
|
|
69
|
+
soldCount: deepData ? Number.parseInt(deepData.volume, 10) : undefined,
|
|
70
|
+
soldPrice: deepData ? Number.parseInt(deepData.median, 10) : undefined,
|
|
71
|
+
maximum: deepData ? Number.parseInt(deepData.max_price, 10) : undefined,
|
|
72
|
+
minimum: deepData ? Number.parseInt(deepData.min_price, 10) : undefined,
|
|
60
73
|
};
|
|
61
|
-
return summary;
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
async resultForItem(urlName, platform = 'pc') {
|
|
@@ -67,11 +79,8 @@ class MarketFetcher {
|
|
|
67
79
|
platform: platform.toLowerCase(),
|
|
68
80
|
},
|
|
69
81
|
};
|
|
70
|
-
const res = await fetch(`${this.urls.market}${this.urls.marketBasePath}${urlName}`, reqOpts)
|
|
71
|
-
|
|
72
|
-
const data = res.payload ? await Promise.all(res.payload.item.items_in_set
|
|
73
|
-
.map((item) => this.summaryForItem(item))) : {};
|
|
74
|
-
return data;
|
|
82
|
+
const res = await fetch(`${this.urls.market}${this.urls.marketBasePath}${urlName}`, reqOpts).then((d) => d.json());
|
|
83
|
+
return res.payload ? Promise.all(res.payload.item.items_in_set.map((item) => this.summaryForItem(item))) : {};
|
|
75
84
|
}
|
|
76
85
|
|
|
77
86
|
/**
|
|
@@ -88,9 +97,7 @@ class MarketFetcher {
|
|
|
88
97
|
}
|
|
89
98
|
const summary = new MarketSummary(item);
|
|
90
99
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
summary.prices = prices;
|
|
100
|
+
summary.prices = await this.averagesForItem(item.url_name);
|
|
94
101
|
const options = {
|
|
95
102
|
url: summary.thumbnail,
|
|
96
103
|
dest: `${global.__basedir}/tmp/${summary.name}.png`,
|
|
@@ -102,6 +109,7 @@ class MarketFetcher {
|
|
|
102
109
|
summary.color = typeof colors !== 'undefined' ? colors[0].hex().replace('#', '0x') : 0xff0000;
|
|
103
110
|
}
|
|
104
111
|
} catch (e) {
|
|
112
|
+
/* istanbul ignore next */
|
|
105
113
|
this.logger.error(e);
|
|
106
114
|
} finally {
|
|
107
115
|
await fs.unlink(`${global.__basedir}/tmp/${summary.name}.png`);
|
|
@@ -115,7 +123,7 @@ class MarketFetcher {
|
|
|
115
123
|
try {
|
|
116
124
|
// get market data
|
|
117
125
|
const marketData = await this.marketCache.getDataJson();
|
|
118
|
-
if (!marketData) {
|
|
126
|
+
/* istanbul ignore if */ if (!marketData) {
|
|
119
127
|
this.logger.info('No market data!');
|
|
120
128
|
return [];
|
|
121
129
|
}
|
|
@@ -133,6 +141,7 @@ class MarketFetcher {
|
|
|
133
141
|
attachments.push(...marketComponents);
|
|
134
142
|
}
|
|
135
143
|
} catch (err) {
|
|
144
|
+
/* istanbul ignore next */
|
|
136
145
|
this.logger.error(err);
|
|
137
146
|
}
|
|
138
147
|
return attachments;
|
package/lib/market/v1/summary.js
CHANGED
|
@@ -18,13 +18,13 @@ class Summary {
|
|
|
18
18
|
this.name = itemData.en.item_name.trim();
|
|
19
19
|
this.thumbnail = `${urls.marketAssets}${itemData.thumb}`;
|
|
20
20
|
this.partThumb = `${urls.marketAssets}${itemData.sub_icon}`;
|
|
21
|
-
this.tradingTax = itemData.trading_tax || 0;
|
|
21
|
+
/* istanbul ignore next */ this.tradingTax = itemData.trading_tax || 0;
|
|
22
22
|
this.ducats = itemData.ducats || 0;
|
|
23
23
|
this.masteryLevel = itemData.mastery_level;
|
|
24
24
|
this.tradable = itemData.tradable;
|
|
25
25
|
this.wikiUrl = itemData.en.wiki_link;
|
|
26
26
|
this.codex = itemData.en.codex;
|
|
27
|
-
this.description = itemData.en.description.replace(/<\/?p>/
|
|
27
|
+
this.description = itemData.en.description.replace(/<\/?p>/gi, '');
|
|
28
28
|
this.drops = itemData.en.drop;
|
|
29
29
|
this.url = `http://warframe.market/items/${itemData.url_name}`;
|
|
30
30
|
|
|
@@ -32,23 +32,23 @@ class Summary {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* The components'
|
|
35
|
+
* The components' string representation
|
|
36
36
|
* @param {string} opt Option, either 'codex', 'item', 'location', 'all'
|
|
37
37
|
* @returns {string}
|
|
38
38
|
*/
|
|
39
39
|
toString(opt = 'item') {
|
|
40
40
|
let value = this.name;
|
|
41
|
-
if (opt === 'codex' || opt === 'all') {
|
|
42
|
-
value +=
|
|
43
|
-
+ `Codex: ${this.codex}\n`;
|
|
41
|
+
/* istanbul ignore if */ if (opt === 'codex' || opt === 'all') {
|
|
42
|
+
value += `\`\`\`\nCodex: ${this.codex}\n`;
|
|
44
43
|
}
|
|
45
|
-
if (opt === 'item' || opt === 'all') {
|
|
46
|
-
value +=
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
/* istanbul ignore else */ if (opt === 'item' || /* istanbul ignore next */ opt === 'all') {
|
|
45
|
+
value +=
|
|
46
|
+
`${this.pad(`Requires: ${this.masteryLevel}`, 15)}| Tax: ${this.pad(`${this.tradingTax}cr`)}\n` +
|
|
47
|
+
`Item is ${/* istanbul ignore next */ this.tradable ? '' : ' not '} tradable\n` +
|
|
48
|
+
`${this.pad(`Sold ${this.prices.soldCount} for ${this.prices.soldPrice}`, 15)}|` +
|
|
49
|
+
`Minimum ${this.prices.minimum} | Maximum ${this.prices.maximum}\n`;
|
|
50
50
|
}
|
|
51
|
-
if (opt === 'location' || opt === 'all') {
|
|
51
|
+
/* istanbul ignore next */ if (opt === 'location' || opt === 'all') {
|
|
52
52
|
value += `${this.pad(`Drops: ${this.drops.map((drop) => drop.name).join(', ')}`, 15)}\n`;
|
|
53
53
|
}
|
|
54
54
|
value += `\`\`\`\n${this.wikiUrl}`;
|
package/lib/promiseTimeout.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "warframe-nexus-query",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Query prices form nexus-stats.com and warframe.market.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"coverage": "npm test && nyc report --reporter=text-lcov | coveralls",
|
|
9
9
|
"build-docs": "jsdoc -c jsdoc-config.json -d docs",
|
|
10
10
|
"lint": "eslint index.js lib/ test/",
|
|
11
|
-
"lint:fix": "eslint index.js lib/ test/ --fix"
|
|
11
|
+
"lint:fix": "eslint index.js lib/ test/ --fix",
|
|
12
|
+
"postinstall": "install-peerdeps @wfcd/eslint-config@^1.3.3 -S"
|
|
12
13
|
},
|
|
13
14
|
"files": [
|
|
14
15
|
"lib",
|
|
@@ -38,7 +39,6 @@
|
|
|
38
39
|
"image-downloader": "^4.0.2",
|
|
39
40
|
"json-fetch-cache": "^1.2.6",
|
|
40
41
|
"json-query": "^2.2.2",
|
|
41
|
-
"nexushub-client": "^1.2.0",
|
|
42
42
|
"node-fetch": "^2.6.0",
|
|
43
43
|
"node-md-config": "^2.0.1",
|
|
44
44
|
"numeral": "^2.0.6"
|
|
@@ -46,21 +46,21 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/json-query": "^2.2.0",
|
|
48
48
|
"@types/node-fetch": "^2.5.4",
|
|
49
|
+
"@wfcd/eslint-config": "^1.3.3",
|
|
49
50
|
"chai": "^4.2.0",
|
|
50
|
-
"coveralls": "^3.1.
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"eslint-plugin-import": "^2.19.1",
|
|
54
|
-
"mocha": "^7.1.1",
|
|
51
|
+
"coveralls": "^3.1.1",
|
|
52
|
+
"install-peerdeps": "^3.0.3",
|
|
53
|
+
"mocha": "^10.2.0",
|
|
55
54
|
"nyc": "^15.1.0"
|
|
56
55
|
},
|
|
57
56
|
"engines": {
|
|
58
|
-
"node": ">=
|
|
59
|
-
"npm": ">=6.
|
|
57
|
+
"node": ">=12.22.12",
|
|
58
|
+
"npm": ">=6.12.0"
|
|
60
59
|
},
|
|
61
60
|
"release": {
|
|
62
61
|
"branch": "master"
|
|
63
62
|
},
|
|
63
|
+
"prettier": "@wfcd/eslint-config/prettier",
|
|
64
64
|
"eslintIgnore": [
|
|
65
65
|
".github/**",
|
|
66
66
|
"docs/**",
|
|
@@ -68,47 +68,39 @@
|
|
|
68
68
|
"types/**"
|
|
69
69
|
],
|
|
70
70
|
"eslintConfig": {
|
|
71
|
-
"extends": "
|
|
71
|
+
"extends": "@wfcd",
|
|
72
72
|
"parserOptions": {
|
|
73
|
-
"
|
|
73
|
+
"ecmaVersion": 13
|
|
74
|
+
},
|
|
75
|
+
"env": {
|
|
76
|
+
"es6": true
|
|
74
77
|
},
|
|
75
78
|
"rules": {
|
|
76
|
-
"
|
|
79
|
+
"no-underscore-dangle": [
|
|
77
80
|
"error",
|
|
78
81
|
{
|
|
79
|
-
"
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
"String": "string",
|
|
83
|
-
"Number": "number",
|
|
84
|
-
"Boolean": "boolean",
|
|
85
|
-
"Function": "function",
|
|
86
|
-
"object": "Object",
|
|
87
|
-
"date": "Date",
|
|
88
|
-
"error": "Error"
|
|
89
|
-
},
|
|
90
|
-
"prefer": {
|
|
91
|
-
"return": "returns"
|
|
92
|
-
}
|
|
82
|
+
"allow": [
|
|
83
|
+
"__basedir"
|
|
84
|
+
]
|
|
93
85
|
}
|
|
94
|
-
]
|
|
95
|
-
"no-underscore-dangle": "off",
|
|
96
|
-
"strict": [
|
|
97
|
-
"error",
|
|
98
|
-
"safe"
|
|
99
|
-
],
|
|
100
|
-
"linebreak-style": "off",
|
|
101
|
-
"no-restricted-syntax": [
|
|
102
|
-
"off"
|
|
103
|
-
],
|
|
104
|
-
"no-await-in-loop": "off",
|
|
105
|
-
"import/no-unresolved": 0
|
|
86
|
+
]
|
|
106
87
|
}
|
|
107
88
|
},
|
|
89
|
+
"babel": {
|
|
90
|
+
"presets": [
|
|
91
|
+
"@babel/preset-env"
|
|
92
|
+
],
|
|
93
|
+
"plugins": [
|
|
94
|
+
"@babel/plugin-proposal-class-properties",
|
|
95
|
+
"@babel/plugin-proposal-private-methods"
|
|
96
|
+
]
|
|
97
|
+
},
|
|
108
98
|
"mocha": {
|
|
109
99
|
"spec": "test/test.js",
|
|
110
|
-
"timeout":
|
|
111
|
-
"bail": true
|
|
100
|
+
"timeout": 30000,
|
|
101
|
+
"bail": true,
|
|
102
|
+
"exit": true,
|
|
103
|
+
"slow": 10000
|
|
112
104
|
},
|
|
113
105
|
"nyc": {
|
|
114
106
|
"reporter": [
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
class Component {
|
|
4
|
-
// eslint-disable-next-line class-methods-use-this
|
|
5
|
-
median(values) {
|
|
6
|
-
values.sort((a, b) => a - b);
|
|
7
|
-
const half = Math.floor(values.length / 2);
|
|
8
|
-
if (values.length % 2) {
|
|
9
|
-
return values[half];
|
|
10
|
-
}
|
|
11
|
-
return (values[half - 1] + values[half]) / 2.0;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The components's string representation
|
|
16
|
-
* @returns {string}
|
|
17
|
-
*/
|
|
18
|
-
toString() {
|
|
19
|
-
return `\u221F${this.padName(this.name)} | average: ${(this.prices.avg && !Number.isNaN(this.prices.avg) ? `${String(parseFloat(this.prices.avg).toFixed(2))}p` : '0p')}`;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Pad the left side of a string so that all componets
|
|
24
|
-
* have the same string length before the pipe
|
|
25
|
-
* @param {string} locationString the location string to pad
|
|
26
|
-
* @returns {string} the padded location string
|
|
27
|
-
*/
|
|
28
|
-
padName(locationString) {
|
|
29
|
-
let stringRet;
|
|
30
|
-
if (locationString.length < 10) {
|
|
31
|
-
stringRet = this.padName(`${locationString} `);
|
|
32
|
-
} else {
|
|
33
|
-
stringRet = locationString;
|
|
34
|
-
}
|
|
35
|
-
return stringRet;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
module.exports = Component;
|
package/lib/nexus/base/Item.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
class Item {
|
|
4
|
-
/**
|
|
5
|
-
* @param {JSON} data to construct an item from
|
|
6
|
-
* @param {string} path for item on site
|
|
7
|
-
* @param {Object} settings a settings object
|
|
8
|
-
* @param {Component} Component class to construct
|
|
9
|
-
*/
|
|
10
|
-
constructor(data, path, settings, Component) {
|
|
11
|
-
/**
|
|
12
|
-
* Array of Component objects
|
|
13
|
-
* @type {Array<Component>}
|
|
14
|
-
*/
|
|
15
|
-
this.components = [];
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Title (name) of item
|
|
19
|
-
* @type {string}
|
|
20
|
-
*/
|
|
21
|
-
this.title = data.name;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Type of the item, such as:
|
|
25
|
-
* * Prime
|
|
26
|
-
* * Mods
|
|
27
|
-
* * Arcane
|
|
28
|
-
* * Syndicate
|
|
29
|
-
* @type {string}
|
|
30
|
-
*/
|
|
31
|
-
this.type = data.type;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Supply for the component
|
|
35
|
-
* @unused on v2
|
|
36
|
-
* @type {Object.<number>}
|
|
37
|
-
*/
|
|
38
|
-
this.supply = data.supply;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Demand for the component
|
|
42
|
-
* @unused on v2
|
|
43
|
-
* @type {Object.<number>}
|
|
44
|
-
*/
|
|
45
|
-
this.demand = data.demand;
|
|
46
|
-
|
|
47
|
-
data.components.forEach((componentData) => {
|
|
48
|
-
this.components.push(new Component(componentData, data.parts));
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
this.url = `${settings.urls.nexusWeb}${path}`;
|
|
52
|
-
this.thumbnail = `${settings.urls.nexusWeb}${data.item.components[0].imgUrl}`;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
module.exports = Item;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Nexus = require('nexushub-client');
|
|
4
|
-
const NexusItem = require('./item.js');
|
|
5
|
-
|
|
6
|
-
class NexusFetcher {
|
|
7
|
-
constructor({ settings, nexusApi, logger }) {
|
|
8
|
-
this.settings = settings;
|
|
9
|
-
const nexusOptions = {
|
|
10
|
-
user_key: settings.nexusHubKey,
|
|
11
|
-
user_secret: settings.nexusHubSecret,
|
|
12
|
-
ignore_limiter: true,
|
|
13
|
-
};
|
|
14
|
-
this.nexusApi = nexusApi || new Nexus(this.settings.nexusKey
|
|
15
|
-
&& this.settings.nexusHubSecret ? nexusOptions : {});
|
|
16
|
-
this.logger = logger;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async queryNexus(query, platform = 'pc') {
|
|
20
|
-
let attachments = [];
|
|
21
|
-
let successfulQuery;
|
|
22
|
-
try {
|
|
23
|
-
const nexusResults = await this.nexusApi.get(`/warframe/v1/search?query=${encodeURIComponent(query)}&limit=2&tradable=true`);
|
|
24
|
-
if (nexusResults.length) {
|
|
25
|
-
const nexusItem = await this.nexusApi.get(nexusResults[0].apiUrl);
|
|
26
|
-
// if there's no results, do no result attachment
|
|
27
|
-
if (typeof nexusItem === 'undefined') {
|
|
28
|
-
attachments = [];
|
|
29
|
-
}
|
|
30
|
-
// if there is, get some item stats
|
|
31
|
-
const queryResults = await this.nexusApi.get(`${nexusResults[0].apiUrl}/prices?platform=${platform.toUpperCase()}`);
|
|
32
|
-
|
|
33
|
-
if (queryResults) {
|
|
34
|
-
successfulQuery = queryResults.name;
|
|
35
|
-
queryResults.type = nexusItem.type;
|
|
36
|
-
queryResults.parts = nexusItem.components
|
|
37
|
-
.map((component) => ({ name: component.name.replace(platform, '').trim() }));
|
|
38
|
-
queryResults.item = nexusItem;
|
|
39
|
-
attachments = [new NexusItem(queryResults, nexusResults[0].webUrl, this.settings)];
|
|
40
|
-
} else {
|
|
41
|
-
// if no results, no attachments
|
|
42
|
-
attachments = [];
|
|
43
|
-
}
|
|
44
|
-
} else {
|
|
45
|
-
attachments = [];
|
|
46
|
-
}
|
|
47
|
-
} catch (e) {
|
|
48
|
-
this.logger.error(`Couldn't fetch nexus data: ${e.message}`);
|
|
49
|
-
attachments = [];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return { attachments, successfulQuery };
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
module.exports = NexusFetcher;
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const BaseComponent = require('../base/Component');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Represents an individual component object of an item.
|
|
7
|
-
*/
|
|
8
|
-
class Component extends BaseComponent {
|
|
9
|
-
/**
|
|
10
|
-
* Represents an individual component object of an item.
|
|
11
|
-
* @param {json} data the component data to parse into a component
|
|
12
|
-
* @param {Array<Ojbect>} items objects with data for ducats
|
|
13
|
-
* @constructor
|
|
14
|
-
*/
|
|
15
|
-
constructor(data) {
|
|
16
|
-
super();
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Name of the component, display value
|
|
20
|
-
* @type {string}
|
|
21
|
-
*/
|
|
22
|
-
this.name = data.name.replace(/(pc|ps4|xb1|switch)/ig, '').trim();
|
|
23
|
-
|
|
24
|
-
const suppTotal = data.prices.selling.current.orders || 0;
|
|
25
|
-
const demandTotal = data.prices.buying.current.orders || 0;
|
|
26
|
-
|
|
27
|
-
const oTotal = (suppTotal + demandTotal) || 1;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Supply for the component
|
|
31
|
-
* @type {number}
|
|
32
|
-
*/
|
|
33
|
-
this.supply = {
|
|
34
|
-
percentage: Number(suppTotal / oTotal).toFixed(2),
|
|
35
|
-
count: suppTotal,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Demand for the component
|
|
40
|
-
* @type {number}
|
|
41
|
-
*/
|
|
42
|
-
this.demand = {
|
|
43
|
-
percentage: Number(demandTotal / oTotal).toFixed(2),
|
|
44
|
-
count: demandTotal,
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const { buying, selling } = this.buildStats(data);
|
|
48
|
-
this.prices = {
|
|
49
|
-
buying,
|
|
50
|
-
selling,
|
|
51
|
-
avg: (buying.avg + selling.avg) / 2,
|
|
52
|
-
median: (buying.median + selling.median) / 2,
|
|
53
|
-
minimum: Math.min(buying.min, selling.min),
|
|
54
|
-
maximum: Math.max(buying.max, selling.max),
|
|
55
|
-
};
|
|
56
|
-
this.ducats = data.ducats;
|
|
57
|
-
this.type = 'nexus-v2';
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Build statistics data from nexus data
|
|
62
|
-
* @param {Object} data Wrapped object to destructure
|
|
63
|
-
* @return {Object} destructured object
|
|
64
|
-
*/
|
|
65
|
-
// eslint-disable-next-line class-methods-use-this
|
|
66
|
-
buildStats(data) {
|
|
67
|
-
return {
|
|
68
|
-
buying: {
|
|
69
|
-
avg: data.prices.buying.current.avg || data.prices.buying.previous.avg || 0,
|
|
70
|
-
median: data.prices.buying.current.median || data.prices.buying.previous.median || 0,
|
|
71
|
-
max: data.prices.buying.current.max || data.prices.buying.previous.max || 0,
|
|
72
|
-
min: data.prices.buying.current.min || data.prices.buying.previous.min || 0,
|
|
73
|
-
},
|
|
74
|
-
selling: {
|
|
75
|
-
avg: data.prices.selling.current.avg || data.prices.selling.previous.avg || 0,
|
|
76
|
-
median: data.prices.selling.current.median || data.prices.selling.previous.median || 0,
|
|
77
|
-
max: data.prices.selling.current.max || data.prices.selling.previous.max || 0,
|
|
78
|
-
min: data.prices.selling.current.min || data.prices.selling.previous.min || 0,
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
module.exports = Component;
|
package/lib/nexus/v2/item.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const md = require('node-md-config');
|
|
4
|
-
const Component = require('./component.js');
|
|
5
|
-
const BaseItem = require('../base/Item');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Describes an item, such as a prime item, mod, arcane, or syndicate item
|
|
9
|
-
*/
|
|
10
|
-
class NexusItem extends BaseItem {
|
|
11
|
-
/**
|
|
12
|
-
* @param {JSON} data to construct an item from
|
|
13
|
-
* @param {string} path for item on nexushub.co
|
|
14
|
-
* @param {Object} settings a settings object
|
|
15
|
-
*/
|
|
16
|
-
constructor(data, path, settings) {
|
|
17
|
-
super(data, path, settings, Component);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* String representation of this Item.
|
|
22
|
-
* @returns {string}
|
|
23
|
-
*/
|
|
24
|
-
toString() {
|
|
25
|
-
const componentTokens = [`${md.codeMulti}${this.title}${md.lineEnd}\u3000\u3000`];
|
|
26
|
-
this.components.forEach((component, index) => {
|
|
27
|
-
componentTokens.push(component.toString() + (index < this.components.length - 1 ? `,${md.lineEnd}\u3000\u3000` : ''));
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return `${componentTokens.join('\n')}${md.blockEnd}`;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
module.exports = NexusItem;
|