INNER CODE UNIT · JavaScript

api

pamgarcia1993/robinhood-lp-bot · legacy/bot.js:24

const api = (m, b) => fetch(`https://api.telegram.org/bot${TOKEN}/${m}`, {
  method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(b), signal: AbortSignal.timeout(35_000),
}).then((r) => r.json()).catch(() => null);
const send = (t, extra = {}) => api("sendMessage", { chat_id: chatId, text: t, parse_mode: "HTML", disable_web_page_preview: true, ...extra });
const edit = (mid, t, extra = {}) => api("editMessageText", { chat_id: chatId, message_id: mid, text: t, parse_mode: "HTML", disable_web_page_preview: true, ...extra });
// Nulis config: MERGE sama isi disk, jangan timpa mentah-mentah.
// (Dulu bug: cfg di memori itu snapshot saat start; kalau file diedit pas bot jalan,
//  saveCfg bakal ngehapus key baru itu diam-diam.)
const saveCfg = () => {
  cfg.telegramChatId = chatId;
  let disk = {}; try { disk = JSON.parse(fs.readFileSync(CFG, "utf8")); } catch { /* baru */ }
  const merged = { ...disk, ...cfg, lp: { ...(disk.lp || {}), ...(cfg.lp || {}) }, contracts: { ...(disk.contracts || {}), ...(cfg.contracts || {}) } };
  fs.writeFileSync(CFG, JSON.stringify(merged, null, 2));
};

const pending = new Map(); // chat → { token, pools }
const exp = (n) => cfg.explorer + "/tx/" + n;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…