xernerx 3.5.2 → 4.0.0
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/dist/build/ContextCommandBuilder.d.ts +47 -0
- package/dist/build/ContextCommandBuilder.js +78 -0
- package/dist/{cjs/build → build}/EventBuilder.d.ts +7 -6
- package/dist/build/EventBuilder.js +35 -0
- package/dist/build/InhibitorBuilder.d.ts +17 -0
- package/dist/build/InhibitorBuilder.js +26 -0
- package/dist/build/MessageCommandBuilder.d.ts +43 -0
- package/dist/build/MessageCommandBuilder.js +71 -0
- package/dist/{cjs/build → build}/SlashCommandBuilder.d.ts +16 -31
- package/dist/build/SlashCommandBuilder.js +122 -0
- package/dist/build copy/ContextCommandBuilder.d.ts +37 -0
- package/dist/build copy/ContextCommandBuilder.js +88 -0
- package/dist/{mjs/build/EventBuilder.d.ts → build copy/EventBuilder.d.ts } +4 -4
- package/dist/build copy/EventBuilder.js +34 -0
- package/dist/{cjs/build/InhibitorBuilder.d.ts → build copy/InhibitorBuilder.d.ts } +2 -2
- package/dist/build copy/InhibitorBuilder.js +27 -0
- package/dist/{cjs/build/MessageCommandBuilder.d.ts → build copy/MessageCommandBuilder.d.ts } +14 -34
- package/dist/build copy/MessageCommandBuilder.js +90 -0
- package/dist/build copy/SlashCommandBuilder.d.ts +41 -0
- package/dist/build copy/SlashCommandBuilder.js +122 -0
- package/dist/client/DBLClient.d.ts +8 -0
- package/dist/client/DBLClient.js +15 -0
- package/dist/client/Top.ggClient.d.ts +1 -0
- package/dist/client/Top.ggClient.js +1 -0
- package/dist/client/XernerxClient.d.ts +54 -0
- package/dist/client/XernerxClient.js +90 -0
- package/dist/events/messageCreate.d.ts +1 -0
- package/dist/events/messageCreate.js +1 -0
- package/dist/functions/AsyncFunctions.d.ts +1 -0
- package/dist/functions/AsyncFunctions.js +1 -0
- package/dist/functions/delay.d.ts +1 -0
- package/dist/functions/delay.js +3 -0
- package/dist/functions/deploy.d.ts +2 -0
- package/dist/functions/deploy.js +29 -0
- package/dist/functions/getPermissionBitField.d.ts +2 -0
- package/dist/functions/getPermissionBitField.js +17 -0
- package/dist/functions/hasVoted.d.ts +1 -0
- package/dist/functions/hasVoted.js +1 -0
- package/dist/functions/isOwner.d.ts +3 -0
- package/dist/functions/isOwner.js +3 -0
- package/dist/functions/isVoter.d.ts +3 -0
- package/dist/functions/isVoter.js +5 -0
- package/dist/functions/load.d.ts +3 -0
- package/dist/functions/load.js +32 -0
- package/dist/functions/reload.d.ts +2 -0
- package/dist/functions/reload.js +39 -0
- package/dist/functions/sendWebhook.d.ts +2 -0
- package/dist/functions/sendWebhook.js +12 -0
- package/dist/functions/voted.d.ts +1 -0
- package/dist/functions/voted.js +1 -0
- package/dist/functions/xernerxUser.d.ts +3 -0
- package/dist/functions/xernerxUser.js +8 -0
- package/dist/handlers/CommandHandler.d.ts +13 -0
- package/dist/handlers/CommandHandler.js +220 -0
- package/dist/handlers/EventHandler.d.ts +7 -0
- package/dist/handlers/EventHandler.js +24 -0
- package/dist/handlers/ExtensionHandler.d.ts +7 -0
- package/dist/handlers/ExtensionHandler.js +19 -0
- package/dist/handlers/Handler.d.ts +14 -0
- package/dist/handlers/Handler.js +36 -0
- package/dist/handlers/InhibitorHandler.d.ts +7 -0
- package/dist/handlers/InhibitorHandler.js +24 -0
- package/dist/handlers/WebhookHandler.d.ts +7 -0
- package/dist/handlers/WebhookHandler.js +50 -0
- package/dist/main.d.ts +11 -0
- package/dist/main.js +11 -0
- package/dist/models/Arguments.d.ts +15 -0
- package/dist/models/Arguments.js +129 -0
- package/dist/{mjs/models → models}/CommandArguments.js +2 -7
- package/dist/{mjs/models → models}/Events.js +44 -54
- package/dist/models/Extensions.js +23 -0
- package/dist/models/XernerxUser.d.ts +2 -0
- package/dist/models/XernerxUser.js +9 -0
- package/dist/tools/XernerxError.d.ts +6 -0
- package/dist/tools/XernerxError.js +10 -0
- package/dist/tools/XernerxLog.d.ts +13 -0
- package/dist/tools/XernerxLog.js +30 -0
- package/dist/tools/classes.d.ts +6 -0
- package/dist/tools/classes.js +10 -0
- package/dist/tools/loggers.d.ts +4 -0
- package/dist/tools/loggers.js +4 -0
- package/dist/{cjs/tools → tools}/package.d.ts +5 -9
- package/dist/{cjs/tools → tools}/package.js +12 -18
- package/dist/{cjs/types → types}/enums.js +8 -11
- package/dist/types/extenders.d.ts +23 -0
- package/dist/types/extenders.js +1 -0
- package/dist/types/interfaces.d.ts +224 -0
- package/dist/types/interfaces.js +1 -0
- package/dist/{cjs/types → types}/options.d.ts +13 -0
- package/dist/types/options.js +1 -0
- package/dist/types/types.d.ts +181 -0
- package/dist/types/types.js +1 -0
- package/dist/utils/ClientUtil.d.ts +6 -0
- package/dist/utils/ClientUtil.js +7 -0
- package/dist/{cjs/utils → utils}/CommandUtil.js +14 -29
- package/dist/utils/InteractionArguments.d.ts +1 -0
- package/dist/utils/InteractionArguments.js +1 -0
- package/dist/utils/InteractionUtil.d.ts +10 -0
- package/dist/utils/InteractionUtil.js +15 -0
- package/dist/utils/MessageUtil.d.ts +11 -0
- package/dist/utils/MessageUtil.js +42 -0
- package/dist/utils/Util.d.ts +5 -0
- package/dist/utils/Util.js +6 -0
- package/dist/{mjs/validators → validators}/CommandValidations.js +11 -14
- package/dist/validators/InhibitorValidations.d.ts +18 -0
- package/dist/validators/InhibitorValidations.js +34 -0
- package/dist/validators/commandValidation.d.ts +6 -0
- package/dist/validators/commandValidation.js +48 -0
- package/dist/validators/commands.d.ts +4 -0
- package/dist/validators/commands.js +25 -0
- package/package.json +10 -13
- package/dist/cjs/build/ContextCommandBuilder.d.ts +0 -68
- package/dist/cjs/build/ContextCommandBuilder.js +0 -97
- package/dist/cjs/build/EventBuilder.js +0 -44
- package/dist/cjs/build/InhibitorBuilder.js +0 -37
- package/dist/cjs/build/MessageCommandBuilder.js +0 -100
- package/dist/cjs/build/SlashCommandBuilder.js +0 -169
- package/dist/cjs/client/XernerxClient.d.ts +0 -28
- package/dist/cjs/client/XernerxClient.js +0 -116
- package/dist/cjs/handlers/CommandHandler.d.ts +0 -27
- package/dist/cjs/handlers/CommandHandler.js +0 -45
- package/dist/cjs/handlers/EventHandler.d.ts +0 -13
- package/dist/cjs/handlers/EventHandler.js +0 -19
- package/dist/cjs/handlers/Handler.d.ts +0 -57
- package/dist/cjs/handlers/Handler.js +0 -308
- package/dist/cjs/handlers/InhibitorHandler.d.ts +0 -18
- package/dist/cjs/handlers/InhibitorHandler.js +0 -24
- package/dist/cjs/main.d.ts +0 -44
- package/dist/cjs/main.js +0 -112
- package/dist/cjs/models/CommandArguments.js +0 -106
- package/dist/cjs/models/Events.js +0 -307
- package/dist/cjs/models/Extensions.js +0 -26
- package/dist/cjs/tools/XernerxError.d.ts +0 -5
- package/dist/cjs/tools/XernerxError.js +0 -11
- package/dist/cjs/types/interfaces.d.ts +0 -25
- package/dist/cjs/types/interfaces.js +0 -2
- package/dist/cjs/types/options.js +0 -2
- package/dist/cjs/types/types.d.ts +0 -61
- package/dist/cjs/types/types.js +0 -2
- package/dist/cjs/utils/ClientUtil.d.ts +0 -25
- package/dist/cjs/utils/ClientUtil.js +0 -211
- package/dist/cjs/validators/CommandValidations.js +0 -169
- package/dist/cjs/validators/InhibitorValidations.d.ts +0 -11
- package/dist/cjs/validators/InhibitorValidations.js +0 -40
- package/dist/mjs/build/ContextCommandBuilder.d.ts +0 -68
- package/dist/mjs/build/ContextCommandBuilder.js +0 -97
- package/dist/mjs/build/EventBuilder.js +0 -44
- package/dist/mjs/build/InhibitorBuilder.d.ts +0 -19
- package/dist/mjs/build/InhibitorBuilder.js +0 -37
- package/dist/mjs/build/MessageCommandBuilder.d.ts +0 -59
- package/dist/mjs/build/MessageCommandBuilder.js +0 -100
- package/dist/mjs/build/SlashCommandBuilder.d.ts +0 -65
- package/dist/mjs/build/SlashCommandBuilder.js +0 -169
- package/dist/mjs/client/XernerxClient.d.ts +0 -28
- package/dist/mjs/client/XernerxClient.js +0 -116
- package/dist/mjs/handlers/CommandHandler.d.ts +0 -27
- package/dist/mjs/handlers/CommandHandler.js +0 -45
- package/dist/mjs/handlers/EventHandler.d.ts +0 -13
- package/dist/mjs/handlers/EventHandler.js +0 -19
- package/dist/mjs/handlers/Handler.d.ts +0 -57
- package/dist/mjs/handlers/Handler.js +0 -308
- package/dist/mjs/handlers/InhibitorHandler.d.ts +0 -18
- package/dist/mjs/handlers/InhibitorHandler.js +0 -24
- package/dist/mjs/main.d.ts +0 -44
- package/dist/mjs/main.js +0 -112
- package/dist/mjs/models/CommandArguments.d.ts +0 -17
- package/dist/mjs/models/Events.d.ts +0 -24
- package/dist/mjs/models/Extensions.d.ts +0 -7
- package/dist/mjs/models/Extensions.js +0 -26
- package/dist/mjs/tools/XernerxError.d.ts +0 -5
- package/dist/mjs/tools/XernerxError.js +0 -11
- package/dist/mjs/tools/package.d.ts +0 -49
- package/dist/mjs/tools/package.js +0 -50
- package/dist/mjs/types/enums.d.ts +0 -44
- package/dist/mjs/types/enums.js +0 -38
- package/dist/mjs/types/interfaces.d.ts +0 -25
- package/dist/mjs/types/interfaces.js +0 -2
- package/dist/mjs/types/options.d.ts +0 -241
- package/dist/mjs/types/options.js +0 -2
- package/dist/mjs/types/types.d.ts +0 -61
- package/dist/mjs/types/types.js +0 -2
- package/dist/mjs/utils/ClientUtil.d.ts +0 -25
- package/dist/mjs/utils/ClientUtil.js +0 -211
- package/dist/mjs/utils/CommandUtil.d.ts +0 -58
- package/dist/mjs/utils/CommandUtil.js +0 -247
- package/dist/mjs/validators/CommandValidations.d.ts +0 -12
- package/dist/mjs/validators/InhibitorValidations.d.ts +0 -11
- package/dist/mjs/validators/InhibitorValidations.js +0 -40
- /package/dist/{cjs/models → models}/CommandArguments.d.ts +0 -0
- /package/dist/{cjs/models → models}/Events.d.ts +0 -0
- /package/dist/{cjs/models → models}/Extensions.d.ts +0 -0
- /package/dist/{cjs/types → types}/enums.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/CommandUtil.d.ts +0 -0
- /package/dist/{cjs/validators → validators}/CommandValidations.d.ts +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import XernerxLog from '../tools/XernerxLog.js';
|
|
2
|
+
export default async function load(client, path, type) {
|
|
3
|
+
try {
|
|
4
|
+
let file = new (await import(`file://${path}`)).default();
|
|
5
|
+
file.fileType = type;
|
|
6
|
+
file.filePath = path;
|
|
7
|
+
file.client = client;
|
|
8
|
+
fileSave(client, file, type);
|
|
9
|
+
return file;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
new XernerxLog(client).error(`Couldn't load ${type} ${path.match(/\w*\.js$/gim)?.at(0) || path}`, error);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function fileSave(client, file, type) {
|
|
15
|
+
switch (type) {
|
|
16
|
+
case 'MessageCommand':
|
|
17
|
+
client.commands.message.set(file.name, file);
|
|
18
|
+
break;
|
|
19
|
+
case 'SlashCommand':
|
|
20
|
+
client.commands.slash.set(file.name, file);
|
|
21
|
+
break;
|
|
22
|
+
case 'ContextCommand':
|
|
23
|
+
client.commands.context.set(file.name, file);
|
|
24
|
+
break;
|
|
25
|
+
case 'Inhibitor':
|
|
26
|
+
client.inhibitors.set(file.name, file);
|
|
27
|
+
break;
|
|
28
|
+
case 'Event':
|
|
29
|
+
client.events.set(file.name, file);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var FileTypes;
|
|
2
|
+
(function (FileTypes) {
|
|
3
|
+
FileTypes['message'] = 'MessageCommand';
|
|
4
|
+
FileTypes['slash'] = 'SlashCommand';
|
|
5
|
+
FileTypes['context'] = 'ContextCommand';
|
|
6
|
+
FileTypes['event'] = 'Event';
|
|
7
|
+
FileTypes['inhibitor'] = 'Inhibitor';
|
|
8
|
+
})(FileTypes || (FileTypes = {}));
|
|
9
|
+
export default function reload(client, type) {
|
|
10
|
+
const files = [];
|
|
11
|
+
if (type === 'message' || type === 'slash' || type === 'context') {
|
|
12
|
+
for (const [name] of client.commands[type]) {
|
|
13
|
+
files.push(client.commands[type].get(name).filePath);
|
|
14
|
+
}
|
|
15
|
+
client.commands[type].sweep(() => true);
|
|
16
|
+
}
|
|
17
|
+
if (type === 'event') {
|
|
18
|
+
for (const [name] of client.events) {
|
|
19
|
+
files.push(client.events.get(name).filePath);
|
|
20
|
+
}
|
|
21
|
+
client.events.sweep(() => true);
|
|
22
|
+
}
|
|
23
|
+
if (type === 'inhibitor') {
|
|
24
|
+
for (const [name] of client.inhibitors) {
|
|
25
|
+
files.push(client.inhibitors.get(name).filePath);
|
|
26
|
+
}
|
|
27
|
+
client.inhibitors.sweep(() => true);
|
|
28
|
+
}
|
|
29
|
+
return files.map(async (file) => {
|
|
30
|
+
let filedata = new (await import(`file://${file}`)).default();
|
|
31
|
+
filedata.fileType = FileTypes[type];
|
|
32
|
+
filedata.filePath = file;
|
|
33
|
+
filedata.client = client;
|
|
34
|
+
if (type === 'message' || type === 'slash' || type === 'context') client.commands[type].set(filedata.name, filedata);
|
|
35
|
+
if (type === 'event') client.events.set(filedata.name, filedata);
|
|
36
|
+
if (type === 'inhibitor') client.inhibitors.set(filedata.name, filedata);
|
|
37
|
+
return filedata;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export default async function sendWebhook(url, body) {
|
|
2
|
+
const response = await fetch(url, {
|
|
3
|
+
method: 'POST',
|
|
4
|
+
headers: {
|
|
5
|
+
'Content-Type': 'application/json',
|
|
6
|
+
},
|
|
7
|
+
body: JSON.stringify(body),
|
|
8
|
+
});
|
|
9
|
+
if (response.status === 204) return true;
|
|
10
|
+
const data = await response.json();
|
|
11
|
+
return data;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import XernerxClient from '../client/XernerxClient.js';
|
|
2
|
+
import { XernerxMessage, XernerxSlashInteraction, XernerxUser, XernerxUserContextInteraction } from '../types/extenders.js';
|
|
3
|
+
export declare function xernerxUser(event: XernerxMessage | XernerxSlashInteraction | XernerxUserContextInteraction | XernerxUserContextInteraction, client: XernerxClient): Promise<XernerxUser>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import isOwner from './isOwner.js';
|
|
2
|
+
export async function xernerxUser(event, client) {
|
|
3
|
+
const author = event.author || event.user;
|
|
4
|
+
const user = author;
|
|
5
|
+
'owner' in user ? null : (user.owner = isOwner(user, client));
|
|
6
|
+
'voted' in user ? null : (user.voted = client.util.hasVoted ? await client.util.hasVoted(user.id) : null);
|
|
7
|
+
return user;
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import XernerxClient from '../client/XernerxClient.js';
|
|
2
|
+
import { ContextHandlerOptions, MessageHandlerOptions, SlashHandlerOptions } from '../types/interfaces.js';
|
|
3
|
+
import Handler from './Handler.js';
|
|
4
|
+
export default class CommandHandler extends Handler {
|
|
5
|
+
constructor(client: XernerxClient);
|
|
6
|
+
loadMessageCommands(options: MessageHandlerOptions): void;
|
|
7
|
+
loadSlashCommands(options: SlashHandlerOptions): void;
|
|
8
|
+
loadContextCommands(options: ContextHandlerOptions): void;
|
|
9
|
+
private messageCommandRun;
|
|
10
|
+
private slashCommandRun;
|
|
11
|
+
private contextCommandRun;
|
|
12
|
+
private exec;
|
|
13
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { GatewayIntentBits } from 'discord.js';
|
|
4
|
+
import Handler from './Handler.js';
|
|
5
|
+
import MessageUtil from '../utils/MessageUtil.js';
|
|
6
|
+
import { xernerxUser } from '../functions/xernerxUser.js';
|
|
7
|
+
import InteractionUtil from '../utils/InteractionUtil.js';
|
|
8
|
+
import commandValidation from '../validators/commandValidation.js';
|
|
9
|
+
import XernerxLog from '../tools/XernerxLog.js';
|
|
10
|
+
import { interactionArguments, messageArguments } from '../models/Arguments.js';
|
|
11
|
+
import deploy from '../functions/deploy.js';
|
|
12
|
+
import { inhibitorValidation } from '../validators/inhibitorValidations.js';
|
|
13
|
+
export default class CommandHandler extends Handler {
|
|
14
|
+
constructor(client) {
|
|
15
|
+
super(client);
|
|
16
|
+
}
|
|
17
|
+
loadMessageCommands(options) {
|
|
18
|
+
if (!this.client.options.intents.has(GatewayIntentBits.MessageContent)) new XernerxLog(this.client).warn(`Message commands might not work as you're missing the intent MessageContent!`);
|
|
19
|
+
if (!this.client.options.intents.has(GatewayIntentBits.GuildMessages)) new XernerxLog(this.client).warn(`Message commands might not work as you're missing the intent GuildMessages!`);
|
|
20
|
+
options = z
|
|
21
|
+
.object({
|
|
22
|
+
directory: z.string(),
|
|
23
|
+
prefix: z.string().or(z.array(z.string())),
|
|
24
|
+
allowMention: z.boolean().default(false),
|
|
25
|
+
cooldown: z.number().default(0),
|
|
26
|
+
permissions: z
|
|
27
|
+
.object({
|
|
28
|
+
user: z.array(z.string()).default([]),
|
|
29
|
+
client: z.array(z.string()).default([]),
|
|
30
|
+
dm: z.boolean().default(true),
|
|
31
|
+
})
|
|
32
|
+
.default({}),
|
|
33
|
+
handleEdits: z.boolean().default(false),
|
|
34
|
+
handleDeletes: z.boolean().default(false),
|
|
35
|
+
handleTyping: z.boolean().default(false),
|
|
36
|
+
logging: z.boolean().default(false),
|
|
37
|
+
})
|
|
38
|
+
.parse(options);
|
|
39
|
+
this.client.modules.options.message = options;
|
|
40
|
+
const files = this.readdir(options.directory);
|
|
41
|
+
for (const file of files) {
|
|
42
|
+
const filePath = `${path.resolve(options.directory)}\\${file}`;
|
|
43
|
+
this.load(filePath, 'MessageCommand');
|
|
44
|
+
}
|
|
45
|
+
new XernerxLog(this.client).info(`Loaded Message Commands.`);
|
|
46
|
+
this.emit({
|
|
47
|
+
name: 'messageCreate',
|
|
48
|
+
fileType: 'MessageCommand',
|
|
49
|
+
run: (message) => this.messageCommandRun(message),
|
|
50
|
+
});
|
|
51
|
+
this.emit({
|
|
52
|
+
name: 'messageUpdate',
|
|
53
|
+
fileType: 'MessageCommand',
|
|
54
|
+
run: (message, message2) => this.messageCommandRun(message, message2),
|
|
55
|
+
});
|
|
56
|
+
this.emit({
|
|
57
|
+
name: 'messageDelete',
|
|
58
|
+
fileType: 'MessageCommand',
|
|
59
|
+
run: (message) => this.messageCommandRun(message, 'delete'),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
// public reloadMessageCommands() {
|
|
63
|
+
// return reload(this.client, 'message');
|
|
64
|
+
// }
|
|
65
|
+
loadSlashCommands(options) {
|
|
66
|
+
options = z
|
|
67
|
+
.object({
|
|
68
|
+
directory: z.string(),
|
|
69
|
+
cooldown: z.number().default(0),
|
|
70
|
+
permissions: z
|
|
71
|
+
.object({
|
|
72
|
+
user: z.array(z.string()).default([]),
|
|
73
|
+
client: z.array(z.string()).default([]),
|
|
74
|
+
dm: z.boolean().default(true),
|
|
75
|
+
})
|
|
76
|
+
.default({}),
|
|
77
|
+
logging: z.boolean().default(false),
|
|
78
|
+
defer: z
|
|
79
|
+
.object({
|
|
80
|
+
reply: z.boolean().default(false),
|
|
81
|
+
ephemeral: z.boolean().default(false),
|
|
82
|
+
fetchReply: z.boolean().default(false),
|
|
83
|
+
})
|
|
84
|
+
.default({}),
|
|
85
|
+
})
|
|
86
|
+
.parse(options);
|
|
87
|
+
this.client.modules.options.slash = options;
|
|
88
|
+
const files = this.readdir(options.directory);
|
|
89
|
+
for (const file of files) {
|
|
90
|
+
const filePath = `${path.resolve(options.directory)}\\${file}`;
|
|
91
|
+
this.load(filePath, 'SlashCommand');
|
|
92
|
+
}
|
|
93
|
+
new XernerxLog(this.client).info(`Loaded Slash Commands.`);
|
|
94
|
+
deploy(this.client, 'slash');
|
|
95
|
+
this.emit({
|
|
96
|
+
name: 'interactionCreate',
|
|
97
|
+
fileType: 'SlashCommand',
|
|
98
|
+
run: (interaction) => this.slashCommandRun(interaction),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
loadContextCommands(options) {
|
|
102
|
+
options = z
|
|
103
|
+
.object({
|
|
104
|
+
directory: z.string(),
|
|
105
|
+
cooldown: z.number().default(0),
|
|
106
|
+
permissions: z
|
|
107
|
+
.object({
|
|
108
|
+
user: z.array(z.string()).default([]),
|
|
109
|
+
client: z.array(z.string()).default([]),
|
|
110
|
+
dm: z.boolean().default(true),
|
|
111
|
+
})
|
|
112
|
+
.default({}),
|
|
113
|
+
logging: z.boolean().default(false),
|
|
114
|
+
defer: z
|
|
115
|
+
.object({
|
|
116
|
+
reply: z.boolean().default(false),
|
|
117
|
+
ephemeral: z.boolean().default(false),
|
|
118
|
+
fetchReply: z.boolean().default(false),
|
|
119
|
+
})
|
|
120
|
+
.default({}),
|
|
121
|
+
})
|
|
122
|
+
.parse(options);
|
|
123
|
+
this.client.modules.options.context = options;
|
|
124
|
+
const files = this.readdir(options.directory);
|
|
125
|
+
for (const file of files) {
|
|
126
|
+
const filePath = `${path.resolve(options.directory)}\\${file}`;
|
|
127
|
+
this.load(filePath, 'ContextCommand');
|
|
128
|
+
}
|
|
129
|
+
new XernerxLog(this.client).info(`Loaded Context Commands.`);
|
|
130
|
+
deploy(this.client, 'context');
|
|
131
|
+
this.emit({
|
|
132
|
+
name: 'interactionCreate',
|
|
133
|
+
fileType: 'ContextCommand',
|
|
134
|
+
run: (interaction) => this.contextCommandRun(interaction),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
async messageCommandRun(message, message2) {
|
|
138
|
+
if (message.author.bot) return;
|
|
139
|
+
message.util = new MessageUtil(this.client, message);
|
|
140
|
+
message.user = await xernerxUser(message, this.client);
|
|
141
|
+
if (typeof message2 === 'object') message = message2;
|
|
142
|
+
if (message2 === 'delete') {
|
|
143
|
+
if (!this.client.cache.messages.has(message.id)) return;
|
|
144
|
+
const id = this.client.cache.messages.get(message.id);
|
|
145
|
+
if (!id) return;
|
|
146
|
+
(async () => {
|
|
147
|
+
const msg = await message.channel.messages.fetch(id);
|
|
148
|
+
await msg.delete();
|
|
149
|
+
this.client.cache.messages.delete(message.id);
|
|
150
|
+
})();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (message.content && this.client.modules.options.message) {
|
|
154
|
+
const commands = this.client.commands.message;
|
|
155
|
+
const prefixes = Array.isArray(this.client.modules.options.message.prefix) ? this.client.modules.options.message.prefix : [this.client.modules.options.message.prefix];
|
|
156
|
+
let commandName, cmd;
|
|
157
|
+
commands.map((command) => {
|
|
158
|
+
let prefix = null;
|
|
159
|
+
if (command.regex && message.content.match(command.regex)) {
|
|
160
|
+
const [match] = message.content.match(command.regex) || [null];
|
|
161
|
+
if (match) commandName = command.name;
|
|
162
|
+
}
|
|
163
|
+
const cp = Array.isArray(command.prefix) ? command.prefix : [command.prefix];
|
|
164
|
+
prefixes.map((p) => {
|
|
165
|
+
if (message.content.startsWith(p)) prefix = p;
|
|
166
|
+
});
|
|
167
|
+
cp.map((p) => {
|
|
168
|
+
if (message.content.startsWith(p)) prefix = p;
|
|
169
|
+
});
|
|
170
|
+
if (!prefix) return;
|
|
171
|
+
if (!commandName)
|
|
172
|
+
commandName = message.content
|
|
173
|
+
.replace(prefix, '')
|
|
174
|
+
.split(command.separator || / +/)
|
|
175
|
+
.shift()
|
|
176
|
+
?.trim()
|
|
177
|
+
?.toLowerCase();
|
|
178
|
+
});
|
|
179
|
+
if (!cmd && this.client.modules.options.message.allowMention) {
|
|
180
|
+
if (message.mentions.users.has(this.client.user?.id) || message.mentions.repliedUser?.id === this.client.user?.id) {
|
|
181
|
+
commandName = message.content.replace(`<@${this.client.user?.id}>`, '').trim().split(/ +/).shift()?.toLowerCase();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (!commandName) commandName = '';
|
|
185
|
+
if (this.client.commands.message.has(commandName)) cmd = this.client.commands.message.get(commandName);
|
|
186
|
+
if (await inhibitorValidation(message, cmd)) return;
|
|
187
|
+
if (!cmd) return this.client.emit('commandNotFound');
|
|
188
|
+
this.exec(cmd, message, await messageArguments(message, cmd), 'MessageCommand');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async slashCommandRun(interaction) {
|
|
192
|
+
interaction.util = new InteractionUtil(this.client, interaction);
|
|
193
|
+
interaction.user = await xernerxUser(interaction, this.client);
|
|
194
|
+
let cmd;
|
|
195
|
+
if (this.client.commands.slash.has(interaction.commandName)) cmd = this.client.commands.slash.get(interaction.commandName);
|
|
196
|
+
if (await inhibitorValidation(interaction, cmd)) return;
|
|
197
|
+
if (!cmd) return this.client.emit('commandNotFound', interaction);
|
|
198
|
+
this.exec(cmd, interaction, await interactionArguments(interaction, cmd), 'SlashCommand');
|
|
199
|
+
}
|
|
200
|
+
async contextCommandRun(interaction) {
|
|
201
|
+
interaction.util = new InteractionUtil(this.client, interaction);
|
|
202
|
+
interaction.user = await xernerxUser(interaction, this.client);
|
|
203
|
+
let cmd;
|
|
204
|
+
if (this.client.commands.context.has(interaction.commandName)) cmd = this.client.commands.context.get(interaction.commandName);
|
|
205
|
+
if (await inhibitorValidation(interaction, cmd)) return;
|
|
206
|
+
if (!cmd) return this.client.emit('commandNotFound', interaction);
|
|
207
|
+
this.exec(cmd, interaction, await interactionArguments(interaction, cmd), 'ContextCommand');
|
|
208
|
+
}
|
|
209
|
+
async exec(cmd, event, args, type) {
|
|
210
|
+
try {
|
|
211
|
+
if (await commandValidation(event, cmd)) return;
|
|
212
|
+
if (cmd.conditions && (await cmd.conditions(event, args))) return;
|
|
213
|
+
cmd.exec(event, args);
|
|
214
|
+
this.client.emit('commandExecute', event, type);
|
|
215
|
+
} catch (error) {
|
|
216
|
+
new XernerxLog(this.client).error(`An error occurred executing ${cmd.name}`, error);
|
|
217
|
+
this.client.emit('commandError', event, error, type);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import XernerxClient from '../client/XernerxClient.js';
|
|
2
|
+
import { EventHandlerOptions } from '../types/interfaces.js';
|
|
3
|
+
import Handler from './Handler.js';
|
|
4
|
+
export default class EventHandler extends Handler {
|
|
5
|
+
constructor(client: XernerxClient);
|
|
6
|
+
loadEvents(options: EventHandlerOptions): Promise<void>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import Handler from './Handler.js';
|
|
4
|
+
import XernerxLog from '../tools/XernerxLog.js';
|
|
5
|
+
export default class EventHandler extends Handler {
|
|
6
|
+
constructor(client) {
|
|
7
|
+
super(client);
|
|
8
|
+
}
|
|
9
|
+
async loadEvents(options) {
|
|
10
|
+
options = z
|
|
11
|
+
.object({
|
|
12
|
+
directory: z.string(),
|
|
13
|
+
})
|
|
14
|
+
.parse(options);
|
|
15
|
+
this.client.modules.options.events = options;
|
|
16
|
+
const files = this.readdir(options.directory);
|
|
17
|
+
for (const file of files) {
|
|
18
|
+
const filePath = `${path.resolve(options.directory)}\\${file}`;
|
|
19
|
+
const data = await this.load(filePath, 'Event');
|
|
20
|
+
this.emit(data);
|
|
21
|
+
}
|
|
22
|
+
new XernerxLog(this.client).info(`Loaded Events.`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import XernerxExtensionBuilder from 'xernerx-extension-builder';
|
|
2
|
+
import XernerxClient from '../main.js';
|
|
3
|
+
import Handler from './Handler.js';
|
|
4
|
+
export default class ExtensionHandler extends Handler {
|
|
5
|
+
constructor(client: XernerxClient);
|
|
6
|
+
loadExtensions(...extensions: Array<XernerxExtensionBuilder>): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Handler from './Handler.js';
|
|
2
|
+
import XernerxLog from '../tools/XernerxLog.js';
|
|
3
|
+
export default class ExtensionHandler extends Handler {
|
|
4
|
+
constructor(client) {
|
|
5
|
+
super(client);
|
|
6
|
+
}
|
|
7
|
+
loadExtensions(...extensions) {
|
|
8
|
+
const active = extensions.map((extension) => {
|
|
9
|
+
try {
|
|
10
|
+
// extension.main(client);
|
|
11
|
+
// extension.await(client);
|
|
12
|
+
return extension.name;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
new XernerxLog(this.client).error(`An error occurred while loading ${extension.name}`);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
new XernerxLog(this.client).info(`Loaded Extensions: ${active.filter((e) => e).join(', ')}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import XernerxClient from '../client/XernerxClient.js';
|
|
2
|
+
import MessageCommandBuilder from '../build/MessageCommandBuilder.js';
|
|
3
|
+
import SlashCommandBuilder from '../build/SlashCommandBuilder.js';
|
|
4
|
+
import ContextCommandBuilder from '../build/ContextCommandBuilder.js';
|
|
5
|
+
import { FileType } from '../types/types.js';
|
|
6
|
+
export default class Handler {
|
|
7
|
+
readonly client: XernerxClient;
|
|
8
|
+
readonly files: Array<MessageCommandBuilder | SlashCommandBuilder | ContextCommandBuilder>;
|
|
9
|
+
readonly readyTimestamp: number;
|
|
10
|
+
constructor(client: XernerxClient);
|
|
11
|
+
readdir(dir: string): string[];
|
|
12
|
+
load(filePath: string, type: FileType): Promise<any>;
|
|
13
|
+
emit<T extends Record<string, string | boolean | Function | void>>(event: T): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import load from '../functions/load.js';
|
|
4
|
+
export default class Handler {
|
|
5
|
+
client;
|
|
6
|
+
files;
|
|
7
|
+
readyTimestamp;
|
|
8
|
+
constructor(client) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
this.files = [];
|
|
11
|
+
this.readyTimestamp = Number(Date.now());
|
|
12
|
+
}
|
|
13
|
+
readdir(dir) {
|
|
14
|
+
try {
|
|
15
|
+
return fs.readdirSync(path.resolve(dir)).filter((file) => file.endsWith('.js'));
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.error(error);
|
|
18
|
+
}
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
async load(filePath, type) {
|
|
22
|
+
const file = await load(this.client, filePath, type);
|
|
23
|
+
this.files.push(file);
|
|
24
|
+
return file;
|
|
25
|
+
}
|
|
26
|
+
async emit(event) {
|
|
27
|
+
if (!event?.fileType) return;
|
|
28
|
+
if (event.fileType === 'Event') {
|
|
29
|
+
if (event.emitter === 'client') event.once ? this.client.once(event.name, (...args) => event.run(...args)) : this.client.on(event.name, (...args) => event.run(...args));
|
|
30
|
+
else if (event.emitter === 'process') event.once ? process.once(event.name, (...args) => event.run(...args)) : process.on(event.name, (...args) => event.run(...args));
|
|
31
|
+
}
|
|
32
|
+
if (['MessageCommand', 'SlashCommand', 'ContextCommand'].includes(event.fileType)) {
|
|
33
|
+
event.once ? this.client.once(event.name, (...args) => event.run(...args)) : this.client.on(event.name, (...args) => event.run(...args));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import XernerxClient from '../client/XernerxClient.js';
|
|
2
|
+
import Handler from './Handler.js';
|
|
3
|
+
import { InhibitorHandlerOptions } from '../types/interfaces.js';
|
|
4
|
+
export default class InhibitorHandler extends Handler {
|
|
5
|
+
constructor(client: XernerxClient);
|
|
6
|
+
loadInhibitors(options: InhibitorHandlerOptions): Promise<void>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import Handler from './Handler.js';
|
|
4
|
+
import XernerxLog from '../tools/XernerxLog.js';
|
|
5
|
+
export default class InhibitorHandler extends Handler {
|
|
6
|
+
constructor(client) {
|
|
7
|
+
super(client);
|
|
8
|
+
}
|
|
9
|
+
async loadInhibitors(options) {
|
|
10
|
+
options = z
|
|
11
|
+
.object({
|
|
12
|
+
directory: z.string(),
|
|
13
|
+
})
|
|
14
|
+
.parse(options);
|
|
15
|
+
this.client.modules.options.inhibitors = options;
|
|
16
|
+
const files = this.readdir(options.directory);
|
|
17
|
+
for (const file of files) {
|
|
18
|
+
const filePath = `${path.resolve(options.directory)}\\${file}`;
|
|
19
|
+
const data = await this.load(filePath, 'Inhibitor');
|
|
20
|
+
this.emit(data);
|
|
21
|
+
}
|
|
22
|
+
new XernerxLog(this.client).info(`Loaded Inhibitors.`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import XernerxLog from '../tools/XernerxLog.js';
|
|
2
|
+
import Handler from './Handler.js';
|
|
3
|
+
export default class WebhookHandler extends Handler {
|
|
4
|
+
constructor(client) {
|
|
5
|
+
super(client);
|
|
6
|
+
}
|
|
7
|
+
async loadWebhooks(options) {
|
|
8
|
+
this.client.once('ready', async (client) => {
|
|
9
|
+
this.post(options.token);
|
|
10
|
+
setInterval(() => {
|
|
11
|
+
this.post(client.token);
|
|
12
|
+
}, 60000 * 30);
|
|
13
|
+
this.client.util.hasVoted = async (userId) => {
|
|
14
|
+
return !!(
|
|
15
|
+
await (
|
|
16
|
+
await fetch(`https://top.gg/api/bots/${this.client.user?.id}/check?userId=${userId}`, {
|
|
17
|
+
headers: { Authorization: options.token, 'Content-Type': 'application/json' },
|
|
18
|
+
})
|
|
19
|
+
).json()
|
|
20
|
+
).voted;
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async post(token) {
|
|
25
|
+
const guilds = await this.client.guilds.fetch();
|
|
26
|
+
this.client.stats.guildCount = guilds.size;
|
|
27
|
+
this.client.stats.userCount = (await Promise.all(guilds.map(async (guild) => (await this.client.guilds.fetch(guild.id)).memberCount))).reduce((a, b) => (a += b));
|
|
28
|
+
this.client.stats.shardId = this.client.options.shards?.at(0) || 0;
|
|
29
|
+
this.client.stats.shardCount = this.client.options.shardCount || this.client.options.shards?.length || 1;
|
|
30
|
+
try {
|
|
31
|
+
new XernerxLog(this.client).info(`Posted Stats to Top.gg!`);
|
|
32
|
+
this.client.emit('webhookCreate', this.client, this.client.stats);
|
|
33
|
+
return await fetch(`https://top.gg/api/bots/stats`, {
|
|
34
|
+
method: 'POST',
|
|
35
|
+
headers: {
|
|
36
|
+
Authorization: token,
|
|
37
|
+
'Content-Type': 'application/json',
|
|
38
|
+
},
|
|
39
|
+
body: JSON.stringify({
|
|
40
|
+
server_count: this.client.stats.guildCount,
|
|
41
|
+
shard_id: this.client.stats.shardId,
|
|
42
|
+
shard_count: this.client.stats.shardCount,
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
45
|
+
} catch (error) {
|
|
46
|
+
new XernerxLog(this.client).error(`An error occurred while posting stats to Top.gg`, error);
|
|
47
|
+
return this.client.emit('webhookError', this.client, this.client.stats);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import XernerxClient from './client/XernerxClient.js';
|
|
2
|
+
import MessageCommandBuilder from './build/MessageCommandBuilder.js';
|
|
3
|
+
import SlashCommandBuilder from './build/SlashCommandBuilder.js';
|
|
4
|
+
import ContextCommandBuilder from './build/ContextCommandBuilder.js';
|
|
5
|
+
import EventBuilder from './build/EventBuilder.js';
|
|
6
|
+
import InhibitorBuilder from './build/InhibitorBuilder.js';
|
|
7
|
+
export default XernerxClient;
|
|
8
|
+
export * from 'discord.js';
|
|
9
|
+
export * from 'dumfunctions';
|
|
10
|
+
import ExtensionBuilder from 'xernerx-extension-builder';
|
|
11
|
+
export { XernerxClient, MessageCommandBuilder, SlashCommandBuilder, ContextCommandBuilder, EventBuilder, InhibitorBuilder, ExtensionBuilder };
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import XernerxClient from './client/XernerxClient.js';
|
|
2
|
+
import MessageCommandBuilder from './build/MessageCommandBuilder.js';
|
|
3
|
+
import SlashCommandBuilder from './build/SlashCommandBuilder.js';
|
|
4
|
+
import ContextCommandBuilder from './build/ContextCommandBuilder.js';
|
|
5
|
+
import EventBuilder from './build/EventBuilder.js';
|
|
6
|
+
import InhibitorBuilder from './build/InhibitorBuilder.js';
|
|
7
|
+
export default XernerxClient;
|
|
8
|
+
export * from 'discord.js';
|
|
9
|
+
export * from 'dumfunctions';
|
|
10
|
+
import ExtensionBuilder from 'xernerx-extension-builder';
|
|
11
|
+
export { XernerxClient, MessageCommandBuilder, SlashCommandBuilder, ContextCommandBuilder, EventBuilder, InhibitorBuilder, ExtensionBuilder };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import SlashCommandBuilder from '../build/SlashCommandBuilder.js';
|
|
2
|
+
import ContextCommandBuilder from '../build/ContextCommandBuilder.js';
|
|
3
|
+
import MessageCommandBuilder from '../build/MessageCommandBuilder.js';
|
|
4
|
+
import { XernerxMessage } from '../types/extenders.js';
|
|
5
|
+
import { MessageCommandArguments } from '../types/interfaces.js';
|
|
6
|
+
import { XernerxInteraction } from '../types/types.js';
|
|
7
|
+
export declare function messageArguments(message: XernerxMessage, command: MessageCommandBuilder): Promise<MessageCommandArguments>;
|
|
8
|
+
export declare function interactionArguments(
|
|
9
|
+
interaction: XernerxInteraction | any,
|
|
10
|
+
command: ContextCommandBuilder | SlashCommandBuilder
|
|
11
|
+
): Promise<{
|
|
12
|
+
args: any;
|
|
13
|
+
group: any;
|
|
14
|
+
subcommand: any;
|
|
15
|
+
}>;
|