apexify.js 1.2.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.
- package/README.md +1117 -0
- package/index.js +111 -0
- package/lib/ai/apexAI.js +312 -0
- package/lib/ai/functions/chunkString.js +8 -0
- package/lib/ai/functions/draw.js +347 -0
- package/lib/ai/functions/generateVoiceResponse.js +239 -0
- package/lib/ai/functions/processImageAttachments.js +93 -0
- package/lib/ai/functions/processMessageContent.js +48 -0
- package/lib/ai/functions/readFiles.js +95 -0
- package/lib/ai/functions/shouldDrawImage.js +12 -0
- package/lib/ai/utils.js +18 -0
- package/lib/canvas/ApexPainter.js +1194 -0
- package/lib/canvas/themes/level ara.ttf +0 -0
- package/lib/canvas/themes/levelFont.ttf +0 -0
- package/lib/canvas/themes/levels-card.js +872 -0
- package/lib/canvas/themes/music-card.js +342 -0
- package/lib/canvas/themes/numbers.ttf +0 -0
- package/lib/canvas/themes/tajawal.ttf +0 -0
- package/lib/database/MongoDB.js +126 -0
- package/lib/database/NanoDB.js +1318 -0
- package/lib/database/mongoDb/aggregate.js +120 -0
- package/lib/database/mongoDb/countDocs.js +115 -0
- package/lib/database/mongoDb/createCollection.js +125 -0
- package/lib/database/mongoDb/dataSize.js +89 -0
- package/lib/database/mongoDb/distinct.js +110 -0
- package/lib/database/mongoDb/drop.js +76 -0
- package/lib/database/mongoDb/find.js +122 -0
- package/lib/database/mongoDb/geoNear.js +91 -0
- package/lib/database/mongoDb/index.js +71 -0
- package/lib/database/mongoDb/listCollections.js +81 -0
- package/lib/database/mongoDb/migrateAndPrune.js +89 -0
- package/lib/database/mongoDb/migrateData.js +79 -0
- package/lib/database/mongoDb/remove.js +73 -0
- package/lib/database/mongoDb/removeMany.js +73 -0
- package/lib/database/mongoDb/removeManyExcept.js +91 -0
- package/lib/database/mongoDb/removeSpecific.js +93 -0
- package/lib/database/mongoDb/save.js +94 -0
- package/lib/database/mongoDb/searchMany.js +109 -0
- package/lib/database/mongoDb/textSearch.js +88 -0
- package/lib/database/mongoDb/updateAll.js +80 -0
- package/lib/database/mongoDb/updateAllExcept.js +108 -0
- package/lib/database/mongoDb/updateData.js +106 -0
- package/lib/database/nanoDb/fetchData.js +39 -0
- package/lib/database/nanoDb/removeField.js +46 -0
- package/lib/database/nanoDb/saveData.js +68 -0
- package/lib/database/nanoDb/updateFilter.js +24 -0
- package/lib/database/ready-schemas.js +245 -0
- package/lib/database/utils.js +58 -0
- package/lib/discord/discord-build/commands-(prefix)/music/functions/buttons.js +361 -0
- package/lib/discord/discord-build/commands-(prefix)/music/functions/end.js +58 -0
- package/lib/discord/discord-build/commands-(prefix)/music/functions/start.js +115 -0
- package/lib/discord/discord-build/commands-(prefix)/music/play.js +152 -0
- package/lib/discord/discord-build/commands-(prefix)/music/previous.js +82 -0
- package/lib/discord/discord-build/commands-(prefix)/music/resume.js +93 -0
- package/lib/discord/discord-build/commands-(prefix)/music/skip.js +82 -0
- package/lib/discord/discord-build/commands-(prefix)/music/stop.js +79 -0
- package/lib/discord/discord-build/components/buttons.js +75 -0
- package/lib/discord/discord-build/components/menus.js +81 -0
- package/lib/discord/discord-build/components/paginator.js +156 -0
- package/lib/discord/discord-build/components/permsChecker.js +81 -0
- package/lib/discord/discord-build/utils.js +21 -0
- package/lib/discord/events/eventer.js +100 -0
- package/lib/discord/events/handler/drawMenu.js +351 -0
- package/lib/discord/events/handler/tools.js +652 -0
- package/lib/discord/events/prefixRegister.js +136 -0
- package/lib/discord/events/prefixResponder.js +163 -0
- package/lib/discord/events/slashRegister.js +199 -0
- package/lib/discord/events/slashResponder.js +108 -0
- package/lib/discord/events/starter.js +335 -0
- package/lib/discord/functions/perms.js +19 -0
- package/lib/discord/utils.js +6 -0
- package/lib/general-functions/discord/type-writer.js +77 -0
- package/lib/general-functions/utils.js +0 -0
- package/lib/utils.js +90 -0
- package/package.json +118 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.commandNames = exports.aliases = exports.commands = exports.readCommands = void 0;
|
|
40
|
+
var fs_1 = require("fs");
|
|
41
|
+
var discord_js_1 = require("discord.js");
|
|
42
|
+
var path_1 = require("path");
|
|
43
|
+
var commands = new discord_js_1.Collection();
|
|
44
|
+
exports.commands = commands;
|
|
45
|
+
var aliases = new discord_js_1.Collection();
|
|
46
|
+
exports.aliases = aliases;
|
|
47
|
+
var commandNames = new Set();
|
|
48
|
+
exports.commandNames = commandNames;
|
|
49
|
+
var readCommands = function (client, folderPath) { return __awaiter(void 0, void 0, void 0, function () {
|
|
50
|
+
var files, prefixCommandCount, _loop_1, _i, files_1, file, error_1;
|
|
51
|
+
return __generator(this, function (_a) {
|
|
52
|
+
switch (_a.label) {
|
|
53
|
+
case 0:
|
|
54
|
+
_a.trys.push([0, 7, , 8]);
|
|
55
|
+
return [4 /*yield*/, fs_1.promises.access(folderPath)];
|
|
56
|
+
case 1:
|
|
57
|
+
_a.sent();
|
|
58
|
+
return [4 /*yield*/, fs_1.promises.readdir(folderPath, { withFileTypes: true })];
|
|
59
|
+
case 2:
|
|
60
|
+
files = _a.sent();
|
|
61
|
+
prefixCommandCount = 0;
|
|
62
|
+
_loop_1 = function (file) {
|
|
63
|
+
var filePath, _b, command_1, error_2;
|
|
64
|
+
return __generator(this, function (_c) {
|
|
65
|
+
switch (_c.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
filePath = path_1.join(folderPath, file.name);
|
|
68
|
+
if (!file.isDirectory()) return [3 /*break*/, 2];
|
|
69
|
+
_b = prefixCommandCount;
|
|
70
|
+
return [4 /*yield*/, readCommands(client, filePath)];
|
|
71
|
+
case 1:
|
|
72
|
+
prefixCommandCount = _b + _c.sent();
|
|
73
|
+
return [3 /*break*/, 6];
|
|
74
|
+
case 2:
|
|
75
|
+
if (!file.isFile()) return [3 /*break*/, 6];
|
|
76
|
+
_c.label = 3;
|
|
77
|
+
case 3:
|
|
78
|
+
_c.trys.push([3, 5, , 6]);
|
|
79
|
+
return [4 /*yield*/, Promise.resolve("".concat(filePath)).then(function (s) { return require(s); })];
|
|
80
|
+
case 4:
|
|
81
|
+
command_1 = _c.sent();
|
|
82
|
+
if (command_1 && (command_1.execute || command_1.run)) {
|
|
83
|
+
commands.set(command_1.name, command_1);
|
|
84
|
+
commandNames.add(command_1.name);
|
|
85
|
+
if (command_1.aliases && Array.isArray(command_1.aliases)) {
|
|
86
|
+
command_1.aliases.forEach(function (alias) {
|
|
87
|
+
aliases.set(alias, command_1.name);
|
|
88
|
+
commandNames.add(alias);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
command_1.description =
|
|
92
|
+
command_1.description || "No description provided.";
|
|
93
|
+
command_1.cooldown = command_1.cooldown || 1;
|
|
94
|
+
command_1.usage = command_1.usage || "No usage information provided.";
|
|
95
|
+
if (command_1.prefix) {
|
|
96
|
+
prefixCommandCount++;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
console.warn("\x1b[31m%s\x1b[0m", "Ignoring invalid command file: ".concat(filePath));
|
|
101
|
+
}
|
|
102
|
+
return [3 /*break*/, 6];
|
|
103
|
+
case 5:
|
|
104
|
+
error_2 = _c.sent();
|
|
105
|
+
console.error("\x1b[31m%s\x1b[0m", "Error in file: ".concat(filePath));
|
|
106
|
+
console.error("\x1b[31m%s\x1b[0m", error_2);
|
|
107
|
+
return [3 /*break*/, 6];
|
|
108
|
+
case 6: return [2 /*return*/];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
_i = 0, files_1 = files;
|
|
113
|
+
_a.label = 3;
|
|
114
|
+
case 3:
|
|
115
|
+
if (!(_i < files_1.length)) return [3 /*break*/, 6];
|
|
116
|
+
file = files_1[_i];
|
|
117
|
+
return [5 /*yield**/, _loop_1(file)];
|
|
118
|
+
case 4:
|
|
119
|
+
_a.sent();
|
|
120
|
+
_a.label = 5;
|
|
121
|
+
case 5:
|
|
122
|
+
_i++;
|
|
123
|
+
return [3 /*break*/, 3];
|
|
124
|
+
case 6: return [2 /*return*/, prefixCommandCount];
|
|
125
|
+
case 7:
|
|
126
|
+
error_1 = _a.sent();
|
|
127
|
+
console.error("\x1b[31m%s\x1b[0m", "Error reading directory: ".concat(folderPath));
|
|
128
|
+
console.error("\x1b[31m%s\x1b[0m", error_1);
|
|
129
|
+
return [2 /*return*/, 0];
|
|
130
|
+
case 8: return [2 /*return*/];
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
exports.readCommands = readCommands;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.prefixRespond = void 0;
|
|
40
|
+
var discord_js_1 = require("discord.js");
|
|
41
|
+
var prefixRegister_1 = require("./prefixRegister");
|
|
42
|
+
var cooldowns = new discord_js_1.Collection();
|
|
43
|
+
/**
|
|
44
|
+
* Handles the 'messageCreate' event
|
|
45
|
+
* @param {Message} message - The received message
|
|
46
|
+
* @param {string} commandPrefix - The command prefix for the bot
|
|
47
|
+
*/
|
|
48
|
+
function handleMessageCreate(message, commandPrefix, logs) {
|
|
49
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
50
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
+
var args, commandName, command, now, timestamps_1, cooldownAmount, expirationTime, expirationTime_1, timeLeft, channel, userName, userid, serverName, serverId, messageLink, embedLog;
|
|
52
|
+
return __generator(this, function (_h) {
|
|
53
|
+
switch (_h.label) {
|
|
54
|
+
case 0:
|
|
55
|
+
if (!message.content.startsWith(commandPrefix) || message.author.bot)
|
|
56
|
+
return [2 /*return*/];
|
|
57
|
+
args = message.content
|
|
58
|
+
.slice(commandPrefix.length)
|
|
59
|
+
.trim()
|
|
60
|
+
.split(/ +/);
|
|
61
|
+
commandName = (_a = args.shift()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
62
|
+
if (!(commandName && prefixRegister_1.commandNames.has(commandName))) return [3 /*break*/, 10];
|
|
63
|
+
command = prefixRegister_1.commands.get(commandName) || prefixRegister_1.commands.get(prefixRegister_1.aliases.get(commandName));
|
|
64
|
+
if (!cooldowns.has(command.name)) {
|
|
65
|
+
cooldowns.set(command.name, new discord_js_1.Collection());
|
|
66
|
+
}
|
|
67
|
+
now = Date.now();
|
|
68
|
+
timestamps_1 = cooldowns.get(command.name);
|
|
69
|
+
cooldownAmount = (command.cooldown || 3) * 1000;
|
|
70
|
+
if (!(timestamps_1 && timestamps_1.has(message.author.id))) return [3 /*break*/, 2];
|
|
71
|
+
expirationTime = timestamps_1.get(message.author.id)
|
|
72
|
+
? timestamps_1.get(message.author.id) + cooldownAmount
|
|
73
|
+
: undefined;
|
|
74
|
+
if (!(timestamps_1 && timestamps_1.has(message.author.id))) return [3 /*break*/, 2];
|
|
75
|
+
expirationTime_1 = timestamps_1.get(message.author.id)
|
|
76
|
+
? timestamps_1.get(message.author.id) + cooldownAmount
|
|
77
|
+
: undefined;
|
|
78
|
+
if (!(expirationTime_1 && now < expirationTime_1)) return [3 /*break*/, 2];
|
|
79
|
+
timeLeft = (expirationTime_1 - now) / 1000;
|
|
80
|
+
return [4 /*yield*/, message.reply("Please wait ".concat(timeLeft.toFixed(1), " more second(s) before reusing the `").concat(command.name, "` command."))];
|
|
81
|
+
case 1:
|
|
82
|
+
_h.sent();
|
|
83
|
+
return [2 /*return*/]; // Add this line to exit the function
|
|
84
|
+
case 2:
|
|
85
|
+
if (timestamps_1) {
|
|
86
|
+
timestamps_1.set(message.author.id, now);
|
|
87
|
+
setTimeout(function () { return timestamps_1.delete(message.author.id); }, cooldownAmount);
|
|
88
|
+
}
|
|
89
|
+
channel = (_b = message.guild) === null || _b === void 0 ? void 0 : _b.channels.cache.get(logs);
|
|
90
|
+
userName = message.author.username;
|
|
91
|
+
userid = message.author.id;
|
|
92
|
+
serverName = ((_c = message.guild) === null || _c === void 0 ? void 0 : _c.name) || null;
|
|
93
|
+
serverId = ((_d = message.guild) === null || _d === void 0 ? void 0 : _d.id) || null;
|
|
94
|
+
messageLink = "https://discord.com/channels/".concat((_e = message.guild) === null || _e === void 0 ? void 0 : _e.id, "/").concat((_f = message.channel) === null || _f === void 0 ? void 0 : _f.id, "/").concat(message.id);
|
|
95
|
+
embedLog = new discord_js_1.EmbedBuilder()
|
|
96
|
+
.setColor("Blue")
|
|
97
|
+
.setThumbnail((_g = message.client.user) === null || _g === void 0 ? void 0 : _g.displayAvatarURL({ dynamic: true }))
|
|
98
|
+
.setTitle("Use Prefix Command")
|
|
99
|
+
.addFields({ name: "\uD83D\uDD27 Cmd:", value: "- ".concat(command.name), inline: true }, {
|
|
100
|
+
name: "\uD83E\uDEAA User:",
|
|
101
|
+
value: "- ".concat(userName, " (<@").concat(userid, ">)"),
|
|
102
|
+
inline: true,
|
|
103
|
+
}, { name: "\u200B", value: "\u200B", inline: true }, {
|
|
104
|
+
name: "\uD83D\uDEF0\uFE0F Server:",
|
|
105
|
+
value: "- ".concat(serverName, ".\n- `[").concat(serverId, "]`."),
|
|
106
|
+
inline: true,
|
|
107
|
+
}, {
|
|
108
|
+
name: "\uD83D\uDCE8 Message:",
|
|
109
|
+
value: "- [Link](".concat(messageLink, ")"),
|
|
110
|
+
inline: true,
|
|
111
|
+
}, { name: "\u200B", value: "\u200B", inline: true }, {
|
|
112
|
+
name: "\u23F1\uFE0F Date:",
|
|
113
|
+
value: "- <t:".concat(Math.floor(Date.now() / 1000), ":R>"),
|
|
114
|
+
inline: true,
|
|
115
|
+
});
|
|
116
|
+
if (!command.run) return [3 /*break*/, 6];
|
|
117
|
+
return [4 /*yield*/, command.run(message.client, message, args)];
|
|
118
|
+
case 3:
|
|
119
|
+
_h.sent();
|
|
120
|
+
if (!(logs && channel)) return [3 /*break*/, 5];
|
|
121
|
+
return [4 /*yield*/, channel.send({
|
|
122
|
+
embeds: [embedLog],
|
|
123
|
+
})];
|
|
124
|
+
case 4:
|
|
125
|
+
_h.sent();
|
|
126
|
+
_h.label = 5;
|
|
127
|
+
case 5: return [3 /*break*/, 9];
|
|
128
|
+
case 6:
|
|
129
|
+
if (!command.execute) return [3 /*break*/, 9];
|
|
130
|
+
return [4 /*yield*/, command.execute(message.client, message, args)];
|
|
131
|
+
case 7:
|
|
132
|
+
_h.sent();
|
|
133
|
+
if (!(logs && channel)) return [3 /*break*/, 9];
|
|
134
|
+
return [4 /*yield*/, channel.send({
|
|
135
|
+
embeds: [embedLog],
|
|
136
|
+
})];
|
|
137
|
+
case 8:
|
|
138
|
+
_h.sent();
|
|
139
|
+
_h.label = 9;
|
|
140
|
+
case 9: return [3 /*break*/, 11];
|
|
141
|
+
case 10:
|
|
142
|
+
console.log("Command not found!");
|
|
143
|
+
_h.label = 11;
|
|
144
|
+
case 11: return [2 /*return*/];
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Setup the 'messageCreate' event
|
|
151
|
+
* @param {Client} client - The Discord client
|
|
152
|
+
* @param {string} commandPrefix - The command prefix for the bot
|
|
153
|
+
*/
|
|
154
|
+
function prefixRespond(client, commandPrefix, logs) {
|
|
155
|
+
if (!commandPrefix) {
|
|
156
|
+
throw new Error("No command prefix provided. Please provide a command prefix.");
|
|
157
|
+
}
|
|
158
|
+
client.on("messageCreate", function (message) {
|
|
159
|
+
return handleMessageCreate(message, commandPrefix, logs);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
exports.prefixRespond = prefixRespond;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
function typeSentence(sentence, speed) {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
13
|
+
var _i, sentence_1, char;
|
|
14
|
+
return __generator(this, function (_a) {
|
|
15
|
+
switch (_a.label) {
|
|
16
|
+
case 0:
|
|
17
|
+
_i = 0, sentence_1 = sentence;
|
|
18
|
+
_a.label = 1;
|
|
19
|
+
case 1:
|
|
20
|
+
if (!(_i < sentence_1.length)) return [3 /*break*/, 4];
|
|
21
|
+
char = sentence_1[_i];
|
|
22
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, speed); })];
|
|
23
|
+
case 2:
|
|
24
|
+
_a.sent();
|
|
25
|
+
process.stdout.write(char);
|
|
26
|
+
_a.label = 3;
|
|
27
|
+
case 3:
|
|
28
|
+
_i++;
|
|
29
|
+
return [3 /*break*/, 1];
|
|
30
|
+
case 4:
|
|
31
|
+
console.log();
|
|
32
|
+
return [2 /*return*/];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
38
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
39
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
|
+
function step(op) {
|
|
42
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
44
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
45
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
+
switch (op[0]) {
|
|
47
|
+
case 0: case 1: t = op; break;
|
|
48
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
+
default:
|
|
52
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
+
if (t[2]) _.ops.pop();
|
|
57
|
+
_.trys.pop(); continue;
|
|
58
|
+
}
|
|
59
|
+
op = body.call(thisArg, _);
|
|
60
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.registerSlashCommands = void 0;
|
|
66
|
+
var rest_1 = require("@discordjs/rest");
|
|
67
|
+
var v10_1 = require("discord-api-types/v10");
|
|
68
|
+
var fs = require("fs/promises");
|
|
69
|
+
var discord_js_1 = require("discord.js");
|
|
70
|
+
var path_1 = require("path");
|
|
71
|
+
/**
|
|
72
|
+
* Register slash commands for the bot
|
|
73
|
+
* @param {Client} client - The Discord client
|
|
74
|
+
* @param {string} token - Bot token
|
|
75
|
+
* @param {string} baseDirectory - Base directory for slash commands
|
|
76
|
+
* @param {string} baseDir - Base directory path
|
|
77
|
+
*/
|
|
78
|
+
function registerSlashCommands(client, token, baseDirectory, baseDir, gId, gl) {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
+
var slashCommands, rest, resolvedPath_1, dirents, slashCommandArray, error_1, guild, slashCommandArray, error_2, error_3;
|
|
82
|
+
var _this = this;
|
|
83
|
+
return __generator(this, function (_c) {
|
|
84
|
+
switch (_c.label) {
|
|
85
|
+
case 0:
|
|
86
|
+
slashCommands = new discord_js_1.Collection();
|
|
87
|
+
client.slashCommands = new discord_js_1.Collection();
|
|
88
|
+
rest = new rest_1.REST({ version: '10' }).setToken(token);
|
|
89
|
+
_c.label = 1;
|
|
90
|
+
case 1:
|
|
91
|
+
_c.trys.push([1, 15, , 16]);
|
|
92
|
+
resolvedPath_1 = path_1.join(baseDir, baseDirectory);
|
|
93
|
+
return [4 /*yield*/, fs.readdir(resolvedPath_1, { withFileTypes: true })];
|
|
94
|
+
case 2:
|
|
95
|
+
dirents = _c.sent();
|
|
96
|
+
return [4 /*yield*/, Promise.all(dirents.map(function (dirent) { return __awaiter(_this, void 0, void 0, function () {
|
|
97
|
+
var folderPath_1, files, command;
|
|
98
|
+
var _this = this;
|
|
99
|
+
return __generator(this, function (_a) {
|
|
100
|
+
switch (_a.label) {
|
|
101
|
+
case 0:
|
|
102
|
+
if (!dirent.isDirectory()) return [3 /*break*/, 3];
|
|
103
|
+
folderPath_1 = path_1.join(resolvedPath_1, dirent.name);
|
|
104
|
+
return [4 /*yield*/, fs.readdir(folderPath_1)];
|
|
105
|
+
case 1:
|
|
106
|
+
files = _a.sent();
|
|
107
|
+
return [4 /*yield*/, Promise.all(files.map(function (file) { return __awaiter(_this, void 0, void 0, function () {
|
|
108
|
+
var command;
|
|
109
|
+
return __generator(this, function (_a) {
|
|
110
|
+
try {
|
|
111
|
+
command = require(path_1.join(folderPath_1, file));
|
|
112
|
+
if (command.data) {
|
|
113
|
+
if (command.cooldown && !isNaN(command.cooldown)) {
|
|
114
|
+
command.data.cooldown = command.cooldown;
|
|
115
|
+
}
|
|
116
|
+
slashCommands.set(command.data.name, command);
|
|
117
|
+
client.slashCommands.set(command.data.name, command);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
console.error('\x1b[31m%s\x1b[0m', "Error in file: ".concat(path_1.join(folderPath_1, file)));
|
|
122
|
+
console.error('\x1b[31m%s\x1b[0m', error);
|
|
123
|
+
}
|
|
124
|
+
return [2 /*return*/];
|
|
125
|
+
});
|
|
126
|
+
}); }))];
|
|
127
|
+
case 2:
|
|
128
|
+
_a.sent();
|
|
129
|
+
return [3 /*break*/, 4];
|
|
130
|
+
case 3:
|
|
131
|
+
try {
|
|
132
|
+
command = require(path_1.join(resolvedPath_1, dirent.name));
|
|
133
|
+
if (command.data) {
|
|
134
|
+
if (command.cooldown && !isNaN(command.cooldown)) {
|
|
135
|
+
command.data.cooldown = command.cooldown || 0;
|
|
136
|
+
}
|
|
137
|
+
slashCommands.set(command.data.name, command);
|
|
138
|
+
client.slashCommands.set(command.data.name, command);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
console.error('\x1b[31m%s\x1b[0m', "Error in file: ".concat(path_1.join(resolvedPath_1, dirent.name)));
|
|
143
|
+
console.error('\x1b[31m%s\x1b[0m', error);
|
|
144
|
+
}
|
|
145
|
+
_a.label = 4;
|
|
146
|
+
case 4: return [2 /*return*/];
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}); }))];
|
|
150
|
+
case 3:
|
|
151
|
+
_c.sent();
|
|
152
|
+
if (!(!gId && gl === true)) return [3 /*break*/, 8];
|
|
153
|
+
slashCommandArray = Array.from(slashCommands.values()).map(function (command) { return command.data.toJSON(); });
|
|
154
|
+
_c.label = 4;
|
|
155
|
+
case 4:
|
|
156
|
+
_c.trys.push([4, 6, , 7]);
|
|
157
|
+
return [4 /*yield*/, rest.put(v10_1.Routes.applicationCommands(((_a = client.user) === null || _a === void 0 ? void 0 : _a.id) || ''), { body: slashCommandArray, headers: { Authorization: "Bot ".concat(token) } })];
|
|
158
|
+
case 5:
|
|
159
|
+
_c.sent();
|
|
160
|
+
typeSentence(`\x1b[36m%sRegistered ${slashCommandArray.length} slash commands.\x1b[0m`, 20);
|
|
161
|
+
return [3 /*break*/, 7];
|
|
162
|
+
case 6:
|
|
163
|
+
error_1 = _c.sent();
|
|
164
|
+
typeSentence(`\x1b[31m%s\x1b[0m', 'Error setting global slash commands:${error_1.message} `,20);
|
|
165
|
+
return [3 /*break*/, 7];
|
|
166
|
+
case 7: return [3 /*break*/, 14];
|
|
167
|
+
case 8:
|
|
168
|
+
if (!(gId && gl === false)) return [3 /*break*/, 14];
|
|
169
|
+
guild = client.guilds.cache.get(gId);
|
|
170
|
+
if (!guild) return [3 /*break*/, 13];
|
|
171
|
+
slashCommandArray = Array.from(slashCommands.values()).map(function (command) { return command.data.toJSON(); });
|
|
172
|
+
_c.label = 9;
|
|
173
|
+
case 9:
|
|
174
|
+
_c.trys.push([9, 11, , 12]);
|
|
175
|
+
return [4 /*yield*/, rest.put(v10_1.Routes.applicationGuildCommands(((_b = client.user) === null || _b === void 0 ? void 0 : _b.id) || '', guild.id), { body: slashCommandArray, headers: { Authorization: "Bot ".concat(token) } })];
|
|
176
|
+
case 10:
|
|
177
|
+
_c.sent();
|
|
178
|
+
typeSentence(`\x1b[36m%sRegistered ${slashCommandArray.length} guild-specific slash commands for guild ${guild.name}.`, 20);
|
|
179
|
+
return [3 /*break*/, 12];
|
|
180
|
+
case 11:
|
|
181
|
+
error_2 = _c.sent();
|
|
182
|
+
console.error('\x1b[31m%s\x1b[0m', "Error setting guild-specific slash commands for guild ".concat(guild.name, ":"), error_2.message);
|
|
183
|
+
return [3 /*break*/, 12];
|
|
184
|
+
case 12: return [3 /*break*/, 14];
|
|
185
|
+
case 13:
|
|
186
|
+
console.error('\x1b[31m%s\x1b[0m', "Guild with ID ".concat(gId, " not found."));
|
|
187
|
+
_c.label = 14;
|
|
188
|
+
case 14: return [3 /*break*/, 16];
|
|
189
|
+
case 15:
|
|
190
|
+
error_3 = _c.sent();
|
|
191
|
+
console.error('\x1b[31m%s\x1b[0m', 'Error registering slash commands:', error_3.message);
|
|
192
|
+
return [3 /*break*/, 16];
|
|
193
|
+
case 16: return [2 /*return*/, slashCommands];
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
exports.registerSlashCommands = registerSlashCommands;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.slashRespond = void 0;
|
|
40
|
+
var discord_js_1 = require("discord.js");
|
|
41
|
+
function slashRespond(client, slashCommands) {
|
|
42
|
+
var _this = this;
|
|
43
|
+
// Check if there is at least one registered slash command
|
|
44
|
+
if (!slashCommands || slashCommands.size === 0) {
|
|
45
|
+
console.log('\x1b[33m%s\x1b[0m', 'No registered slash commands. The slashRespond function will not work.');
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
var interactionCooldowns = new discord_js_1.Collection();
|
|
49
|
+
client.on('interactionCreate', function (interaction) { return __awaiter(_this, void 0, void 0, function () {
|
|
50
|
+
var command, userCooldowns, cooldownExpiration, remainingCooldown, startExecutionTime, executionTime, error_1;
|
|
51
|
+
return __generator(this, function (_a) {
|
|
52
|
+
switch (_a.label) {
|
|
53
|
+
case 0:
|
|
54
|
+
if (!interaction.isCommand() || !interaction.guild || !interaction.isChatInputCommand() || interaction.user.bot)
|
|
55
|
+
return [2 /*return*/];
|
|
56
|
+
command = slashCommands.get(interaction.commandName);
|
|
57
|
+
if (!command)
|
|
58
|
+
return [2 /*return*/];
|
|
59
|
+
if (!(command.cooldown && !isNaN(command.cooldown))) return [3 /*break*/, 3];
|
|
60
|
+
userCooldowns = interactionCooldowns.get(interaction.user.id) || new discord_js_1.Collection();
|
|
61
|
+
cooldownExpiration = userCooldowns.get(command.name);
|
|
62
|
+
if (!(cooldownExpiration && cooldownExpiration > Date.now())) return [3 /*break*/, 2];
|
|
63
|
+
remainingCooldown = (cooldownExpiration - Date.now()) / 1000;
|
|
64
|
+
return [4 /*yield*/, interaction.reply("\u001B[33mCommand is on cooldown. Please wait ".concat(remainingCooldown.toFixed(1), " seconds.\u001B[0m"))];
|
|
65
|
+
case 1:
|
|
66
|
+
_a.sent();
|
|
67
|
+
return [2 /*return*/];
|
|
68
|
+
case 2:
|
|
69
|
+
userCooldowns.set(command.name, Date.now() + command.cooldown * 1000);
|
|
70
|
+
interactionCooldowns.set(interaction.user.id, userCooldowns);
|
|
71
|
+
_a.label = 3;
|
|
72
|
+
case 3:
|
|
73
|
+
_a.trys.push([3, 9, , 11]);
|
|
74
|
+
startExecutionTime = Date.now();
|
|
75
|
+
if (!command.run) return [3 /*break*/, 5];
|
|
76
|
+
return [4 /*yield*/, command.run(client, interaction)];
|
|
77
|
+
case 4:
|
|
78
|
+
_a.sent();
|
|
79
|
+
return [3 /*break*/, 8];
|
|
80
|
+
case 5:
|
|
81
|
+
if (!command.execute) return [3 /*break*/, 7];
|
|
82
|
+
return [4 /*yield*/, command.execute(client, interaction)];
|
|
83
|
+
case 6:
|
|
84
|
+
_a.sent();
|
|
85
|
+
return [3 /*break*/, 8];
|
|
86
|
+
case 7:
|
|
87
|
+
console.log('\x1b[33m%s\x1b[0m', "Command \"".concat(command.name, "\" has neither run nor execute method."));
|
|
88
|
+
_a.label = 8;
|
|
89
|
+
case 8:
|
|
90
|
+
executionTime = Date.now() - startExecutionTime;
|
|
91
|
+
if (executionTime > 3000) {
|
|
92
|
+
console.log('\x1b[33m%s\x1b[0m', "Command \"".concat(command.name, "\" took ").concat(executionTime, "ms to execute."));
|
|
93
|
+
}
|
|
94
|
+
return [3 /*break*/, 11];
|
|
95
|
+
case 9:
|
|
96
|
+
error_1 = _a.sent();
|
|
97
|
+
console.error('\x1b[31m%s\x1b[0m', "Error executing command \"".concat(command.name, "\":"), error_1);
|
|
98
|
+
return [4 /*yield*/, interaction.channel.send('An error occurred while executing the command.')];
|
|
99
|
+
case 10:
|
|
100
|
+
_a.sent();
|
|
101
|
+
return [3 /*break*/, 11];
|
|
102
|
+
case 11: return [2 /*return*/];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}); });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
exports.slashRespond = slashRespond;
|