#!/usr/bin/env node // NYX PROJECT — modul epic · satu file // Author : Akwila Dimas · https://github.com/Akwds01 // Telegram: https://t.me/nyx_projectss · WhatsApp: https://whatsapp.com/channel/0029VbEMMAQHbFUzKKOE5o0Y // Sumber : endpoint publik Epic Games Store (launcher GraphQL + freeGamesPromotions) // License : MIT (2026, Akwila Dimas) — bebas dipakai/diubah/dibagikan dengan notice // Hasil build dari cli-epic.mjs + lib/{epic,brand}.mjs import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; /* =========================== BRAND =========================== */ // Identitas & kredit NYX PROJECT. Isi link di sini — otomatis muncul di // `nyx about`, banner, dan README. Bisa juga lewat env: NYX_AUTHOR, NYX_GITHUB, // NYX_WA, NYX_TG, NYX_TG_PERSONAL. const BRAND = { name: 'NYX PROJECT', tagline: 'terminal toolkit', version: '1.0.0', author: process.env.NYX_AUTHOR || 'Akwila Dimas', github: process.env.NYX_GITHUB || 'https://github.com/Akwds01', waChannel: process.env.NYX_WA || 'https://whatsapp.com/channel/0029VbEMMAQHbFUzKKOE5o0Y', telegram: process.env.NYX_TG || 'https://t.me/nyx_projectss', // channel NYX telegramPersonal: process.env.NYX_TG_PERSONAL || 'https://t.me/NYX_PROJECTS', // kontak/akun refs: [ ['vermaysha/bima-plus', 'https://github.com/vermaysha/bima-plus'], ['0xtbug/telbot', 'https://github.com/0xtbug/telbot'], ['Najihh/EnQuota', 'https://github.com/Najihh/EnQuota'], ['gist myIM3 (ayashiiiyo)', 'https://gist.github.com/ayashiiiyo/e2561dddd66e1259a17b3eac28c47b55'], ], }; /** Baris kredit ringkas untuk banner/help. */ const creditLine = () => { const bits = [`by ${BRAND.author}`]; if (BRAND.github) bits.push(BRAND.github.replace(/^https?:\/\//, '')); if (BRAND.telegram) bits.push('t.me/nyx_projectss'); return bits.join(' · '); }; /* =========================== EPIC =========================== */ // NYX PROJECT — klien Epic Games Store (tanpa login, tanpa API key) // Author : Akwila Dimas · https://github.com/Akwds01 // Telegram: https://t.me/nyx_projectss · WhatsApp: https://whatsapp.com/channel/0029VbEMMAQHbFUzKKOE5o0Y // Sumber : store-site-backend-static.ak.epicgames.com + launcher.store.epicgames.com/graphql // License : MIT (2026, Akwila Dimas) // // Dua pintu yang dipakai: // 1. freeGamesPromotions — daftar game gratis mingguan (JSON biasa) // 2. GraphQL launcher — pencarian, harga, diskon // store.epicgames.com menolak permintaan tanpa browser, jadi host launcher yang dipakai. // Harga datang dalam satuan sen (399 = $3.99), dan fmtPrice kadang null. const FREE_URL = 'https://store-site-backend-static.ak.epicgames.com/freeGamesPromotions'; const GQL = 'https://launcher.store.epicgames.com/graphql'; const TIMEOUT_MS = Number(process.env.EPIC_TIMEOUT_MS || 25000); const UA = 'EpicGamesLauncher/17.0.0-12345678 Windows/10.0.19045.1.256.64bit'; class EpicError extends Error { constructor(message, extra = {}) { super(message); this.name = 'EpicError'; Object.assign(this, extra); } } const minta = async (url, opsi = {}) => { const ctl = new AbortController(); const t = setTimeout(() => ctl.abort(), TIMEOUT_MS); try { const res = await fetch(url, { ...opsi, signal: ctl.signal, headers: { 'User-Agent': UA, 'Content-Type': 'application/json', ...(opsi.headers || {}) }, }); if (!res.ok) throw new EpicError(`Epic membalas HTTP ${res.status}`, { code: 'HTTP', status: res.status }); return await res.json(); } catch (err) { if (err instanceof EpicError) throw err; throw new EpicError(`Gagal konek ke Epic: ${err.message}`, { code: 'NETWORK' }); } finally { clearTimeout(t); } }; /** 399 → "$3.99" (atau "gratis" bila 0). */ const uang = (nilai, fmt = null, country = 'US') => { // fmtPrice dipakai kalau ada. Kalau null, angka mentah dibagi 100: Epic menyimpan // 20699900 untuk Rp206.999 dan 399 untuk $3.99. if (fmt && typeof fmt === 'string') return fmt; if (nilai == null) return '—'; if (nilai === 0) return 'gratis'; if (String(country).toUpperCase() === 'ID') { return 'Rp' + new Intl.NumberFormat('id-ID').format(Math.round(nilai / 100)); } return '$' + (nilai / 100).toFixed(2); }; const slugDari = (el) => { const raw = el.productSlug || el.urlSlug || (el.catalogNs?.mappings?.[0]?.pageSlug) || null; if (!raw) return null; return String(raw).replace(/\/home$/, ''); }; const tanggal = (iso) => { if (!iso) return null; try { return new Date(iso).toLocaleString('id-ID', { day: '2-digit', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit' }); } catch { return iso; } }; /* ------------------------------------------------------------- game gratis */ /** * Daftar promosi gratis. Epic menaruh dua kelompok: * promotionalOffers → sedang gratis * upcomingPromotionalOffers → akan gratis */ const gratis = async ({ country = 'ID', locale = 'en-US' } = {}) => { const q = `?locale=${locale}&country=${country}&allowCountries=${country}`; const data = await minta(FREE_URL + q, { headers: { 'Content-Type': 'application/json' }, method: 'GET' }); const daftar = data?.data?.Catalog?.searchStore?.elements || []; const sekarang = []; const nanti = []; for (const el of daftar) { const promo = el.promotions; if (!promo) continue; const dasar = { judul: el.title, id: el.id, slug: slugDari(el), gambar: (el.keyImages || []).find((k) => k.type === 'Thumbnail' || k.type === 'OfferImageWide')?.url || null, hargaAsli: el.price?.totalPrice?.originalPrice ?? null, hargaAsliTeks: el.price?.totalPrice?.fmtPrice?.originalPrice || uang(el.price?.totalPrice?.originalPrice ?? null), }; const ambil = (grup) => (grup || []).flatMap((p) => p.promotionalOffers || []); for (const o of ambil(promo.promotionalOffers)) { const persen = o.discountSetting?.discountPercentage ?? 0; if (persen === 0 && (dasar.hargaAsli ?? 0) > 0) { sekarang.push({ ...dasar, mulai: tanggal(o.startDate), selesai: tanggal(o.endDate) }); } } for (const o of ambil(promo.upcomingPromotionalOffers)) { const persen = o.discountSetting?.discountPercentage ?? 0; if (persen === 0 && (dasar.hargaAsli ?? 0) > 0) { nanti.push({ ...dasar, mulai: tanggal(o.startDate), selesai: tanggal(o.endDate) }); } } } const unik = (arr) => { const peta = new Map(); for (const x of arr) if (!peta.has(x.id)) peta.set(x.id, x); return [...peta.values()]; }; return { sekarang: unik(sekarang), nanti: unik(nanti) }; }; /* --------------------------------------------------------------- pencarian */ const potong = (el, country = 'US') => { const tp = el.price?.totalPrice; const asli = tp?.originalPrice ?? null; const akhir = tp?.discountPrice ?? null; return { judul: el.title, id: el.id, slug: slugDari(el), asli, akhir, asliTeks: uang(asli, tp?.fmtPrice?.originalPrice, country), akhirTeks: uang(akhir, tp?.fmtPrice?.discountPrice, country), diskon: asli && akhir != null && asli > 0 ? Math.round((1 - akhir / asli) * 100) : 0, }; }; const cari = async (kata, { country = 'ID', locale = 'en-US', jumlah = 10 } = {}) => { const kueri = String(kata || '').trim(); if (!kueri) throw new EpicError('Kata kunci kosong.', { code: 'BAD_INPUT' }); const gql = { query: `query s($q:String,$c:String!,$l:String!,$n:Int){ Catalog{ searchStore(keywords:$q,country:$c,locale:$l,count:$n){ elements{ title id productSlug urlSlug price(country:$c){ totalPrice{ discountPrice originalPrice fmtPrice{ originalPrice discountPrice } } } } } } }`, variables: { q: kueri, c: country, l: locale, n: Math.min(Number(jumlah) || 10, 30) }, }; const data = await minta(GQL, { method: 'POST', body: JSON.stringify(gql) }); const els = data?.data?.Catalog?.searchStore?.elements || []; return els.map((el) => potong(el, country)); }; /** Sedang diskon, urut harga terendah. */ const diskon = async ({ country = 'ID', locale = 'en-US', jumlah = 12 } = {}) => { const gql = { query: `query s($c:String!,$l:String!,$n:Int){ Catalog{ searchStore(country:$c,locale:$l,count:$n,onSale:true,sortBy:"currentPrice",sortDir:"ASC"){ elements{ title id productSlug urlSlug price(country:$c){ totalPrice{ discountPrice originalPrice fmtPrice{ originalPrice discountPrice } } } } } } }`, variables: { c: country, l: locale, n: Math.min(Number(jumlah) || 12, 40) }, }; const data = await minta(GQL, { method: 'POST', body: JSON.stringify(gql) }); const els = data?.data?.Catalog?.searchStore?.elements || []; // yang sudah gratis (akhir 0) bukan diskon, itu urusan perintah `gratis` return els.map((el) => potong(el, country)).filter((x) => x.diskon > 0 && (x.akhir ?? 0) > 0); }; /* ============================ CLI ============================ */ // NYX PROJECT — CLI modul epic // Author : Akwila Dimas · https://github.com/Akwds01 // Telegram: https://t.me/nyx_projectss · WhatsApp: https://whatsapp.com/channel/0029VbEMMAQHbFUzKKOE5o0Y // License : MIT (2026, Akwila Dimas) // // Perintah: // gratis game gratis minggu ini + yang akan datang // cari pencarian toko // diskon [--maks N] yang sedang diskon, urut termurah // info detail satu game (cari lalu ambil yang paling cocok) // bantuan menu ini // // Flag umum: --json, --cc=ID|US, --maks N const argv = process.argv.slice(2); const ambilFlag = (nama, bawaan = null) => { const i = argv.findIndex((a) => a === `--${nama}` || a.startsWith(`--${nama}=`)); if (i < 0) return bawaan; const a = argv[i]; if (a.includes('=')) return a.split('=').slice(1).join('='); const next = argv[i + 1]; return next && !next.startsWith('--') ? next : true; }; const JSON_OUT = argv.includes('--json'); const CC = String(ambilFlag('cc', process.env.EPIC_CC || 'ID')).toUpperCase(); const MAKS = Number(ambilFlag('maks', 10)) || 10; const W = Math.min(process.stdout.isTTY ? (process.stdout.columns || 76) : 76, 86); const garis = (c = '─') => c.repeat(W); const bingkai = (judul, baris) => [garis('─'), ` ${judul}`, garis('─'), ...baris, garis('─')].join('\n'); // argumen posisi saja; nilai milik flag (mis. "3" pada --maks 3) jangan ikut const posisi = () => { const keluar = []; for (let i = 0; i < argv.length; i++) { const a = argv[i]; if (a.startsWith('--')) { if (!a.includes('=') && argv[i + 1] && !argv[i + 1].startsWith('--')) i++; continue; } keluar.push(a); } return keluar; }; const bantuan = () => console.log(` ${BRAND.name} · epic ${BRAND.tagline} ${garis('─')} gratis game gratis sekarang, plus yang akan datang cari cari game di toko Epic diskon [--maks 10] sedang diskon, urut termurah info detail satu game Flag: --json --cc=ID|US --maks N Contoh: node cli-epic.mjs gratis node cli-epic.mjs cari hades node cli-epic.mjs diskon --maks 5 node cli-epic.mjs info "elden ring" ${creditLine()} `); const cmdGratis = async () => { const r = await gratis({ country: CC }); if (JSON_OUT) return console.log(JSON.stringify(r, null, 1)); const baris = []; if (!r.sekarang.length) baris.push(' tidak ada game gratis yang sedang berjalan'); for (const g of r.sekarang) { baris.push(` ${g.judul.slice(0, 44)}`); baris.push(` harga asli ${g.hargaAsliTeks} · gratis sampai ${g.selesai || '—'}`); if (g.slug) baris.push(` https://store.epicgames.com/p/${g.slug}`); baris.push(''); } if (r.nanti.length) { baris.push(' akan datang:'); for (const g of r.nanti) { baris.push(` ${g.judul.slice(0, 44)} · mulai ${g.mulai || '—'}`); } } console.log(bingkai(`Game gratis — ${CC} (${r.sekarang.length} aktif, ${r.nanti.length} menyusul)`, baris)); }; const cmdCari = async (kata) => { const r = await cari(kata, { country: CC, jumlah: MAKS }); if (JSON_OUT) return console.log(JSON.stringify(r, null, 1)); if (!r.length) return console.log(`Tidak ada hasil untuk "${kata}".`); const baris = r.map((x) => { const harga = x.akhir === 0 ? 'gratis' : (x.diskon ? `${x.akhirTeks} (−${x.diskon}% dari ${x.asliTeks})` : x.akhirTeks); return ` ${x.judul.slice(0, 38).padEnd(38)} ${harga}`; }); console.log(bingkai(`Hasil "${kata}" — ${CC}`, baris)); }; const cmdDiskon = async () => { const r = await diskon({ country: CC, jumlah: Math.max(MAKS * 3, 24), }); if (JSON_OUT) return console.log(JSON.stringify(r.slice(0, MAKS), null, 1)); if (!r.length) return console.log('Tidak ada diskon yang terbaca.'); const urut = [...r].sort((a, b) => b.diskon - a.diskon).slice(0, MAKS); const baris = urut.map((x) => ` -${String(x.diskon).padStart(2)}% ${x.judul.slice(0, 34).padEnd(34)} ${x.akhirTeks}`); console.log(bingkai(`Sedang diskon — ${CC} (${r.length} item terbaca)`, baris)); }; const cmdInfo = async (judul) => { const r = await cari(judul, { country: CC, jumlah: 5 }); if (!r.length) return console.log(`Tidak ketemu: ${judul}`); const x = r[0]; if (JSON_OUT) return console.log(JSON.stringify({ ...x, alternatif: r.slice(1) }, null, 1)); const baris = [ ` ${x.judul}`, '', ` Harga ${x.akhir === 0 ? 'gratis' : x.akhirTeks + (x.diskon ? ` (−${x.diskon}% dari ${x.asliTeks})` : '')}`, ` Halaman https://store.epicgames.com/p/${x.slug || ''}`, ]; if (r.length > 1) { baris.push('', ' hasil lain:'); r.slice(1, 4).forEach((y) => baris.push(` ${y.judul.slice(0, 40)} · ${y.akhir === 0 ? 'gratis' : y.akhirTeks}`)); } console.log(bingkai(`Epic · ${CC}`, baris)); }; const main = async () => { const cmd = (argv.find((a) => !a.startsWith('--')) || 'gratis').toLowerCase(); const sisa = posisi(); try { if (cmd === 'gratis' || cmd === 'free') return await cmdGratis(); if (cmd === 'cari' || cmd === 'search') return await cmdCari(sisa.slice(1).join(' ')); if (cmd === 'diskon' || cmd === 'promo') return await cmdDiskon(); if (cmd === 'info') return await cmdInfo(sisa.slice(1).join(' ')); if (cmd === 'bantuan' || cmd === 'help') return bantuan(); return await cmdCari(sisa.join(' ')); } catch (err) { console.error(`Gagal: ${err.message}`); process.exitCode = err instanceof EpicError ? 2 : 3; } }; main();