-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathAkhiro.js
More file actions
400 lines (361 loc) ยท 12.2 KB
/
Akhiro.js
File metadata and controls
400 lines (361 loc) ยท 12.2 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
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
const login = require("./fb-chat-api/index");
const fs = require("fs-extra");
const express = require("express");
const chalk = require("chalk");
const gradient = require("gradient-string");
const path = require("path");
const PORT = 3000;
const app = express();
const configPath = path.join(process.cwd(), "akhiro_config.json");
const config = fs.readJsonSync(configPath, { throws: true });
global.AkhiroBot = {
botName: config.botName,
botPrefix: config.botPrefix,
botDev: config.botDev,
contact: config.contact,
botOwner: config.botOwner,
ownerUID: config.ownerUID,
botAdmins: config.botAdmins,
commands: {},
loadCmd: loadCmd,
unloadCmd: unloadCmd,
loadAll: loadAll,
};
app.use(express.static("public"));
app.get("/", (req, res) => {
res.sendFile(__dirname + "/public/index.html");
});
app.get("/README.md", (req, res) => {
res.sendFile(__dirname + "/README.md");
});
function loadCommands() {
const commandsPath = path.join(__dirname, "akhiro", "cmds");
const commandFiles = fs
.readdirSync(commandsPath)
.filter((file) => file.endsWith(".js"));
commandFiles.forEach((file) => {
const startTime = new Date();
const commandName = file.replace(".js", "");
const command = require(path.join(commandsPath, file));
const endTime = new Date();
if (command.config && command.onRun) {
global.AkhiroBot.commands[commandName] = command;
const duration = endTime - startTime;
const loadingLog = gradient.rainbow(
`[ COMMAND ] Loaded ${commandName}.js (${duration}ms)`,
);
console.log(loadingLog);
}
});
console.log("");
}
function loadCmd(file) {
const filePath = path.join(__dirname, "akhiro", "cmds", `${file}.js`);
try {
const command = require(filePath);
const { name } = command.config;
global.AkhiroBot.commands[name] = command;
return { success: true, message: `Command "${name}" loaded successfully.` };
} catch (error) {
return {
success: false,
message: `Error loading command from file "${file}.js": ${error.message}`,
};
}
}
function unloadCmd(name) {
const command = global.AkhiroBot.commands[name];
if (command) {
delete global.AkhiroBot.commands[name];
return {
success: true,
message: `Command "${name}" unloaded successfully.`,
};
} else {
return { success: false, message: `Command "${name}" not found.` };
}
}
function loadAll() {
const commandsDir = path.join(__dirname, "akhiro", "cmds");
const files = fs.readdirSync(commandsDir);
const results = [];
for (const file of files) {
if (file.endsWith(".js")) {
const result = loadCmd(file.replace(".js", ""));
results.push(result);
}
}
return results;
}
function initializeBot() {
try {
const appState = JSON.parse(fs.readFileSync("appstate.json", "utf8"));
login({ appState }, (err, api) => {
try {
if (err) {
throw new Error(`โ | Error while logging in: ${err}`);
}
fs.writeFileSync("appstate.json", JSON.stringify(api.getAppState()));
api.setOptions({
listenEvents: true,
logLevel: "silent",
});
api.listen(async (err, event, message) => {
try {
if (err) {
throw new Error(`โ | Error while listening: ${err}`);
}
const applyFonts = (text, fontType) => {
const selectedFont = fonts[fontType.toLowerCase()];
if (!selectedFont) return text;
const result = text
.split("")
.map((char) => selectedFont[char] || char)
.join("");
return result;
};
const fonts = {
sans: {
a: "๐บ",
b: "๐ป",
c: "๐ผ",
d: "๐ฝ",
e: "๐พ",
f: "๐ฟ",
g: "๐",
h: "๐",
i: "๐",
j: "๐",
k: "๐",
l: "๐
",
m: "๐",
n: "๐",
o: "๐",
p: "๐",
q: "๐",
r: "๐",
s: "๐",
t: "๐",
u: "๐",
v: "๐",
w: "๐",
x: "๐",
y: "๐",
z: "๐",
A: "๐ ",
B: "๐ก",
C: "๐ข",
D: "๐ฃ",
E: "๐ค",
F: "๐ฅ",
G: "๐ฆ",
H: "๐ง",
I: "๐จ",
J: "๐ฉ",
K: "๐ช",
L: "๐ซ",
M: "๐ฌ",
N: "๐ญ",
O: "๐ฎ",
P: "๐ฏ",
Q: "๐ฐ",
R: "๐ฑ",
S: "๐ฒ",
T: "๐ณ",
U: "๐ด",
V: "๐ต",
W: "๐ถ",
X: "๐ท",
Y: "๐ธ",
Z: "๐น",
0: "๐ข",
1: "๐ฃ",
2: "๐ค",
3: "๐ฅ",
4: "๐ฆ",
5: "๐ง",
6: "๐จ",
7: "๐ฉ",
8: "๐ช",
9: "๐ซ",
},
bold: {
a: "๐ฎ",
b: "๐ฏ",
c: "๐ฐ",
d: "๐ฑ",
e: "๐ฒ",
f: "๐ณ",
g: "๐ด",
h: "๐ต",
i: "๐ถ",
j: "๐ท",
k: "๐ธ",
l: "๐น",
m: "๐บ",
n: "๐ป",
o: "๐ผ",
p: "๐ฝ",
q: "๐พ",
r: "๐ฟ",
s: "๐",
t: "๐",
u: "๐",
v: "๐",
w: "๐",
x: "๐
",
y: "๐",
z: "๐",
A: "๐",
B: "๐",
C: "๐",
D: "๐",
E: "๐",
F: "๐",
G: "๐",
H: "๐",
I: "๐",
J: "๐",
K: "๐",
L: "๐",
M: "๐ ",
N: "๐ก",
O: "๐ข",
P: "๐ฃ",
Q: "๐ค",
R: "๐ฅ",
S: "๐ฆ",
T: "๐ง",
U: "๐จ",
V: "๐ฉ",
W: "๐ช",
X: "๐ซ",
Y: "๐ฌ",
Z: "๐ญ",
0: "๐ข",
1: "๐ฃ",
2: "๐ค",
3: "๐ฅ",
4: "๐ฆ",
5: "๐ง",
6: "๐จ",
7: "๐ฉ",
8: "๐ช",
9: "๐ซ",
},
applyFonts: applyFonts,
};
const processCommand = async () => {
const [inputCommand, ...args] = event.body
.slice(global.AkhiroBot.botPrefix.length)
.trim()
.split(" ");
const commandName = Object.keys(global.AkhiroBot.commands).find(
(key) =>
global.AkhiroBot.commands[key].config.aliases?.includes(
inputCommand,
) || key === inputCommand,
);
if (commandName) {
const command = global.AkhiroBot.commands[commandName];
if (command && command.onRun) {
if (command.config && command.config.role) {
const requiredRole = command.config.role;
if (requiredRole === 1) {
function isAdmin(userId) {
return global.AkhiroBot.botAdmins.includes(userId);
}
if (!isAdmin(event.senderID)) {
api.sendMessage(
"โ | You don't have the required role to execute this command.",
event.threadID,
event.messageID,
);
return;
}
}
}
await command.onRun({ api, event, args, fonts });
} else {
api.sendMessage(
`โ | Invalid command, use \`${global.AkhiroBot.botPrefix}help\` to show available commands.`,
event.threadID,
event.messageID,
);
}
} else {
api.sendMessage(
`โ | Invalid command, use \`${global.AkhiroBot.botPrefix}help\` to show available commands.`,
event.threadID,
event.messageID,
);
}
};
if (event.body && event.body.toLowerCase() === "prefix") {
api.sendMessage(
fonts.applyFonts(
`โโโ โโโ โโโ โ โโโ โโโ
โโโ โโโ โโโ โ โโโ โโโ
โโโโโโโโโโโโโโโโโโโ
Hello there User, Im AkhiroBot. My Prefix Is This [ ${global.AkhiroBot.botPrefix} ]. I Hope You Will Enjoy Using Me, Have Fun. Thanks!
AkhiroBot Is A Collab Bot File Project Made By AkhiroDev, LiANE And Yu3Bot, So Please If You Managed To Find This File, Please Don't Abuse This Bot File Project Of Our's.
DEVELOPERS OF AKHIROBOT:
- YueBot ( Rui Reogo )
- AkhiroDev ( Francis Loyd Raval )
- LiANE ( Liane Cagara )
YSD: AkhiroBot`,
"sans",
),
event.threadID,
event.messageID,
);
} else if (
event.body &&
event.body.toLowerCase().startsWith(global.AkhiroBot.botPrefix)
) {
await processCommand();
}
} catch (error) {
console.error(chalk.red(`${error}`));
}
});
} catch (error) {
console.error(chalk.red(`${error}`));
}
});
} catch (error) {
console.error(chalk.red(`โ | Error initializing bot: ${error}`));
}
}
app.listen(PORT, () => {
initializeBot();
console.log(
gradient.retro(` โโโ โโโ โโโ โ โโโ โโโ โโโ โโโ โโโ
โโโ โโโ โโโ โ โโโ โโโ โโโ โโโ โโโ
Version 1.0.0`),
);
console.log(gradient.retro("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"));
console.log(gradient.retro("[ SYSTEM ] Getting started..."));
console.log(gradient.retro(`[ SYSTEM ] Website running on port ${PORT}`));
console.log(gradient.retro("[ SYSTEM ] Successfully connected to Database"));
console.log(gradient.retro(`[ SYSTEM ] Starting AkhiroBot`));
console.log(gradient.retro(`โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ`));
console.log(
gradient.rainbow(`
โโ โโโ โโโโโ โโโโโ โโโ โโโโ โโโ โโ
โโ โโโ โโโโโ โโโโโ โโโ โโโโ โโโ โโ`),
);
console.log();
loadCommands();
console.log(gradient.retro(`โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ`));
console.log(
gradient.retro(` โโโ โโโ โโโ โ โโโ โโโ โโโ โโโ โโโ
โโโ โโโ โโโ โ โโโ โโโ โโโ โโโ โโโ
BOT INFORMATION`),
);
console.log();
console.log(gradient.retro(`[ BOT NAME ] AKHIROBOT`));
console.log(gradient.retro(`[ BOT PRFX ] ${global.AkhiroBot.botPrefix} `));
console.log(gradient.retro(`[ BOT OWNER ] ${global.AkhiroBot.botOwner}`));
console.log(gradient.retro(`[ BOT DEVS ] ${global.AkhiroBot.botDev}`));
});