warframe-nexus-query 1.6.15 → 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 +51 -67
- package/lib/AttachmentCreator.js +30 -110
- package/lib/Settings.js +15 -19
- package/lib/market/v1/MarketFetcher.js +40 -23
- package/lib/market/v1/summary.js +13 -13
- package/lib/promiseTimeout.js +1 -4
- package/package.json +48 -42
- 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,51 +6,34 @@ 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');
|
|
13
|
-
|
|
14
|
-
const noResultAttachment = {
|
|
15
|
-
type: 'rich',
|
|
16
|
-
description: 'No result',
|
|
17
|
-
color: '0xff55ff',
|
|
18
|
-
url: 'https://warframe.market',
|
|
19
|
-
footer: {
|
|
20
|
-
text: 'Pricechecks from NexusStats and Warframe.Market',
|
|
21
|
-
},
|
|
22
|
-
};
|
|
9
|
+
const Settings = require('./lib/Settings');
|
|
10
|
+
const Creator = require('./lib/AttachmentCreator');
|
|
11
|
+
const MarketFetcher = require('./lib/market/v1/MarketFetcher');
|
|
23
12
|
|
|
24
13
|
if (!global.__basedir) {
|
|
25
14
|
global.__basedir = __dirname;
|
|
26
15
|
}
|
|
27
16
|
|
|
28
|
-
|
|
29
|
-
* Represents a queryable datastore of information derived from `https://nexus-stats.com/api`
|
|
30
|
-
*/
|
|
31
|
-
class PriceCheckQuerier {
|
|
17
|
+
module.exports = class PriceCheckQuerier {
|
|
32
18
|
/**
|
|
33
19
|
* Creates an instance representing a WarframeNexusStats data object
|
|
34
20
|
* @constructor
|
|
35
21
|
*/
|
|
36
|
-
constructor({ logger = console,
|
|
22
|
+
constructor({ logger = console, marketCache = undefined, skipMarket = false }) {
|
|
37
23
|
this.settings = new Settings();
|
|
38
24
|
this.logger = logger;
|
|
25
|
+
this.skipMarket = skipMarket;
|
|
39
26
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
*/
|
|
51
|
-
this.marketFetcher = new MarketFetcher({ logger, settings: this.settings, marketCache });
|
|
52
|
-
} catch (e) {
|
|
53
|
-
this.logger.error(`couldn't set up market fetcher: ${e.message}`);
|
|
27
|
+
if (!skipMarket) {
|
|
28
|
+
try {
|
|
29
|
+
/**
|
|
30
|
+
* Fetch market data
|
|
31
|
+
* @type {MarketFetcher}
|
|
32
|
+
*/
|
|
33
|
+
this.marketFetcher = new MarketFetcher({ logger, settings: this.settings, marketCache });
|
|
34
|
+
} catch (e) {
|
|
35
|
+
/* istanbul ignore next */ this.logger.error(`couldn't set up market fetcher: ${e.message}`);
|
|
36
|
+
}
|
|
54
37
|
}
|
|
55
38
|
|
|
56
39
|
/**
|
|
@@ -67,36 +50,34 @@ class PriceCheckQuerier {
|
|
|
67
50
|
* @returns {Promise<Array<NexusItem>>} a Promise of an array of Item objects
|
|
68
51
|
*/
|
|
69
52
|
async priceCheckQuery(query, platform = 'pc') {
|
|
53
|
+
this.logger.info(`state:\n\tskipMarket: ${this.skipMarket}\n\tquery: ${query}\n\tplatform: ${platform}`);
|
|
70
54
|
if (!query) {
|
|
71
55
|
throw new Error('This funtcion requires a query to be provided');
|
|
72
56
|
}
|
|
73
57
|
// eslint-disable-next-line no-param-reassign
|
|
74
|
-
platform = this.settings.
|
|
58
|
+
platform = this.settings.lookupAlias(platform.toLowerCase());
|
|
75
59
|
|
|
76
|
-
let nexusResults;
|
|
77
60
|
let successfulQuery;
|
|
78
61
|
let attachments = [];
|
|
79
|
-
if (platform !== 'switch') {
|
|
80
|
-
try {
|
|
81
|
-
const nexusPromise = this.nexusFetcher.queryNexus(query, platform);
|
|
82
|
-
nexusResults = await promiseTimeout(this.settings.timeouts.nexus, nexusPromise);
|
|
83
|
-
({ successfulQuery, attachments } = nexusResults);
|
|
84
|
-
} catch (e) {
|
|
85
|
-
this.logger.error(`Couldn't process ${query} on nexus-hub... time out.`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
62
|
|
|
89
|
-
|
|
63
|
+
/* istanbul ignore else */
|
|
64
|
+
if (this.marketFetcher && !this.skipMarket) {
|
|
65
|
+
this.logger.info(`querying market for ${query} on ${platform}`);
|
|
90
66
|
try {
|
|
91
|
-
const marketPromise = this.marketFetcher.queryMarket(query, {
|
|
67
|
+
const marketPromise = this.marketFetcher.queryMarket(query, {
|
|
68
|
+
successfulQuery,
|
|
69
|
+
platform: this.settings.lookupAlias(platform, true),
|
|
70
|
+
});
|
|
92
71
|
const marketResults = await promiseTimeout(this.settings.timeouts.market, marketPromise);
|
|
93
72
|
attachments = [...attachments, ...marketResults];
|
|
94
73
|
} catch (e) {
|
|
95
|
-
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.`);
|
|
96
75
|
}
|
|
76
|
+
} else {
|
|
77
|
+
this.logger.info('No market fetcher, skipping market');
|
|
97
78
|
}
|
|
98
79
|
|
|
99
|
-
return attachments
|
|
80
|
+
return attachments;
|
|
100
81
|
}
|
|
101
82
|
|
|
102
83
|
/**
|
|
@@ -107,15 +88,13 @@ class PriceCheckQuerier {
|
|
|
107
88
|
* @returns {Promise<string>} a Promise of a string containing the results of the query
|
|
108
89
|
*/
|
|
109
90
|
async priceCheckQueryString(query, priorResults, platform = 'pc') {
|
|
110
|
-
const components = priorResults || await this.priceCheckQuery(query, platform);
|
|
111
|
-
const tokens = [];
|
|
91
|
+
const components = priorResults || (await this.priceCheckQuery(query, platform));
|
|
92
|
+
const tokens = [`[${platform.toUpperCase()}] ${query}`];
|
|
112
93
|
components.slice(0, 4).forEach((component) => {
|
|
113
94
|
tokens.push(`${md.lineEnd}${component.toString()}`);
|
|
114
95
|
});
|
|
115
96
|
let componentsToReturnString = `${md.codeMulti}${tokens.join()}${md.blockEnd}`;
|
|
116
|
-
componentsToReturnString = components.length > 0
|
|
117
|
-
? componentsToReturnString
|
|
118
|
-
: this.settings.defaultString;
|
|
97
|
+
componentsToReturnString = components.length > 0 ? componentsToReturnString : this.settings.defaultString;
|
|
119
98
|
return componentsToReturnString;
|
|
120
99
|
}
|
|
121
100
|
|
|
@@ -124,10 +103,10 @@ class PriceCheckQuerier {
|
|
|
124
103
|
* @param {string} query Query to search the nexus-stats database against
|
|
125
104
|
* @param {Object[]} priorResults results provided from a prior search
|
|
126
105
|
* @param {string} platform Platform to query price data for. One of 'pc', 'ps4', 'xb1'
|
|
127
|
-
* @returns {Array<Object
|
|
106
|
+
* @returns {Promise<Array<Object>>} a Promise of an array of attachment objects
|
|
128
107
|
*/
|
|
129
108
|
async priceCheckQueryAttachment(query, priorResults, platform = 'pc') {
|
|
130
|
-
const components = priorResults || await this.priceCheckQuery(query, platform);
|
|
109
|
+
const components = priorResults || (await this.priceCheckQuery(query, platform));
|
|
131
110
|
const realPlatform = this.settings.lookupAlias(platform);
|
|
132
111
|
|
|
133
112
|
const attachment = this.creator.attachmentFromComponents(components, query, realPlatform);
|
|
@@ -138,27 +117,32 @@ class PriceCheckQuerier {
|
|
|
138
117
|
* Stop updating caches
|
|
139
118
|
*/
|
|
140
119
|
async stopUpdating() {
|
|
141
|
-
|
|
120
|
+
/* istanbul ignore else */
|
|
121
|
+
if (!this.skipMarket && this.marketFetcher.marketCache) {
|
|
142
122
|
this.marketFetcher.marketCache.stop();
|
|
123
|
+
} else {
|
|
124
|
+
this.logger.log('no market cache, or skipMarket was true');
|
|
143
125
|
}
|
|
144
126
|
|
|
145
127
|
if (fss.existsSync(`${global.__basedir}/tmp`)) {
|
|
146
128
|
const files = await fs.readdir(`${global.__basedir}/tmp`);
|
|
147
129
|
let allSuccess = true;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
+
);
|
|
156
142
|
|
|
157
143
|
if (allSuccess) {
|
|
158
144
|
await fs.rmdir(`${global.__basedir}/tmp`);
|
|
159
145
|
}
|
|
160
146
|
}
|
|
161
147
|
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
module.exports = PriceCheckQuerier;
|
|
148
|
+
};
|
package/lib/AttachmentCreator.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
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 = {
|
|
15
11
|
type: 'rich',
|
|
16
|
-
|
|
12
|
+
title: 'No result',
|
|
17
13
|
color: 0xff55ff,
|
|
18
14
|
url: 'https://warframe.market',
|
|
19
15
|
footer: {
|
|
@@ -54,143 +50,65 @@ 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'
|
|
146
90
|
* @returns {Object} Discord-ready attachment describing the item
|
|
147
91
|
*/
|
|
148
92
|
attachmentFromComponents(components, query, platform = 'pc') {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const nexusComponents = components
|
|
152
|
-
.filter((component) => component && component.components && component.components[0].type === 'nexus-v2');
|
|
153
|
-
|
|
154
|
-
const marketComponents = components
|
|
155
|
-
.filter((component) => component && component.type === 'market-v1' && typeof component.prices.soldPrice !== 'undefined');
|
|
93
|
+
if (!components || !components.length || !Array.isArray(components)) return noResultAttachment;
|
|
156
94
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
nexusComponent.components.forEach((component) => {
|
|
162
|
-
attachment.thumbnail.url = nexusComponent.thumbnail;
|
|
163
|
-
|
|
164
|
-
const marketMatch = marketComponents.find((mk) => mk.prices && mk.prices.soldPrice
|
|
165
|
-
&& mk.name.toLowerCase().includes(component.name.toLowerCase()));
|
|
166
|
-
|
|
167
|
-
component.title = nexusComponent.title;
|
|
168
|
-
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
|
+
);
|
|
169
99
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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));
|
|
180
111
|
});
|
|
181
|
-
} else if (marketComponents.length > 0) {
|
|
182
|
-
const mCLen = marketComponents.length;
|
|
183
|
-
marketComponents
|
|
184
|
-
.forEach((marketComponent, index) => {
|
|
185
|
-
if (!index) {
|
|
186
|
-
attachment.color = parseInt(marketComponent.color, 16);
|
|
187
|
-
attachment.title = `[${platform.toUpperCase()}] ${marketComponent.name.replace(/\sset/i, '')}`;
|
|
188
|
-
attachment.url = marketComponent.url;
|
|
189
|
-
attachment.thumbnail.url = marketComponent.thumbnail;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
attachment.fields.push(fieldValue(undefined, marketComponent, mCLen));
|
|
193
|
-
});
|
|
194
112
|
|
|
195
113
|
attachment.footer = {
|
|
196
114
|
icon_url: wfcdLogo,
|
|
@@ -199,9 +117,11 @@ class AttachmentCreator {
|
|
|
199
117
|
} else {
|
|
200
118
|
return noResultAttachment;
|
|
201
119
|
}
|
|
120
|
+
/* istanbul ignore else */
|
|
202
121
|
if (attachment.fields.length) {
|
|
203
122
|
return attachment;
|
|
204
123
|
}
|
|
124
|
+
/* istanbul ignore next */
|
|
205
125
|
return noResultAttachment;
|
|
206
126
|
}
|
|
207
127
|
}
|
package/lib/Settings.js
CHANGED
|
@@ -4,26 +4,11 @@
|
|
|
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
|
};
|
|
@@ -38,11 +23,21 @@ class Settings {
|
|
|
38
23
|
swi: 'switch',
|
|
39
24
|
switch: 'switch',
|
|
40
25
|
ns: 'switch',
|
|
26
|
+
market: {
|
|
27
|
+
pc: 'pc',
|
|
28
|
+
ps4: 'ps4',
|
|
29
|
+
playstation: 'ps4',
|
|
30
|
+
xbone: 'xbox',
|
|
31
|
+
xbox: 'xbox',
|
|
32
|
+
xb1: 'xbox',
|
|
33
|
+
swi: 'switch',
|
|
34
|
+
switch: 'switch',
|
|
35
|
+
ns: 'switch',
|
|
36
|
+
},
|
|
41
37
|
};
|
|
42
38
|
|
|
43
39
|
this.timeouts = {
|
|
44
|
-
|
|
45
|
-
market: process.env.MARKET_TIMEOUT || 3000,
|
|
40
|
+
market: process.env.MARKET_TIMEOUT || /* istanbul ignore next */ 3000,
|
|
46
41
|
};
|
|
47
42
|
|
|
48
43
|
this.defaultString = 'Operator, there is no such item pricecheck available.';
|
|
@@ -51,10 +46,11 @@ class Settings {
|
|
|
51
46
|
/**
|
|
52
47
|
* Look up real platform for platform alias
|
|
53
48
|
* @param {string} platformAlias Alias of platform
|
|
49
|
+
* @param {boolean} market Whether or not to use market-specific aliases
|
|
54
50
|
* @returns {string} Real platform identifier
|
|
55
51
|
*/
|
|
56
|
-
lookupAlias(platformAlias) {
|
|
57
|
-
return this.platforms[platformAlias.toLowerCase()];
|
|
52
|
+
lookupAlias(platformAlias, market = false) {
|
|
53
|
+
return market ? this.platforms.market[platformAlias.toLowerCase()] : this.platforms[platformAlias.toLowerCase()];
|
|
58
54
|
}
|
|
59
55
|
}
|
|
60
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 = {
|
|
@@ -27,6 +35,8 @@ class MarketFetcher {
|
|
|
27
35
|
};
|
|
28
36
|
|
|
29
37
|
this.logger = logger;
|
|
38
|
+
|
|
39
|
+
this.logger.info('finished setting up market fetcher');
|
|
30
40
|
}
|
|
31
41
|
|
|
32
42
|
async averagesForItem(urlName, platform = 'pc') {
|
|
@@ -35,8 +45,12 @@ class MarketFetcher {
|
|
|
35
45
|
platform: platform.toLowerCase(),
|
|
36
46
|
},
|
|
37
47
|
};
|
|
38
|
-
const data = await fetch(`${this.urls.market}${this.urls.marketBasePath}${urlName}/statistics`, reqOpts)
|
|
39
|
-
|
|
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
|
+
*/
|
|
40
54
|
const stats = data.payload.statistics_live['48hours'];
|
|
41
55
|
|
|
42
56
|
// Descending sort
|
|
@@ -46,17 +60,17 @@ class MarketFetcher {
|
|
|
46
60
|
if (tsA === tsB) return 0;
|
|
47
61
|
if (tsA < tsB) return -1;
|
|
48
62
|
if (tsA > tsB) return 1;
|
|
63
|
+
/* istanbul ignore next */
|
|
49
64
|
return 0;
|
|
50
65
|
});
|
|
51
66
|
|
|
52
67
|
const deepData = stats[0];
|
|
53
|
-
|
|
54
|
-
soldCount: deepData ? Number.parseInt(deepData.volume, 10) :
|
|
55
|
-
soldPrice: deepData ? Number.parseInt(deepData.median, 10) :
|
|
56
|
-
maximum: deepData ? Number.parseInt(deepData.max_price, 10) :
|
|
57
|
-
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,
|
|
58
73
|
};
|
|
59
|
-
return summary;
|
|
60
74
|
}
|
|
61
75
|
|
|
62
76
|
async resultForItem(urlName, platform = 'pc') {
|
|
@@ -65,11 +79,8 @@ class MarketFetcher {
|
|
|
65
79
|
platform: platform.toLowerCase(),
|
|
66
80
|
},
|
|
67
81
|
};
|
|
68
|
-
const res = await fetch(`${this.urls.market}${this.urls.marketBasePath}${urlName}`, reqOpts)
|
|
69
|
-
|
|
70
|
-
const data = res.payload ? await Promise.all(res.payload.item.items_in_set
|
|
71
|
-
.map((item) => this.summaryForItem(item))) : {};
|
|
72
|
-
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))) : {};
|
|
73
84
|
}
|
|
74
85
|
|
|
75
86
|
/**
|
|
@@ -86,9 +97,7 @@ class MarketFetcher {
|
|
|
86
97
|
}
|
|
87
98
|
const summary = new MarketSummary(item);
|
|
88
99
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
summary.prices = prices;
|
|
100
|
+
summary.prices = await this.averagesForItem(item.url_name);
|
|
92
101
|
const options = {
|
|
93
102
|
url: summary.thumbnail,
|
|
94
103
|
dest: `${global.__basedir}/tmp/${summary.name}.png`,
|
|
@@ -100,6 +109,7 @@ class MarketFetcher {
|
|
|
100
109
|
summary.color = typeof colors !== 'undefined' ? colors[0].hex().replace('#', '0x') : 0xff0000;
|
|
101
110
|
}
|
|
102
111
|
} catch (e) {
|
|
112
|
+
/* istanbul ignore next */
|
|
103
113
|
this.logger.error(e);
|
|
104
114
|
} finally {
|
|
105
115
|
await fs.unlink(`${global.__basedir}/tmp/${summary.name}.png`);
|
|
@@ -108,15 +118,21 @@ class MarketFetcher {
|
|
|
108
118
|
}
|
|
109
119
|
|
|
110
120
|
async queryMarket(query, { successfulQuery, platform = 'pc' }) {
|
|
121
|
+
this.logger.info(`querying market for ${query} on ${platform}`);
|
|
111
122
|
const attachments = [];
|
|
112
123
|
try {
|
|
113
124
|
// get market data
|
|
114
125
|
const marketData = await this.marketCache.getDataJson();
|
|
115
|
-
|
|
126
|
+
/* istanbul ignore if */ if (!marketData) {
|
|
127
|
+
this.logger.info('No market data!');
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
const marketResults = jsonQuery(`items[*item_name~/^${successfulQuery || query}.*/i]`, {
|
|
116
131
|
data: marketData.payload || {},
|
|
117
132
|
allowRegexp: true,
|
|
118
133
|
}).value;
|
|
119
134
|
if (!marketResults || marketResults.length < 1) {
|
|
135
|
+
this.logger.info('No market results!');
|
|
120
136
|
return [];
|
|
121
137
|
}
|
|
122
138
|
|
|
@@ -125,6 +141,7 @@ class MarketFetcher {
|
|
|
125
141
|
attachments.push(...marketComponents);
|
|
126
142
|
}
|
|
127
143
|
} catch (err) {
|
|
144
|
+
/* istanbul ignore next */
|
|
128
145
|
this.logger.error(err);
|
|
129
146
|
}
|
|
130
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
|
-
toString(opt) {
|
|
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,14 +1,15 @@
|
|
|
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": {
|
|
7
|
-
"test": "nyc
|
|
7
|
+
"test": "nyc mocha",
|
|
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,23 +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
|
-
"ink-docstrap": "^1.3.2",
|
|
55
|
-
"jsdoc": "^3.6.6",
|
|
56
|
-
"mocha": "^7.1.1",
|
|
51
|
+
"coveralls": "^3.1.1",
|
|
52
|
+
"install-peerdeps": "^3.0.3",
|
|
53
|
+
"mocha": "^10.2.0",
|
|
57
54
|
"nyc": "^15.1.0"
|
|
58
55
|
},
|
|
59
56
|
"engines": {
|
|
60
|
-
"node": ">=
|
|
61
|
-
"npm": ">=6.
|
|
57
|
+
"node": ">=12.22.12",
|
|
58
|
+
"npm": ">=6.12.0"
|
|
62
59
|
},
|
|
63
60
|
"release": {
|
|
64
61
|
"branch": "master"
|
|
65
62
|
},
|
|
63
|
+
"prettier": "@wfcd/eslint-config/prettier",
|
|
66
64
|
"eslintIgnore": [
|
|
67
65
|
".github/**",
|
|
68
66
|
"docs/**",
|
|
@@ -70,41 +68,49 @@
|
|
|
70
68
|
"types/**"
|
|
71
69
|
],
|
|
72
70
|
"eslintConfig": {
|
|
73
|
-
"extends": "
|
|
71
|
+
"extends": "@wfcd",
|
|
74
72
|
"parserOptions": {
|
|
75
|
-
"
|
|
73
|
+
"ecmaVersion": 13
|
|
74
|
+
},
|
|
75
|
+
"env": {
|
|
76
|
+
"es6": true
|
|
76
77
|
},
|
|
77
78
|
"rules": {
|
|
78
|
-
"
|
|
79
|
+
"no-underscore-dangle": [
|
|
79
80
|
"error",
|
|
80
81
|
{
|
|
81
|
-
"
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"String": "string",
|
|
85
|
-
"Number": "number",
|
|
86
|
-
"Boolean": "boolean",
|
|
87
|
-
"Function": "function",
|
|
88
|
-
"object": "Object",
|
|
89
|
-
"date": "Date",
|
|
90
|
-
"error": "Error"
|
|
91
|
-
},
|
|
92
|
-
"prefer": {
|
|
93
|
-
"return": "returns"
|
|
94
|
-
}
|
|
82
|
+
"allow": [
|
|
83
|
+
"__basedir"
|
|
84
|
+
]
|
|
95
85
|
}
|
|
96
|
-
]
|
|
97
|
-
"no-underscore-dangle": "off",
|
|
98
|
-
"strict": [
|
|
99
|
-
"error",
|
|
100
|
-
"safe"
|
|
101
|
-
],
|
|
102
|
-
"linebreak-style": "off",
|
|
103
|
-
"no-restricted-syntax": [
|
|
104
|
-
"off"
|
|
105
|
-
],
|
|
106
|
-
"no-await-in-loop": "off",
|
|
107
|
-
"import/no-unresolved": 0
|
|
86
|
+
]
|
|
108
87
|
}
|
|
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
|
+
},
|
|
98
|
+
"mocha": {
|
|
99
|
+
"spec": "test/test.js",
|
|
100
|
+
"timeout": 30000,
|
|
101
|
+
"bail": true,
|
|
102
|
+
"exit": true,
|
|
103
|
+
"slow": 10000
|
|
104
|
+
},
|
|
105
|
+
"nyc": {
|
|
106
|
+
"reporter": [
|
|
107
|
+
"lcov",
|
|
108
|
+
"text"
|
|
109
|
+
],
|
|
110
|
+
"skip-full": true,
|
|
111
|
+
"exclude": [
|
|
112
|
+
"test/*",
|
|
113
|
+
"lib/nexus/*"
|
|
114
|
+
]
|
|
109
115
|
}
|
|
110
116
|
}
|
|
@@ -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;
|