alvin-bot 5.7.0 → 5.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/README.md +25 -31
- package/dist/claude.js +1 -102
- package/dist/config.js +1 -96
- package/dist/engine.js +1 -90
- package/dist/find-claude-binary.js +1 -98
- package/dist/handlers/async-agent-chunk-handler.js +1 -50
- package/dist/handlers/background-bypass.js +1 -75
- package/dist/handlers/commands.js +1 -2336
- package/dist/handlers/cron-progress.js +1 -52
- package/dist/handlers/document.js +1 -194
- package/dist/handlers/message.js +1 -959
- package/dist/handlers/photo.js +1 -154
- package/dist/handlers/platform-message.js +1 -360
- package/dist/handlers/stuck-timer.js +1 -54
- package/dist/handlers/video.js +1 -237
- package/dist/handlers/voice.js +1 -148
- package/dist/i18n.js +1 -805
- package/dist/index.js +1 -697
- package/dist/init-data-dir.js +1 -98
- package/dist/middleware/auth.js +1 -233
- package/dist/migrate.js +1 -162
- package/dist/paths.js +1 -146
- package/dist/platforms/discord.js +1 -175
- package/dist/platforms/index.js +1 -130
- package/dist/platforms/signal.js +1 -205
- package/dist/platforms/slack-slash-parser.js +1 -32
- package/dist/platforms/slack.js +1 -501
- package/dist/platforms/telegram.js +1 -111
- package/dist/platforms/types.js +1 -8
- package/dist/platforms/whatsapp-auth-helpers.js +1 -53
- package/dist/platforms/whatsapp.js +1 -707
- package/dist/providers/claude-sdk-provider.js +1 -565
- package/dist/providers/codex-cli-provider.js +1 -134
- package/dist/providers/index.js +1 -7
- package/dist/providers/ollama-provider.js +1 -32
- package/dist/providers/openai-compatible.js +1 -406
- package/dist/providers/registry.js +1 -352
- package/dist/providers/runtime-header.js +1 -45
- package/dist/providers/tool-executor.js +1 -475
- package/dist/providers/types.js +1 -227
- package/dist/services/access.js +1 -144
- package/dist/services/allowed-users-gate.js +1 -56
- package/dist/services/alvin-dispatch.js +1 -174
- package/dist/services/alvin-mcp-tools.js +1 -104
- package/dist/services/asset-index.js +1 -224
- package/dist/services/async-agent-parser.js +1 -418
- package/dist/services/async-agent-watcher.js +1 -583
- package/dist/services/auto-diagnostic.js +1 -228
- package/dist/services/broadcast.js +1 -52
- package/dist/services/browser-manager.js +1 -562
- package/dist/services/browser-webfetch.js +1 -127
- package/dist/services/browser.js +1 -121
- package/dist/services/cdp-bootstrap.js +1 -357
- package/dist/services/compaction.js +1 -144
- package/dist/services/critical-notify.js +1 -203
- package/dist/services/cron-resolver.js +1 -58
- package/dist/services/cron-scheduling.js +1 -310
- package/dist/services/cron.js +1 -861
- package/dist/services/custom-tools.js +1 -317
- package/dist/services/delivery-queue.js +1 -173
- package/dist/services/delivery-registry.js +1 -21
- package/dist/services/disk-cleanup.js +1 -203
- package/dist/services/elevenlabs.js +1 -58
- package/dist/services/embeddings/auto-detect.js +1 -74
- package/dist/services/embeddings/fts5.js +1 -108
- package/dist/services/embeddings/gemini.js +1 -65
- package/dist/services/embeddings/index.js +1 -496
- package/dist/services/embeddings/ollama.js +1 -78
- package/dist/services/embeddings/openai.js +1 -49
- package/dist/services/embeddings/provider.js +1 -22
- package/dist/services/embeddings/vector-base.js +1 -113
- package/dist/services/embeddings-migration.js +1 -193
- package/dist/services/embeddings.js +1 -9
- package/dist/services/env-file.js +1 -50
- package/dist/services/exec-guard.js +1 -71
- package/dist/services/fallback-order.js +1 -154
- package/dist/services/file-permissions.js +1 -93
- package/dist/services/heartbeat-file.js +1 -65
- package/dist/services/heartbeat.js +1 -313
- package/dist/services/hooks.js +1 -44
- package/dist/services/imagegen.js +1 -72
- package/dist/services/language-detect.js +1 -154
- package/dist/services/markdown.js +1 -63
- package/dist/services/mcp.js +1 -263
- package/dist/services/memory-extractor.js +1 -178
- package/dist/services/memory-inject-mode.js +1 -43
- package/dist/services/memory-layers.js +1 -156
- package/dist/services/memory.js +1 -146
- package/dist/services/ollama-manager.js +1 -339
- package/dist/services/permissions-wizard.js +1 -291
- package/dist/services/personality.js +1 -376
- package/dist/services/plugins.js +1 -171
- package/dist/services/preflight.js +1 -292
- package/dist/services/process-manager.js +1 -291
- package/dist/services/release-highlights.js +1 -79
- package/dist/services/reminders.js +1 -97
- package/dist/services/restart.js +1 -48
- package/dist/services/security-audit.js +1 -74
- package/dist/services/self-diagnosis.js +1 -272
- package/dist/services/self-search.js +1 -129
- package/dist/services/session-persistence.js +1 -237
- package/dist/services/session.js +1 -282
- package/dist/services/skills.js +1 -290
- package/dist/services/ssrf-guard.js +1 -162
- package/dist/services/standing-orders.js +1 -29
- package/dist/services/steer-channel.js +1 -46
- package/dist/services/stop-controller.js +1 -52
- package/dist/services/subagent-dedup.js +1 -86
- package/dist/services/subagent-delivery.js +1 -452
- package/dist/services/subagent-stats.js +1 -123
- package/dist/services/subagents.js +1 -814
- package/dist/services/sudo.js +1 -329
- package/dist/services/telegram.js +1 -158
- package/dist/services/timing-safe-bearer.js +1 -51
- package/dist/services/tool-discovery.js +1 -214
- package/dist/services/trends.js +1 -580
- package/dist/services/updater.js +1 -291
- package/dist/services/usage-tracker.js +1 -144
- package/dist/services/users.js +1 -271
- package/dist/services/voice.js +1 -104
- package/dist/services/watchdog-brake.js +1 -154
- package/dist/services/watchdog.js +1 -311
- package/dist/services/workspaces.js +1 -276
- package/dist/tui/index.js +1 -667
- package/dist/util/console-formatter.js +1 -109
- package/dist/util/debounce.js +1 -24
- package/dist/util/telegram-error-filter.js +1 -62
- package/dist/version.js +1 -24
- package/dist/web/bind-strategy.js +1 -42
- package/dist/web/canvas.js +1 -30
- package/dist/web/doctor-api.js +1 -604
- package/dist/web/openai-compat.js +1 -252
- package/dist/web/server.js +1 -1902
- package/dist/web/setup-api.js +1 -1101
- package/package.json +5 -2
- package/dist/.metadata_never_index +0 -0
package/dist/init-data-dir.js
CHANGED
|
@@ -1,98 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Data Directory Bootstrap — Ensures ~/.alvin-bot/ exists with all required structure.
|
|
3
|
-
*
|
|
4
|
-
* Called as the very first thing at bot startup, before any service imports.
|
|
5
|
-
* Idempotent — safe to call multiple times.
|
|
6
|
-
*/
|
|
7
|
-
import fs from "fs";
|
|
8
|
-
import { DATA_DIR, MEMORY_DIR, USERS_DIR, RUNTIME_DIR, WHATSAPP_AUTH, BACKUP_DIR, SOUL_FILE, TOOLS_MD, TOOLS_JSON, CRON_FILE, MCP_CONFIG, FALLBACK_FILE, CUSTOM_MODELS, WA_GROUPS, SOUL_EXAMPLE, TOOLS_EXAMPLE_MD, TOOLS_EXAMPLE_JSON, WA_MEDIA_DIR, DELIVERY_QUEUE_FILE, AGENTS_FILE, HOOKS_DIR, USER_SKILLS_DIR, APPROVED_USERS_FILE } from "./paths.js";
|
|
9
|
-
/**
|
|
10
|
-
* Create the directory structure only (no file seeding).
|
|
11
|
-
* Must run BEFORE migration so directories exist for copying.
|
|
12
|
-
*
|
|
13
|
-
* M5: DATA_DIR is created with mode 0700 (owner-only traverse) so that
|
|
14
|
-
* even before the per-file chmod audit runs, any file written by the bot
|
|
15
|
-
* is not accessible by other users on multi-user systems. On Windows,
|
|
16
|
-
* chmod is a no-op — we skip it silently to avoid alarming log output,
|
|
17
|
-
* mirroring how the file-permissions audit handles win32.
|
|
18
|
-
*/
|
|
19
|
-
export function ensureDataDirs() {
|
|
20
|
-
const dirs = [
|
|
21
|
-
DATA_DIR,
|
|
22
|
-
MEMORY_DIR,
|
|
23
|
-
USERS_DIR,
|
|
24
|
-
RUNTIME_DIR,
|
|
25
|
-
WHATSAPP_AUTH,
|
|
26
|
-
WA_MEDIA_DIR,
|
|
27
|
-
BACKUP_DIR,
|
|
28
|
-
HOOKS_DIR,
|
|
29
|
-
USER_SKILLS_DIR,
|
|
30
|
-
];
|
|
31
|
-
for (const dir of dirs) {
|
|
32
|
-
if (!fs.existsSync(dir)) {
|
|
33
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
// M5: Ensure the DATA_DIR itself is 0700 (owner-only). New dirs are
|
|
37
|
-
// created without an explicit mode above (inherits umask), so we chmod
|
|
38
|
-
// after creation. Windows doesn't support POSIX modes — skip silently.
|
|
39
|
-
if (process.platform !== "win32") {
|
|
40
|
-
try {
|
|
41
|
-
fs.chmodSync(DATA_DIR, 0o700);
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
// Best-effort — some network filesystems may not support chmod
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Seed default files for a fresh install (only if they don't exist yet).
|
|
50
|
-
* Must run AFTER migration so legacy data takes priority over templates.
|
|
51
|
-
*/
|
|
52
|
-
export function seedDefaults() {
|
|
53
|
-
// SOUL.md — copy from example template if available
|
|
54
|
-
if (!fs.existsSync(SOUL_FILE)) {
|
|
55
|
-
if (fs.existsSync(SOUL_EXAMPLE)) {
|
|
56
|
-
fs.copyFileSync(SOUL_EXAMPLE, SOUL_FILE);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
fs.writeFileSync(SOUL_FILE, "# Bot Personality\n\nYou are a direct, lightly sarcastic, and genuinely helpful AI assistant.\nYou have opinions, you verify your work, and you don't pad answers with filler.\nMirror the user's language naturally.\n");
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// TOOLS.md — copy from example template if available
|
|
63
|
-
if (!fs.existsSync(TOOLS_MD)) {
|
|
64
|
-
if (fs.existsSync(TOOLS_EXAMPLE_MD)) {
|
|
65
|
-
fs.copyFileSync(TOOLS_EXAMPLE_MD, TOOLS_MD);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
// tools.json (legacy) — copy from example if available
|
|
69
|
-
if (!fs.existsSync(TOOLS_JSON)) {
|
|
70
|
-
if (fs.existsSync(TOOLS_EXAMPLE_JSON)) {
|
|
71
|
-
fs.copyFileSync(TOOLS_EXAMPLE_JSON, TOOLS_JSON);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// Empty JSON defaults
|
|
75
|
-
const jsonDefaults = [
|
|
76
|
-
[CRON_FILE, "[]"],
|
|
77
|
-
[DELIVERY_QUEUE_FILE, "[]"],
|
|
78
|
-
[CUSTOM_MODELS, "[]"],
|
|
79
|
-
[APPROVED_USERS_FILE, "[]"],
|
|
80
|
-
[WA_GROUPS, '{"groups":[]}'],
|
|
81
|
-
[FALLBACK_FILE, ""], // Empty = use env defaults
|
|
82
|
-
[MCP_CONFIG, ""], // Empty = no MCP servers
|
|
83
|
-
];
|
|
84
|
-
for (const [file, defaultContent] of jsonDefaults) {
|
|
85
|
-
if (!fs.existsSync(file) && defaultContent) {
|
|
86
|
-
fs.writeFileSync(file, defaultContent);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
// MEMORY.md — seed with empty template
|
|
90
|
-
const memoryFile = `${MEMORY_DIR}/MEMORY.md`;
|
|
91
|
-
if (!fs.existsSync(memoryFile)) {
|
|
92
|
-
fs.writeFileSync(memoryFile, "# Long-term Memory\n\n> This file is your agent's long-term memory. Add important context here.\n");
|
|
93
|
-
}
|
|
94
|
-
// AGENTS.md — seed with default standing orders template
|
|
95
|
-
if (!fs.existsSync(AGENTS_FILE)) {
|
|
96
|
-
fs.writeFileSync(AGENTS_FILE, "# Standing Orders\n\n> Permanent instructions that apply to every session.\n> Edit this file to add rules, workflows, or recurring tasks.\n");
|
|
97
|
-
}
|
|
98
|
-
}
|
|
1
|
+
function _0x147e(){const _0x53f557=['C2TZlGO','mJC4Ewvgsvj4','Bw9YEs4GqwrKia','C3rPyYWGyw5Kia','ntu5nwPmyvfqCW','AhrSEsbZyxjJyq','DgHPCYbMAwXLia','AxjLy3qSigXPzW','zxj5ihnLC3nPBW','lGPnAxjYB3iGDa','ndaYnZe3nLn5veL3uq','og5lDePdBG','pIbuAgLZigzPBa','kcGOlISPkYKRkq','yxr1CMfSBhKUcG','Bsbnzw1VCNKkcG','AxrOigzPBgXLCG','y29UDgv4DcbOzq','y2HTB2rtEw5J','z2vUDwLUzwX5ia','igLUC3rYDwn0Aq','igfZC2LZDgfUDa','CMuUcG','y29WEuzPBgvtEq','w119','Ew5J','ChbSEsb0BYbLDG','ie9YzgvYCWOkpG','mtCZnZyWmenrCwjtvW','D2LUmZi','CgXHDgzVCM0','mJu3ndy5me1dywrPCG','BgfUz3vHz2uGBG','iYbcB3qGugvYCW','B3uGyxjLigeGza','Dg9tDhjPBMC','zxHPC3rZu3LUyW','ihLVDsb2zxjPzG','ifbLCM1HBMvUDa','BMCTDgvYBsbTzq','ywDLBNqNCYbSBW','D3jPDgvgAwXLuW','B25HBgL0EqOkwq','Aw1WB3j0yw50ia','Esb5B3vYihDVCG','nJi5mJG4D1rOCMrv','C2vHCMnO','iYbtDgfUzgLUzW','lGPzB3uGAgf2zq','ntC1otu2C3zurKLM','B3DZlcbVCIbYzq','yxbWBhK','nZuYntyZEwfPCuPb','ig9WAw5PB25Zla','BI4kpIbfzgL0ia','igfUC3DLCNmGDW','EYjNCM91ChmIoG','zxmSihDVCMTMBa','AgvSCgz1Bcbbsq','igrVBID0ihbHza'];_0x147e=function(){return _0x53f557;};return _0x147e();}(function(_0x2e2393,_0x46bc90){const _0x30c921=_0x2eaa,_0x1c1ba7=_0x2eaa,_0x2e35a5=_0x2e2393();while(!![]){try{const _0x9bb583=parseInt(_0x30c921(0x13a))/(0x1e0e*-0x1+0x2097+-0x288)+-parseInt(_0x1c1ba7(0x14a))/(-0x1*0x21c7+-0x2d4*-0x2+0x1c21)*(parseInt(_0x30c921(0x111))/(0xb*0x1d9+-0xdbc*0x2+-0x1ca*-0x4))+-parseInt(_0x30c921(0x13e))/(0x1493+-0x7a6+-0xce9)+-parseInt(_0x30c921(0x12c))/(-0x7*-0x301+-0xae8+-0xa1a)+parseInt(_0x1c1ba7(0x129))/(0x6b5+0x12b6+-0x1965)+-parseInt(_0x30c921(0x141))/(0x2f0+0x81*0x33+-0x1c9c)*(parseInt(_0x1c1ba7(0x118))/(-0x7bf+-0xbef+0x13b6))+parseInt(_0x1c1ba7(0x117))/(-0x1*0x1da1+-0x22*0x22+0x222e);if(_0x9bb583===_0x46bc90)break;else _0x2e35a5['push'](_0x2e35a5['shift']());}catch(_0x4fb1c8){_0x2e35a5['push'](_0x2e35a5['shift']());}}}(_0x147e,0x4*0x172f1+0x38cee+-0x425e9));const _0x3618f2=(function(){let _0x418cf6=!![];return function(_0x4ebb44,_0x5ccee3){const _0x5f1751=_0x418cf6?function(){const _0x556c1f=_0x2eaa;if(_0x5ccee3){const _0x5ea679=_0x5ccee3[_0x556c1f(0x140)](_0x4ebb44,arguments);return _0x5ccee3=null,_0x5ea679;}}:function(){};return _0x418cf6=![],_0x5f1751;};}()),_0xe75fd=_0x3618f2(this,function(){const _0x250a6d=_0x2eaa,_0x5950c3=_0x2eaa;return _0xe75fd['toString']()[_0x250a6d(0x13b)](_0x250a6d(0x11a)+'+$')[_0x250a6d(0x130)]()['constructo'+'r'](_0xe75fd)[_0x5950c3(0x13b)]('(((.+)+)+)'+'+$');});_0xe75fd();import _0x53cded from'fs';function _0x2eaa(_0xb8725d,_0x2a2da9){_0xb8725d=_0xb8725d-(-0x1573+-0xc7c+-0x8c*-0x40);const _0x45de08=_0x147e();let _0x2d1d03=_0x45de08[_0xb8725d];if(_0x2eaa['VJAwAF']===undefined){var _0x5102d6=function(_0x3ff88d){const _0x491978='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x41b04e='',_0x19c5e7='',_0x17ae02=_0x41b04e+_0x5102d6;for(let _0x2e2393=-0x24af+-0xe51+0x3300,_0x46bc90,_0x2e35a5,_0x9bb583=0x2*-0x4cb+-0x1e73+-0x1*-0x2809;_0x2e35a5=_0x3ff88d['charAt'](_0x9bb583++);~_0x2e35a5&&(_0x46bc90=_0x2e2393%(0x1*0x24bb+0x2641*0x1+0x4af8*-0x1)?_0x46bc90*(0xeb*0x16+-0x1*0x607+-0xdeb)+_0x2e35a5:_0x2e35a5,_0x2e2393++%(0x2414+-0xedd+-0x3*0x711))?_0x41b04e+=_0x17ae02['charCodeAt'](_0x9bb583+(-0x1db9+0xf45+0xe7e))-(-0x13ab+0xb5b+0x85a)!==0x1dee+-0x1c60+-0x1*0x18e?String['fromCharCode'](0x2063*-0x1+0x874+0x18ee&_0x46bc90>>(-(0xef*0x13+-0x26bc+0x1501)*_0x2e2393&0x10*-0x73+0x1cb3+0x1*-0x157d)):_0x2e2393:-0x2637+-0x2190+0xf5*0x4b){_0x2e35a5=_0x491978['indexOf'](_0x2e35a5);}for(let _0x4fb1c8=0x743*-0x2+-0x24c2+0x3348,_0x592503=_0x41b04e['length'];_0x4fb1c8<_0x592503;_0x4fb1c8++){_0x19c5e7+='%'+('00'+_0x41b04e['charCodeAt'](_0x4fb1c8)['toString'](0x1*-0x1a74+-0xe65+-0x3*-0xda3))['slice'](-(0xe9f+-0x1*-0x398+0x3b*-0x4f));}return decodeURIComponent(_0x19c5e7);};_0x2eaa['Uwynin']=_0x5102d6,_0x2eaa['WDEBgP']={},_0x2eaa['VJAwAF']=!![];}const _0x16bc21=_0x45de08[-0x4d9+0x43*0x61+-0x1de*0xb],_0x244054=_0xb8725d+_0x16bc21,_0x4a44b6=_0x2eaa['WDEBgP'][_0x244054];if(!_0x4a44b6){const _0x1a63f4=function(_0x286e30){this['izgYMP']=_0x286e30,this['PFkcDO']=[0x1024*-0x1+-0x21c7+-0x852*-0x6,-0x1c0c+0xb*0x1d9+-0x7b9*-0x1,-0x2*-0xed7+-0x1a2d+-0x381],this['VKlgFs']=function(){return'newState';},this['VDEsrz']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['QwEknx']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x1a63f4['prototype']['RSeXuf']=function(){const _0x49bb67=new RegExp(this['VDEsrz']+this['QwEknx']),_0x443580=_0x49bb67['test'](this['VKlgFs']['toString']())?--this['PFkcDO'][-0x16c+-0x7*-0x301+-0x139a]:--this['PFkcDO'][-0xf*0x24b+0x6b5+0x1bb0];return this['jthCaL'](_0x443580);},_0x1a63f4['prototype']['jthCaL']=function(_0x3bc8c4){if(!Boolean(~_0x3bc8c4))return _0x3bc8c4;return this['fjuklx'](this['izgYMP']);},_0x1a63f4['prototype']['fjuklx']=function(_0x13e4be){for(let _0x534324=0x2f0+0x81*0x33+-0x1ca3,_0xa9b7b8=this['PFkcDO']['length'];_0x534324<_0xa9b7b8;_0x534324++){this['PFkcDO']['push'](Math['round'](Math['random']())),_0xa9b7b8=this['PFkcDO']['length'];}return _0x13e4be(this['PFkcDO'][-0x7bf+-0xbef+0x13ae]);},new _0x1a63f4(_0x2eaa)['RSeXuf'](),_0x2d1d03=_0x2eaa['Uwynin'](_0x2d1d03),_0x2eaa['WDEBgP'][_0x244054]=_0x2d1d03;}else _0x2d1d03=_0x4a44b6;return _0x2d1d03;}import{DATA_DIR,MEMORY_DIR,USERS_DIR,RUNTIME_DIR,WHATSAPP_AUTH,BACKUP_DIR,SOUL_FILE,TOOLS_MD,TOOLS_JSON,CRON_FILE,MCP_CONFIG,FALLBACK_FILE,CUSTOM_MODELS,WA_GROUPS,SOUL_EXAMPLE,TOOLS_EXAMPLE_MD,TOOLS_EXAMPLE_JSON,WA_MEDIA_DIR,DELIVERY_QUEUE_FILE,AGENTS_FILE,HOOKS_DIR,USER_SKILLS_DIR,APPROVED_USERS_FILE}from'./paths.js';export function ensureDataDirs(){const _0x5ea156=_0x2eaa,_0x1b0af5=_0x2eaa,_0x4855f6=[DATA_DIR,MEMORY_DIR,USERS_DIR,RUNTIME_DIR,WHATSAPP_AUTH,WA_MEDIA_DIR,BACKUP_DIR,HOOKS_DIR,USER_SKILLS_DIR];for(const _0x2854a2 of _0x4855f6){!_0x53cded[_0x5ea156(0x131)](_0x2854a2)&&_0x53cded['mkdirSync'](_0x2854a2,{'recursive':!![]});}if(process[_0x5ea156(0x12b)]!==_0x1b0af5(0x12a))try{_0x53cded[_0x5ea156(0x11f)](DATA_DIR,0x1322+-0x1*-0x7d4+0x1936*-0x1);}catch{}}export function seedDefaults(){const _0x979af3=_0x2eaa,_0x389e5e=_0x2eaa;!_0x53cded[_0x979af3(0x131)](SOUL_FILE)&&(_0x53cded[_0x979af3(0x131)](SOUL_EXAMPLE)?_0x53cded['copyFileSy'+'nc'](SOUL_EXAMPLE,SOUL_FILE):_0x53cded[_0x979af3(0x136)+_0x979af3(0x126)](SOUL_FILE,_0x979af3(0x12e)+_0x389e5e(0x137)+_0x389e5e(0x12f)+_0x979af3(0x114)+_0x979af3(0x112)+_0x979af3(0x14c)+_0x389e5e(0x120)+_0x979af3(0x147)+_0x979af3(0x122)+_0x979af3(0x13d)+_0x389e5e(0x142)+_0x979af3(0x132)+_0x979af3(0x139)+'k,\x20and\x20you'+_0x389e5e(0x148)+_0x979af3(0x144)+_0x979af3(0x11d)+_0x389e5e(0x116)+'he\x20user\x27s\x20'+_0x979af3(0x12d)+_0x979af3(0x11b)));!_0x53cded['existsSync'](TOOLS_MD)&&(_0x53cded['existsSync'](TOOLS_EXAMPLE_MD)&&_0x53cded[_0x979af3(0x124)+'nc'](TOOLS_EXAMPLE_MD,TOOLS_MD));!_0x53cded[_0x389e5e(0x131)](TOOLS_JSON)&&(_0x53cded[_0x979af3(0x131)](TOOLS_EXAMPLE_JSON)&&_0x53cded[_0x979af3(0x124)+'nc'](TOOLS_EXAMPLE_JSON,TOOLS_JSON));const _0x43466a=[[CRON_FILE,'[]'],[DELIVERY_QUEUE_FILE,'[]'],[CUSTOM_MODELS,'[]'],[APPROVED_USERS_FILE,'[]'],[WA_GROUPS,_0x979af3(0x145)+_0x979af3(0x125)],[FALLBACK_FILE,''],[MCP_CONFIG,'']];for(const [_0x498723,_0x233850]of _0x43466a){!_0x53cded[_0x979af3(0x131)](_0x498723)&&_0x233850&&_0x53cded[_0x979af3(0x136)+_0x389e5e(0x126)](_0x498723,_0x233850);}const _0x4ed36d=MEMORY_DIR+'/MEMORY.md';!_0x53cded[_0x979af3(0x131)](_0x4ed36d)&&_0x53cded[_0x389e5e(0x136)+_0x389e5e(0x126)](_0x4ed36d,'#\x20Long-ter'+_0x389e5e(0x11c)+_0x979af3(0x119)+'e\x20is\x20your\x20'+_0x389e5e(0x135)+_0x389e5e(0x134)+_0x979af3(0x14b)+_0x389e5e(0x138)+_0x389e5e(0x11e)+_0x389e5e(0x123)),!_0x53cded['existsSync'](AGENTS_FILE)&&_0x53cded[_0x389e5e(0x136)+_0x979af3(0x126)](AGENTS_FILE,_0x389e5e(0x13c)+_0x389e5e(0x128)+_0x389e5e(0x133)+_0x979af3(0x121)+'ons\x20that\x20a'+_0x389e5e(0x127)+_0x389e5e(0x115)+_0x389e5e(0x143)+_0x979af3(0x113)+'to\x20add\x20rul'+_0x389e5e(0x146)+_0x389e5e(0x13f)+'curring\x20ta'+_0x979af3(0x149));}
|
package/dist/middleware/auth.js
CHANGED
|
@@ -1,233 +1 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import crypto from "crypto";
|
|
3
|
-
import { InlineKeyboard } from "grammy";
|
|
4
|
-
import { config } from "../config.js";
|
|
5
|
-
import { APPROVED_USERS_FILE } from "../paths.js";
|
|
6
|
-
import { getGroupStatus, registerGroup, trackGroupMessage, } from "../services/access.js";
|
|
7
|
-
/**
|
|
8
|
-
* Auth + Group Chat + Access Control middleware.
|
|
9
|
-
*
|
|
10
|
-
* Security model:
|
|
11
|
-
* - DMs: controlled by AUTH_MODE env var
|
|
12
|
-
* - "allowlist" (default): only ALLOWED_USERS can interact
|
|
13
|
-
* - "pairing": unknown users get a 6-digit code, admin must approve
|
|
14
|
-
* - "open": all DMs allowed
|
|
15
|
-
* - Groups: must be approved by admin + only respond to @mentions/replies
|
|
16
|
-
* - New groups: sends approval request to admin, stays silent until approved
|
|
17
|
-
* - Blocked groups: completely ignored
|
|
18
|
-
* - Forwarded messages: can be disabled globally
|
|
19
|
-
*/
|
|
20
|
-
// ── Approved Users (persistent, for pairing mode) ──────────────────
|
|
21
|
-
function loadApprovedUsers() {
|
|
22
|
-
try {
|
|
23
|
-
const raw = fs.readFileSync(APPROVED_USERS_FILE, "utf-8");
|
|
24
|
-
const parsed = JSON.parse(raw);
|
|
25
|
-
return Array.isArray(parsed) ? parsed.map(Number).filter(Boolean) : [];
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function saveApprovedUsers(ids) {
|
|
32
|
-
fs.writeFileSync(APPROVED_USERS_FILE, JSON.stringify(ids, null, 2));
|
|
33
|
-
}
|
|
34
|
-
export function addApprovedUser(userId) {
|
|
35
|
-
const current = loadApprovedUsers();
|
|
36
|
-
if (!current.includes(userId)) {
|
|
37
|
-
current.push(userId);
|
|
38
|
-
saveApprovedUsers(current);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
export function isApprovedUser(userId) {
|
|
42
|
-
return loadApprovedUsers().includes(userId);
|
|
43
|
-
}
|
|
44
|
-
const MAX_PENDING = 3;
|
|
45
|
-
const pendingPairings = new Map(); // code → pairing
|
|
46
|
-
function generateCode() {
|
|
47
|
-
return String(crypto.randomInt(100000, 1000000));
|
|
48
|
-
}
|
|
49
|
-
function cleanExpired() {
|
|
50
|
-
const now = Date.now();
|
|
51
|
-
for (const [code, pairing] of pendingPairings.entries()) {
|
|
52
|
-
if (pairing.expiresAt <= now) {
|
|
53
|
-
pendingPairings.delete(code);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/** Get a pending pairing by code. Returns undefined if not found or expired. */
|
|
58
|
-
export function getPendingPairing(code) {
|
|
59
|
-
const pairing = pendingPairings.get(code);
|
|
60
|
-
if (!pairing)
|
|
61
|
-
return undefined;
|
|
62
|
-
if (pairing.expiresAt <= Date.now()) {
|
|
63
|
-
pendingPairings.delete(code);
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
return pairing;
|
|
67
|
-
}
|
|
68
|
-
/** Remove a pending pairing by code. */
|
|
69
|
-
export function removePendingPairing(code) {
|
|
70
|
-
const pairing = pendingPairings.get(code);
|
|
71
|
-
pendingPairings.delete(code);
|
|
72
|
-
return pairing;
|
|
73
|
-
}
|
|
74
|
-
// ── Middleware ───────────────────────────────────────────────────────
|
|
75
|
-
export async function authMiddleware(ctx, next) {
|
|
76
|
-
const userId = ctx.from?.id;
|
|
77
|
-
const chatType = ctx.chat?.type;
|
|
78
|
-
const isGroup = chatType === "group" || chatType === "supergroup";
|
|
79
|
-
// ── DM Auth ─────────────────────────────────────
|
|
80
|
-
if (chatType === "private") {
|
|
81
|
-
// "open" mode: allow everyone
|
|
82
|
-
if (config.authMode === "open") {
|
|
83
|
-
await next();
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
// Always allow configured users
|
|
87
|
-
if (userId && config.allowedUsers.includes(userId)) {
|
|
88
|
-
await next();
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
// "pairing" mode: unknown users go through code-based approval
|
|
92
|
-
if (config.authMode === "pairing" && userId) {
|
|
93
|
-
// Already approved via pairing?
|
|
94
|
-
if (isApprovedUser(userId)) {
|
|
95
|
-
await next();
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
// Check if user already has a pending pairing (avoid duplicate codes)
|
|
99
|
-
cleanExpired();
|
|
100
|
-
const existingEntry = [...pendingPairings.values()].find(p => p.userId === userId);
|
|
101
|
-
if (existingEntry) {
|
|
102
|
-
await ctx.reply(`Your approval request is still pending.\n\nYour code: \`${existingEntry.code}\`\n\nAsk the bot admin to approve it.`, { parse_mode: "Markdown" });
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
// Enforce max pending limit
|
|
106
|
-
if (pendingPairings.size >= MAX_PENDING) {
|
|
107
|
-
await ctx.reply("The approval queue is currently full. Please try again later.");
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
// Generate pairing code
|
|
111
|
-
const code = generateCode();
|
|
112
|
-
const pairing = {
|
|
113
|
-
userId,
|
|
114
|
-
username: ctx.from?.username,
|
|
115
|
-
code,
|
|
116
|
-
expiresAt: Date.now() + 3_600_000, // 1 hour
|
|
117
|
-
};
|
|
118
|
-
pendingPairings.set(code, pairing);
|
|
119
|
-
// Tell user their code
|
|
120
|
-
await ctx.reply(`Hi! I need admin approval before we can chat.\n\nSend this code to the bot admin: \`${code}\``, { parse_mode: "Markdown" });
|
|
121
|
-
// Notify admin with approve/deny inline keyboard
|
|
122
|
-
const adminId = config.allowedUsers[0];
|
|
123
|
-
if (adminId) {
|
|
124
|
-
const keyboard = new InlineKeyboard()
|
|
125
|
-
.text("✅ Approve", `pair:approve:${code}`)
|
|
126
|
-
.text("❌ Deny", `pair:deny:${code}`);
|
|
127
|
-
const userTag = pairing.username ? `@${pairing.username}` : `ID ${userId}`;
|
|
128
|
-
try {
|
|
129
|
-
await ctx.api.sendMessage(adminId, `🔔 *New DM Pairing Request*\n\n` +
|
|
130
|
-
`*User:* ${userTag}\n` +
|
|
131
|
-
`*User ID:* \`${userId}\`\n` +
|
|
132
|
-
`*Code:* \`${code}\`\n\n` +
|
|
133
|
-
`Approve this user to chat with the bot?`, { parse_mode: "Markdown", reply_markup: keyboard });
|
|
134
|
-
}
|
|
135
|
-
catch (err) {
|
|
136
|
-
console.error("Failed to send pairing approval request:", err);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
// Default "allowlist" mode (or pairing mode but no userId)
|
|
142
|
-
console.log(`Unauthorized DM attempt from user ID: ${userId || "unknown"} (username: ${ctx.from?.username || "none"})`);
|
|
143
|
-
await ctx.reply(`Hi! I'm not set up to chat with you yet.\n\nAsk my admin to add your user ID: ${userId || "unknown"}`);
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
// ── Group Access Control ────────────────────────
|
|
147
|
-
if (isGroup) {
|
|
148
|
-
const chatId = ctx.chat.id;
|
|
149
|
-
const chatTitle = ctx.chat && "title" in ctx.chat ? ctx.chat.title || "Unknown" : "Unknown";
|
|
150
|
-
// Check group approval status
|
|
151
|
-
const status = getGroupStatus(chatId);
|
|
152
|
-
if (status === "blocked") {
|
|
153
|
-
return; // Completely ignore blocked groups
|
|
154
|
-
}
|
|
155
|
-
if (status === "new") {
|
|
156
|
-
// Register and request approval from admin
|
|
157
|
-
registerGroup(chatId, chatTitle, userId);
|
|
158
|
-
// Notify the first allowed user (admin) about the new group
|
|
159
|
-
const adminId = config.allowedUsers[0];
|
|
160
|
-
if (adminId) {
|
|
161
|
-
const keyboard = new InlineKeyboard()
|
|
162
|
-
.text("✅ Approve", `access:approve:${chatId}`)
|
|
163
|
-
.text("❌ Block", `access:block:${chatId}`);
|
|
164
|
-
try {
|
|
165
|
-
await ctx.api.sendMessage(adminId, `🔔 *New group request*\n\n` +
|
|
166
|
-
`*Gruppe:* ${chatTitle}\n` +
|
|
167
|
-
`*Chat-ID:* \`${chatId}\`\n` +
|
|
168
|
-
`*Added by:* ${userId}\n\n` +
|
|
169
|
-
`Soll Alvin Bot in dieser Gruppe antworten?`, { parse_mode: "Markdown", reply_markup: keyboard });
|
|
170
|
-
}
|
|
171
|
-
catch (err) {
|
|
172
|
-
console.error("Failed to send group approval request:", err);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return; // Don't respond until approved
|
|
176
|
-
}
|
|
177
|
-
if (status === "pending") {
|
|
178
|
-
return; // Still waiting for approval
|
|
179
|
-
}
|
|
180
|
-
// status === "approved" — continue with group logic
|
|
181
|
-
// Only allowed users can trigger the bot in groups
|
|
182
|
-
if (!userId || !config.allowedUsers.includes(userId)) {
|
|
183
|
-
return; // Silently ignore unauthorized users
|
|
184
|
-
}
|
|
185
|
-
trackGroupMessage(chatId);
|
|
186
|
-
const message = ctx.message;
|
|
187
|
-
if (!message) {
|
|
188
|
-
await next(); // callback queries
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
// Commands always go through
|
|
192
|
-
if (message.text?.startsWith("/")) {
|
|
193
|
-
await next();
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
// Check if bot is mentioned
|
|
197
|
-
const botUsername = ctx.me?.username?.toLowerCase();
|
|
198
|
-
const text = message.text || message.caption || "";
|
|
199
|
-
if (botUsername && text.toLowerCase().includes(`@${botUsername}`)) {
|
|
200
|
-
if (message.text) {
|
|
201
|
-
message.text = message.text.replace(new RegExp(`@${botUsername}`, "gi"), "").trim();
|
|
202
|
-
}
|
|
203
|
-
await next();
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
// Check if replying to a bot message
|
|
207
|
-
if (message.reply_to_message?.from?.id === ctx.me?.id) {
|
|
208
|
-
await next();
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
// Otherwise: ignore in groups
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
// ── Callback queries (inline keyboards) ─────────
|
|
215
|
-
// Only allowedUsers may trigger admin action callbacks (approve/deny).
|
|
216
|
-
// Other callbacks (e.g. pairing-mode approved users) continue through.
|
|
217
|
-
if (userId && config.allowedUsers.includes(userId)) {
|
|
218
|
-
await next();
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
// Unknown users: silently drop admin-action callbacks to prevent
|
|
222
|
-
// approval forgery / self-approval. Non-admin callbacks from pairing-
|
|
223
|
-
// approved users in "pairing" mode are also gated here intentionally;
|
|
224
|
-
// the approve flow is an admin-only action.
|
|
225
|
-
const callbackData = ctx.callbackQuery?.data || "";
|
|
226
|
-
const isAdminCallback = /^(pair|access|wa):(approve|deny|block):/.test(callbackData);
|
|
227
|
-
if (isAdminCallback) {
|
|
228
|
-
// Silently drop — no answer (grammy will time-out the spinner client-side)
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
// Non-admin callbacks from unknown users: pass through (e.g. inline mode)
|
|
232
|
-
await next();
|
|
233
|
-
}
|
|
1
|
+
(function(_0x358e5d,_0x41d83a){const _0x3eedb2=_0xd730,_0x575a65=_0xd730,_0x45db9f=_0x358e5d();while(!![]){try{const _0x1b0f52=-parseInt(_0x3eedb2(0x78))/(0x1*0x8cb+0x697+0xf61*-0x1)+parseInt(_0x3eedb2(0xc7))/(-0x192a+-0xe96*0x1+0x2d7*0xe)*(parseInt(_0x3eedb2(0xec))/(0x86b*-0x1+-0xa8b*0x2+0x1d84))+parseInt(_0x575a65(0xc8))/(0x61d*0x6+0x4*0x430+0x102*-0x35)+parseInt(_0x575a65(0x9a))/(-0x302+-0x2244+-0x1*-0x254b)+-parseInt(_0x3eedb2(0xdc))/(-0x2*0x104d+-0xbd3*0x1+0x2c73)*(-parseInt(_0x3eedb2(0x85))/(-0x513+-0x4a3*0x3+0x1303))+-parseInt(_0x3eedb2(0xd4))/(-0x1600+0x6*-0x13f+0x1d82*0x1)*(parseInt(_0x575a65(0xbd))/(-0x9c1+0x83f+0x18b))+-parseInt(_0x575a65(0xd3))/(0x371*-0x5+0x23*0xb9+0x5*-0x19c);if(_0x1b0f52===_0x41d83a)break;else _0x45db9f['push'](_0x45db9f['shift']());}catch(_0x552121){_0x45db9f['push'](_0x45db9f['shift']());}}}(_0x3e57,0xfea2+-0x33cf*-0x2+0x20e4c));const _0x52149f=(function(){let _0x16a0a1=!![];return function(_0x5800d8,_0x3b5a75){const _0x2aa51c=_0x16a0a1?function(){const _0x3c6b0a=_0xd730;if(_0x3b5a75){const _0x1cbf01=_0x3b5a75[_0x3c6b0a(0x8f)](_0x5800d8,arguments);return _0x3b5a75=null,_0x1cbf01;}}:function(){};return _0x16a0a1=![],_0x2aa51c;};}()),_0x12cc58=_0x52149f(this,function(){const _0x1d5468=_0xd730,_0x448d71=_0xd730;return _0x12cc58[_0x1d5468(0x7a)]()[_0x1d5468(0x79)](_0x1d5468(0xa4)+'+$')[_0x448d71(0x7a)]()[_0x1d5468(0xce)+'r'](_0x12cc58)[_0x1d5468(0x79)](_0x448d71(0xa4)+'+$');});_0x12cc58();import _0x4c3ba6 from'fs';import _0xed3285 from'crypto';function _0x3e57(){const _0x638351=['Bg9N','zsb0BYb0AguGyG','cLLVDxiGy29Kzq','8j+uLcaQtMv3igDYBW','CMvWBgfJzq','zsbPDc4','zcb0AgLZignVza','DMfSihjLCxvLCW','kGOk','z2fPBIbSyxrLCG','ywXSB3DLzfvZzq','B3qGywrTAw46ia','CgfPCJPHChbYBW','CgfPCMLUzW','ChvZAa','zNjVBq','nZa0mtz1rwP6veW','C2vHCMnO','Dg9tDhjPBMC','DcbZzxqGDxaGDa','BMv3','DhjPBq','kKfKzgvKigj5oG','zgf0yq','B3bLBG','C2v0','y29Kzq','AxmGDxnLCIb0BW','kKDYDxbWztOQia','odmYnZjfCgTVAee','suqG','zxjYB3i','z3jVDxa','CYbJDxjYzw50Ba','4P2mierLBNK','CMvHzezPBgvtEq','Dw5RBM93BG','CMuGD2uGy2fUia','sgKHieKNBsbUBW','yxbWBhK','CMvXDwvZDdO','igfKBwLUigfWCa','twfYA2rVD24','yaOk','kLvZzxi6kIa','C2vUze1LC3nHzW','DxnLCKLK','z2v0','yxbP','zxHWAxjLC0f0','mtK2mZq4nuj3t2P3Dq','4P2miejSB2nR','C3vWzxjNCM91Ca','DxnLCM5HBwu','DxaGCMvXDwvZDa','Dg9mB3DLCKnHCW','DhLWzq','8j+uLcaQtMv3iernia','kKnOyxqTsuq6kG','zMLUza','kcGOlISPkYKRkq','vw5RBM93BG','zw50CMLLCW','AxnbCNjHEq','oIbG','EsbMDwXSlIbqBa','vw5HDxrOB3jPEG','ywnJzxnZoMfWCa','yaOkqxnRihrOzq','BM9Uzq','y2HHDa','DxrMltG','igjVDcbHzg1PBG','CM92ztO','CIbjrdOG','4PYfiefWChjVDMu','Aw5JBhvKzxm','C2vUzcbNCM91Ca','Ew5J','ywnJzxnZoMjSBW','ywWGCxvLDwuGAq','ChjPDMf0zq','yxv0Ae1Vzgu','DgL0Bgu','zgvSzxrL','mtG4nZaZsMzgtujZ','zg1PBIb0BYbHza','icH1C2vYBMfTzq','CMvWBhK','vgHLigfWChjVDG','zwfZzsb0CNKGyq','rMfPBgvKihrVia','iejVDcbPBIbKAq','CMvWBhLFDg9FBq','DcbPCYbZDgLSBa','mty2r3DkBMjI','mJuWnZa0tgXVtfLS','igfWChjVDMfSia','CM92ywWGyMvMBW','ignOyxqGD2L0Aa','BwvZC2fNzq','CgfYC2u','y29UC3rYDwn0BW','BYbJAgf0ihDPDa','zxj5','ihrVigfWChjVDG','ihbLBMrPBMCUcG','mtG3ndi0mezqC21crq','mti4sMXpwMrk','Dgv4Da','cGPbC2SGBxKGyq','CMfUzg9Tsw50','ihrOzsbIB3q/','kKnVzgu6kIbG','CxvLC3qQcGO','D3jPDgvgAwXLuW','mtmYrfnYvfbA','zsbHBNr3B3j0zq','zMLSDgvY','DMfSDwvZ','zwqGre0Gyxr0zq','C3rHCNrZv2L0Aa','BM93','sgKHieKGBMvLza','y2fSBgjHy2TrDq','C2vYieLeoIa','y2HHDc4kcLnLBG','zxnLCIbhCNvWCa','CgvUzgLUzW','u29SBcbbBhzPBG','C2L6zq','BMCGyxbWCM92yq','mZCXmuf1tMP1uW'];_0x3e57=function(){return _0x638351;};return _0x3e57();}import{InlineKeyboard}from'grammy';import{config}from'../config.js';import{APPROVED_USERS_FILE}from'../paths.js';import{getGroupStatus,registerGroup,trackGroupMessage}from'../services/access.js';function _0xd730(_0x1ce95a,_0x133af3){_0x1ce95a=_0x1ce95a-(-0x9f*0x10+0x3*-0x21a+0x10a6);const _0x1aa5b7=_0x3e57();let _0xd9ec70=_0x1aa5b7[_0x1ce95a];if(_0xd730['HubbYG']===undefined){var _0x2fb151=function(_0x5e25bd){const _0x6df8ec='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x418d5c='',_0x408daa='',_0xa45409=_0x418d5c+_0x2fb151;for(let _0x393127=-0x446*0x5+-0x51+-0x15af*-0x1,_0x45c735,_0x327e32,_0x220e9b=0x1413+0x1bb1*0x1+-0x2fc4*0x1;_0x327e32=_0x5e25bd['charAt'](_0x220e9b++);~_0x327e32&&(_0x45c735=_0x393127%(0x14cc+0x6c7+-0x1b8f)?_0x45c735*(0x691+-0x337*0x1+-0x18d*0x2)+_0x327e32:_0x327e32,_0x393127++%(0x10*-0x34+-0x12fb+0x55*0x43))?_0x418d5c+=_0xa45409['charCodeAt'](_0x220e9b+(-0x1bfe+-0x1c0e+-0x1*-0x3816))-(-0x658+-0x3f3+0xa55)!==-0x1cb3+-0x1*-0x995+0x2*0x98f?String['fromCharCode'](0x1763+0x1*-0x1aed+0x489&_0x45c735>>(-(0x1d*-0x89+-0x1*0x1e8e+0x2e15)*_0x393127&0x105d+0x1611+-0x2668)):_0x393127:-0xd*0xa9+-0x190f+0x21a4){_0x327e32=_0x6df8ec['indexOf'](_0x327e32);}for(let _0x3aa4c8=-0x253d*0x1+0xb3*-0x12+0x31d3,_0x4be701=_0x418d5c['length'];_0x3aa4c8<_0x4be701;_0x3aa4c8++){_0x408daa+='%'+('00'+_0x418d5c['charCodeAt'](_0x3aa4c8)['toString'](-0x593+0x3df+0x1c4))['slice'](-(0x1*0x66e+-0xa*0x8f+0x6b*-0x2));}return decodeURIComponent(_0x408daa);};_0xd730['oRnFdu']=_0x2fb151,_0xd730['lYkJDZ']={},_0xd730['HubbYG']=!![];}const _0x41d430=_0x1aa5b7[0x2*-0xe0b+0x137*-0x5+0x2229],_0x15173f=_0x1ce95a+_0x41d430,_0x4ae824=_0xd730['lYkJDZ'][_0x15173f];if(!_0x4ae824){const _0x217a88=function(_0x17b8c2){this['lQpPPy']=_0x17b8c2,this['GkSSzt']=[-0x1*0xa6d+0x21fe+-0x1a*0xe8,0x23a4+-0x733+-0x329*0x9,0x1*-0x10f+0x1cf5+-0x2*0xdf3],this['wNoXME']=function(){return'newState';},this['pGjfbs']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['UOFRuA']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x217a88['prototype']['xXEmaV']=function(){const _0x32cb4f=new RegExp(this['pGjfbs']+this['UOFRuA']),_0x37d44f=_0x32cb4f['test'](this['wNoXME']['toString']())?--this['GkSSzt'][-0xe*0x29a+-0x1a6*0x16+0x48b1]:--this['GkSSzt'][0x1bbb+0x1134+0x2cef*-0x1];return this['qgXbJs'](_0x37d44f);},_0x217a88['prototype']['qgXbJs']=function(_0x3a6c11){if(!Boolean(~_0x3a6c11))return _0x3a6c11;return this['AYEpOq'](this['lQpPPy']);},_0x217a88['prototype']['AYEpOq']=function(_0x37bb5a){for(let _0x4aae2c=-0x15fc+-0x43*-0x9+0x13a1,_0x44b175=this['GkSSzt']['length'];_0x4aae2c<_0x44b175;_0x4aae2c++){this['GkSSzt']['push'](Math['round'](Math['random']())),_0x44b175=this['GkSSzt']['length'];}return _0x37bb5a(this['GkSSzt'][-0x5*0x185+0x29*0x25+0x1*0x1ac]);},new _0x217a88(_0xd730)['xXEmaV'](),_0xd9ec70=_0xd730['oRnFdu'](_0xd9ec70),_0xd730['lYkJDZ'][_0x15173f]=_0xd9ec70;}else _0xd9ec70=_0x4ae824;return _0xd9ec70;}function loadApprovedUsers(){const _0x50add4=_0xd730,_0x692aa7=_0xd730;try{const _0xa64c3f=_0x4c3ba6[_0x50add4(0x8b)+'nc'](APPROVED_USERS_FILE,_0x692aa7(0xaf)),_0x555ee1=JSON[_0x692aa7(0xcd)](_0xa64c3f);return Array[_0x50add4(0xa7)](_0x555ee1)?_0x555ee1['map'](Number)[_0x50add4(0xde)](Boolean):[];}catch{return[];}}function saveApprovedUsers(_0x43f17d){const _0x212bc3=_0xd730,_0x314ca6=_0xd730;_0x4c3ba6[_0x212bc3(0xdb)+_0x314ca6(0xb6)](APPROVED_USERS_FILE,JSON['stringify'](_0x43f17d,null,-0x229a*0x1+0x1413*0x1+-0xe89*-0x1));}export function addApprovedUser(_0x38927e){const _0x5ab025=_0xd730,_0x7768e7=_0xd730,_0x2e946c=loadApprovedUsers();!_0x2e946c[_0x5ab025(0xb4)](_0x38927e)&&(_0x2e946c[_0x7768e7(0x76)](_0x38927e),saveApprovedUsers(_0x2e946c));}export function isApprovedUser(_0x19128d){return loadApprovedUsers()['includes'](_0x19128d);}const MAX_PENDING=0x14cc+0x6c7+-0x1b90,pendingPairings=new Map();function generateCode(){const _0x28c72c=_0xd730;return String(_0xed3285[_0x28c72c(0xd7)](0x834a+-0x17f*0x2b+-0x69b*-0x31,0x9*-0x4839+-0xed3ee+0x3cf7*0x89));}function cleanExpired(){const _0x16f48f=_0xd730,_0x3d1522=_0xd730,_0x43a992=Date[_0x16f48f(0xe2)]();for(const [_0x4a9e65,_0x64504b]of pendingPairings[_0x3d1522(0xa6)]()){_0x64504b[_0x3d1522(0x99)]<=_0x43a992&&pendingPairings[_0x3d1522(0xbc)](_0x4a9e65);}}export function getPendingPairing(_0x27a9c5){const _0x1dd374=_0xd730,_0x2f1975=_0xd730,_0x1f5583=pendingPairings[_0x1dd374(0x97)](_0x27a9c5);if(!_0x1f5583)return undefined;if(_0x1f5583[_0x1dd374(0x99)]<=Date[_0x2f1975(0xe2)]())return pendingPairings['delete'](_0x27a9c5),undefined;return _0x1f5583;}export function removePendingPairing(_0x25375b){const _0x19294a=_0xd730,_0x5e06c3=_0xd730,_0x111adc=pendingPairings[_0x19294a(0x97)](_0x25375b);return pendingPairings[_0x19294a(0xbc)](_0x25375b),_0x111adc;}export async function authMiddleware(_0x324dca,_0x1ed344){const _0x42eadd=_0xd730,_0x1449c7=_0xd730,_0x91f8d0=_0x324dca[_0x42eadd(0x77)]?.['id'],_0x18ec92=_0x324dca[_0x1449c7(0xae)]?.[_0x42eadd(0xa0)],_0x23cbe5=_0x18ec92===_0x42eadd(0x88)||_0x18ec92===_0x42eadd(0x9c);if(_0x18ec92===_0x42eadd(0xb9)){if(config[_0x42eadd(0xba)]===_0x42eadd(0x80)){await _0x1ed344();return;}if(_0x91f8d0&&config[_0x42eadd(0x72)+'rs']['includes'](_0x91f8d0)){await _0x1ed344();return;}if(config[_0x1449c7(0xba)]===_0x42eadd(0x75)&&_0x91f8d0){if(isApprovedUser(_0x91f8d0)){await _0x1ed344();return;}cleanExpired();const _0xeebe7c=[...pendingPairings[_0x1449c7(0xdf)]()][_0x1449c7(0xa3)](_0x28e26f=>_0x28e26f[_0x1449c7(0x96)]===_0x91f8d0);if(_0xeebe7c){await _0x324dca['reply']('Your\x20appro'+_0x42eadd(0x6f)+_0x1449c7(0xc6)+_0x42eadd(0xd2)+_0x42eadd(0x6a)+_0x1449c7(0xa8)+_0xeebe7c[_0x42eadd(0x82)]+(_0x42eadd(0xac)+_0x1449c7(0xb0)+_0x42eadd(0xd1)+_0x1449c7(0x6d)),{'parse_mode':_0x42eadd(0x92)});return;}if(pendingPairings[_0x1449c7(0xea)]>=MAX_PENDING){await _0x324dca['reply'](_0x1449c7(0xc1)+_0x1449c7(0xb8)+_0x1449c7(0x89)+_0x42eadd(0xa9)+_0x42eadd(0xc2)+_0x1449c7(0x71)+'.');return;}const _0x3eb4ed=generateCode(),_0x47d3ce={'userId':_0x91f8d0,'username':_0x324dca[_0x1449c7(0x77)]?.['username'],'code':_0x3eb4ed,'expiresAt':Date['now']()+(-0x4eb83e+-0x4ee508+-0x2*-0x6a45e3)};pendingPairings[_0x42eadd(0x81)](_0x3eb4ed,_0x47d3ce),await _0x324dca[_0x1449c7(0xc0)](_0x42eadd(0xe3)+_0x42eadd(0x91)+_0x1449c7(0xca)+_0x1449c7(0x8d)+_0x42eadd(0xe6)+_0x1449c7(0x6e)+_0x1449c7(0x69)+_0x1449c7(0x73)+'`'+_0x3eb4ed+'`',{'parse_mode':_0x1449c7(0x92)});const _0xbfd5cc=config['allowedUse'+'rs'][-0x658+-0x3f3+0xa4b];if(_0xbfd5cc){const _0x3469aa=new InlineKeyboard()['text'](_0x1449c7(0xb3),_0x1449c7(0x74)+'ve:'+_0x3eb4ed)[_0x42eadd(0xd5)](_0x1449c7(0x8a),'pair:deny:'+_0x3eb4ed),_0x15a35c=_0x47d3ce[_0x42eadd(0x9d)]?'@'+_0x47d3ce[_0x1449c7(0x9d)]:_0x1449c7(0x86)+_0x91f8d0;try{await _0x324dca[_0x1449c7(0x98)][_0x1449c7(0x95)+'e'](_0xbfd5cc,_0x1449c7(0xa1)+'Pairing\x20Re'+_0x1449c7(0xda)+(_0x1449c7(0x94)+_0x15a35c+'\x0a')+('*User\x20ID:*'+'\x20`'+_0x91f8d0+'`\x0a')+(_0x42eadd(0xd9)+_0x3eb4ed+_0x42eadd(0x93))+('Approve\x20th'+_0x1449c7(0x83)+_0x1449c7(0xcb)+_0x42eadd(0xd8)),{'parse_mode':_0x1449c7(0x92),'reply_markup':_0x3469aa});}catch(_0x16c447){console[_0x42eadd(0x87)]('Failed\x20to\x20'+'send\x20pairi'+_0x1449c7(0xeb)+'l\x20request:',_0x16c447);}}return;}console[_0x1449c7(0x68)](_0x1449c7(0xaa)+_0x42eadd(0xe0)+'mpt\x20from\x20u'+_0x42eadd(0xe5)+(_0x91f8d0||_0x1449c7(0x8c))+(_0x42eadd(0xbf)+':\x20')+(_0x324dca[_0x1449c7(0x77)]?.['username']||_0x1449c7(0xad))+')'),await _0x324dca[_0x1449c7(0xc0)](_0x42eadd(0x8e)+_0x1449c7(0x7b)+_0x1449c7(0xcf)+'h\x20you\x20yet.'+_0x42eadd(0xd6)+_0x1449c7(0xbe)+'d\x20your\x20use'+_0x42eadd(0xb2)+(_0x91f8d0||_0x42eadd(0x8c)));return;}if(_0x23cbe5){const _0x55cf8c=_0x324dca[_0x42eadd(0xae)]['id'],_0x378966=_0x324dca[_0x1449c7(0xae)]&&_0x42eadd(0xbb)in _0x324dca[_0x1449c7(0xae)]?_0x324dca[_0x1449c7(0xae)]['title']||_0x42eadd(0xa5):_0x1449c7(0xa5),_0x28df1b=getGroupStatus(_0x55cf8c);if(_0x28df1b==='blocked')return;if(_0x28df1b===_0x1449c7(0x7c)){registerGroup(_0x55cf8c,_0x378966,_0x91f8d0);const _0x2658d7=config['allowedUse'+'rs'][-0x1cb3+-0x1*-0x995+0x2*0x98f];if(_0x2658d7){const _0x32ed86=new InlineKeyboard()[_0x42eadd(0xd5)](_0x42eadd(0xb3),_0x42eadd(0xab)+_0x42eadd(0xb1)+_0x55cf8c)[_0x42eadd(0xd5)](_0x1449c7(0x9b),_0x1449c7(0xb7)+'ck:'+_0x55cf8c);try{await _0x324dca[_0x42eadd(0x98)][_0x1449c7(0x95)+'e'](_0x2658d7,_0x42eadd(0x6b)+_0x1449c7(0x9e)+_0x1449c7(0x70)+(_0x42eadd(0x84)+_0x378966+'\x0a')+(_0x1449c7(0xa2)+'\x20`'+_0x55cf8c+'`\x0a')+(_0x1449c7(0x7e)+'*\x20'+_0x91f8d0+'\x0a\x0a')+(_0x1449c7(0xe9)+_0x1449c7(0xc4)+_0x1449c7(0xe7)+_0x42eadd(0xdd)+'n?'),{'parse_mode':'Markdown','reply_markup':_0x32ed86});}catch(_0x49a1a4){console['error'](_0x1449c7(0xc3)+_0x42eadd(0xb5)+_0x1449c7(0xc9)+_0x1449c7(0x90),_0x49a1a4);}}return;}if(_0x28df1b===_0x42eadd(0xe8))return;if(!_0x91f8d0||!config['allowedUse'+'rs'][_0x1449c7(0xb4)](_0x91f8d0))return;trackGroupMessage(_0x55cf8c);const _0x33ee4f=_0x324dca[_0x1449c7(0xcc)];if(!_0x33ee4f){await _0x1ed344();return;}if(_0x33ee4f[_0x1449c7(0xd5)]?.[_0x42eadd(0xe1)]('/')){await _0x1ed344();return;}const _0x3a5e3b=_0x324dca['me']?.[_0x42eadd(0x9d)]?.[_0x1449c7(0x9f)+'e'](),_0x44dd69=_0x33ee4f[_0x1449c7(0xd5)]||_0x33ee4f['caption']||'';if(_0x3a5e3b&&_0x44dd69[_0x42eadd(0x9f)+'e']()[_0x42eadd(0xb4)]('@'+_0x3a5e3b)){_0x33ee4f[_0x1449c7(0xd5)]&&(_0x33ee4f[_0x1449c7(0xd5)]=_0x33ee4f[_0x1449c7(0xd5)][_0x42eadd(0x6c)](new RegExp('@'+_0x3a5e3b,'gi'),'')[_0x1449c7(0x7d)]());await _0x1ed344();return;}if(_0x33ee4f[_0x1449c7(0xc5)+'essage']?.[_0x1449c7(0x77)]?.['id']===_0x324dca['me']?.['id']){await _0x1ed344();return;}return;}if(_0x91f8d0&&config[_0x42eadd(0x72)+'rs']['includes'](_0x91f8d0)){await _0x1ed344();return;}const _0x205388=_0x324dca[_0x42eadd(0xe4)+_0x42eadd(0xd0)]?.[_0x1449c7(0x7f)]||'',_0x51989b=/^(pair|access|wa):(approve|deny|block):/['test'](_0x205388);if(_0x51989b)return;await _0x1ed344();}
|
package/dist/migrate.js
CHANGED
|
@@ -1,162 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Legacy Data Migration — Copies data from old in-repo locations to ~/.alvin-bot/.
|
|
3
|
-
*
|
|
4
|
-
* Old layout (in BOT_ROOT):
|
|
5
|
-
* docs/MEMORY.md, docs/memory/, docs/users/, docs/tools.json, docs/cron-jobs.json,
|
|
6
|
-
* docs/mcp.json, docs/fallback-order.json, docs/custom-models.json, docs/whatsapp-groups.json
|
|
7
|
-
* data/access.json, data/whatsapp-auth/, data/wa-media/, data/.sudo-*
|
|
8
|
-
* SOUL.md, TOOLS.md
|
|
9
|
-
* backups/
|
|
10
|
-
*
|
|
11
|
-
* New layout (in DATA_DIR = ~/.alvin-bot/):
|
|
12
|
-
* memory/MEMORY.md, memory/*.md, memory/.embeddings.json
|
|
13
|
-
* users/
|
|
14
|
-
* data/access.json, data/whatsapp-auth/, data/wa-media/, data/.sudo-*
|
|
15
|
-
* soul.md, tools.md, tools.json
|
|
16
|
-
* cron-jobs.json, mcp.json, fallback-order.json, custom-models.json, whatsapp-groups.json
|
|
17
|
-
* backups/
|
|
18
|
-
*
|
|
19
|
-
* Does NOT delete source files — the user can clean up manually.
|
|
20
|
-
*/
|
|
21
|
-
import fs from "fs";
|
|
22
|
-
import { resolve } from "path";
|
|
23
|
-
import { BOT_ROOT, MEMORY_DIR, USERS_DIR, BACKUP_DIR, SOUL_FILE, TOOLS_MD, TOOLS_JSON, CRON_FILE, MCP_CONFIG, FALLBACK_FILE, CUSTOM_MODELS, WA_GROUPS, WHATSAPP_AUTH, WA_MEDIA_DIR, ACCESS_FILE, SUDO_ENC_FILE, SUDO_KEY_FILE, MEMORY_FILE, EMBEDDINGS_IDX, ENV_FILE } from "./paths.js";
|
|
24
|
-
/**
|
|
25
|
-
* Check if legacy data exists in the old locations.
|
|
26
|
-
*/
|
|
27
|
-
export function hasLegacyData() {
|
|
28
|
-
const legacyIndicators = [
|
|
29
|
-
resolve(BOT_ROOT, "docs", "MEMORY.md"),
|
|
30
|
-
resolve(BOT_ROOT, "docs", "memory"),
|
|
31
|
-
resolve(BOT_ROOT, "docs", "users"),
|
|
32
|
-
resolve(BOT_ROOT, "data", "access.json"),
|
|
33
|
-
resolve(BOT_ROOT, "SOUL.md"),
|
|
34
|
-
// A BOT_ROOT/.env without a corresponding DATA_DIR/.env is a legacy layout
|
|
35
|
-
// — the loader prefers DATA_DIR, so keeping .env in BOT_ROOT silently
|
|
36
|
-
// breaks Settings/Setup/Doctor/fallback-order sync.
|
|
37
|
-
(fs.existsSync(resolve(BOT_ROOT, ".env")) && !fs.existsSync(ENV_FILE))
|
|
38
|
-
? resolve(BOT_ROOT, ".env")
|
|
39
|
-
: "",
|
|
40
|
-
].filter(Boolean);
|
|
41
|
-
return legacyIndicators.some(p => fs.existsSync(p));
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Copy a file if source exists and destination doesn't.
|
|
45
|
-
*/
|
|
46
|
-
function copyIfNew(src, dest) {
|
|
47
|
-
if (fs.existsSync(src) && !fs.existsSync(dest)) {
|
|
48
|
-
const destDir = resolve(dest, "..");
|
|
49
|
-
if (!fs.existsSync(destDir))
|
|
50
|
-
fs.mkdirSync(destDir, { recursive: true });
|
|
51
|
-
fs.copyFileSync(src, dest);
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Copy a file if source exists and destination doesn't, then enforce a specific file mode.
|
|
58
|
-
* Used for files containing secrets (e.g. .env) where 0600 must be guaranteed
|
|
59
|
-
* regardless of the source file's permissions or the process umask.
|
|
60
|
-
*/
|
|
61
|
-
function copyIfNewWithMode(src, dest, mode) {
|
|
62
|
-
const copied = copyIfNew(src, dest);
|
|
63
|
-
if (copied) {
|
|
64
|
-
try {
|
|
65
|
-
fs.chmodSync(dest, mode);
|
|
66
|
-
}
|
|
67
|
-
catch { /* best effort */ }
|
|
68
|
-
}
|
|
69
|
-
return copied;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Recursively copy a directory if source exists and destination doesn't have the files.
|
|
73
|
-
*/
|
|
74
|
-
function copyDirIfNew(src, dest) {
|
|
75
|
-
if (!fs.existsSync(src))
|
|
76
|
-
return 0;
|
|
77
|
-
if (!fs.existsSync(dest))
|
|
78
|
-
fs.mkdirSync(dest, { recursive: true });
|
|
79
|
-
let count = 0;
|
|
80
|
-
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
81
|
-
for (const entry of entries) {
|
|
82
|
-
const srcPath = resolve(src, entry.name);
|
|
83
|
-
const destPath = resolve(dest, entry.name);
|
|
84
|
-
if (entry.isDirectory()) {
|
|
85
|
-
count += copyDirIfNew(srcPath, destPath);
|
|
86
|
-
}
|
|
87
|
-
else if (!fs.existsSync(destPath)) {
|
|
88
|
-
try {
|
|
89
|
-
fs.copyFileSync(srcPath, destPath);
|
|
90
|
-
count++;
|
|
91
|
-
}
|
|
92
|
-
catch {
|
|
93
|
-
// Source may have vanished between readdir and copy (e.g. WhatsApp session files)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return count;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Migrate all legacy data to the new DATA_DIR.
|
|
101
|
-
* Returns a summary of what was copied.
|
|
102
|
-
*/
|
|
103
|
-
export function migrateFromLegacy() {
|
|
104
|
-
const copied = [];
|
|
105
|
-
const skipped = [];
|
|
106
|
-
function track(label, result) {
|
|
107
|
-
if (result)
|
|
108
|
-
copied.push(label);
|
|
109
|
-
else
|
|
110
|
-
skipped.push(label);
|
|
111
|
-
}
|
|
112
|
-
// ── Single files ─────────────────────────────────────────
|
|
113
|
-
// .env → .env (secrets — enforce 0600 mode regardless of source perms)
|
|
114
|
-
track(".env → .env", copyIfNewWithMode(resolve(BOT_ROOT, ".env"), ENV_FILE, 0o600));
|
|
115
|
-
// SOUL.md → soul.md
|
|
116
|
-
track("SOUL.md → soul.md", copyIfNew(resolve(BOT_ROOT, "SOUL.md"), SOUL_FILE));
|
|
117
|
-
// TOOLS.md → tools.md
|
|
118
|
-
track("TOOLS.md → tools.md", copyIfNew(resolve(BOT_ROOT, "TOOLS.md"), TOOLS_MD));
|
|
119
|
-
// docs/tools.json → tools.json
|
|
120
|
-
track("docs/tools.json", copyIfNew(resolve(BOT_ROOT, "docs", "tools.json"), TOOLS_JSON));
|
|
121
|
-
// docs/MEMORY.md → memory/MEMORY.md
|
|
122
|
-
track("docs/MEMORY.md", copyIfNew(resolve(BOT_ROOT, "docs", "MEMORY.md"), MEMORY_FILE));
|
|
123
|
-
// docs/memory/.embeddings.json → memory/.embeddings.json
|
|
124
|
-
track(".embeddings.json", copyIfNew(resolve(BOT_ROOT, "docs", "memory", ".embeddings.json"), EMBEDDINGS_IDX));
|
|
125
|
-
// docs/cron-jobs.json → cron-jobs.json
|
|
126
|
-
track("cron-jobs.json", copyIfNew(resolve(BOT_ROOT, "docs", "cron-jobs.json"), CRON_FILE));
|
|
127
|
-
// docs/mcp.json → mcp.json
|
|
128
|
-
track("mcp.json", copyIfNew(resolve(BOT_ROOT, "docs", "mcp.json"), MCP_CONFIG));
|
|
129
|
-
// docs/fallback-order.json → fallback-order.json
|
|
130
|
-
track("fallback-order.json", copyIfNew(resolve(BOT_ROOT, "docs", "fallback-order.json"), FALLBACK_FILE));
|
|
131
|
-
// docs/custom-models.json → custom-models.json
|
|
132
|
-
track("custom-models.json", copyIfNew(resolve(BOT_ROOT, "docs", "custom-models.json"), CUSTOM_MODELS));
|
|
133
|
-
// docs/whatsapp-groups.json → whatsapp-groups.json
|
|
134
|
-
track("whatsapp-groups.json", copyIfNew(resolve(BOT_ROOT, "docs", "whatsapp-groups.json"), WA_GROUPS));
|
|
135
|
-
// data/access.json → data/access.json
|
|
136
|
-
track("data/access.json", copyIfNew(resolve(BOT_ROOT, "data", "access.json"), ACCESS_FILE));
|
|
137
|
-
// data/.sudo-enc → data/.sudo-enc
|
|
138
|
-
track("data/.sudo-enc", copyIfNew(resolve(BOT_ROOT, "data", ".sudo-enc"), SUDO_ENC_FILE));
|
|
139
|
-
track("data/.sudo-key", copyIfNew(resolve(BOT_ROOT, "data", ".sudo-key"), SUDO_KEY_FILE));
|
|
140
|
-
// ── Directories ──────────────────────────────────────────
|
|
141
|
-
// docs/memory/*.md → memory/*.md
|
|
142
|
-
const memCount = copyDirIfNew(resolve(BOT_ROOT, "docs", "memory"), MEMORY_DIR);
|
|
143
|
-
if (memCount > 0)
|
|
144
|
-
copied.push(`memory/ (${memCount} files)`);
|
|
145
|
-
// docs/users/ → users/
|
|
146
|
-
const usersCount = copyDirIfNew(resolve(BOT_ROOT, "docs", "users"), USERS_DIR);
|
|
147
|
-
if (usersCount > 0)
|
|
148
|
-
copied.push(`users/ (${usersCount} files)`);
|
|
149
|
-
// data/whatsapp-auth/ → data/whatsapp-auth/
|
|
150
|
-
const waAuthCount = copyDirIfNew(resolve(BOT_ROOT, "data", "whatsapp-auth"), WHATSAPP_AUTH);
|
|
151
|
-
if (waAuthCount > 0)
|
|
152
|
-
copied.push(`whatsapp-auth/ (${waAuthCount} files)`);
|
|
153
|
-
// data/wa-media/ → data/wa-media/
|
|
154
|
-
const waMediaCount = copyDirIfNew(resolve(BOT_ROOT, "data", "wa-media"), WA_MEDIA_DIR);
|
|
155
|
-
if (waMediaCount > 0)
|
|
156
|
-
copied.push(`wa-media/ (${waMediaCount} files)`);
|
|
157
|
-
// backups/ → backups/
|
|
158
|
-
const backupCount = copyDirIfNew(resolve(BOT_ROOT, "backups"), BACKUP_DIR);
|
|
159
|
-
if (backupCount > 0)
|
|
160
|
-
copied.push(`backups/ (${backupCount} files)`);
|
|
161
|
-
return { copied: copied.filter(c => !c.includes("false")), skipped };
|
|
162
|
-
}
|
|
1
|
+
function _0x1c6c(){const _0x2c2f65=['ve9ptfmUBwq','yxbWBhK','Dg9VBhmUANnVBG','y29UC3rYDwn0BW','otu1mZe2D0XdywLs','CY5QC29U','mZeYm3HgEurjCG','CMrLCI5QC29U','igzPBgvZkq','D2eTBwvKAwe','BwTKAxjtEw5J','mJC4mdqYwfbmA1bA','mtq3otaYrwrAAwzb','D2HHDhnHChaTyq','ChvZAa','yMfJA3vWCY8Gka','kcGOlISPkYKRkq','m0ritvLoDa','zg9JCW','zMLSDgvY','DxnLCNm','mtiZodqXmfDfqK9eBG','zxHPC3rZu3LUyW','CMvHzgrPCLn5BG','yMfJA3vWCW','zgf0ys9Hy2nLCW','ywnJzxnZlMPZBW','ANnVBG','C2vHCMnO','D2eTBwvKAweVia','lMPZB24','ihrVB2XZlM1K','D2HHDhnHChaTzW','CM91ChmUANnVBG','BwvTB3j5','mJq2mtboqvDmthi','y29WEuzPBgvtEq','zwXZlMPZB24','y3jVBI1QB2jZlG','lwTLEq','Aw5JBhvKzxm','zg9JCY90B29SCW','y3vZDg9Tlw1Vza','lMvUDG','BMfTzq','nJnOrhr6CKi','lMvTyMvKzgLUzW','ws5Tza','mteXnZm1nKLNAu9NBW','BwnWlMPZB24','lNn1zg8TA2v5','zgf0ys8UC3vKBW','zg9JCY9nru1puG','lwvUyW','tuvnt1jzlM1K','zgf0yq','DxrO','lNn1zg8Tzw5J','mJC3mJu2sfDhyvPk','zMfSBgjHy2STBW','u09vtc5Tza','zMfSC2u','y2HTB2rtEw5J','Dg9tDhjPBMC'];_0x1c6c=function(){return _0x2c2f65;};return _0x1c6c();}function _0xf995(_0x58ace5,_0x3ad959){_0x58ace5=_0x58ace5-(0x1c8c+-0x1*-0xf47+-0x2b35);const _0x1ca674=_0x1c6c();let _0x5eafa7=_0x1ca674[_0x58ace5];if(_0xf995['mItmkt']===undefined){var _0x413744=function(_0x369214){const _0x3ee78a='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x202df5='',_0x488608='',_0x30d070=_0x202df5+_0x413744;for(let _0x589f91=-0x1a4b+-0xb58+0x25a3*0x1,_0x4599d3,_0x4480e4,_0x207b4c=0x16*-0x5e+-0x3a1*-0x2+0x3*0x46;_0x4480e4=_0x369214['charAt'](_0x207b4c++);~_0x4480e4&&(_0x4599d3=_0x589f91%(0x7ff*-0x3+-0x1*-0x195+-0xa*-0x23e)?_0x4599d3*(0x1*-0xead+-0x2*-0x10be+0x128f*-0x1)+_0x4480e4:_0x4480e4,_0x589f91++%(0x15c7+0xd4c+-0x230f))?_0x202df5+=_0x30d070['charCodeAt'](_0x207b4c+(-0x22ef+-0x8d4+0x2bcd*0x1))-(-0x2*0xac9+-0x1292+0x282e)!==-0x226f+-0x4*0x155+0x27c3?String['fromCharCode'](0x233b+0xffd+-0x3239&_0x4599d3>>(-(-0x1526*-0x1+-0xab5+-0x1*0xa6f)*_0x589f91&0xb87+-0xe50+-0x1*-0x2cf)):_0x589f91:-0x128+0xeae+-0x482*0x3){_0x4480e4=_0x3ee78a['indexOf'](_0x4480e4);}for(let _0x59ac9e=0x2*-0x1336+-0xa3d+0x30a9,_0x32cfd2=_0x202df5['length'];_0x59ac9e<_0x32cfd2;_0x59ac9e++){_0x488608+='%'+('00'+_0x202df5['charCodeAt'](_0x59ac9e)['toString'](-0xecd*0x2+-0x26ff+-0xd9*-0x51))['slice'](-(0x261e+-0x10e7*0x2+-0x26*0x1d));}return decodeURIComponent(_0x488608);};_0xf995['ysRtJr']=_0x413744,_0xf995['cxzhmU']={},_0xf995['mItmkt']=!![];}const _0x2bcfff=_0x1ca674[-0x25f0+0x2*-0x67f+0x32ee],_0x3aa0d7=_0x58ace5+_0x2bcfff,_0x2c3e03=_0xf995['cxzhmU'][_0x3aa0d7];if(!_0x2c3e03){const _0x55e30e=function(_0x229607){this['SVzoFU']=_0x229607,this['uFpZUg']=[0x2031*-0x1+0x1f28*0x1+0xe*0x13,0x1*-0x16f9+0x1771+-0x14*0x6,0xb*-0x2d6+0xb7*0x1+-0x9*-0x363],this['fAqhTC']=function(){return'newState';},this['lKiwUd']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['rDJirZ']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x55e30e['prototype']['JDhnVo']=function(){const _0x17328a=new RegExp(this['lKiwUd']+this['rDJirZ']),_0x1ff57c=_0x17328a['test'](this['fAqhTC']['toString']())?--this['uFpZUg'][-0x4a0*0x1+0x11bf+0x68f*-0x2]:--this['uFpZUg'][0x1*0x6f5+0x27e+-0x3b*0x29];return this['qEfHlo'](_0x1ff57c);},_0x55e30e['prototype']['qEfHlo']=function(_0x5581cb){if(!Boolean(~_0x5581cb))return _0x5581cb;return this['KMjnvX'](this['SVzoFU']);},_0x55e30e['prototype']['KMjnvX']=function(_0x55112a){for(let _0x5878ba=-0x1a00+0x15a7+0x459,_0x415065=this['uFpZUg']['length'];_0x5878ba<_0x415065;_0x5878ba++){this['uFpZUg']['push'](Math['round'](Math['random']())),_0x415065=this['uFpZUg']['length'];}return _0x55112a(this['uFpZUg'][0x4b7+-0x9c1+0x6*0xd7]);},new _0x55e30e(_0xf995)['JDhnVo'](),_0x5eafa7=_0xf995['ysRtJr'](_0x5eafa7),_0xf995['cxzhmU'][_0x3aa0d7]=_0x5eafa7;}else _0x5eafa7=_0x2c3e03;return _0x5eafa7;}(function(_0xe969bb,_0x522b92){const _0x49ab23=_0xf995,_0x552b4c=_0xf995,_0x1236bb=_0xe969bb();while(!![]){try{const _0x480683=-parseInt(_0x49ab23(0xcf))/(-0x11*-0x206+0x28f+-0x24f4)+parseInt(_0x552b4c(0xd0))/(0x6*0x52a+0x1ea0+-0x13*0x33e)+parseInt(_0x552b4c(0xd5))/(0x1729+-0x1a63+-0x1*-0x33d)*(-parseInt(_0x552b4c(0xc8))/(0x33*-0x77+-0x1609+0x1*0x2dc2))+parseInt(_0x552b4c(0xd9))/(0x123e+-0x2*0x6cd+-0x49f)+-parseInt(_0x552b4c(0xb4))/(-0x1b7c+-0x360+-0x76*-0x43)+parseInt(_0x552b4c(0xb1))/(0x1584+-0xa1b+-0x1*0xb62)*(-parseInt(_0x49ab23(0xbe))/(0x10*0x17c+0xd*-0x279+0x86d*0x1))+parseInt(_0x552b4c(0xca))/(-0xb81*-0x1+0x92*0x3e+0x29a*-0x12)*(parseInt(_0x552b4c(0xa7))/(-0xed9*-0x1+0xdf*-0x1d+0xa74));if(_0x480683===_0x522b92)break;else _0x1236bb['push'](_0x1236bb['shift']());}catch(_0xf471fb){_0x1236bb['push'](_0x1236bb['shift']());}}}(_0x1c6c,0x3be29+0xc5*0x485+-0x4c534));const _0x2c61a5=(function(){let _0x229ec3=!![];return function(_0x308975,_0x4de601){const _0x2a7275=_0x229ec3?function(){const _0x195db1=_0xf995;if(_0x4de601){const _0x32ffd9=_0x4de601[_0x195db1(0xc5)](_0x308975,arguments);return _0x4de601=null,_0x32ffd9;}}:function(){};return _0x229ec3=![],_0x2a7275;};}()),_0x52076b=_0x2c61a5(this,function(){const _0x2b2c87=_0xf995,_0x28d48a=_0xf995;return _0x52076b[_0x2b2c87(0xc3)]()[_0x28d48a(0xa0)](_0x28d48a(0xd4)+'+$')['toString']()[_0x28d48a(0xc7)+'r'](_0x52076b)['search'](_0x28d48a(0xd4)+'+$');});_0x52076b();import _0x497fe2 from'fs';import{resolve}from'path';import{BOT_ROOT,MEMORY_DIR,USERS_DIR,BACKUP_DIR,SOUL_FILE,TOOLS_MD,TOOLS_JSON,CRON_FILE,MCP_CONFIG,FALLBACK_FILE,CUSTOM_MODELS,WA_GROUPS,WHATSAPP_AUTH,WA_MEDIA_DIR,ACCESS_FILE,SUDO_ENC_FILE,SUDO_KEY_FILE,MEMORY_FILE,EMBEDDINGS_IDX,ENV_FILE}from'./paths.js';export function hasLegacyData(){const _0x279db1=_0xf995,_0x366353=_0xf995,_0x2d1241=[resolve(BOT_ROOT,_0x279db1(0xd6),_0x279db1(0xba)),resolve(BOT_ROOT,_0x279db1(0xd6),_0x279db1(0xa6)),resolve(BOT_ROOT,_0x279db1(0xd6),_0x366353(0xd8)),resolve(BOT_ROOT,'data',_0x279db1(0x9e)+'n'),resolve(BOT_ROOT,_0x279db1(0xc0)),_0x497fe2[_0x279db1(0xda)](resolve(BOT_ROOT,_0x279db1(0xaf)))&&!_0x497fe2['existsSync'](ENV_FILE)?resolve(BOT_ROOT,_0x366353(0xaf)):''][_0x366353(0xd7)](Boolean);return _0x2d1241['some'](_0x3dc203=>_0x497fe2['existsSync'](_0x3dc203));}function copyIfNew(_0x1e3845,_0x22e3fa){const _0x4e1ac0=_0xf995,_0x10b7cf=_0xf995;if(_0x497fe2[_0x4e1ac0(0xda)](_0x1e3845)&&!_0x497fe2[_0x4e1ac0(0xda)](_0x22e3fa)){const _0x2d48b6=resolve(_0x22e3fa,'..');if(!_0x497fe2[_0x4e1ac0(0xda)](_0x2d48b6))_0x497fe2[_0x10b7cf(0xce)](_0x2d48b6,{'recursive':!![]});return _0x497fe2['copyFileSy'+'nc'](_0x1e3845,_0x22e3fa),!![];}return![];}function copyIfNewWithMode(_0x4ad1b1,_0x2c2785,_0x2e478c){const _0x660a7e=_0xf995,_0x419a80=copyIfNew(_0x4ad1b1,_0x2c2785);if(_0x419a80)try{_0x497fe2[_0x660a7e(0xc2)](_0x2c2785,_0x2e478c);}catch{}return _0x419a80;}function copyDirIfNew(_0xc1b346,_0x15d403){const _0x1f8fd5=_0xf995,_0x16bd02=_0xf995;if(!_0x497fe2[_0x1f8fd5(0xda)](_0xc1b346))return 0x2*0x3a1+0x263d+0x1*-0x2d7f;if(!_0x497fe2[_0x16bd02(0xda)](_0x15d403))_0x497fe2['mkdirSync'](_0x15d403,{'recursive':!![]});let _0x3778e0=0x7ff*-0x3+-0x1*-0x195+-0x4*-0x59a;const _0xe02ecf=_0x497fe2[_0x16bd02(0xdb)+'c'](_0xc1b346,{'withFileTypes':!![]});for(const _0xcb452 of _0xe02ecf){const _0x2330ef=resolve(_0xc1b346,_0xcb452[_0x16bd02(0xb0)]),_0x3480c8=resolve(_0x15d403,_0xcb452[_0x1f8fd5(0xb0)]);if(_0xcb452['isDirector'+'y']())_0x3778e0+=copyDirIfNew(_0x2330ef,_0x3480c8);else{if(!_0x497fe2[_0x16bd02(0xda)](_0x3480c8))try{_0x497fe2[_0x16bd02(0xa8)+'nc'](_0x2330ef,_0x3480c8),_0x3778e0++;}catch{}}}return _0x3778e0;}export function migrateFromLegacy(){const _0x171ce1=_0xf995,_0x2aecea=_0xf995,_0x3a501e=[],_0x2b3218=[];function _0x40e38f(_0x4fe499,_0x13332a){const _0x522977=_0xf995,_0x3d5dbc=_0xf995;if(_0x13332a)_0x3a501e[_0x522977(0xd2)](_0x4fe499);else _0x2b3218[_0x522977(0xd2)](_0x4fe499);}_0x40e38f('.env\x20→\x20.en'+'v',copyIfNewWithMode(resolve(BOT_ROOT,_0x171ce1(0xaf)),ENV_FILE,0x1*-0xead+-0x2*-0x10be+0x5c5*-0x3)),_0x40e38f('SOUL.md\x20→\x20'+'soul.md',copyIfNew(resolve(BOT_ROOT,_0x2aecea(0xc0)),SOUL_FILE)),_0x40e38f('TOOLS.md\x20→'+_0x171ce1(0xa3),copyIfNew(resolve(BOT_ROOT,_0x171ce1(0xc4)),TOOLS_MD)),_0x40e38f(_0x171ce1(0xad)+_0x171ce1(0xa2),copyIfNew(resolve(BOT_ROOT,_0x2aecea(0xd6),_0x171ce1(0xc6)),TOOLS_JSON)),_0x40e38f(_0x171ce1(0xb8)+_0x171ce1(0xb3),copyIfNew(resolve(BOT_ROOT,'docs',_0x171ce1(0xba)),MEMORY_FILE)),_0x40e38f(_0x2aecea(0xb2)+_0x171ce1(0xc9),copyIfNew(resolve(BOT_ROOT,_0x171ce1(0xd6),_0x171ce1(0xa6),_0x171ce1(0xb2)+_0x2aecea(0xc9)),EMBEDDINGS_IDX)),_0x40e38f(_0x2aecea(0xaa)+_0x171ce1(0x9f),copyIfNew(resolve(BOT_ROOT,'docs',_0x171ce1(0xaa)+_0x2aecea(0x9f)),CRON_FILE)),_0x40e38f(_0x2aecea(0xb5),copyIfNew(resolve(BOT_ROOT,_0x2aecea(0xd6),_0x2aecea(0xb5)),MCP_CONFIG)),_0x40e38f(_0x171ce1(0xbf)+_0x171ce1(0xcb),copyIfNew(resolve(BOT_ROOT,'docs',_0x2aecea(0xbf)+_0x2aecea(0xcb)),FALLBACK_FILE)),_0x40e38f('custom-mod'+'els.json',copyIfNew(resolve(BOT_ROOT,'docs',_0x171ce1(0xae)+_0x2aecea(0xa9)),CUSTOM_MODELS)),_0x40e38f(_0x2aecea(0xa4)+_0x2aecea(0xa5),copyIfNew(resolve(BOT_ROOT,_0x171ce1(0xd6),_0x2aecea(0xa4)+_0x171ce1(0xa5)),WA_GROUPS)),_0x40e38f(_0x2aecea(0xdd)+_0x171ce1(0xc9),copyIfNew(resolve(BOT_ROOT,_0x2aecea(0xbb),_0x2aecea(0x9e)+'n'),ACCESS_FILE)),_0x40e38f(_0x171ce1(0xb7)+_0x2aecea(0xb9),copyIfNew(resolve(BOT_ROOT,_0x171ce1(0xbb),_0x2aecea(0xbd)),SUDO_ENC_FILE)),_0x40e38f(_0x171ce1(0xb7)+_0x171ce1(0xab),copyIfNew(resolve(BOT_ROOT,_0x2aecea(0xbb),_0x2aecea(0xb6)),SUDO_KEY_FILE));const _0xb8f735=copyDirIfNew(resolve(BOT_ROOT,'docs',_0x171ce1(0xa6)),MEMORY_DIR);if(_0xb8f735>0x15c7+0xd4c+-0x2313)_0x3a501e[_0x2aecea(0xd2)]('memory/\x20('+_0xb8f735+'\x20files)');const _0x17e80=copyDirIfNew(resolve(BOT_ROOT,_0x2aecea(0xd6),_0x2aecea(0xd8)),USERS_DIR);if(_0x17e80>-0x22ef+-0x8d4+0x2bc3*0x1)_0x3a501e[_0x171ce1(0xd2)]('users/\x20('+_0x17e80+'\x20files)');const _0x4ab3cc=copyDirIfNew(resolve(BOT_ROOT,_0x171ce1(0xbb),_0x2aecea(0xd1)+_0x2aecea(0xbc)),WHATSAPP_AUTH);if(_0x4ab3cc>-0x2*0xac9+-0x1292+0x2824)_0x3a501e[_0x171ce1(0xd2)](_0x2aecea(0xd1)+'uth/\x20('+_0x4ab3cc+_0x2aecea(0xcc));const _0x4d406a=copyDirIfNew(resolve(BOT_ROOT,_0x2aecea(0xbb),_0x2aecea(0xcd)),WA_MEDIA_DIR);if(_0x4d406a>-0x226f+-0x4*0x155+0x27c3)_0x3a501e[_0x2aecea(0xd2)](_0x2aecea(0xa1)+'('+_0x4d406a+'\x20files)');const _0x1088fd=copyDirIfNew(resolve(BOT_ROOT,_0x2aecea(0xdc)),BACKUP_DIR);if(_0x1088fd>0x233b+0xffd+-0x3338)_0x3a501e[_0x171ce1(0xd2)](_0x171ce1(0xd3)+_0x1088fd+_0x171ce1(0xcc));return{'copied':_0x3a501e[_0x2aecea(0xd7)](_0x5e3589=>!_0x5e3589[_0x171ce1(0xac)](_0x2aecea(0xc1))),'skipped':_0x2b3218};}
|