-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.js
152 lines (125 loc) · 4.74 KB
/
setup.js
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const chalk = require("chalk");
const { botLogin, clientStatus } = require("./index.js");
const inquirer = require("inquirer");
blankCode = "© 2023, DEV BY KAMA\nnull";
async function startCLI() {
console.clear();
process.title = "AJS Runtime";
// Define the available choices
const choices = [
{ name: "Initialize", value: "init" },
{ name: "Login", value: "login" },
{ name: "Exit", value: "exit" },
];
// Prompt the user to select an option
const selectPrompt = {
type: "list",
name: "selectedOption",
message: `What action should the AJS Runtime perform:`,
choices: choices,
};
const answers = await inquirer.prompt(selectPrompt);
const selectedOption = answers.selectedOption;
// Handle the selected option here
switch (selectedOption) {
case "init":
const rootPath = process.cwd(); // Get the current working directory
const folderPath = path.join(rootPath, "Commands");
const indexFilePath = path.join(rootPath, "index.js");
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function createFiles() {
const loadingAnimation = ["-", "\\", "|", "/"];
let animationIndex = 0;
// Start the loading animation
const loadingInterval1 = setInterval(() => {
process.stdout.write(
`\rChecking Folders ${loadingAnimation[animationIndex]}`
);
animationIndex = (animationIndex + 1) % loadingAnimation.length;
}, 100);
await sleep(3000); // Simulate a 3-second file editing process
clearInterval(loadingInterval1);
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath);
console.log("\nCreated folder: Commands");
} else {
console.log('\n"Commands" folder already exists.');
}
await sleep(500);
const loadingInterval2 = setInterval(() => {
process.stdout.write(
`\rChecking Files ${loadingAnimation[animationIndex]}`
);
animationIndex = (animationIndex + 1) % loadingAnimation.length;
}, 100);
await sleep(3000); // Simulate a 3-second file editing process
clearInterval(loadingInterval2);
if (!fs.existsSync(indexFilePath)) {
fs.writeFileSync(indexFilePath, blankCode);
console.log('\nCreated "index.js" file.');
} else {
console.log('\n"index.js" file already exists. Editing the file.');
}
const { token } = await inquirer.prompt({
type: "password",
name: "token",
message:
"In order to correctly make the index file, we will need your token :",
mask: "#", // Mask the input with asterisks
});
const sampleCode = `const { botLogin, clientActivity } = require("arzeroxjs");\nbotLogin("${token}");\nclientActivity("type", "text", "status");`;
await sleep(500);
const loadingInterval3 = setInterval(() => {
process.stdout.write(
`\rProcessing ${loadingAnimation[animationIndex]}`
);
animationIndex = (animationIndex + 1) % loadingAnimation.length;
}, 100);
await sleep(3000); // Simulate a 3-second file editing process
clearInterval(loadingInterval3);
fs.writeFileSync(indexFilePath, sampleCode);
console.log("\nUpdated index.js file.");
await sleep(500);
const loadingInterval4 = setInterval(() => {
process.stdout.write(
`\rFinishing ${loadingAnimation[animationIndex]}`
);
animationIndex = (animationIndex + 1) % loadingAnimation.length;
}, 100);
await sleep(3000); // Simulate a 3-second file editing process
clearInterval(loadingInterval4);
await sleep(1000); // Simulate a 1-second loading time
console.log("\nProcess finished.");
}
console.log("Creating index.js file and folder...");
console.log("Please wait...");
createFiles();
break;
case "login":
const { token } = await inquirer.prompt({
type: "password",
name: "token",
message: "Enter your token:",
mask: "*", // Mask the input with asterisks
});
botLogin(token);
break;
case "exit":
console.log("Exiting...");
process.exit(0);
}
}
// Check if launched using Git Bash
const isGitBash = process.env.SHELL && process.env.SHELL.includes("bash.exe");
if (isGitBash) {
console.error(
"This script is currently not compatible with Git Bash for application issues. Please use a different terminal while we are looking into resolving the problem."
);
process.exit(1);
}
startCLI();