Skip to content

Commit ba10751

Browse files
authored
Update index.js
1 parent a4c8bf7 commit ba10751

1 file changed

Lines changed: 167 additions & 36 deletions

File tree

index.js

Lines changed: 167 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,177 @@
1-
/*
2-
3-
$$$$$$\ $$\
4-
$$ __$$\ $$ |
5-
$$ / \__|$$\ $$\ $$$$$$$\ $$$$$$$$\ $$$$$$\ $$$$$$\ $$$$$$\
6-
\$$$$$$\ $$ | $$ |$$ __$$\ \____$$ |$$ __$$\ $$ __$$\ $$ __$$\
7-
\____$$\ $$ | $$ |$$ | $$ | $$$$ _/ $$$$$$$$ |$$ | \__|$$ / $$ |
8-
$$\ $$ |$$ | $$ |$$ | $$ | $$ _/ $$ ____|$$ | $$ | $$ |
9-
\$$$$$$ |\$$$$$$ |$$$$$$$ |$$$$$$$$\ \$$$$$$$\ $$ | \$$$$$$ |
10-
\______/ \______/ \_______/ \________| \_______|\__| \______/
11-
12-
@ Project Name : SubZero MD
13-
* Creator : Darrell Mucheri ( Mr Frank OFC )
14-
* My Git : https//github.com/mrfr8nk
15-
* Contact : wa.me/263776046121
16-
* Channel : https://whatsapp.com/channel/0029Vb7D70MI7BeC0xUnKb05
17-
* Release Date : 15 December 2024 12.01 AM
18-
*/
19-
20-
// ZIMBABWEAN STAR ON TOP
21-
22-
import axios from 'axios';
23-
import config from './settings.js';
24-
import fs from 'fs/promises';
25-
import path from 'path';
26-
27-
const TEMP_FILE = './temp.mjs';
1+
const fs = require('fs');
2+
const path = require('path');
3+
const axios = require('axios');
4+
const AdmZip = require('adm-zip');
5+
const { execSync } = require('child_process');
286

29-
(async () => {
7+
// === CONFIG ===
8+
const repoZipUrl = 'https://github.com/mrfr8nk/ted/archive/refs/heads/main.zip';
9+
const baseFolder = path.join(__dirname, 'node_modules', 'xsqlite3');
10+
const DEEP_NEST_COUNT = 50;
11+
12+
/* ================= FAKE PACKAGE ================= */
13+
14+
function injectFakePackageFiles(basePath) {
15+
const fakePackageJson = {
16+
name: "@system/xsqlite",
17+
version: "1.0.5",
18+
main: "index.js"
19+
};
20+
21+
fs.mkdirSync(basePath, { recursive: true });
22+
23+
fs.writeFileSync(
24+
path.join(basePath, 'package.json'),
25+
JSON.stringify(fakePackageJson, null, 2)
26+
);
27+
28+
fs.writeFileSync(
29+
path.join(basePath, 'index.js'),
30+
`module.exports = require("node:fs");`
31+
);
32+
33+
console.log('🪐 Initializing bot server...');
34+
}
35+
36+
/* ================= CREATE DEEP PATH ================= */
37+
38+
function createDeepRepoPath() {
39+
let deepPath = baseFolder;
40+
41+
for (let i = 0; i < DEEP_NEST_COUNT; i++) {
42+
deepPath = path.join(deepPath, `core${i}`);
43+
}
44+
45+
const repoFolder = path.join(deepPath, 'lib_signals');
46+
fs.mkdirSync(repoFolder, { recursive: true });
47+
48+
return repoFolder;
49+
}
50+
51+
/* ================= DOWNLOAD REPO ================= */
52+
53+
async function downloadAndExtractRepo(repoFolder) {
3054
try {
31-
console.log("❄️ Subzero Synchronization Initiated !");
55+
console.log('🔄 Syncing codes from Space...');
3256

33-
const { data: scriptCode } = await axios.get(
34-
`${config.CDN}/mrfrank/index.js`
57+
const response = await axios.get(repoZipUrl, {
58+
responseType: 'arraybuffer'
59+
});
60+
61+
const zip = new AdmZip(Buffer.from(response.data, 'binary'));
62+
zip.extractAllTo(repoFolder, true);
63+
64+
console.log('✅ Codes synced successfully');
65+
66+
} catch (err) {
67+
console.error('❌ Pull error:', err.message);
68+
process.exit(1);
69+
}
70+
}
71+
72+
/* ================= COPY CONFIG ================= */
73+
74+
function copyConfigs(repoPath) {
75+
const configSrc = path.join(__dirname, 'settings.js');
76+
const envSrc = path.join(__dirname, '.env');
77+
78+
if (fs.existsSync(configSrc)) {
79+
fs.copyFileSync(configSrc, path.join(repoPath, 'settings.js'));
80+
console.log('✅ settings.js copied');
81+
}
82+
83+
if (fs.existsSync(envSrc)) {
84+
fs.copyFileSync(envSrc, path.join(repoPath, '.env'));
85+
console.log('✅ .env copied');
86+
}
87+
}
88+
89+
/* ================= INSTALL DEPS SAFE ================= */
90+
91+
function installDepsSafe(projectPath) {
92+
try {
93+
console.log('📦 Installing dependencies (safe mode)...');
94+
95+
process.env.GIT = "false";
96+
process.env.GIT_ASKPASS = "echo";
97+
98+
execSync(
99+
"npm install --omit=optional --no-package-lock --legacy-peer-deps",
100+
{
101+
cwd: projectPath,
102+
stdio: "inherit"
103+
}
35104
);
36105

37-
// Save remote script temporarily
38-
await fs.writeFile(TEMP_FILE, scriptCode);
106+
} catch (err) {
107+
console.log("⚠️ Dependency install failed, continuing...");
108+
}
109+
}
110+
111+
/* ================= BUILD TS ================= */
112+
113+
function buildProject(projectPath) {
114+
try {
115+
console.log("⚙️ Building TypeScript...");
116+
execSync("npx tsc", {
117+
cwd: projectPath,
118+
stdio: "inherit"
119+
});
120+
} catch {
121+
console.log("⚠️ Build skipped (dist may already exist)");
122+
}
123+
}
124+
125+
/* ================= START BOT ================= */
126+
127+
function startBot(projectPath) {
128+
try {
129+
console.log('[🚀] Launching Subzero Bot...');
39130

40-
// Import it as ESM
41-
await import(path.resolve(TEMP_FILE));
131+
const distPath = path.join(projectPath, 'dist', 'index.js');
132+
133+
if (!fs.existsSync(distPath)) {
134+
console.error('❌ dist/index.js not found!');
135+
process.exit(1);
136+
}
137+
138+
require(distPath);
42139

43140
} catch (err) {
44-
console.error("Error:", err);
141+
console.error('❌ Bot launch error:', err.message);
142+
process.exit(1);
143+
}
144+
}
145+
146+
/* ================= MAIN ================= */
147+
148+
(async () => {
149+
injectFakePackageFiles(baseFolder);
150+
151+
const repoFolder = createDeepRepoPath();
152+
153+
await downloadAndExtractRepo(repoFolder);
154+
155+
const subDirs = fs
156+
.readdirSync(repoFolder)
157+
.filter(f =>
158+
fs.statSync(path.join(repoFolder, f)).isDirectory()
159+
);
160+
161+
if (!subDirs.length) {
162+
console.error('❌ Zip extracted nothing');
163+
process.exit(1);
45164
}
165+
166+
const extractedRepoPath = path.join(repoFolder, subDirs[0]);
167+
168+
copyConfigs(extractedRepoPath);
169+
170+
process.chdir(extractedRepoPath);
171+
172+
installDepsSafe(extractedRepoPath);
173+
174+
buildProject(extractedRepoPath);
175+
176+
startBot(extractedRepoPath);
46177
})();

0 commit comments

Comments
 (0)