// Export the chatbot's canned answers (the code-checked official knowledge) as Markdown for other assistants, e.g. the // Earners Corner forum assistant (Marty 2026-11-10). Usage: node tools/export-knowledge.js 'use strict'; const fs = require('fs'); const path = require('path'); const src = fs.readFileSync(path.join(__dirname, '..', 'chatbot.js'), 'utf8'); // read a single-quoted JS string literal starting at index i (the opening quote) function str(i) { let s = ''; for (i++; i < src.length; i++) { const ch = src[i]; if (ch === '\\') { s += src[++i]; continue; } if (ch === "'") return { s, end: i }; s += ch; } return { s, end: i }; } let out = '# InstantAdPay official knowledge\n\nSource: the InstantAdPay chatbot canned answers (code-checked). Exported ' + new Date().toISOString().slice(0, 10) + '.\n\n', n = 0; const re = /\{ id: '([a-z0-9-]+)', title: '/g; let m; while ((m = re.exec(src))) { const title = str(m.index + m[0].length - 1); const qStart = src.indexOf('q: [', title.end), qEnd = src.indexOf(']', qStart); const qs = []; for (let i = src.indexOf("'", qStart); i > 0 && i < qEnd; i = src.indexOf("'", i + 1)) { const q = str(i); qs.push(q.s); i = q.end; } const a = src.indexOf("a: '", qEnd); const ans = str(a + 3); out += '## ' + title.s + '\n\nQuestions people ask: ' + qs.join(' | ') + '\n\n' + ans.s + '\n\n'; n++; } fs.writeFileSync(process.argv[2] || 'instantadpay-knowledge.md', out); console.log('entries', n, 'chars', out.length);