Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support keychain and Bumps globaloffensive from 3.1.0 to 3.2.0. #226

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ queue.process(CONFIG.logins.length, botController, async (job) => {

itemData.iteminfo = utils.removeNullValues(itemData.iteminfo);
itemData.iteminfo.stickers = itemData.iteminfo.stickers.map((s) => utils.removeNullValues(s));
itemData.iteminfo.keychains = itemData.iteminfo.keychains.map((s) => utils.removeNullValues(s));

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

Expand Down
13 changes: 13 additions & 0 deletions lib/game_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ class GameData {

if (name) sticker.name = name;
}
// Get keychain name
const keychainDefinitions = this.items_game.keychain_definitions;
for (const keychain of iteminfo.keychains || []) {
const kit = keychainDefinitions[keychain.sticker_id];

if (!kit) continue;

let name = this.csgo_english[kit.loc_name.replace('#', '')];

if (name) keychain.name = name;
}

// Get the skin name
let skin_name = '';
Expand Down Expand Up @@ -330,6 +341,8 @@ class GameData {

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

// Vanilla items have an item_name of '-'
Expand Down
48 changes: 41 additions & 7 deletions lib/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Postgres {
ALTER TABLE items ADD COLUMN IF NOT EXISTS floatid BIGINT;
ALTER TABLE items ADD COLUMN IF NOT EXISTS price INTEGER;
ALTER TABLE items ADD COLUMN IF NOT EXISTS listed_price INTEGER;
ALTER TABLE items ADD COLUMN IF NOT EXISTS keychains JSONB;
ALTER TABLE history ADD COLUMN IF NOT EXISTS price INTEGER;

-- Float ID is defined as the first asset id we've seen for an item
Expand Down Expand Up @@ -209,9 +210,10 @@ class Postgres {
buf.writeFloatBE(item.floatvalue, 0);
item.paintwear = buf.readInt32BE(0);

if (item.floatvalue <= 0 && item.defindex !== 507) {
// Only insert weapons, naive check
// Special case for the 0 float Karambit
if (item.floatvalue <= 0 && item.defindex !== 507 && item.defindex !== 1355) {
// Only insert weapons and keychains, naive check
// Special case for the 0 float Karambit and keychains.
// The keychains has a unique pattern
wangxingzhen marked this conversation as resolved.
Show resolved Hide resolved
continue;
}

Expand Down Expand Up @@ -249,6 +251,26 @@ class Postgres {
}
}

const keychains = item.keychains.length > 0 ? item.keychains.map((s) => {
const res = {s: s.slot, i: s.sticker_id};
if (s.pattern) {
res.pattern = s.pattern;
}
if (s.name) {
wangxingzhen marked this conversation as resolved.
Show resolved Hide resolved
res.name = s.name;
}
if (s.offset_x) {
res.x = s.offset_x;
}
if (s.offset_y) {
res.y = s.offset_y;
}
if (s.offset_z) {
res.z = s.offset_z;
}
return res;
}) : null;

const ms = item.s !== '0' ? item.s : item.m;
const isStattrak = item.killeatervalue !== null;
const isSouvenir = item.quality === 12;
Expand All @@ -266,7 +288,7 @@ class Postgres {
}

values.push([ms, item.a, item.d, item.paintseed, item.paintwear, item.defindex, item.paintindex, isStattrak,
isSouvenir, props, JSON.stringify(stickers), item.rarity, price]);
isSouvenir, props, JSON.stringify(stickers), item.rarity, price, JSON.stringify(keychains)]);
}

if (values.length === 0) {
Expand All @@ -288,11 +310,11 @@ class Postgres {

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

return `INSERT INTO items (ms, a, d, paintseed, paintwear, defindex, paintindex, stattrak, souvenir, props, stickers, updated, rarity, floatid, price)
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()`;
return `INSERT INTO items (ms, a, d, paintseed, paintwear, defindex, paintindex, stattrak, souvenir, props, stickers, updated, rarity, floatid, price, keychains)
wangxingzhen marked this conversation as resolved.
Show resolved Hide resolved
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(), keychains=excluded.keychains`;
}

updateItemPrice(assetId, price) {
Expand Down Expand Up @@ -358,6 +380,18 @@ class Postgres {
offset_y: s.y,
}
});
item.keychains = item.keychains || [];
item.keychains = item.keychains.map((s) => {
return {
sticker_id: s.i,
slot: s.s,
pattern: s.pattern,
name: s.name,
offset_x: s.x,
offset_y: s.y,
offset_z: s.z,
}
});

item = Object.assign(Postgres.extractProperties(item.props), item);

Expand Down
Loading
Loading