-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathload-usable-sticker-packs.js
85 lines (68 loc) · 2.92 KB
/
load-usable-sticker-packs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const { VK } = require('vk-io');
const { sleep, getToken } = require('./utils');
const fs = require('fs');
const token = getToken();
const vk = new VK({ token });
async function loadUsableStickerPacks() {
const response = await vk.api.store.getProducts({
type: "stickers",
filters: ["purchased", "active"],
extended: true,
});
console.log("getProducts stickers: ", response.items.length)
const stickerPacks = response.items;
const usableStickerPacks = {};
const usableStickers = {};
for (const stickerPack of stickerPacks) {
if (stickerPack.purchased && stickerPack.active) {
if (!usableStickerPacks[stickerPack.id]) {
delete stickerPack["type"];
delete stickerPack["purchased"];
delete stickerPack["active"];
delete stickerPack["is_new"];
delete stickerPack["icon"];
delete stickerPack["previews"];
for (const sticker of stickerPack.stickers) {
const images = sticker.images.filter(i => i.width == 512 && i.height == 512);
const imagesWithBackground = sticker.images_with_background.filter(i => i.width == 512 && i.height == 512);
if (sticker.inner_type == "base_sticker_new") {
delete sticker["inner_type"];
}
if (sticker.render) {
const images = sticker.render.images.filter(i => i.width == 512 && i.height == 512);
const lightImages = images.filter(i => i.theme == "light");
const darkImages = images.filter(i => i.theme == "dark");
delete sticker.render["images"];
sticker.render.lightPreviewImageUrl = lightImages[0]?.url;
sticker.render.darkPreviewImageUrl = darkImages[0]?.url;
}
delete sticker["images"];
delete sticker["images_with_background"];
sticker.id = sticker.sticker_id;
delete sticker.sticker_id;
sticker.usable = sticker.is_allowed;
delete sticker.is_allowed;
sticker.previewImageUrl = images[0].url;
sticker.previewImageWithBackground = imagesWithBackground[0].url;
if (!usableStickers[sticker.id]) {
usableStickers[sticker.id] = sticker;
}
sticker.pack = stickerPack.title;
if (!usableStickers[stickerPack.title]) {
usableStickers[stickerPack.title] = {}
}
if (!usableStickers[stickerPack.title][sticker.id]) {
usableStickers[stickerPack.title][sticker.id] = sticker;
}
}
stickerPack.usable = true;
usableStickerPacks[stickerPack.id] = stickerPack;
}
}
}
const usableStickerPacksJson = JSON.stringify(usableStickerPacks, null, 2);
fs.writeFileSync("usable-sticker-packs.json", usableStickerPacksJson);
const usableStickersJson = JSON.stringify(usableStickers, null, 2);
fs.writeFileSync("usable-stickers.json", usableStickersJson);
}
loadUsableStickerPacks().catch(console.error);