apexify.js 2.4.2 → 2.4.4-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,38 +44,53 @@ var prefixRegister_1 = require("./prefixRegister");
44
44
  var slashResponder_1 = require("./slashResponder");
45
45
  var prefixResponder_1 = require("./prefixResponder");
46
46
  var riffy_1 = require("riffy");
47
- var { mongoConnect, initializeDb} = require("../../database/MongoDB");
47
+ var utils_1 = require("../../database/utils");
48
48
  var start_1 = require("../discord-build/commands-(prefix)/music/functions/start");
49
49
  var end_1 = require("../discord-build/commands-(prefix)/music/functions/end");
50
50
  var buttons_1 = require("../discord-build/commands-(prefix)/music/functions/buttons");
51
- var axios = require("axios");
51
+ var axios_1 = require("axios");
52
52
  var fs_1 = require("fs");
53
- var express = require("express");
54
- function typeSentence(sentence, speed) {
55
- return __awaiter(this, void 0, void 0, function () {
56
- var _i, sentence_1, char;
57
- return __generator(this, function (_a) {
58
- switch (_a.label) {
59
- case 0:
60
- _i = 0, sentence_1 = sentence;
61
- _a.label = 1;
62
- case 1:
63
- if (!(_i < sentence_1.length)) return [3 /*break*/, 4];
64
- char = sentence_1[_i];
65
- return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, speed); })];
66
- case 2:
67
- _a.sent();
68
- process.stdout.write(char);
69
- _a.label = 3;
70
- case 3:
71
- _i++;
72
- return [3 /*break*/, 1];
73
- case 4:
74
- console.log();
75
- return [2 /*return*/];
76
- }
77
- });
78
- });
53
+ var express_1 = require("express");
54
+ var colors = {
55
+ reset: "\x1b[0m",
56
+ bright: "\x1b[1m",
57
+ dim: "\x1b[2m",
58
+ underscore: "\x1b[4m",
59
+ blink: "\x1b[5m",
60
+ reverse: "\x1b[7m",
61
+ hidden: "\x1b[8m",
62
+ fg: {
63
+ black: "\x1b[30m",
64
+ red: "\x1b[31m",
65
+ green: "\x1b[32m",
66
+ yellow: "\x1b[33m",
67
+ blue: "\x1b[34m",
68
+ magenta: "\x1b[35m",
69
+ cyan: "\x1b[36m",
70
+ white: "\x1b[37m",
71
+ },
72
+ bg: {
73
+ black: "\x1b[40m",
74
+ red: "\x1b[41m",
75
+ green: "\x1b[42m",
76
+ yellow: "\x1b[43m",
77
+ blue: "\x1b[44m",
78
+ magenta: "\x1b[45m",
79
+ cyan: "\x1b[46m",
80
+ white: "\x1b[47m",
81
+ },
82
+ };
83
+ function logError(message) {
84
+ console.log("".concat(colors.bright).concat(colors.fg.red, "[Error]:").concat(colors.reset, " ").concat(message));
85
+ }
86
+ function logSuccess(message) {
87
+ console.log("".concat(colors.bright).concat(colors.fg.green, "[Successful]:").concat(colors.reset, " ").concat(message));
88
+ }
89
+ function logWarning(message) {
90
+ console.log("".concat(colors.bright).concat(colors.fg.yellow, "[Warning]:").concat(colors.reset, " ").concat(message));
91
+ }
92
+ function logInfo(message) {
93
+ console.log("".concat(colors.bright).concat(colors.fg.blue, "[Info]:").concat(colors.reset, " ").concat(message));
79
94
  }
80
95
  function starter(client, options) {
81
96
  var _a, _b, _c, _d, _e, _f;
@@ -88,16 +103,17 @@ function starter(client, options) {
88
103
  case 0:
89
104
  _g.trys.push([0, 3, , 4]);
90
105
  if (!client) {
91
- throw new Error('\x1b[31mMissing client parameter. Please provide a valid Discord client.\x1b[0m');
106
+ throw new Error("\x1b[31mMissing client parameter. Please provide a valid Discord client.\x1b[0m");
92
107
  }
93
108
  if (!options.token) return [3 /*break*/, 2];
94
- return [4 /*yield*/, client.login(options.token)
109
+ return [4 /*yield*/, client
110
+ .login(options.token)
95
111
  .then(function () {
96
112
  var _a;
97
- typeSentence("\u001B[32mBot ".concat((_a = client.user) === null || _a === void 0 ? void 0 : _a.tag, " is online! \u001B[0m"), 50);
113
+ logSuccess("Bot ".concat((_a = client.user) === null || _a === void 0 ? void 0 : _a.tag, " is online! "));
98
114
  })
99
115
  .catch(function (error) {
100
- typeSentence('\x1b[31mError: Invalid token provided. Please provide a valid bot token.\x1b[0m', 50);
116
+ logError("Invalid token provided. Please provide a valid bot token");
101
117
  process.exit(1);
102
118
  })];
103
119
  case 1:
@@ -108,7 +124,7 @@ function starter(client, options) {
108
124
  slash: ((_a = options.slashCommandPath) === null || _a === void 0 ? void 0 : _a.logsId) || null,
109
125
  prefix: ((_b = options.prefixCommandPath) === null || _b === void 0 ? void 0 : _b.logsId) || null,
110
126
  };
111
- client.on('ready', function () { return __awaiter(_this, void 0, void 0, function () {
127
+ client.on("ready", function () { return __awaiter(_this, void 0, void 0, function () {
112
128
  var error_2, presenceOptions, path, dir, gId, gl, slashCommands, avatarData, response, _a, _b, _c, prefix, error_3;
113
129
  var _d, _e;
114
130
  var _f, _g, _h, _j;
@@ -122,9 +138,9 @@ function starter(client, options) {
122
138
  if (!options.lavalink.nodes || options.lavalink.nodes.length === 0) {
123
139
  options.lavalink.nodes = [
124
140
  {
125
- host: '195.58.58.23',
141
+ host: "195.58.58.23",
126
142
  port: 25565,
127
- password: 'best',
143
+ password: "best",
128
144
  secure: false,
129
145
  },
130
146
  ];
@@ -132,25 +148,25 @@ function starter(client, options) {
132
148
  return [4 /*yield*/, client.riffy.init((_f = client === null || client === void 0 ? void 0 : client.user) === null || _f === void 0 ? void 0 : _f.id)];
133
149
  case 2:
134
150
  _k.sent();
135
- typeSentence("Lavalink has been initialized. Please wait we are trying to connect", 50);
151
+ logInfo("Lavalink has been initialized. Please wait we are trying to connect");
136
152
  return [3 /*break*/, 5];
137
153
  case 3:
138
154
  error_2 = _k.sent();
139
- console.error("Failed to initialize Riffy: ".concat(error_2.message));
155
+ logError("Failed to initialize Riffy: ".concat(error_2.message));
140
156
  return [3 /*break*/, 5];
141
157
  case 4:
142
- typeSentence("Before connecting please check your lavalink is v3/v4 to connect successfully.", 50);
158
+ logWarning("Before connecting please check your lavalink is v3/v4 to connect successfully.");
143
159
  return [7 /*endfinally*/];
144
160
  case 5:
145
161
  if (!(options.status || options.name || options.type)) return [3 /*break*/, 7];
146
162
  presenceOptions = {
147
163
  activities: [
148
164
  {
149
- name: options.name || '/help',
150
- type: typeof options.type === 'number' ? options.type : 2,
165
+ name: options.name || "/help",
166
+ type: typeof options.type === "number" ? options.type : 2,
151
167
  },
152
168
  ],
153
- status: options.status || 'idle',
169
+ status: options.status || "idle",
154
170
  };
155
171
  return [4 /*yield*/, ((_g = client.user) === null || _g === void 0 ? void 0 : _g.setPresence(presenceOptions))];
156
172
  case 6:
@@ -165,10 +181,10 @@ function starter(client, options) {
165
181
  case 9:
166
182
  if (!(options.slashCommandPath && options.slashCommandPath.path)) return [3 /*break*/, 12];
167
183
  if (!options.slashCommandPath.baseDir) {
168
- return [2 /*return*/, typeSentence('\x1b[31m%sPlease provide a baseDir. Type in options for slash (baseDir: __dirname).\x1b[0m', 50)];
184
+ return [2 /*return*/, logWarning("Please provide a baseDir. Type in options for slash (baseDir: __dirname).")];
169
185
  }
170
186
  if (!options.token) {
171
- throw new Error('Error: No token is being provided in options.');
187
+ throw new Error("Error: No token is being provided in options.");
172
188
  }
173
189
  path = options.slashCommandPath.path;
174
190
  dir = options.slashCommandPath.baseDir;
@@ -184,13 +200,13 @@ function starter(client, options) {
184
200
  case 12:
185
201
  if (!options.botAvatar) return [3 /*break*/, 18];
186
202
  avatarData = void 0;
187
- if (!options.botAvatar.startsWith('http')) return [3 /*break*/, 14];
188
- return [4 /*yield*/, axios.get(options.botAvatar, {
189
- responseType: 'arraybuffer',
203
+ if (!options.botAvatar.startsWith("http")) return [3 /*break*/, 14];
204
+ return [4 /*yield*/, axios_1.get(options.botAvatar, {
205
+ responseType: "arraybuffer",
190
206
  })];
191
207
  case 13:
192
208
  response = _k.sent();
193
- avatarData = Buffer.from(response.data, 'binary');
209
+ avatarData = Buffer.from(response.data, "binary");
194
210
  return [3 /*break*/, 16];
195
211
  case 14: return [4 /*yield*/, fs_1.promises.readFile(options.botAvatar)];
196
212
  case 15:
@@ -220,7 +236,7 @@ function starter(client, options) {
220
236
  _k.label = 23;
221
237
  case 23:
222
238
  if (!(options.prefixCommandPath && options.prefixCommandPath.path)) return [3 /*break*/, 25];
223
- prefix = options.prefix || '!';
239
+ prefix = options.prefixCommandPath.prefix || "!";
224
240
  return [4 /*yield*/, (0, prefixRegister_1.readCommands)(client, options.prefixCommandPath.path)];
225
241
  case 24:
226
242
  _k.sent();
@@ -234,11 +250,11 @@ function starter(client, options) {
234
250
  _k.label = 26;
235
251
  case 26:
236
252
  _k.trys.push([26, 30, , 31]);
237
- return [4 /*yield*/, (0, mongoConnect)(options.mongo.mongoURI, options.mongo.dataName)];
253
+ return [4 /*yield*/, (0, utils_1.mongoConnect)(options.mongo.mongoURI, options.mongo.dataName)];
238
254
  case 27:
239
255
  _k.sent();
240
256
  if (!(options.mongo.initialize === true)) return [3 /*break*/, 29];
241
- return [4 /*yield*/, (0, initializeDb)(20000)];
257
+ return [4 /*yield*/, (0, utils_1.initializeDb)(20000)];
242
258
  case 28:
243
259
  _k.sent();
244
260
  _k.label = 29;
@@ -253,8 +269,8 @@ function starter(client, options) {
253
269
  }); });
254
270
  if (options.webView) {
255
271
  port_1 = options.webView.port || 3000;
256
- hostname_1 = options.webView.hostname || 'localhost';
257
- app = (0, express)();
272
+ hostname_1 = options.webView.hostname || "localhost";
273
+ app = (0, express_1)();
258
274
  if (options.webView.middleware) {
259
275
  options.webView.middleware(app);
260
276
  }
@@ -262,8 +278,8 @@ function starter(client, options) {
262
278
  options.webView.routes(app);
263
279
  }
264
280
  else {
265
- app.get('/', function (req, res) {
266
- res.send('Hello, this is a simple web server!');
281
+ app.get("/", function (req, res) {
282
+ res.send("Hello, this is a simple web server!");
267
283
  });
268
284
  }
269
285
  app.listen(port_1, hostname_1, function () {
@@ -275,15 +291,15 @@ function starter(client, options) {
275
291
  if (nodes.length === 0) {
276
292
  nodes = [
277
293
  {
278
- host: '195.58.58.23',
294
+ host: "195.58.58.23",
279
295
  port: 25565,
280
- password: 'best',
296
+ password: "best",
281
297
  secure: false,
282
298
  },
283
299
  ];
284
300
  }
285
- searchPlateForm = ((_c = options.lavalink) === null || _c === void 0 ? void 0 : _c.search) || 'ytmsearch';
286
- restVersion = ((_d = options.lavalink) === null || _d === void 0 ? void 0 : _d.version) || 'v4';
301
+ searchPlateForm = ((_c = options.lavalink) === null || _c === void 0 ? void 0 : _c.search) || "ytmsearch";
302
+ restVersion = ((_d = options.lavalink) === null || _d === void 0 ? void 0 : _d.version) || "v4";
287
303
  client.riffy = new riffy_1.Riffy(client, nodes, {
288
304
  send: function (payload) {
289
305
  var guild = client.guilds.cache.get(payload.d.guild_id);
@@ -294,10 +310,10 @@ function starter(client, options) {
294
310
  restVersion: restVersion,
295
311
  });
296
312
  client.restVersion = restVersion;
297
- client.riffy.on('nodeConnect', function (node) {
298
- typeSentence("\u001B[34mNode \"".concat(node.name, "\" connected.\u001B[0m "), 50);
313
+ client.riffy.on("nodeConnect", function (node) {
314
+ logSuccess("Node \"".concat(node.name, "\" connected."));
299
315
  });
300
- client.riffy.on('trackStart', function (player, track) { return __awaiter(_this, void 0, void 0, function () {
316
+ client.riffy.on("trackStart", function (player, track) { return __awaiter(_this, void 0, void 0, function () {
301
317
  return __generator(this, function (_a) {
302
318
  switch (_a.label) {
303
319
  case 0: return [4 /*yield*/, (0, start_1.handleTrackStart)(client, player, track)];
@@ -307,7 +323,7 @@ function starter(client, options) {
307
323
  }
308
324
  });
309
325
  }); });
310
- client.riffy.on('queueEnd', function (player) { return __awaiter(_this, void 0, void 0, function () {
326
+ client.riffy.on("queueEnd", function (player) { return __awaiter(_this, void 0, void 0, function () {
311
327
  return __generator(this, function (_a) {
312
328
  switch (_a.label) {
313
329
  case 0: return [4 /*yield*/, (0, end_1.handleQueueEnd)(client, player)];
@@ -317,7 +333,7 @@ function starter(client, options) {
317
333
  }
318
334
  });
319
335
  }); });
320
- client.on('interactionCreate', function (interaction) { return __awaiter(_this, void 0, void 0, function () {
336
+ client.on("interactionCreate", function (interaction) { return __awaiter(_this, void 0, void 0, function () {
321
337
  return __generator(this, function (_a) {
322
338
  if (interaction.isButton()) {
323
339
  (0, buttons_1.handleButtonInteraction)(interaction);
@@ -325,7 +341,7 @@ function starter(client, options) {
325
341
  return [2 /*return*/];
326
342
  });
327
343
  }); });
328
- client.on('raw', function (d) {
344
+ client.on("raw", function (d) {
329
345
  if (![
330
346
  discord_js_1.GatewayDispatchEvents.VoiceStateUpdate,
331
347
  discord_js_1.GatewayDispatchEvents.VoiceServerUpdate,
@@ -337,30 +353,35 @@ function starter(client, options) {
337
353
  return [3 /*break*/, 4];
338
354
  case 3:
339
355
  error_1 = _g.sent();
340
- typeSentence("Error in start function: ".concat(error_1.message), 50);
356
+ logError("Error in start function: ".concat(error_1.message));
341
357
  return [3 /*break*/, 4];
342
358
  case 4:
343
359
  if ((_e = options.antiCrash) === null || _e === void 0 ? void 0 : _e.enabled) {
344
- process.on('uncaughtException', function (error, origin) { return __awaiter(_this, void 0, void 0, function () {
360
+ process.on("uncaughtException", function (error, origin) { return __awaiter(_this, void 0, void 0, function () {
345
361
  var fileNameMatch, fileName, embed, error_4;
346
362
  var _a, _b, _c, _d;
347
363
  return __generator(this, function (_e) {
348
364
  switch (_e.label) {
349
365
  case 0:
350
366
  fileNameMatch = (_a = error.stack) === null || _a === void 0 ? void 0 : _a.match(/at .* \((.*):\d+:\d+\)/);
351
- fileName = fileNameMatch ? fileNameMatch[1] : 'Unknown File';
352
- console.error('Uncaught exception:', error, 'origin:', origin);
367
+ fileName = fileNameMatch ? fileNameMatch[1] : "Unknown File";
368
+ console.error("Uncaught exception:", error, "origin:", origin);
353
369
  if (!((_b = options.antiCrash) === null || _b === void 0 ? void 0 : _b.webhookURL)) return [3 /*break*/, 4];
354
370
  _e.label = 1;
355
371
  case 1:
356
372
  _e.trys.push([1, 3, , 4]);
357
- webhookClient_1 = new discord_js_1.WebhookClient({ url: (_c = options.antiCrash) === null || _c === void 0 ? void 0 : _c.webhookURL });
373
+ webhookClient_1 = new discord_js_1.WebhookClient({
374
+ url: (_c = options.antiCrash) === null || _c === void 0 ? void 0 : _c.webhookURL,
375
+ });
358
376
  embed = new discord_js_1.EmbedBuilder()
359
- .setTitle('Uncaught Exception Monitor')
377
+ .setTitle("Uncaught Exception Monitor")
360
378
  .setDescription("**File:** `".concat(fileName, "`\n**Error:** `").concat(error.message, "`\n**Stack Trace:** ```").concat(error.stack, "```"))
361
- .setColor('Red')
379
+ .setColor("Red")
362
380
  .setTimestamp();
363
- return [4 /*yield*/, webhookClient_1.send({ content: "<@".concat(((_d = options.antiCrash) === null || _d === void 0 ? void 0 : _d.userToMention) || '', ">"), embeds: [embed] })];
381
+ return [4 /*yield*/, webhookClient_1.send({
382
+ content: "<@".concat(((_d = options.antiCrash) === null || _d === void 0 ? void 0 : _d.userToMention) || "", ">"),
383
+ embeds: [embed],
384
+ })];
364
385
  case 2:
365
386
  _e.sent();
366
387
  return [3 /*break*/, 4];
@@ -372,26 +393,31 @@ function starter(client, options) {
372
393
  }
373
394
  });
374
395
  }); });
375
- process.on('uncaughtExceptionMonitor', function (err, origin) { return __awaiter(_this, void 0, void 0, function () {
396
+ process.on("uncaughtExceptionMonitor", function (err, origin) { return __awaiter(_this, void 0, void 0, function () {
376
397
  var fileNameMatch, fileName, embed, error_5;
377
398
  var _a, _b, _c, _d;
378
399
  return __generator(this, function (_e) {
379
400
  switch (_e.label) {
380
401
  case 0:
381
- console.error('Uncaught exception monitored:', err, 'origin:', origin);
402
+ console.error("Uncaught exception monitored:", err, "origin:", origin);
382
403
  fileNameMatch = (_a = err.stack) === null || _a === void 0 ? void 0 : _a.match(/at .* \((.*):\d+:\d+\)/);
383
- fileName = fileNameMatch ? fileNameMatch[1] : 'Unknown File';
404
+ fileName = fileNameMatch ? fileNameMatch[1] : "Unknown File";
384
405
  if (!((_b = options.antiCrash) === null || _b === void 0 ? void 0 : _b.webhookURL)) return [3 /*break*/, 4];
385
406
  _e.label = 1;
386
407
  case 1:
387
408
  _e.trys.push([1, 3, , 4]);
388
- webhookClient_1 = new discord_js_1.WebhookClient({ url: (_c = options.antiCrash) === null || _c === void 0 ? void 0 : _c.webhookURL });
409
+ webhookClient_1 = new discord_js_1.WebhookClient({
410
+ url: (_c = options.antiCrash) === null || _c === void 0 ? void 0 : _c.webhookURL,
411
+ });
389
412
  embed = new discord_js_1.EmbedBuilder()
390
- .setTitle('Uncaught Exception Monitor')
413
+ .setTitle("Uncaught Exception Monitor")
391
414
  .setDescription("**File:** `".concat(fileName, "`\n**Error:** `").concat(err.message, "`\n**Stack Trace:** ```").concat(err.stack, "```"))
392
- .setColor('Red')
415
+ .setColor("Red")
393
416
  .setTimestamp();
394
- return [4 /*yield*/, webhookClient_1.send({ content: "<@".concat(((_d = options.antiCrash) === null || _d === void 0 ? void 0 : _d.userToMention) || '', ">"), embeds: [embed] })];
417
+ return [4 /*yield*/, webhookClient_1.send({
418
+ content: "<@".concat(((_d = options.antiCrash) === null || _d === void 0 ? void 0 : _d.userToMention) || "", ">"),
419
+ embeds: [embed],
420
+ })];
395
421
  case 2:
396
422
  _e.sent();
397
423
  return [3 /*break*/, 4];
@@ -412,4 +438,4 @@ function starter(client, options) {
412
438
  });
413
439
  });
414
440
  }
415
- exports.starter = starter;
441
+ exports.starter = starter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apexify.js",
3
- "version": "2.4.2",
3
+ "version": "2.4.4-beta.1",
4
4
  "description": "Ai with Canvas and Database library. Supports typescript and javascript",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -134,6 +134,7 @@
134
134
  "@napi-rs/canvas": "^0.1.51",
135
135
  "api": "^6.1.1",
136
136
  "archiver": "^7.0.0",
137
+ "ascii-table": "^0.0.9",
137
138
  "axios": "^1.6.7",
138
139
  "crypto": "^1.0.1",
139
140
  "express": "^4.18.3",