-
Notifications
You must be signed in to change notification settings - Fork 18
/
yue.js
264 lines (227 loc) Β· 6.96 KB
/
yue.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
// yue.js
const fs = require("fs");
const path = require("path");
const login = require("fb-chat-api-temp");
const axios = require("axios");
const express = require("express");
const chalk = require("chalk");
const gradient = require("gradient-string");
const {
addUserToDB,
getThreadInfoFromDB,
getUserInfoFromDB,
addThreadToDB,
} = require("./database/commands/index");
const app = express();
const commandPath = path.join(__dirname, "scripts", "commands");
const PREFIX = ":";
const PORT = process.env.PORT || 3000;
const commands = {};
// Load the version from version.json
const versionPath = path.join(__dirname, "version.json");
let version = loadVersion();
function loadCommands() {
const commandFiles = fs
.readdirSync(commandPath)
.filter((file) => file.endsWith(".js"));
commandFiles.forEach((file) => {
const startTime = new Date();
const commandName = path.basename(file, ".js");
commands[commandName] = require(path.join(commandPath, file));
const endTime = new Date();
// Loading commands logger
const duration = endTime - startTime;
const loadingLog = gradient.rainbow(
`Loaded ${commandName}.js (${duration}ms)`,
);
console.log(loadingLog);
});
}
function loadVersion() {
try {
return JSON.parse(fs.readFileSync(versionPath, "utf8")).version;
} catch (error) {
console.error("Error loading version:", error);
return null;
}
}
// Assuming this is where you create the API instance
function initializeBot() {
login({ appState: loadAppState() }, (err, api) => {
if (err) return console.error(err);
api.setOptions({
listenEvents: true,
logLevel: "silent",
});
// Additional global variables
const fbstate = api.getAppState();
global.client = {};
global.data = {};
global.account = {
cookie: fbstate.map((i) => (i = i.key + "=" + i.value)).join(";"),
};
// Check for updates
updateCheck();
fs.writeFileSync("appstate.json", JSON.stringify(api.getAppState()));
// Set global variables
global.client = {};
global.data = {};
global.account = {
cookie: fbstate.map((i) => (i = i.key + "=" + i.value)).join(";"),
};
api.listen(async (err, event) => {
if (err) {
console.error("Error occurred while processing event:", err);
return;
}
const userExists = await getUserInfoFromDB(event.senderID);
if (!userExists) {
// Use the addUserToDB command to add the user to the database
addUserToDB(api, event.senderID);
}
const threadExists = await getThreadInfoFromDB(event.threadID);
if (!threadExists) {
// Manually add the thread information to the database
await addThreadToDB(api, event.threadID);
}
const box = {
react: (emoji) => {
api.setMessageReaction(emoji, event.messageID, () => {}, true);
},
reply: (msg) => {
api.sendMessage(msg, event.threadID, event.messageID);
},
add: (uid) => {
api.addUserToGroup(uid, event.threadID);
},
kick: (uid) => {
api.removeUserFromGroup(uid, event.threadID);
},
send: (msg) => {
api.sendMessage(msg, event.threadID);
},
};
try {
if (event.body && event.body.toLowerCase() === "prefix") {
api.sendMessage(
`My prefix is: \`${PREFIX}\``,
event.threadID,
event.messageID,
);
} else if (event.body && event.body.toLowerCase().startsWith(PREFIX)) {
const [command, ...args] = event.body
.slice(PREFIX.length)
.trim()
.split(" ");
if (commands[command]) {
commands[command].run({ api, event, args, box });
} else {
api.sendMessage(
"Invalid command.",
event.threadID,
event.messageID,
);
}
}
} catch (error) {
console.error("Error occurred while executing command:", error);
// Handle the error or log it to your preferred logging service
}
});
});
}
function loadAppState() {
try {
const appStatePath = path.join(__dirname, "appstate.json");
return JSON.parse(fs.readFileSync(appStatePath, "utf8"));
} catch (error) {
console.error("Error loading app state:", error);
return null;
}
}
function updateCheck() {
axios
.get("https://api.github.com/repos/ruingl/Yue/releases/latest")
.then((response) => {
const latestVersion = response.data.tag_name;
if (latestVersion && latestVersion !== version) {
console.log(
gradient.retro(
`β© New version found! Update to ${latestVersion} using npm run update`,
),
);
}
})
.catch((error) => {
console.error("Error checking for updates:", error);
});
}
// Initialize the bot
initializeBot();
app.get("/", (req, res) => {
res.send(`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Website in Construction ποΈ</title>
<!-- Include Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
margin: 0;
}
.construction-container {
text-align: center;
padding: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.construction-icon {
font-size: 40px;
margin-bottom: 20px;
}
.construction-text {
font-size: 18px;
color: #555;
}
.footer {
margin-top: 20px;
font-size: 12px;
color: #777;
}
</style>
</head>
<body>
<div class="construction-container">
<div class="construction-icon">ποΈ</div>
<div class="construction-text">Website in Construction</div>
<div class="footer">Β© Copyright 2024 ruingl.</div>
</div>
<!-- Include Bootstrap JS (optional, for Bootstrap features) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
`);
});
app.listen(PORT, () => {
console.log(gradient.retro(`β© yuev1 - (${version}) π`));
// Additional logging for 'by ruingl'
console.log(gradient.retro("β© by ruingl β₯οΈ"));
// ... (rest of your logging)
console.log("");
// Log the loaded commands
console.log(gradient.rainbow("Loaded Commands:"));
loadCommands();
// Additional console.log(""); for separation
console.log("");
});