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

Created a new configuration entry to enable saving keychains charms to the local DB. #227

Closed
wants to merge 7 commits into from
Prev Previous commit
Next Next commit
Add support keychain.
wangxingzhen committed Oct 11, 2024
commit ca407c4a073239da86a635cc4d5ba5f9ce6a7f58
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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);

13 changes: 13 additions & 0 deletions lib/game_data.js
Original file line number Diff line number Diff line change
@@ -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 = '';
@@ -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 '-'
51 changes: 43 additions & 8 deletions lib/postgres.js
Original file line number Diff line number Diff line change
@@ -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
@@ -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
continue;
}

@@ -249,6 +251,27 @@ class Postgres {
}
}

const keychains = item.keychains.length > 0 ? item.keychains.map((s) => {
const res = {s: s.slot, i: s.sticker_id};
// TODO: 似乎没有?
if (s.pattern) {
res.pattern = s.pattern;
}
if (s.name) {
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;
@@ -266,7 +289,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) {
@@ -288,11 +311,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)
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) {
@@ -358,6 +381,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);