Last active
April 11, 2024 12:34
-
-
Save RealYukiSan/b07dd0463417f8ba03f297550edb750e to your computer and use it in GitHub Desktop.
fetch telegram sticker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { get } = require("node:https"); | |
(async () => { | |
const stickerName = ['Elaina_san', 'bagasgoyang'] | |
const token = "bot7003873933:AAFKl0LwWViMJIA34-qjbTh7nZwcNQr2hFs" | |
const domain = "https://api.telegram.org" | |
const file_baseurl = `${domain}/file/${token}` | |
const api_baseurl = `${domain}/${token}` | |
stickerName.forEach(async (name) => { | |
try { | |
let files = await fetch(`${api_baseurl}/getStickerSet?name=${name}`) | |
files = JSON.parse(files.toString()) | |
files.result.stickers.forEach(async (sticker) => { | |
try { | |
let metadata = await fetch(`${api_baseurl}/getFile?file_id=${sticker.file_id}`) | |
metadata = JSON.parse(metadata.toString()) | |
const file = Buffer.from(await fetch(`${file_baseurl}/${metadata.result.file_path}`)) | |
console.log(file.length) | |
} catch (error) { | |
if (error.name == 'AggregateError') { | |
for (let index = 0; index < error.errors.length; index++) { | |
process.stdout.write(error.errors[i].cause.code + ' - ') | |
} | |
} else process.stdout.write(error.cause.code + ' - ') | |
console.log("don't exit the loop"); | |
} | |
}) | |
} catch (error) { | |
if (error.name == 'AggregateError') { | |
for (let index = 0; index < error.errors.length; index++) { | |
process.stdout.write(error.errors[i].cause.code + ' - ') | |
} | |
} else process.stdout.write(error.cause.code + ' - ') | |
console.error("don't exit the program") | |
} | |
}) | |
})() | |
function fetch(link) { | |
return new Promise((resolve, reject) => { | |
get(link, { timeout: 60e3 }, (res) => { | |
let buff = Buffer.alloc(0); | |
res.on( | |
'data', | |
(chunk) => (buff = Buffer.concat([buff, Buffer.from(chunk)])) | |
); | |
res.on('error', reject); | |
res.on('end', () => resolve(buff)); | |
}).on('error', (e) => { | |
if (e.code != 'ECONNRESET') reject(e); | |
console.log("warn: peer decided to close socket!") | |
fetch(link).then(resolve).catch(reject); | |
}); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { spawn } = require("node:child_process"); | |
(async () => { | |
const stickerName = ['Elaina_san', 'bagasgoyang'] | |
const token = "bot7003873933:AAFKl0LwWViMJIA34-qjbTh7nZwcNQr2hFs" | |
const domain = "https://api.telegram.org" | |
const file_baseurl = `${domain}/file/${token}` | |
const api_baseurl = `${domain}/${token}` | |
for (let index = 0; index < 3; index++) { | |
stickerName.forEach(async (name) => { | |
try { | |
let files = '' | |
let curl = spawn("curl", ["-s", `${api_baseurl}/getStickerSet?name=${name}`]) | |
curl.stdout.on("data", (chunk) => files += chunk) | |
curl.stdout.on("end", () => { | |
files = JSON.parse(files) | |
files.result.stickers.forEach(async (sticker) => { | |
try { | |
let metadata = '' | |
curl = spawn("curl", ["-s", `${api_baseurl}/getFile?file_id=${sticker.file_id}`]) | |
curl.stdout.on("data", (chunk) => metadata += chunk) | |
curl.stdout.on("end", () => { | |
metadata = JSON.parse(metadata) | |
let file = Buffer.alloc(0) | |
curl = spawn("curl", ["-s", "-o-", `${file_baseurl}/${metadata.result.file_path}`]) | |
curl.stdout.on("data", (chunk) => { | |
file = Buffer.concat([file, Buffer.from(chunk)]) | |
}) | |
curl.stdout.on("end", () => { | |
console.log(file.length) | |
}) | |
}) | |
} catch (error) { | |
if (error.name == 'TypeError') process.stdout.write(error.cause.code + ' - ') | |
else if (error.name == 'AggregateError') { | |
for (let index = 0; index < error.errors.length; index++) { | |
process.stdout.write(error.errors[i].cause.code + ' - ') | |
} | |
} | |
console.log("don't exit the loop"); | |
} | |
}) | |
}) | |
} catch (error) { | |
if (error.name == 'TypeError') process.stdout.write(error.cause.code + ' - ') | |
else if (error.name == 'AggregateError') { | |
for (let index = 0; index < error.errors.length; index++) { | |
process.stdout.write(error.errors[i].cause.code + ' - ') | |
} | |
} | |
console.error("don't exit the program") | |
} | |
}) | |
} | |
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { spawnSync } = require("node:child_process"); | |
(async () => { | |
const stickerName = ['Elaina_san', 'bagasgoyang'] | |
const token = "bot7003873933:AAFKl0LwWViMJIA34-qjbTh7nZwcNQr2hFs" | |
const domain = "https://api.telegram.org" | |
const file_baseurl = `${domain}/file/${token}` | |
const api_baseurl = `${domain}/${token}` | |
for (let index = 0; index < 3; index++) { | |
stickerName.forEach(async (name) => { | |
try { | |
let files = spawnSync("curl", ["-s", `${api_baseurl}/getStickerSet?name=${name}`]) | |
files = JSON.parse(files.stdout.toString()) | |
files.result.stickers.forEach(async (sticker) => { | |
try { | |
let metadata = spawnSync("curl", ["-s", `${api_baseurl}/getFile?file_id=${sticker.file_id}`]) | |
metadata = JSON.parse(metadata.stdout.toString()) | |
let file = spawnSync("curl", ["-s", "-o-", `${file_baseurl}/${metadata.result.file_path}`]) | |
file = Buffer.from(file.stdout) | |
console.log(file.length) | |
} catch (error) { | |
if (error.name == 'AggregateError') { | |
for (let index = 0; index < error.errors.length; index++) { | |
process.stdout.write(error.errors[i].cause.code + ' - ') | |
} | |
} else process.stdout.write(error.cause.code + ' - ') | |
console.log("don't exit the loop"); | |
} | |
}) | |
} catch (error) { | |
if (error.name == 'AggregateError') { | |
for (let index = 0; index < error.errors.length; index++) { | |
process.stdout.write(error.errors[i].cause.code + ' - ') | |
} | |
} else process.stdout.write(error.cause.code + ' - ') | |
console.error("don't exit the program") | |
} | |
}) | |
} | |
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async () => { | |
const stickerName = ['Elaina_san', 'bagasgoyang'] | |
const token = "bot7003873933:AAFKl0LwWViMJIA34-qjbTh7nZwcNQr2hFs" | |
const domain = "https://api.telegram.org" | |
const file_baseurl = `${domain}/file/${token}` | |
const api_baseurl = `${domain}/${token}` | |
stickerName.forEach(async (name) => { | |
try { | |
const files = await fetch(`${api_baseurl}/getStickerSet?name=${name}`).then(res => res.json()) | |
files.result.stickers.forEach(async (sticker) => { | |
try { | |
const metadata = await fetch(`${api_baseurl}/getFile?file_id=${sticker.file_id}`).then(res => res.json()) | |
const file = Buffer.from(await fetch(`${file_baseurl}/${metadata.result.file_path}`).then(res => res.arrayBuffer())) | |
console.log(file.length) | |
} catch (error) { | |
if (error.name == 'AggregateError') { | |
for (let index = 0; index < error.errors.length; index++) { | |
process.stdout.write(error.errors[i].cause.code + ' - ') | |
} | |
} else process.stdout.write(error.cause.code + ' - ') | |
console.log("don't exit the loop"); | |
} | |
}) | |
} catch (error) { | |
if (error.name == 'AggregateError') { | |
for (let index = 0; index < error.errors.length; index++) { | |
process.stdout.write(error.errors[i].cause.code + ' - ') | |
} | |
} else process.stdout.write(error.cause.code + ' - ') | |
console.error("don't exit the program") | |
} | |
}) | |
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async () => { | |
const stickerName = ['Elaina_san', 'bagasgoyang'] | |
const token = "bot7003873933:AAFKl0LwWViMJIA34-qjbTh7nZwcNQr2hFs" | |
const domain = "https://api.telegram.org" | |
const file_baseurl = `${domain}/file/${token}` | |
const api_baseurl = `${domain}/${token}` | |
for (const key in stickerName) { | |
try { | |
const name = stickerName[key] | |
const files = await fetch(`${api_baseurl}/getStickerSet?name=${name}`).then(res => res.json()) | |
for (const key in files.result.stickers) { | |
try { | |
const sticker = files.result.stickers[key] | |
const metadata = await fetch(`${api_baseurl}/getFile?file_id=${sticker.file_id}`).then(res => res.json()) | |
const file = Buffer.from(await fetch(`${file_baseurl}/${metadata.result.file_path}`).then(res => res.arrayBuffer())) | |
console.log(file.length) | |
} catch (error) { | |
if (error.name == 'AggregateError') { | |
for (let index = 0; index < error.errors.length; index++) { | |
process.stdout.write(error.errors[i].cause.code + ' - ') | |
} | |
} | |
else process.stdout.write(error.cause.code + ' - ') | |
console.log("don't exit the loop"); | |
} | |
} | |
} catch (error) { | |
if (error.name == 'AggregateError') { | |
for (let index = 0; index < error.errors.length; index++) { | |
process.stdout.write(error.errors[i].cause.code + ' - ') | |
} | |
} | |
else process.stdout.write(error.cause.code + ' - ') | |
console.error("don't exit the program") | |
} | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
case closed nodejs/undici#2777 (comment)
code
result