#!/usr/bin/env node // NYX PROJECT — modul steam · satu file // Author : Akwila Dimas · https://github.com/Akwds01 // Telegram: https://t.me/nyx_projectss · WhatsApp: https://whatsapp.com/channel/0029VbEMMAQHbFUzKKOE5o0Y // Sumber : toko publik Steam (store.steampowered.com), tanpa API key, tanpa login // License : MIT (2026, Akwila Dimas) — bebas dipakai/diubah/dibagikan dengan notice // Hasil build dari cli-steam.mjs + lib/{steam,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(' · '); }; /* =========================== STEAM =========================== */ // NYX PROJECT — klien Steam (toko publik, tanpa API key) // Author : Akwila Dimas · https://github.com/Akwds01 // Telegram: https://t.me/nyx_projectss · WhatsApp: https://whatsapp.com/channel/0029VbEMMAQHbFUzKKOE5o0Y // Sumber : endpoint publik store.steampowered.com + api.steampowered.com // License : MIT (2026, Akwila Dimas) // // Yang dipakai hanya endpoint terbuka — tidak ada login, tidak ada API key. // Semua nilai uang dari Steam dikirim dalam satuan minor (sen), lalu dibagi 100. const STORE = 'https://store.steampowered.com'; const API = 'https://api.steampowered.com'; const COMMUNITY = 'https://steamcommunity.com'; const TIMEOUT_MS = Number(process.env.STEAM_TIMEOUT_MS || 20000); const NYX_DIR = path.join(os.homedir(), '.nyx'); const WATCH_PATH = path.join(NYX_DIR, 'steam-watch.json'); class SteamError extends Error { constructor(message, extra = {}) { super(message); this.name = 'SteamError'; Object.assign(this, extra); } } /* ------------------------------------------------------------------ util */ const UA = 'Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0 Mobile Safari/537.36'; const getJSON = async (url) => { const ctl = new AbortController(); const t = setTimeout(() => ctl.abort(), TIMEOUT_MS); let res; try { res = await fetch(url, { signal: ctl.signal, headers: { 'User-Agent': UA, 'Accept': 'application/json,text/plain,*/*', 'Accept-Language': 'id-ID,id;q=0.9,en;q=0.8' }, }); } catch (err) { throw new SteamError(`Gagal konek ke Steam: ${err.message}`, { code: 'NETWORK' }); } finally { clearTimeout(t); } if (!res.ok) throw new SteamError(`Steam membalas HTTP ${res.status}`, { code: 'HTTP', status: res.status }); const text = await res.text(); try { return JSON.parse(text); } catch { throw new SteamError('Respons bukan JSON', { code: 'NOT_JSON', status: res.status }); } }; /** "id" → "IDR" supaya parameter konsisten. */ const normalizeCC = (cc) => String(cc || process.env.STEAM_CC || 'id').toLowerCase(); /** * Steam mengirim harga dalam satuan minor. IDR memakai 2 desimal di baliknya, * jadi 59900000 = Rp599.000. */ const fmtMoney = (minor, currency = 'IDR') => { if (minor == null) return '—'; const cur = (currency || 'IDR').toUpperCase(); if (cur === 'IDR') { const v = Math.round(minor / 100); return 'Rp' + new Intl.NumberFormat('id-ID').format(v); } const v = minor / 100; try { return new Intl.NumberFormat(cur === 'USD' ? 'en-US' : 'en-US', { style: 'currency', currency: cur }).format(v); } catch { return `${cur} ${v.toFixed(2)}`; } }; /** Harga dari blok price_overview / price. */ const priceOf = (node) => { if (!node) return null; const p = node.price_overview || node.price || null; if (!p) return null; const currency = p.currency || 'IDR'; const final = p.final ?? null; const initial = p.initial ?? final; const discount = p.discount_percent ?? 0; return { currency, initial, final, discount, free: Boolean(node.is_free) || final === 0, finalText: p.final_formatted || fmtMoney(final, currency), initialText: p.initial_formatted || fmtMoney(initial, currency), }; }; /* ------------------------------------------------------------------- cari */ /** Pencarian toko — cepat, sudah membawa harga. */ const search = async (term, { cc = 'id', lang = 'indonesian' } = {}) => { const q = String(term || '').trim(); if (!q) throw new SteamError('Kata kunci kosong.', { code: 'BAD_INPUT' }); const data = await getJSON(`${STORE}/api/storesearch/?term=${encodeURIComponent(q)}&cc=${normalizeCC(cc)}&l=${lang}`); const items = (data.items || []).map((it) => { const price = it.price || null; return { appid: it.id, name: it.name, type: it.type, price: price ? { currency: price.currency, initial: price.initial, final: price.final, discount: price.discount_percent ?? (price.initial > price.final ? Math.round((1 - price.final / price.initial) * 100) : 0), finalText: fmtMoney(price.final, price.currency), initialText: fmtMoney(price.initial, price.currency), } : null, }; }); return { total: data.total ?? items.length, items }; }; /* ------------------------------------------------------------------- info */ /** Detail satu aplikasi: harga, genre, platform, tanggal rilis, skor. */ const appInfo = async (appid, { cc = 'id', lang = 'indonesian' } = {}) => { const id = String(appid || '').trim(); if (!/^\d+$/.test(id)) throw new SteamError('appid harus angka.', { code: 'BAD_INPUT' }); const data = await getJSON(`${STORE}/api/appdetails?appids=${id}&cc=${normalizeCC(cc)}&l=${lang}`); const node = data[id]; if (!node || !node.success) throw new SteamError(`App ${id} tidak ditemukan di toko.`, { code: 'NOT_FOUND', appid: id }); const d = node.data; const price = priceOf(d); return { appid: Number(id), name: d.name, type: d.type, isFree: Boolean(d.is_free), developers: d.developers || [], publishers: d.publishers || [], releaseDate: d.release_date?.date || null, comingSoon: Boolean(d.release_date?.coming_soon), genres: (d.genres || []).map((g) => g.description), categories: (d.categories || []).map((c) => c.description).slice(0, 8), platforms: { windows: Boolean(d.platforms?.windows), mac: Boolean(d.platforms?.mac), linux: Boolean(d.platforms?.linux) }, metascore: d.metacritic?.score ?? null, recommendations: d.recommendations?.total ?? null, price, discountPercent: price?.discount ?? 0, headerImage: d.header_image || null, shortDescription: (d.short_description || '').replace(/<[^>]+>/g, '').trim(), dlcCount: (d.dlc || []).length, packages: (d.package_groups || []).flatMap((g) => g.subs || []).map((s) => ({ id: s.packageid, text: s.option_text })), }; }; /* ---------------------------------------------------------------- diskon */ /** Sedang diskon di toko (region sesuai cc). */ const specials = async ({ cc = 'id', lang = 'indonesian' } = {}) => { const data = await getJSON(`${STORE}/api/featuredcategories?cc=${normalizeCC(cc)}&l=${lang}`); const list = data.specials?.items || []; return list.map((it) => { const currency = it.currency || 'IDR'; return { appid: it.id, name: it.name, discount: it.discount_percent ?? 0, currency, initial: it.original_price ?? null, final: it.final_price ?? null, initialText: fmtMoney(it.original_price, currency), finalText: fmtMoney(it.final_price, currency), expiry: it.discount_expiration ? new Date(it.discount_expiration * 1000).toISOString() : null, }; }).filter((it) => it.discount > 0).sort((a, b) => b.discount - a.discount); }; /* ---------------------------------------------------------------- berita */ const news = async (appid, { count = 5 } = {}) => { const id = String(appid || '').trim(); if (!/^\d+$/.test(id)) throw new SteamError('appid harus angka.', { code: 'BAD_INPUT' }); const data = await getJSON(`${API}/ISteamNews/GetNewsForApp/v2/?appid=${id}&count=${Math.min(Number(count) || 5, 20)}&maxlength=400`); const items = (data.appnews?.newsitems || []).map((n) => ({ title: n.title, url: n.url, author: n.author, at: new Date(n.date * 1000).toISOString(), feed: n.feedname, excerpt: (n.contents || '').replace(/\[[^\]]*\]/g, ' ').replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 220), })); return { appid: Number(id), count: items.length, items }; }; /* ------------------------------------------------ pantau (riwayat lokal) */ const bacaWatch = () => { try { const raw = fs.readFileSync(WATCH_PATH, 'utf8'); const d = JSON.parse(raw); return d && typeof d === 'object' ? d : {}; } catch { return {}; } }; const tulisWatch = (data) => { try { fs.mkdirSync(path.dirname(WATCH_PATH), { recursive: true }); fs.writeFileSync(WATCH_PATH, JSON.stringify(data, null, 1), { mode: 0o600 }); } catch (err) { throw new SteamError(`Gagal menyimpan riwayat: ${err.message}`, { code: 'SAVE_FAILED' }); } }; /** * Simpan satu titik harga. Riwayat dibatasi 180 titik terakhir supaya berkas * tidak membengkak. Steam tidak menyediakan harga historis, jadi ini yang * mengumpulkannya. */ const pantau = async (appid, { target = null, cc = 'id' } = {}) => { const info = await appInfo(appid, { cc }); const db = bacaWatch(); const key = String(info.appid); const now = new Date().toISOString(); const cur = db[key] || { appid: info.appid, name: info.name, target: null, history: [] }; cur.name = info.name; if (target != null) cur.target = Number(target); const last = cur.history[cur.history.length - 1]; const price = info.price?.final ?? null; if (!last || last.final !== price) { cur.history.push({ at: now, final: price, discount: info.discountPercent }); if (cur.history.length > 180) cur.history = cur.history.slice(-180); } cur.checkedAt = now; db[key] = cur; tulisWatch(db); // target disimpan dalam rupiah penuh, harga dari Steam dalam satuan minor const hargaRupiah = price != null ? Math.round(price / 100) : null; const terpenuhi = cur.target != null && hargaRupiah != null && hargaRupiah <= cur.target; return { appid: info.appid, name: info.name, price: info.price, target: cur.target, targetText: cur.target != null ? 'Rp' + new Intl.NumberFormat('id-ID').format(cur.target) : null, hargaRupiah, terpenuhi, pertama: cur.history[0], terendah: cur.history.reduce((m, h) => (h.final != null && (m == null || h.final < m) ? h.final : m), null), poin: cur.history.length, riwayat: cur.history.slice(-10), }; }; /* ------------------------------------------------- pemain & pasar (baru) */ /** Jumlah pemain yang sedang online untuk satu appid. */ const pemainSekarang = async (appid) => { const id = String(appid || '').trim(); if (!/^\d+$/.test(id)) throw new SteamError('appid harus angka.', { code: 'BAD_INPUT' }); const d = await getJSON(`${API}/ISteamUserStats/GetNumberOfCurrentPlayers/v1/?appid=${id}`); const n = d?.response?.player_count; if (typeof n !== 'number') throw new SteamError('Steam tidak mengirim jumlah pemain.', { code: 'NO_DATA' }); return { appid: Number(id), pemain: n }; }; /** * Harga item Steam Community Market (skin, kartu, dll). * currency: 1 = USD, 2 = GBP, 3 = EUR. Steam tidak menyediakan IDR di sini. */ const hargaPasar = async (appid, nama, { currency = 1 } = {}) => { const id = String(appid || '').trim(); if (!/^\d+$/.test(id)) throw new SteamError('appid harus angka.', { code: 'BAD_INPUT' }); const item = String(nama || '').trim(); if (!item) throw new SteamError('Nama item kosong.', { code: 'BAD_INPUT' }); const url = `${COMMUNITY}/market/priceoverview/?appid=${id}¤cy=${currency}&market_hash_name=${encodeURIComponent(item)}`; const d = await getJSON(url); if (!d.success) throw new SteamError(`Item tidak ditemukan di pasar: ${item}`, { code: 'NOT_FOUND' }); return { appid: Number(id), item, lowest: d.lowest_price || null, median: d.median_price || null, volume: d.volume ? Number(String(d.volume).replace(/[^0-9]/g, '')) : null, }; }; /** Profil publik Steam (XML) — tanpa login, selama profilnya tidak privat penuh. */ const profil = async (steamid) => { const q = String(steamid || '').trim(); if (!q) throw new SteamError('SteamID atau nama kustom kosong.', { code: 'BAD_INPUT' }); const jenis = /^\d{17}$/.test(q) ? 'profiles' : 'id'; const res = await fetch(`${COMMUNITY}/${jenis}/${encodeURIComponent(q)}/?xml=1`, { headers: { 'User-Agent': UA, 'Accept': 'text/xml,application/xml' }, }); if (!res.ok) throw new SteamError(`Profil tidak bisa dibaca (HTTP ${res.status})`, { code: 'HTTP', status: res.status }); const xml = await res.text(); if (!//i.test(xml)) throw new SteamError('Profil tidak ditemukan atau privat.', { code: 'NOT_FOUND' }); const ambil = (tag) => { const m = xml.match(new RegExp(`<${tag}>(?:)?`, 'i')); return m ? m[1].trim() : null; }; const num = (tag) => { const v = ambil(tag); return v != null && /^\d+$/.test(v) ? Number(v) : null; }; return { steamId64: ambil('steamID64') || (/^\d{17}$/.test(q) ? q : null), nama: ambil('steamID'), online: ambil('onlineState'), status: ambil('stateMessage'), privasi: ambil('privacyState'), level: num('level'), avatar: ambil('avatarFull') || ambil('avatarMedium'), terdaftar: ambil('memberSince'), lokasi: ambil('location'), ringkasan: ambil('summary'), namaAsli: ambil('realname'), }; }; /** Terlaris / rilis baru / segera hadir — dari blok featuredcategories. */ const daftarToko = async (jenis = 'top_sellers', { cc = 'id', lang = 'indonesian' } = {}) => { const blok = ['top_sellers', 'new_releases', 'coming_soon', 'specials']; if (!blok.includes(jenis)) throw new SteamError(`Jenis harus salah satu: ${blok.join(', ')}`, { code: 'BAD_INPUT' }); const d = await getJSON(`${STORE}/api/featuredcategories?cc=${normalizeCC(cc)}&l=${lang}`); const items = d[jenis]?.items || []; return items.map((it) => { const currency = it.currency || 'IDR'; const harga = it.final_price ?? null; return { appid: it.id, name: it.name, discount: it.discount_percent ?? 0, harga, hargaText: harga != null && harga > 0 ? fmtMoney(harga, currency) : (it.final_price === 0 ? 'gratis' : null), rilis: it.release_date ?? null, }; }); }; const daftarPantau = () => { const db = bacaWatch(); return Object.values(db).map((e) => ({ appid: e.appid, name: e.name, target: e.target, last: e.history?.[e.history.length - 1] || null, checkedAt: e.checkedAt || null, poin: e.history?.length || 0, })); }; const hapusPantau = (appid) => { const db = bacaWatch(); const key = String(appid); if (!db[key]) return false; delete db[key]; tulisWatch(db); return true; }; /* ------------------------------------------------------- API resmi (key) */ const APIKEY_PATH = path.join(NYX_DIR, 'steam-apikey'); const bacaApiKey = () => { if (process.env.STEAM_API_KEY) return process.env.STEAM_API_KEY.trim(); try { return fs.readFileSync(APIKEY_PATH, 'utf8').trim() || null; } catch { return null; } }; const simpanApiKey = (key) => { const k = String(key || '').trim(); if (!/^[0-9A-Fa-f]{32}$/.test(k)) throw new SteamError('API key harus 32 karakter heksadesimal.', { code: 'BAD_KEY' }); fs.mkdirSync(NYX_DIR, { recursive: true }); fs.writeFileSync(APIKEY_PATH, k, { mode: 0o600 }); return k; }; const perlu = () => { const k = bacaApiKey(); if (!k) throw new SteamError('Belum ada API key. Ambil di steamcommunity.com/dev/apikey lalu: nyx-steam api ', { code: 'NO_KEY' }); return k; }; /** Profil lewat API resmi — lebih lengkap daripada XML. */ const profilApi = async (steamids) => { const key = perlu(); const ids = [].concat(steamids).join(','); const d = await getJSON(`${API}/ISteamUser/GetPlayerSummaries/v2/?key=${key}&steamids=${ids}`); return (d?.response?.players || []).map((p) => ({ steamId64: p.steamid, nama: p.personaname, namaAsli: p.realname || null, url: p.profileurl, avatar: p.avatarfull, status: p.personastate, negara: p.locality || p.countrycode || null, dibuat: p.timecreated ? new Date(p.timecreated * 1000).toISOString().slice(0, 10) : null, terakhirOnline: p.lastlogoff ? new Date(p.lastlogoff * 1000).toISOString().slice(0, 10) : null, sedangMain: p.gameextrainfo ? { appid: p.gameid, nama: p.gameextrainfo } : null, })); }; /** Daftar game yang dimiliki + jam main (profil harus publik). */ const daftarGame = async (steamid) => { const key = perlu(); const d = await getJSON(`${API}/IPlayerService/GetOwnedGames/v1/?key=${key}&steamid=${steamid}&include_appinfo=1&include_played_free_games=1`); const g = d?.response?.games || []; return { jumlah: d?.response?.game_count ?? g.length, totalJam: Math.round(g.reduce((s, x) => s + (x.playtime_forever || 0), 0) / 60), items: g.sort((a, b) => b.playtime_forever - a.playtime_forever).map((x) => ({ appid: x.appid, name: x.name, jam: Math.round((x.playtime_forever || 0) / 60), jam2minggu: Math.round((x.playtime_2weeks || 0) / 60), })), }; }; /** Daftar teman (jika publik). */ const daftarTeman = async (steamid) => { const key = perlu(); const d = await getJSON(`${API}/ISteamUser/GetFriendList/v1/?key=${key}&steamid=${steamid}&relationship=friend`); return (d?.friendslist?.friends || []).map((f) => f.steamid); }; /** Pencapaian untuk satu game. */ const capaian = async (steamid, appid) => { const key = perlu(); const d = await getJSON(`${API}/ISteamUserStats/GetPlayerAchievements/v1/?key=${key}&steamid=${steamid}&appid=${appid}&l=indonesian`); const st = d?.playerstats; if (st?.error) throw new SteamError(st.error, { code: 'NO_STATS' }); const list = st?.achievements || []; const buka = list.filter((a) => a.achieved === 1); return { appid: Number(appid), total: list.length, terbuka: buka.length, items: list.slice(0, 40) }; }; /* ============================ CLI ============================ */ // NYX PROJECT — CLI modul steam // 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: // cari cari aplikasi di toko // info detail satu aplikasi // diskon [--maks N] yang sedang diskon // pantau catat harga, opsional --target // daftar semua yang dipantau // hapus berhenti memantau // berita [--n N] berita terbaru // pemain jumlah pemain online sekarang // pasar harga item Community Market // profil profil publik Steam // terlaris / baru / segera // bantuan menu ini // // Flag umum: --json, --cc= const argv = process.argv.slice(2); const flag = (name, def = null) => { const i = argv.findIndex((a) => a === `--${name}` || a.startsWith(`--${name}=`)); if (i < 0) return def; 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(flag('cc', process.env.STEAM_CC || 'id')); const W = Math.min(process.stdout.isTTY ? (process.stdout.columns || 74) : 74, 82); const garis = (ch = '─') => ch.repeat(W); const box = (title, lines) => { const out = [garis('─'), ` ${title}`, garis('─'), ...lines, garis('─')]; return out.join('\n'); }; const rp = (n) => 'Rp' + new Intl.NumberFormat('id-ID').format(Math.round((n ?? 0) / 100)); const help = () => { console.log(` ${BRAND.name} · steam ${BRAND.tagline} ${garis('─')} cari cari aplikasi di toko Steam info harga, genre, platform, skor diskon [--maks 10] daftar yang sedang diskon pantau catat harga sekarang --target 150000 tandai batas harga (Rupiah penuh) daftar semua yang dipantau hapus berhenti memantau berita [--n 5] kabar terbaru dari game pemain jumlah pemain online sekarang pasar harga item Community Market profil profil publik Steam terlaris / baru / segera daftar dari toko --- dengan API key (gratis di steamcommunity.com/dev/apikey) --- api simpan API key (mode 600) akun profil resmi + sedang main apa game daftar game + jam main teman daftar teman capaian Flag umum: --json --cc=id|us|sg (default: id) Contoh: node cli-steam.mjs cari hades node cli-steam.mjs info 1245620 node cli-steam.mjs diskon --maks 5 node cli-steam.mjs pantau 1245620 --target 350000 Riwayat harga: ${WATCH_PATH} ${creditLine()} `); }; const tulisHasil = (teks) => console.log(teks); const cmdCari = async (kata) => { const r = await search(kata, { cc: CC }); if (JSON_OUT) return console.log(JSON.stringify(r, null, 1)); if (!r.items.length) return console.log(`Tidak ada hasil untuk "${kata}".`); const lines = r.items.slice(0, 12).map((it) => { const harga = it.price ? (it.price.discount > 0 ? `${rp(it.price.final)} (${it.price.discount}% dari ${rp(it.price.initial)})` : rp(it.price.final)) : 'gratis / tanpa harga'; return ` ${String(it.appid).padEnd(8)} ${it.name.slice(0, 38).padEnd(38)} ${harga}`; }); tulisHasil(box(`Hasil untuk "${kata}" — ${r.total} entri (${CC})`, lines)); }; const cmdInfo = async (appid) => { const d = await appInfo(appid, { cc: CC }); if (JSON_OUT) return console.log(JSON.stringify(d, null, 1)); const harga = d.price ? (d.price.discount > 0 ? `${rp(d.price.final)} — diskon ${d.price.discount}% dari ${rp(d.price.initial)}` : rp(d.price.final)) : 'gratis'; const lines = [ ` ${d.name}`, ` appid ${d.appid} · ${d.type}${d.comingSoon ? ' · belum rilis' : ''}`, '', ` Harga ${harga}`, ` Rilis ${d.releaseDate || '—'}`, ` Pengembang ${d.developers.join(', ') || '—'}`, ` Penerbit ${d.publishers.join(', ') || '—'}`, ` Genre ${d.genres.join(', ') || '—'}`, ` Platform ${[d.platforms.windows && 'Windows', d.platforms.mac && 'macOS', d.platforms.linux && 'Linux'].filter(Boolean).join(' · ') || '—'}`, ` Metacritic ${d.metascore ?? '—'}`, ` Ulasan ${d.recommendations ? new Intl.NumberFormat('id-ID').format(d.recommendations) : '—'}`, ]; if (d.dlcCount) lines.push(` DLC ${d.dlcCount} item`); if (d.shortDescription) { lines.push('', ...wrap(d.shortDescription, W - 3).map((l) => ' ' + l)); } tulisHasil(box(`Steam · ${d.appid}`, lines)); }; const cmdDiskon = async () => { const maks = Number(flag('maks', 10)); const r = await specials({ cc: CC }); if (JSON_OUT) return console.log(JSON.stringify(r.slice(0, maks), null, 1)); if (!r.length) return console.log('Tidak ada diskon saat ini.'); const lines = r.slice(0, maks).map((it) => ` -${String(it.discount).padStart(2)}% ${it.name.slice(0, 34).padEnd(34)} ${rp(it.final)}`); tulisHasil(box(`Sedang diskon — ${CC.toUpperCase()} (${r.length} item)`, lines)); }; const cmdPantau = async (appid) => { const target = flag('target', null); const r = await pantau(appid, { target: target ? Number(target) : null, cc: CC }); if (JSON_OUT) return console.log(JSON.stringify(r, null, 1)); const harga = r.price ? `${rp(r.price.final)}${r.price.discount ? ` (−${r.price.discount}%)` : ''}` : 'gratis'; const lines = [ ` ${r.name}`, '', ` Harga kini ${harga}`, ` Terendah ${r.terendah != null ? rp(r.terendah) : '—'} (dari ${r.poin} catatan)`, ]; if (r.target != null) { lines.push(` Target ${r.targetText} → ${r.terpenuhi ? 'TERCAPAI' : 'belum'}`); } if (r.riwayat.length > 1) { lines.push('', ' Riwayat terakhir:'); for (const h of r.riwayat.slice(-4)) { lines.push(` ${h.at.slice(0, 10)} ${rp(h.final)}${h.discount ? ` (−${h.discount}%)` : ''}`); } } tulisHasil(box(`Pantau · ${r.appid}`, lines)); process.exitCode = r.terpenuhi ? 0 : 1; }; const cmdDaftar = () => { const list = daftarPantau(); if (JSON_OUT) return console.log(JSON.stringify(list, null, 1)); if (!list.length) return console.log(`Belum ada yang dipantau. Mulai: pantau `); const lines = list.map((e) => { const now = e.last?.final != null ? rp(e.last.final) : '—'; const tgt = e.target != null ? 'Rp' + new Intl.NumberFormat('id-ID').format(e.target) : '—'; return ` ${String(e.appid).padEnd(8)} ${e.name.slice(0, 30).padEnd(30)} ${now.padEnd(12)} target ${tgt}`; }); tulisHasil(box(`Dipantau — ${list.length} aplikasi`, lines)); }; const cmdHapus = (appid) => { const ok = hapusPantau(appid); console.log(ok ? `Dihapus dari pantauan: ${appid}` : `Tidak ada di pantauan: ${appid}`); }; const cmdApi = (kunci) => { simpanApiKey(kunci); console.log('API key tersimpan di ~/.nyx/steam-apikey (mode 600).'); }; const cmdAkun = async (id) => { const r = (await profilApi(id))[0]; if (!r) return console.log('Profil tidak ditemukan.'); if (JSON_OUT) return console.log(JSON.stringify(r, null, 1)); const lines = [ ` ${r.nama} (${r.steamId64})`, '', ` Dibuat ${r.dibuat || '—'}`, ` Terakhir ${r.terakhirOnline || '—'}`, ` Negara ${r.negara || '—'}`, ` Status ${r.sedangMain ? `sedang main ${r.sedangMain.nama}` : 'tidak sedang main'}`, ]; tulisHasil(box('Akun Steam', lines)); }; const cmdGame = async (id) => { const r = await daftarGame(id); if (JSON_OUT) return console.log(JSON.stringify(r, null, 1)); const lines = [` ${r.jumlah} game · ${new Intl.NumberFormat('id-ID').format(r.totalJam)} jam total`, '']; r.items.slice(0, 15).forEach((g) => lines.push(` ${String(g.jam).padStart(6)} jam ${g.name.slice(0, 40)}`)); tulisHasil(box('Koleksi Steam', lines)); }; const cmdTeman = async (id) => { const r = await daftarTeman(id); if (JSON_OUT) return console.log(JSON.stringify(r, null, 1)); const profilTeman = r.length ? await profilApi(r.slice(0, 30)).catch(() => []) : []; const lines = [` ${r.length} teman`, '']; profilTeman.forEach((t) => lines.push(` ${t.nama.slice(0, 34).padEnd(34)} ${t.sedangMain ? t.sedangMain.nama.slice(0, 24) : ''}`)); tulisHasil(box('Teman', lines)); }; const cmdCapaian = async (id, appid) => { const r = await capaian(id, appid); if (JSON_OUT) return console.log(JSON.stringify(r, null, 1)); const persen = r.total ? Math.round((r.terbuka / r.total) * 100) : 0; const lines = [` ${r.terbuka}/${r.total} terbuka (${persen}%)`, '']; r.items.filter((a) => a.achieved === 1).slice(0, 10).forEach((a) => lines.push(` ✔ ${a.name || a.apiname}`)); tulisHasil(box(`Pencapaian · appid ${r.appid}`, lines)); }; const cmdPemain = async (appid) => { const r = await pemainSekarang(appid); if (JSON_OUT) return console.log(JSON.stringify(r, null, 1)); let nama = `appid ${r.appid}`; try { nama = (await appInfo(r.appid, { cc: CC })).name; } catch {} tulisHasil(box(`Pemain online · ${nama}`, [` ${new Intl.NumberFormat('id-ID').format(r.pemain)} orang sedang bermain`, ` dicatat ${new Date().toISOString().slice(0, 16).replace('T', ' ')} UTC`])); }; const cmdPasar = async (appid, namaItem) => { const r = await hargaPasar(appid, namaItem, { currency: Number(flag('cur', 1)) }); if (JSON_OUT) return console.log(JSON.stringify(r, null, 1)); const lines = [ ` ${r.item}`, '', ` Terendah ${r.lowest ?? '—'}`, ` Median ${r.median ?? '—'}`, ` Terjual ${r.volume != null ? new Intl.NumberFormat('id-ID').format(r.volume) : '—'} dalam 24 jam`, ]; tulisHasil(box(`Pasar · appid ${r.appid}`, lines)); }; const cmdProfil = async (id) => { const r = await profil(id); if (JSON_OUT) return console.log(JSON.stringify(r, null, 1)); const lines = [ ` ${r.nama || '—'} (${r.steamId64 || '—'})`, '', ` Status ${r.online || '—'}${r.status ? ' · ' + r.status : ''}`, ` Privasi ${r.privasi || '—'}`, ` Level ${r.level ?? '—'}`, ` Terdaftar ${r.terdaftar || '—'}`, ` Lokasi ${r.lokasi || '—'}`, ]; if (r.ringkasan) lines.push('', ...wrap(r.ringkasan, W - 3).map((l) => ' ' + l)); tulisHasil(box('Profil Steam', lines)); }; const cmdDaftarToko = async (jenis) => { const maks = Number(flag('maks', 10)); const r = await daftarToko(jenis, { cc: CC }); if (JSON_OUT) return console.log(JSON.stringify(r.slice(0, maks), null, 1)); const judul = { top_sellers: 'Terlaris', new_releases: 'Rilis baru', coming_soon: 'Segera hadir', specials: 'Diskon' }[jenis]; if (!r.length) return console.log(`Tidak ada data untuk ${judul.toLowerCase()}.`); const lines = r.slice(0, maks).map((it) => ` ${String(it.appid).padEnd(8)} ${it.name.slice(0, 36).padEnd(36)} ${it.hargaText ?? (it.rilis || '—')}`); tulisHasil(box(`${judul} — ${CC.toUpperCase()}`, lines)); }; const cmdBerita = async (appid, n) => { const r = await news(appid, { count: n }); if (JSON_OUT) return console.log(JSON.stringify(r, null, 1)); if (!r.items.length) return console.log('Belum ada berita untuk appid ini.'); const lines = []; r.items.forEach((it, i) => { lines.push(` ${i + 1}. ${it.title.slice(0, W - 6)}`); lines.push(` ${it.at.slice(0, 10)} · ${it.feed}`); if (it.excerpt) lines.push(...wrap(it.excerpt, W - 5).map((l) => ' ' + l)); lines.push(''); }); tulisHasil(box(`Berita · appid ${r.appid}`, lines.slice(0, -1))); }; function wrap(text, width) { const kata = String(text).split(/\s+/); const out = []; let baris = ''; for (const k of kata) { if ((baris + ' ' + k).trim().length > width) { if (baris) out.push(baris.trim()); baris = k; } else baris += ' ' + k; } if (baris.trim()) out.push(baris.trim()); return out; } const main = async () => { const cmd = (argv.find((a) => !a.startsWith('--')) || 'bantuan').toLowerCase(); const sisa = argv.filter((a) => !a.startsWith('--')); const arg1 = sisa[1]; try { if (cmd === 'cari' || cmd === 'search') return await cmdCari(sisa.slice(1).join(' ')); if (cmd === 'info') return await cmdInfo(arg1); if (cmd === 'diskon' || cmd === 'promo') return await cmdDiskon(); if (cmd === 'pantau') return await cmdPantau(arg1); if (cmd === 'daftar') return cmdDaftar(); if (cmd === 'hapus') return cmdHapus(arg1); if (cmd === 'berita' || cmd === 'news') return await cmdBerita(arg1, Number(flag('n', 5))); if (cmd === 'pemain' || cmd === 'players') return await cmdPemain(arg1); if (cmd === 'pasar' || cmd === 'market') return await cmdPasar(arg1, sisa.slice(2).join(' ')); if (cmd === 'profil' || cmd === 'profile') return await cmdProfil(arg1); if (cmd === 'terlaris') return await cmdDaftarToko('top_sellers'); if (cmd === 'baru') return await cmdDaftarToko('new_releases'); if (cmd === 'segera') return await cmdDaftarToko('coming_soon'); if (cmd === 'api') return cmdApi(arg1); if (cmd === 'akun') return await cmdAkun(arg1); if (cmd === 'game') return await cmdGame(arg1); if (cmd === 'teman') return await cmdTeman(arg1); if (cmd === 'capaian') return await cmdCapaian(arg1, sisa[2]); if (cmd === 'bantuan' || cmd === 'help' || cmd === 'about') return help(); // kalau bukan perintah yang dikenal, anggap kata kunci pencarian return await cmdCari(sisa.join(' ')); } catch (err) { if (err instanceof SteamError) { console.error(`Gagal: ${err.message}`); process.exitCode = 2; } else { console.error(`Gagal: ${err.message}`); process.exitCode = 3; } } }; main();