-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
99 lines (86 loc) · 2.56 KB
/
index.js
File metadata and controls
99 lines (86 loc) · 2.56 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
console.clear()
import { spawn } from 'child_process'
import path from 'path'
import CFonts from 'cfonts'
import chalk from 'chalk'
import fetch from 'node-fetch'
import axios from 'axios'
import fs from 'fs'
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const unhandledRejections = new Map()
process.on('uncaughtException', (err) => {
if (err.code === 'ENOMEM') {
console.error('Out of memory error detected. Cleaning up resources...')
} else {
console.error('Uncaught Exception:', err)
}
})
process.on('unhandledRejection', (reason, promise) => {
unhandledRejections.set(promise, reason)
if (reason.code === 'ENOMEM') {
console.error('Out of memory error detected. Attempting recovery...')
Object.keys(require.cache).forEach((key) => {
delete require.cache[key]
})
} else {
console.log('Unhandled Rejection at:', promise, 'reason:', reason)
}
})
process.on('rejectionHandled', (promise) => {
unhandledRejections.delete(promise)
})
process.on('Something went wrong', function (err) {
console.log('Caught exception: ', err)
})
process.on('warning', (warning) => {
if (warning.name === 'MaxListenersExceededWarning') {
console.warn('Potential memory leak detected:', warning.message)
}
})
function start() {
let args = [path.join(__dirname, 'main.js'), ...process.argv.slice(2)]
let p = spawn(process.argv[0], args, { stdio: ['inherit', 'inherit', 'inherit', 'ipc'] })
.on('message', data => {
if (data == 'reset') {
console.log('Restarting...')
p.kill()
}
})
.on('exit', code => {
console.error('Exited with code:', code)
start()
})
}
const major = parseInt(process.versions.node.split('.')[0], 10)
if (major < 20) {
console.error(
`\n❌ This script requires Node.js 20+ to run reliably.\n` +
` You are using Node.js ${process.versions.node}.\n` +
` Please upgrade to Node.js 20+ to proceed.\n`
)
process.exit(1)
}
CFonts.say('Keys', {
colors: ["cyan", "blue"],
font: "block",
align: "center",
gradient: ["cyan", "blue"],
transitionGradient: true,
})
axios({
url: 'https://raw.githubusercontent.com/RayNozawa/TeleBot/refs/heads/main/main.js',
method: 'GET',
responseType: 'stream'
})
.then((response) => {
const writer = fs.createWriteStream('main.js');
response.data.pipe(writer);
writer.on('finish', () => {
start()
})
writer.on('error', (err) => {
console.error(err);
})
});