-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.mjs
More file actions
102 lines (91 loc) · 3.77 KB
/
Copy pathindex.mjs
File metadata and controls
102 lines (91 loc) · 3.77 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env node
/**
* Solana rug-check Telegram bot — MadeOnSol API starter.
*
* Paste token mint address(es) in a Telegram chat → get back a scored
* rug-risk report. Zero dependencies (raw Telegram Bot API long polling).
*
* - PRO/ULTRA key → full 0–100 rug-risk score with 10 auditable factors
* - Free key → 0–100 early-buyer quality score (dump clusters, bots, KOLs)
*
* Free API key: https://madeonsol.com/pricing
* Telegram bot token: talk to @BotFather → /newbot
*
* CLI mode (no Telegram needed): node index.mjs <mint> [mint...]
*/
import { extractMints, checkMints, formatReport, HELP_TEXT } from "./lib.mjs";
const KEY = process.env.MADEONSOL_API_KEY;
const TG = process.env.TELEGRAM_BOT_TOKEN;
const API_BASE = process.env.MADEONSOL_API_BASE || "https://madeonsol.com/api/v1";
if (!KEY) {
console.error("Missing MADEONSOL_API_KEY. Free key: https://madeonsol.com/pricing");
process.exit(1);
}
// ── CLI mode: node index.mjs <mint...> ──────────────────────────────────────
const cliMints = extractMints(process.argv.slice(2).join(" "));
if (cliMints.length > 0) {
const check = await checkMints(cliMints, { key: KEY, base: API_BASE });
console.log(`mode: ${check.mode}\n`);
console.log(formatReport(check).replace(/<[^>]+>/g, "")); // strip HTML for terminal
process.exit(0);
}
if (!TG) {
console.error("Missing TELEGRAM_BOT_TOKEN (from @BotFather).");
console.error("Tip: you can test without Telegram: node index.mjs <mint_address>");
process.exit(1);
}
// ── Telegram long polling (no framework, no deps) ───────────────────────────
const tg = async (method, payload) => {
const res = await fetch(`https://api.telegram.org/bot${TG}/${method}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
const data = await res.json();
if (!data.ok) throw new Error(`Telegram ${method}: ${data.description}`);
return data.result;
};
const send = (chat_id, text) =>
tg("sendMessage", { chat_id, text, parse_mode: "HTML", disable_web_page_preview: true })
.catch((err) => console.error("send failed:", err.message));
const me = await tg("getMe", {});
console.log(`@${me.username} is up. Paste mint addresses at it. (Ctrl-C to stop)`);
let offset = 0;
for (;;) {
let updates = [];
try {
updates = await tg("getUpdates", { offset, timeout: 50, allowed_updates: ["message"] });
} catch (err) {
console.error("poll error:", err.message);
await new Promise((r) => setTimeout(r, 5000));
continue;
}
for (const u of updates) {
offset = u.update_id + 1;
const msg = u.message;
if (!msg?.text || !msg.chat?.id) continue;
if (msg.text.startsWith("/start") || msg.text.startsWith("/help")) {
await send(msg.chat.id, HELP_TEXT);
continue;
}
const mints = extractMints(msg.text);
if (mints.length === 0) {
await send(msg.chat.id, "No mint address found — paste a Solana token mint (base58, 32–44 chars). /help for more.");
continue;
}
try {
const check = await checkMints(mints, { key: KEY, base: API_BASE });
await send(msg.chat.id, formatReport(check));
console.log(`checked ${mints.length} mint(s) for chat ${msg.chat.id} (${check.mode})`);
} catch (err) {
const hint = err.status === 429
? "Rate limited — free tier is 200 req/day. PRO is 10k/day: madeonsol.com/pricing"
: `Lookup failed (${err.message}). Try again in a moment.`;
await send(msg.chat.id, escape(hint));
console.error("check failed:", err.message);
}
}
}
function escape(s) {
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
}