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 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
55 changes: 50 additions & 5 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 @@ -249,6 +250,35 @@ class Postgres {
}
}

const keychains = item.keychains.length > 0 ? item.keychains.map((s) => {
const res = {s: s.slot, i: s.sticker_id};
if (s.wear) {
res.w = s.wear;
}
if (s.scale) {
res.scale = s.scale;
}
if (s.rotation) {
res.r = s.rotation;
}
if (s.tint_id) {
res.tint_id = s.tint_id;
}
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;
}
if (s.pattern) {
res.pattern = s.pattern;
}
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 +296,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), JSON.stringify(keychains), item.rarity, price]);
}

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

// Builds binding pattern such as ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11::jsonb, now(), $12, NULL, $13)
// Builds binding pattern such as ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11::jsonb, $12::jsonb, now(), $13, NULL, $14)
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, $${i++}::jsonb, now(), $${i++}, NULL, $${i++})`);
}

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, keychains, 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, keychains=excluded.keychains, updated=now()`;
}

updateItemPrice(assetId, price) {
Expand Down Expand Up @@ -358,6 +388,21 @@ class Postgres {
offset_y: s.y,
}
});
item.keychains = item.keychains || [];
item.keychains = item.keychains.map((s) => {
return {
sticker_id: s.i,
slot: s.s,
wear: s.w,
scale: s.scale,
rotation: s.r,
tint_id: s.tint_id,
offset_x: s.x,
offset_y: s.y,
offset_z: s.z,
pattern: s.pattern,
}
});

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

Expand Down
Loading
Loading