Skip to content

Commit 296f0cd

Browse files
authored
Merge pull request #226 from wangxingzhen/charm
Add support keychain and Bumps globaloffensive from 3.1.0 to 3.2.0.
2 parents df920ab + d603b9b commit 296f0cd

File tree

6 files changed

+2065
-1207
lines changed

6 files changed

+2065
-1207
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ queue.process(CONFIG.logins.length, botController, async (job) => {
247247

248248
itemData.iteminfo = utils.removeNullValues(itemData.iteminfo);
249249
itemData.iteminfo.stickers = itemData.iteminfo.stickers.map((s) => utils.removeNullValues(s));
250+
itemData.iteminfo.keychains = itemData.iteminfo.keychains.map((s) => utils.removeNullValues(s));
250251

251252
job.data.job.setResponse(job.data.link.getParams().a, itemData.iteminfo);
252253

lib/game_data.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,17 @@ class GameData {
192192

193193
if (name) sticker.name = name;
194194
}
195+
// Get keychain name
196+
const keychainDefinitions = this.items_game.keychain_definitions;
197+
for (const keychain of iteminfo.keychains || []) {
198+
const kit = keychainDefinitions[keychain.sticker_id];
199+
200+
if (!kit) continue;
201+
202+
let name = this.csgo_english[kit.loc_name.replace('#', '')];
203+
204+
if (name) keychain.name = name;
205+
}
195206

196207
// Get the skin name
197208
let skin_name = '';
@@ -330,6 +341,8 @@ class GameData {
330341

331342
if (iteminfo.weapon_type === 'Sticker' || iteminfo.weapon_type === 'Sealed Graffiti') {
332343
name += `| ${iteminfo.stickers[0].name}`;
344+
} else if (iteminfo.weapon_type === 'Charm') {
345+
name += `| ${iteminfo.keychains[0].name}`;
333346
}
334347

335348
// Vanilla items have an item_name of '-'

lib/postgres.js

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class Postgres {
8484
ALTER TABLE items ADD COLUMN IF NOT EXISTS floatid BIGINT;
8585
ALTER TABLE items ADD COLUMN IF NOT EXISTS price INTEGER;
8686
ALTER TABLE items ADD COLUMN IF NOT EXISTS listed_price INTEGER;
87+
ALTER TABLE items ADD COLUMN IF NOT EXISTS keychains JSONB;
8788
ALTER TABLE history ADD COLUMN IF NOT EXISTS price INTEGER;
8889
8990
-- Float ID is defined as the first asset id we've seen for an item
@@ -249,6 +250,35 @@ class Postgres {
249250
}
250251
}
251252

253+
const keychains = item.keychains.length > 0 ? item.keychains.map((s) => {
254+
const res = {s: s.slot, i: s.sticker_id};
255+
if (s.wear) {
256+
res.w = s.wear;
257+
}
258+
if (s.scale) {
259+
res.sc = s.scale;
260+
}
261+
if (s.rotation) {
262+
res.r = s.rotation;
263+
}
264+
if (s.tint_id) {
265+
res.t = s.tint_id;
266+
}
267+
if (s.offset_x) {
268+
res.x = s.offset_x;
269+
}
270+
if (s.offset_y) {
271+
res.y = s.offset_y;
272+
}
273+
if (s.offset_z) {
274+
res.z = s.offset_z;
275+
}
276+
if (s.pattern) {
277+
res.p = s.pattern;
278+
}
279+
return res;
280+
}) : null;
281+
252282
const ms = item.s !== '0' ? item.s : item.m;
253283
const isStattrak = item.killeatervalue !== null;
254284
const isSouvenir = item.quality === 12;
@@ -266,7 +296,7 @@ class Postgres {
266296
}
267297

268298
values.push([ms, item.a, item.d, item.paintseed, item.paintwear, item.defindex, item.paintindex, isStattrak,
269-
isSouvenir, props, JSON.stringify(stickers), item.rarity, price]);
299+
isSouvenir, props, JSON.stringify(stickers), JSON.stringify(keychains), item.rarity, price]);
270300
}
271301

272302
if (values.length === 0) {
@@ -286,13 +316,13 @@ class Postgres {
286316
const values = [];
287317
let i = 1;
288318

289-
// Builds binding pattern such as ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11::jsonb, now(), $12, NULL, $13)
319+
// Builds binding pattern such as ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11::jsonb, $12::jsonb, now(), $13, NULL, $14)
290320
for (let c = 0; c < itemCount; c++) {
291-
values.push(`($${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}::jsonb, now(), $${i++}, NULL, $${i++})`);
321+
values.push(`($${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}::jsonb, $${i++}::jsonb, now(), $${i++}, NULL, $${i++})`);
292322
}
293323

294-
return `INSERT INTO items (ms, a, d, paintseed, paintwear, defindex, paintindex, stattrak, souvenir, props, stickers, updated, rarity, floatid, price)
295-
VALUES ${values.join(', ')} ON CONFLICT(defindex, paintindex, paintwear, paintseed) DO UPDATE SET ms=excluded.ms, a=excluded.a, d=excluded.d, stickers=excluded.stickers, updated=now()`;
324+
return `INSERT INTO items (ms, a, d, paintseed, paintwear, defindex, paintindex, stattrak, souvenir, props, stickers, keychains, updated, rarity, floatid, price)
325+
VALUES ${values.join(', ')} ON CONFLICT(defindex, paintindex, paintwear, paintseed) DO UPDATE SET ms=excluded.ms, a=excluded.a, d=excluded.d, stickers=excluded.stickers, keychains=excluded.keychains, updated=now()`;
296326
}
297327

298328
updateItemPrice(assetId, price) {
@@ -359,6 +389,22 @@ class Postgres {
359389
}
360390
});
361391

392+
item.keychains = item.keychains || [];
393+
item.keychains = item.keychains.map((s) => {
394+
return {
395+
sticker_id: s.i,
396+
slot: s.s,
397+
wear: s.w,
398+
scale: s.sc,
399+
rotation: s.r,
400+
tint_id: s.t,
401+
offset_x: s.x,
402+
offset_y: s.y,
403+
offset_z: s.z,
404+
pattern: s.p,
405+
}
406+
});
407+
362408
item = Object.assign(Postgres.extractProperties(item.props), item);
363409

364410
const buf = Buffer.alloc(4);

0 commit comments

Comments
 (0)