xernerx 4.4.2 → 4.4.3
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/package.json +2 -2
- package/dist/build/ContextCommandBuilder.d.ts +0 -48
- package/dist/build/ContextCommandBuilder.js +0 -67
- package/dist/build/EventBuilder.d.ts +0 -22
- package/dist/build/EventBuilder.js +0 -29
- package/dist/build/InhibitorBuilder.d.ts +0 -17
- package/dist/build/InhibitorBuilder.js +0 -22
- package/dist/build/MessageCommandBuilder.d.ts +0 -45
- package/dist/build/MessageCommandBuilder.js +0 -60
- package/dist/build/SlashCommandBuilder.d.ts +0 -52
- package/dist/build/SlashCommandBuilder.js +0 -113
- package/dist/client/XernerxClient.d.ts +0 -55
- package/dist/client/XernerxClient.js +0 -82
- package/dist/client/XernerxShardClient.d.ts +0 -16
- package/dist/client/XernerxShardClient.js +0 -32
- package/dist/functions/delay.d.ts +0 -1
- package/dist/functions/delay.js +0 -3
- package/dist/functions/deploy.d.ts +0 -2
- package/dist/functions/deploy.js +0 -33
- package/dist/functions/isOwner.d.ts +0 -3
- package/dist/functions/isOwner.js +0 -3
- package/dist/functions/isVoter.d.ts +0 -3
- package/dist/functions/isVoter.js +0 -5
- package/dist/functions/load.d.ts +0 -3
- package/dist/functions/load.js +0 -32
- package/dist/functions/reload.d.ts +0 -2
- package/dist/functions/reload.js +0 -39
- package/dist/functions/sendWebhook.d.ts +0 -2
- package/dist/functions/sendWebhook.js +0 -12
- package/dist/functions/setPresence.d.ts +0 -3
- package/dist/functions/setPresence.js +0 -19
- package/dist/functions/xernerxUser.d.ts +0 -3
- package/dist/functions/xernerxUser.js +0 -8
- package/dist/handlers/CommandHandler.d.ts +0 -13
- package/dist/handlers/CommandHandler.js +0 -251
- package/dist/handlers/EventHandler.d.ts +0 -7
- package/dist/handlers/EventHandler.js +0 -24
- package/dist/handlers/ExtensionHandler.d.ts +0 -7
- package/dist/handlers/ExtensionHandler.js +0 -21
- package/dist/handlers/Handler.d.ts +0 -14
- package/dist/handlers/Handler.js +0 -36
- package/dist/handlers/InhibitorHandler.d.ts +0 -7
- package/dist/handlers/InhibitorHandler.js +0 -24
- package/dist/handlers/WebhookHandler.d.ts +0 -7
- package/dist/handlers/WebhookHandler.js +0 -50
- package/dist/main.d.ts +0 -42
- package/dist/main.js +0 -43
- package/dist/models/Arguments.d.ts +0 -15
- package/dist/models/Arguments.js +0 -129
- package/dist/tools/XernerxError.d.ts +0 -6
- package/dist/tools/XernerxError.js +0 -10
- package/dist/tools/XernerxLog.d.ts +0 -14
- package/dist/tools/XernerxLog.js +0 -48
- package/dist/types/extenders.d.ts +0 -28
- package/dist/types/extenders.js +0 -1
- package/dist/types/interfaces.d.ts +0 -236
- package/dist/types/interfaces.js +0 -1
- package/dist/types/types.d.ts +0 -181
- package/dist/types/types.js +0 -1
- package/dist/utils/ClientUtil.d.ts +0 -10
- package/dist/utils/ClientUtil.js +0 -30
- package/dist/utils/InteractionUtil.d.ts +0 -10
- package/dist/utils/InteractionUtil.js +0 -15
- package/dist/utils/MessageUtil.d.ts +0 -15
- package/dist/utils/MessageUtil.js +0 -46
- package/dist/utils/Util.d.ts +0 -5
- package/dist/utils/Util.js +0 -6
- package/dist/validators/commandValidation.d.ts +0 -6
- package/dist/validators/commandValidation.js +0 -49
- package/dist/validators/inhibitorValidations.d.ts +0 -18
- package/dist/validators/inhibitorValidations.js +0 -34
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ShardingManager } from 'discord.js';
|
|
2
|
-
import XernerxLog from '../tools/XernerxLog.js';
|
|
3
|
-
export default class XernerxShardClient extends ShardingManager {
|
|
4
|
-
constructor(file, discordOptions, xernerxOptions) {
|
|
5
|
-
super(file, discordOptions);
|
|
6
|
-
this.stats = { guildCount: 0, userCount: 0, shardCount: 0 };
|
|
7
|
-
this.user = null;
|
|
8
|
-
this.on('shardCreate', async (shard) => {
|
|
9
|
-
shard.on('ready', async () => {
|
|
10
|
-
const guilds = await shard.fetchClientValue('guilds.cache');
|
|
11
|
-
const guildCount = guilds.length;
|
|
12
|
-
const userCount = guilds.map((guild) => guild.memberCount).length ? guilds.map((guild) => guild.memberCount).reduce((a, b) => (a += b)) : 0;
|
|
13
|
-
this.stats.guildCount += Number(guildCount);
|
|
14
|
-
this.stats.userCount += Number(userCount);
|
|
15
|
-
this.stats.shardCount++;
|
|
16
|
-
this.user = await shard.fetchClientValue('user');
|
|
17
|
-
});
|
|
18
|
-
new XernerxLog({ settings: xernerxOptions }).info(`Launching shard ${shard.id} for ${this.user?.tag}!`);
|
|
19
|
-
});
|
|
20
|
-
this.spawn().then(async (shards) => {
|
|
21
|
-
const collector = setInterval(() => {
|
|
22
|
-
const index = shards.size - 1;
|
|
23
|
-
if (shards.get(index)?.ready) {
|
|
24
|
-
new XernerxLog({ settings: xernerxOptions }).info(
|
|
25
|
-
`Launched all ${this.stats.shardCount} shards for ${this.user?.tag}, watching ${this.stats.guildCount} guilds, and ${this.stats.userCount} users!`
|
|
26
|
-
);
|
|
27
|
-
clearInterval(collector);
|
|
28
|
-
}
|
|
29
|
-
}, 1000);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function delay(time: number): Promise<unknown>;
|
package/dist/functions/delay.js
DELETED
package/dist/functions/deploy.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { GatewayVersion, REST, Routes } from 'discord.js';
|
|
2
|
-
import XernerxLog from '../tools/XernerxLog.js';
|
|
3
|
-
import XernerxError from '../tools/XernerxError.js';
|
|
4
|
-
const commands = { slash: [], context: [] };
|
|
5
|
-
export default function deploy(client, type) {
|
|
6
|
-
client.prependOnceListener('ready', (client) => {
|
|
7
|
-
commands[type] = client.commands[type].map((command) => command.data.toJSON());
|
|
8
|
-
if (!(!!client.modules.options.slash && !!client.modules.options.context && commands.slash.length > 0 && commands.context.length > 0)) return;
|
|
9
|
-
try {
|
|
10
|
-
if (client.settings.global) {
|
|
11
|
-
put(client, client.settings.global, [...commands.slash, ...commands.context]);
|
|
12
|
-
put(client, !client.settings.global, []);
|
|
13
|
-
} else {
|
|
14
|
-
put(client, !client.settings.global, [...commands.slash, ...commands.context]);
|
|
15
|
-
put(client, client.settings.global, []);
|
|
16
|
-
}
|
|
17
|
-
} catch (error) {
|
|
18
|
-
new XernerxLog(client).error(`An error occurred while deploying the interaction commands!`, error);
|
|
19
|
-
} finally {
|
|
20
|
-
new XernerxLog(client).info(
|
|
21
|
-
`Deployed ${[client.commands.message.size, client.commands.slash.size, client.commands.context.size].reduce((a, b) => (a += b))} Commands ${
|
|
22
|
-
client.settings.global ? 'globally' : 'locally'
|
|
23
|
-
}.`
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
function put(client, global, body) {
|
|
29
|
-
const rest = new REST({ version: GatewayVersion }).setToken(client.token);
|
|
30
|
-
if (!global && !client.settings?.local) throw new XernerxError(`No guild ID provided as local guild!`);
|
|
31
|
-
if (!global && client.settings?.local) rest.put(Routes.applicationGuildCommands(client.user?.id, client.settings.local), { body });
|
|
32
|
-
else rest.put(Routes.applicationCommands(client.user?.id), { body });
|
|
33
|
-
}
|
package/dist/functions/load.d.ts
DELETED
package/dist/functions/load.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/functions/reload.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export default function setPresence(client, options) {
|
|
2
|
-
const presence = () =>
|
|
3
|
-
client.user?.setPresence({
|
|
4
|
-
activities: [
|
|
5
|
-
{
|
|
6
|
-
name: options.text,
|
|
7
|
-
type: options.type,
|
|
8
|
-
url: options.url,
|
|
9
|
-
},
|
|
10
|
-
],
|
|
11
|
-
status: options.status,
|
|
12
|
-
});
|
|
13
|
-
let response = presence();
|
|
14
|
-
if (options.interval)
|
|
15
|
-
setInterval(() => {
|
|
16
|
-
response = presence();
|
|
17
|
-
}, options.interval);
|
|
18
|
-
return response;
|
|
19
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
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>;
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,251 +0,0 @@
|
|
|
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 ${files.length} 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
|
-
if (!this.client.settings.local) new XernerxLog(this.client).warn(`Slash commands might not work as you haven't specified a local guild ID.`);
|
|
67
|
-
options = z
|
|
68
|
-
.object({
|
|
69
|
-
directory: z.string(),
|
|
70
|
-
cooldown: z.number().default(0),
|
|
71
|
-
permissions: z
|
|
72
|
-
.object({
|
|
73
|
-
user: z.array(z.string()).default([]),
|
|
74
|
-
client: z.array(z.string()).default([]),
|
|
75
|
-
dm: z.boolean().default(true),
|
|
76
|
-
})
|
|
77
|
-
.default({}),
|
|
78
|
-
logging: z.boolean().default(false),
|
|
79
|
-
defer: z
|
|
80
|
-
.object({
|
|
81
|
-
reply: z.boolean().default(false),
|
|
82
|
-
ephemeral: z.boolean().default(false),
|
|
83
|
-
fetchReply: z.boolean().default(false),
|
|
84
|
-
})
|
|
85
|
-
.default({}),
|
|
86
|
-
})
|
|
87
|
-
.parse(options);
|
|
88
|
-
this.client.modules.options.slash = options;
|
|
89
|
-
const files = this.readdir(options.directory);
|
|
90
|
-
for (const file of files) {
|
|
91
|
-
const filePath = `${path.resolve(options.directory)}\\${file}`;
|
|
92
|
-
this.load(filePath, 'SlashCommand');
|
|
93
|
-
}
|
|
94
|
-
new XernerxLog(this.client).info(`Loaded ${files.length} Slash Commands.`);
|
|
95
|
-
deploy(this.client, 'slash');
|
|
96
|
-
this.emit({
|
|
97
|
-
name: 'interactionCreate',
|
|
98
|
-
fileType: 'SlashCommand',
|
|
99
|
-
run: (interaction) => this.slashCommandRun(interaction),
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
loadContextCommands(options) {
|
|
103
|
-
if (!this.client.settings.local) new XernerxLog(this.client).warn(`Context commands might not work as you haven't specified a local guild ID.`);
|
|
104
|
-
options = z
|
|
105
|
-
.object({
|
|
106
|
-
directory: z.string(),
|
|
107
|
-
cooldown: z.number().default(0),
|
|
108
|
-
permissions: z
|
|
109
|
-
.object({
|
|
110
|
-
user: z.array(z.string()).default([]),
|
|
111
|
-
client: z.array(z.string()).default([]),
|
|
112
|
-
dm: z.boolean().default(true),
|
|
113
|
-
})
|
|
114
|
-
.default({}),
|
|
115
|
-
logging: z.boolean().default(false),
|
|
116
|
-
defer: z
|
|
117
|
-
.object({
|
|
118
|
-
reply: z.boolean().default(false),
|
|
119
|
-
ephemeral: z.boolean().default(false),
|
|
120
|
-
fetchReply: z.boolean().default(false),
|
|
121
|
-
})
|
|
122
|
-
.default({}),
|
|
123
|
-
})
|
|
124
|
-
.parse(options);
|
|
125
|
-
this.client.modules.options.context = options;
|
|
126
|
-
const files = this.readdir(options.directory);
|
|
127
|
-
for (const file of files) {
|
|
128
|
-
const filePath = `${path.resolve(options.directory)}\\${file}`;
|
|
129
|
-
this.load(filePath, 'ContextCommand');
|
|
130
|
-
}
|
|
131
|
-
new XernerxLog(this.client).info(`Loaded ${files.length} Context Commands.`);
|
|
132
|
-
deploy(this.client, 'context');
|
|
133
|
-
this.emit({
|
|
134
|
-
name: 'interactionCreate',
|
|
135
|
-
fileType: 'ContextCommand',
|
|
136
|
-
run: (interaction) => this.contextCommandRun(interaction),
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
async messageCommandRun(message, message2) {
|
|
140
|
-
const filetype = 'MessageCommand';
|
|
141
|
-
if (message.author.bot) return;
|
|
142
|
-
message.util = new MessageUtil(this.client, message);
|
|
143
|
-
message.user = await xernerxUser(message, this.client);
|
|
144
|
-
if (typeof message2 === 'object') message = message2;
|
|
145
|
-
if (message2 === 'delete') {
|
|
146
|
-
if (!this.client.cache.messages.has(message.id)) return;
|
|
147
|
-
const id = this.client.cache.messages.get(message.id);
|
|
148
|
-
if (!id) return;
|
|
149
|
-
(async () => {
|
|
150
|
-
const msg = await message.channel.messages.fetch(id);
|
|
151
|
-
await msg.delete();
|
|
152
|
-
this.client.cache.messages.delete(message.id);
|
|
153
|
-
})();
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if (message.content && this.client.modules.options.message) {
|
|
157
|
-
const commands = this.client.commands.message;
|
|
158
|
-
const prefixes = Array.isArray(this.client.modules.options.message.prefix) ? this.client.modules.options.message.prefix : [this.client.modules.options.message.prefix];
|
|
159
|
-
let commandName = null,
|
|
160
|
-
cmd,
|
|
161
|
-
commandAlias = null,
|
|
162
|
-
commandPrefix = null;
|
|
163
|
-
commands.map((command) => {
|
|
164
|
-
let prefix = null;
|
|
165
|
-
if (command.regex && message.content.match(command.regex)) {
|
|
166
|
-
const [match] = message.content.match(command.regex) || [null];
|
|
167
|
-
if (match) commandName = command.name;
|
|
168
|
-
}
|
|
169
|
-
const cp = Array.isArray(command.prefix) ? command.prefix : [command.prefix];
|
|
170
|
-
prefixes.map((p) => {
|
|
171
|
-
if (message.content.startsWith(p)) prefix = p;
|
|
172
|
-
});
|
|
173
|
-
cp.map((p) => {
|
|
174
|
-
if (message.content.startsWith(p)) prefix = p;
|
|
175
|
-
});
|
|
176
|
-
if (!prefix) return;
|
|
177
|
-
if (!commandName)
|
|
178
|
-
commandName =
|
|
179
|
-
message.content
|
|
180
|
-
.replace(prefix, '')
|
|
181
|
-
.split(command.separator || / +/)
|
|
182
|
-
.shift()
|
|
183
|
-
?.trim()
|
|
184
|
-
?.toLowerCase() || '';
|
|
185
|
-
if (!this.client.commands.message.has(commandName) && command.aliases?.includes(commandName)) {
|
|
186
|
-
commandAlias = commandName;
|
|
187
|
-
commandName = command.name;
|
|
188
|
-
}
|
|
189
|
-
commandAlias = commandAlias ? commandAlias : commandName;
|
|
190
|
-
commandPrefix = prefix;
|
|
191
|
-
});
|
|
192
|
-
if (!cmd && this.client.modules.options.message.allowMention) {
|
|
193
|
-
if (message.mentions.users.has(this.client.user?.id) || message.mentions.repliedUser?.id === this.client.user?.id) {
|
|
194
|
-
commandName = message.content.replace(`<@${this.client.user?.id}>`, '').trim().split(/ +/).shift()?.toLowerCase() || null;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
if (this.client.commands.message.has(commandName)) cmd = this.client.commands.message.get(commandName);
|
|
198
|
-
if (await inhibitorValidation(message, cmd)) return;
|
|
199
|
-
if (!cmd) return this.client.emit('commandNotFound', message, filetype);
|
|
200
|
-
message.util.parsed = {
|
|
201
|
-
alias: commandAlias,
|
|
202
|
-
prefix: commandPrefix,
|
|
203
|
-
};
|
|
204
|
-
this.client.emit('commandStart', message, filetype);
|
|
205
|
-
this.exec(cmd, message, await messageArguments(message, cmd), filetype);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
async slashCommandRun(interaction) {
|
|
209
|
-
const filetype = 'SlashCommand';
|
|
210
|
-
interaction.util = new InteractionUtil(this.client, interaction);
|
|
211
|
-
interaction.user = await xernerxUser(interaction, this.client);
|
|
212
|
-
let cmd = null;
|
|
213
|
-
if (this.client.commands.slash.has(interaction.commandName)) cmd = this.client.commands.slash.get(interaction.commandName);
|
|
214
|
-
if (await inhibitorValidation(interaction, cmd)) return;
|
|
215
|
-
if (!cmd) return this.client.emit('commandNotFound', interaction);
|
|
216
|
-
new Promise(async (resolve) => {
|
|
217
|
-
if (interaction.isAutocomplete()) {
|
|
218
|
-
const focused = interaction.options.getFocused(true);
|
|
219
|
-
const options = interaction.options;
|
|
220
|
-
await cmd.autocomplete(interaction, focused, options);
|
|
221
|
-
} else resolve(true);
|
|
222
|
-
})
|
|
223
|
-
.then(async () => {
|
|
224
|
-
this.client.emit('commandStart', interaction, filetype);
|
|
225
|
-
await this.exec(cmd, interaction, await interactionArguments(interaction, cmd), filetype);
|
|
226
|
-
})
|
|
227
|
-
.catch((error) => this.client.emit('commandError', interaction, error, filetype));
|
|
228
|
-
}
|
|
229
|
-
async contextCommandRun(interaction) {
|
|
230
|
-
const filetype = 'ContextCommand';
|
|
231
|
-
interaction.util = new InteractionUtil(this.client, interaction);
|
|
232
|
-
interaction.user = await xernerxUser(interaction, this.client);
|
|
233
|
-
let cmd;
|
|
234
|
-
if (this.client.commands.context.has(interaction.commandName)) cmd = this.client.commands.context.get(interaction.commandName);
|
|
235
|
-
if (await inhibitorValidation(interaction, cmd)) return;
|
|
236
|
-
if (!cmd) return this.client.emit('commandNotFound', interaction, filetype);
|
|
237
|
-
this.client.emit('commandStart', interaction, filetype);
|
|
238
|
-
this.exec(cmd, interaction, await interactionArguments(interaction, cmd), filetype);
|
|
239
|
-
}
|
|
240
|
-
async exec(cmd, event, args, type) {
|
|
241
|
-
try {
|
|
242
|
-
if (await commandValidation(event, cmd)) return;
|
|
243
|
-
if (cmd.conditions && (await cmd.conditions(event, args))) return;
|
|
244
|
-
cmd.exec(event, args);
|
|
245
|
-
this.client.emit('commandFinish', event, type);
|
|
246
|
-
} catch (error) {
|
|
247
|
-
new XernerxLog(this.client).error(`An error occurred executing ${cmd.name}`, error);
|
|
248
|
-
this.client.emit('commandError', event, error, type);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
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 ${this.client.events.size} Events.`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import XernerxExtensionBuilder from 'xernerx-extension-builder';
|
|
2
|
-
import XernerxClient from '../client/XernerxClient.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
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
if (extension.main) extension.main(this.client);
|
|
11
|
-
if (extension.defer) {
|
|
12
|
-
this.client.on('ready', (client) => extension.defer(client));
|
|
13
|
-
}
|
|
14
|
-
return extension.name;
|
|
15
|
-
} catch (error) {
|
|
16
|
-
new XernerxLog(this.client).error(`An error occurred while loading ${extension.name}`, error);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
new XernerxLog(this.client).info(`Loaded ${extensions.length} Extensions: ${active.filter((e) => e).join(', ')}`);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/handlers/Handler.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
}
|