Skip to content

Commit 0daae82

Browse files
committed
remove schema dependency
1 parent 3042533 commit 0daae82

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

commands/skins/update.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
const path = require('path');
2-
require('dotenv').config({ path: path.join(__dirname, './.env') });
3-
const config = require('config');
42
const vdf = require('simple-vdf');
53
const async = require('async');
64
const axios = require('axios');
@@ -15,7 +13,6 @@ const sources = {
1513
itemsGame: 'https://raw.githubusercontent.com/SteamDatabase/GameTracking-CSGO/master/csgo/scripts/items/items_game.txt',
1614
itemsGameCdn: 'https://raw.githubusercontent.com/SteamDatabase/GameTracking-CSGO/master/csgo/scripts/items/items_game_cdn.txt',
1715
csgoEnglish: 'https://raw.githubusercontent.com/SteamDatabase/GameTracking-CSGO/master/csgo/resource/csgo_english.txt',
18-
schema: `https://api.steampowered.com/IEconItems_730/GetSchema/v2/?key=${config.get('steam.apiKey')}&format=vdf&language=`,
1916
};
2017

2118
(async () => {
@@ -32,7 +29,6 @@ const sources = {
3229

3330
results.itemsGame = vdf.parse(results.itemsGame);
3431
results.csgoEnglish = vdf.parse(results.csgoEnglish);
35-
results.schema = vdf.parse(results.schema);
3632
results.itemsGameCdn = results.itemsGameCdn.split('\n').reduce((result, line) => {
3733
if (line.charAt(0) === '#' || line === '') {
3834
return result;
@@ -67,7 +63,7 @@ const sources = {
6763
return translation;
6864
};
6965

70-
const { items } = results.schema.result;
66+
const { items } = results.itemsGame.items_game;
7167
const paintkits = results.itemsGame.items_game.paint_kits;
7268
const skins = results.itemsGameCdn;
7369

@@ -82,12 +78,15 @@ const sources = {
8278

8379
let matchingItem = null;
8480

85-
_.forEach(items, (item) => {
81+
_.forEach(items, (item, key) => {
8682
const isCurrentlyBestMatch = name.startsWith(item.name)
8783
&& (matchingItem === null || item.name.length > matchingItem.name.length);
8884

8985
if (isCurrentlyBestMatch) {
90-
matchingItem = item;
86+
matchingItem = {
87+
...item,
88+
defindex: key,
89+
};
9190
}
9291
});
9392

@@ -106,17 +105,26 @@ const sources = {
106105

107106
const skinImageUrl = image.replace('http://media.steampowered.com', 'https://steamcdn-a.akamaihd.net');
108107

108+
// Gloves have no item image, use the skin image instead.
109+
const imageUrl = results.itemsGameCdn[matchingItem.name] || skinImageUrl;
110+
111+
const prefab = results.itemsGame.items_game.prefabs[matchingItem.prefab];
112+
const subPrefab = results.itemsGame.items_game.prefabs[prefab.prefab];
113+
114+
const itemClass = prefab.item_class || subPrefab.item_class || 'wearable_item';
115+
116+
const itemName = matchingItem.item_name || prefab.item_name;
117+
109118
const res = {
110119
name_technical: name,
111120
image_url: skinImageUrl,
112121
item: {
113122
name_technical: matchingItem.name,
114123
defindex: matchingItem.defindex,
115-
// Gloves have no item image, use the skin image instead.
116-
image_url: matchingItem.image_url || skinImageUrl,
117-
class: matchingItem.item_class,
118-
name: getTranslation(matchingItem.item_name),
119-
type: getTranslation(matchingItem.item_type_name),
124+
image_url: imageUrl,
125+
class: itemClass,
126+
name: getTranslation(itemName),
127+
type: getTranslation(subPrefab.item_type_name),
120128
},
121129
paintkit: {
122130
name_technical: matchingPaintkit.name,

0 commit comments

Comments
 (0)