1
1
const path = require ( 'path' ) ;
2
- require ( 'dotenv' ) . config ( { path : path . join ( __dirname , './.env' ) } ) ;
3
- const config = require ( 'config' ) ;
4
2
const vdf = require ( 'simple-vdf' ) ;
5
3
const async = require ( 'async' ) ;
6
4
const axios = require ( 'axios' ) ;
@@ -15,7 +13,6 @@ const sources = {
15
13
itemsGame : 'https://raw.githubusercontent.com/SteamDatabase/GameTracking-CSGO/master/csgo/scripts/items/items_game.txt' ,
16
14
itemsGameCdn : 'https://raw.githubusercontent.com/SteamDatabase/GameTracking-CSGO/master/csgo/scripts/items/items_game_cdn.txt' ,
17
15
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=` ,
19
16
} ;
20
17
21
18
( async ( ) => {
@@ -32,7 +29,6 @@ const sources = {
32
29
33
30
results . itemsGame = vdf . parse ( results . itemsGame ) ;
34
31
results . csgoEnglish = vdf . parse ( results . csgoEnglish ) ;
35
- results . schema = vdf . parse ( results . schema ) ;
36
32
results . itemsGameCdn = results . itemsGameCdn . split ( '\n' ) . reduce ( ( result , line ) => {
37
33
if ( line . charAt ( 0 ) === '#' || line === '' ) {
38
34
return result ;
@@ -67,7 +63,7 @@ const sources = {
67
63
return translation ;
68
64
} ;
69
65
70
- const { items } = results . schema . result ;
66
+ const { items } = results . itemsGame . items_game ;
71
67
const paintkits = results . itemsGame . items_game . paint_kits ;
72
68
const skins = results . itemsGameCdn ;
73
69
@@ -82,12 +78,15 @@ const sources = {
82
78
83
79
let matchingItem = null ;
84
80
85
- _ . forEach ( items , ( item ) => {
81
+ _ . forEach ( items , ( item , key ) => {
86
82
const isCurrentlyBestMatch = name . startsWith ( item . name )
87
83
&& ( matchingItem === null || item . name . length > matchingItem . name . length ) ;
88
84
89
85
if ( isCurrentlyBestMatch ) {
90
- matchingItem = item ;
86
+ matchingItem = {
87
+ ...item ,
88
+ defindex : key ,
89
+ } ;
91
90
}
92
91
} ) ;
93
92
@@ -106,17 +105,26 @@ const sources = {
106
105
107
106
const skinImageUrl = image . replace ( 'http://media.steampowered.com' , 'https://steamcdn-a.akamaihd.net' ) ;
108
107
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
+
109
118
const res = {
110
119
name_technical : name ,
111
120
image_url : skinImageUrl ,
112
121
item : {
113
122
name_technical : matchingItem . name ,
114
123
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 ) ,
120
128
} ,
121
129
paintkit : {
122
130
name_technical : matchingPaintkit . name ,
0 commit comments