xernerx 4.17.9 → 5.0.2

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.
Files changed (78) hide show
  1. package/README.md +14 -67
  2. package/dist/main.cjs +63 -0
  3. package/dist/main.cjs.map +1 -0
  4. package/dist/main.d.cts +21 -0
  5. package/dist/main.d.ts +18 -37
  6. package/dist/main.js +23 -42
  7. package/dist/main.js.map +1 -0
  8. package/package.json +63 -48
  9. package/src/main.ts +26 -0
  10. package/dist/build/XernerxContextCommand.d.ts +0 -54
  11. package/dist/build/XernerxContextCommand.js +0 -121
  12. package/dist/build/XernerxEvent.d.ts +0 -21
  13. package/dist/build/XernerxEvent.js +0 -27
  14. package/dist/build/XernerxInhibitor.d.ts +0 -29
  15. package/dist/build/XernerxInhibitor.js +0 -27
  16. package/dist/build/XernerxMessageCommand.d.ts +0 -58
  17. package/dist/build/XernerxMessageCommand.js +0 -119
  18. package/dist/build/XernerxSlashCommand.d.ts +0 -70
  19. package/dist/build/XernerxSlashCommand.js +0 -178
  20. package/dist/client/XernerxClient.d.ts +0 -64
  21. package/dist/client/XernerxClient.js +0 -109
  22. package/dist/client/XernerxShardClient.d.ts +0 -21
  23. package/dist/client/XernerxShardClient.js +0 -54
  24. package/dist/functions/deploy.d.ts +0 -3
  25. package/dist/functions/deploy.js +0 -63
  26. package/dist/functions/load.d.ts +0 -4
  27. package/dist/functions/load.js +0 -35
  28. package/dist/functions/reload.d.ts +0 -3
  29. package/dist/functions/reload.js +0 -30
  30. package/dist/functions/setPresence.d.ts +0 -4
  31. package/dist/functions/setPresence.js +0 -21
  32. package/dist/handlers/CommandHandler.d.ts +0 -16
  33. package/dist/handlers/CommandHandler.js +0 -351
  34. package/dist/handlers/EventHandler.d.ts +0 -11
  35. package/dist/handlers/EventHandler.js +0 -84
  36. package/dist/handlers/ExtensionHandler.d.ts +0 -9
  37. package/dist/handlers/ExtensionHandler.js +0 -29
  38. package/dist/handlers/Handler.d.ts +0 -26
  39. package/dist/handlers/Handler.js +0 -64
  40. package/dist/handlers/InhibitorHandler.d.ts +0 -9
  41. package/dist/handlers/InhibitorHandler.js +0 -31
  42. package/dist/handlers/IntegrationHandler.d.ts +0 -15
  43. package/dist/handlers/IntegrationHandler.js +0 -26
  44. package/dist/models/Arguments.d.ts +0 -9
  45. package/dist/models/Arguments.js +0 -154
  46. package/dist/models/Cooldowns.d.ts +0 -11
  47. package/dist/models/Cooldowns.js +0 -33
  48. package/dist/models/XernerxEntitlement.d.ts +0 -45
  49. package/dist/models/XernerxEntitlement.js +0 -57
  50. package/dist/models/XernerxUser.d.ts +0 -14
  51. package/dist/models/XernerxUser.js +0 -13
  52. package/dist/tools/XernerxError.d.ts +0 -7
  53. package/dist/tools/XernerxError.js +0 -11
  54. package/dist/tools/XernerxIntents.d.ts +0 -6
  55. package/dist/tools/XernerxIntents.js +0 -26
  56. package/dist/tools/XernerxLog.d.ts +0 -31
  57. package/dist/tools/XernerxLog.js +0 -139
  58. package/dist/tools/XernerxText.d.ts +0 -31
  59. package/dist/tools/XernerxText.js +0 -94
  60. package/dist/types/extenders.d.ts +0 -76
  61. package/dist/types/extenders.js +0 -2
  62. package/dist/types/interfaces.d.ts +0 -258
  63. package/dist/types/interfaces.js +0 -2
  64. package/dist/types/types.d.ts +0 -12
  65. package/dist/types/types.js +0 -2
  66. package/dist/utils/ClientUtil.d.ts +0 -20
  67. package/dist/utils/ClientUtil.js +0 -123
  68. package/dist/utils/InteractionUtil.d.ts +0 -25
  69. package/dist/utils/InteractionUtil.js +0 -153
  70. package/dist/utils/MessageUtil.d.ts +0 -26
  71. package/dist/utils/MessageUtil.js +0 -167
  72. package/dist/utils/Util.d.ts +0 -12
  73. package/dist/utils/Util.js +0 -11
  74. package/dist/validators/commandValidation.d.ts +0 -7
  75. package/dist/validators/commandValidation.js +0 -124
  76. package/dist/validators/inhibitorValidations.d.ts +0 -9
  77. package/dist/validators/inhibitorValidations.js +0 -44
  78. package/tsup.config.ts +0 -19
@@ -1,109 +0,0 @@
1
- /** @format */
2
- import { Client, Collection } from 'discord.js';
3
- import { z } from 'zod';
4
- import * as clack from '@clack/prompts';
5
- import CommandHandler from '../handlers/CommandHandler.js';
6
- import EventHandler from '../handlers/EventHandler.js';
7
- import InhibitorHandler from '../handlers/InhibitorHandler.js';
8
- import IntegrationHandler from '../handlers/IntegrationHandler.js';
9
- import XernerxLog from '../tools/XernerxLog.js';
10
- import ClientUtil from '../utils/ClientUtil.js';
11
- import ExtensionHandler from '../handlers/ExtensionHandler.js';
12
- import deploy from '../functions/deploy.js';
13
- import Cooldowns from '../models/Cooldowns.js';
14
- export default class XernerxClient extends Client {
15
- constructor(discordOptions, xernerxOptions, config) {
16
- super(discordOptions);
17
- clack.intro('Xernerx');
18
- this.settings = z
19
- .object({
20
- local: z.string(),
21
- global: z.boolean().default(false).optional(),
22
- debug: z.boolean().default(false).optional(),
23
- ownerId: z.string().or(z.array(z.string())).default([]),
24
- ceaseless: z.boolean().default(false),
25
- permissions: z
26
- .object({
27
- client: z.array(z.string()).or(z.null()).default(null),
28
- user: z.array(z.string()).or(z.null()).default(null),
29
- dm: z.boolean().default(false),
30
- })
31
- .optional(),
32
- ignore: z
33
- .object({
34
- owner: z.boolean().default(false),
35
- self: z.boolean().default(true),
36
- bots: z.boolean().default(true),
37
- system: z.boolean().default(true),
38
- users: z.array(z.string()).default([]),
39
- channels: z.array(z.string()).default([]),
40
- guilds: z.array(z.string()).default([]),
41
- })
42
- .optional(),
43
- log: z
44
- .object({
45
- ready: z.boolean().default(false),
46
- info: z.boolean().default(false),
47
- warn: z.boolean().default(false),
48
- error: z.boolean().default(false),
49
- table: z.array(z.string()).or(z.null()).default(null),
50
- format: z.array(z.string()).or(z.null()).default(null),
51
- })
52
- .or(z.boolean())
53
- .optional(),
54
- cooldown: z
55
- .object({
56
- command: z.number().default(0),
57
- cache: z.number().default(0),
58
- collections: z.array(z.string()).default(['commands']),
59
- })
60
- .optional(),
61
- })
62
- .parse(xernerxOptions);
63
- this.config = config;
64
- this.commands = {
65
- message: new Collection(),
66
- slash: new Collection(),
67
- context: new Collection(),
68
- };
69
- this.events = new Collection();
70
- this.inhibitors = new Collection();
71
- this.util = new ClientUtil(this);
72
- this.stats = {
73
- guildCount: this.guilds.cache.size,
74
- userCount: 0,
75
- shardId: 0,
76
- shardCount: this.options.shardCount || 1,
77
- voteCount: 0,
78
- };
79
- this.dbl = {};
80
- this.cache = {
81
- messages: new Collection(),
82
- cooldowns: new Collection(),
83
- };
84
- this.cooldowns = new Cooldowns(this, xernerxOptions.cooldown?.collections);
85
- this.modules = {
86
- options: {},
87
- commandHandler: new CommandHandler(this),
88
- eventHandler: new EventHandler(this),
89
- inhibitorHandler: new InhibitorHandler(this),
90
- integrationHandler: new IntegrationHandler(this),
91
- extensionHandler: new ExtensionHandler(this),
92
- };
93
- this.store = {};
94
- }
95
- async connect(token) {
96
- if (this.settings.debug)
97
- new XernerxLog(this).debug(`Connecting to discord using token ${token}...`);
98
- const login = await this.login(token).catch(() => {
99
- new XernerxLog(this).error('An invalid token was provided. Please make sure to provide a valid Discord bot token.');
100
- });
101
- if (this.settings.debug)
102
- new XernerxLog(this).debug(`Connected to discord using token ${token}`);
103
- deploy(this);
104
- new XernerxLog(this).ready();
105
- const spinner = clack.spinner();
106
- spinner.start();
107
- return login;
108
- }
109
- }
@@ -1,21 +0,0 @@
1
- /** @format */
2
- import { ShardingManager, ShardingManagerOptions, ClientUser } from 'discord.js';
3
- interface XernerxOptions {
4
- log?: {
5
- info?: boolean;
6
- };
7
- timeout?: number;
8
- }
9
- export default class XernerxShardClient extends ShardingManager {
10
- readonly stats: {
11
- guildCount: number;
12
- userCount: number;
13
- shardCount: number;
14
- voteCount: number;
15
- shards: {};
16
- };
17
- user: ClientUser | null;
18
- spawner: Promise<import("discord.js").Collection<number, import("discord.js").Shard>>;
19
- constructor(file: string, discordOptions: ShardingManagerOptions, xernerxOptions?: XernerxOptions, data?: unknown);
20
- }
21
- export {};
@@ -1,54 +0,0 @@
1
- /** @format */
2
- import { ShardingManager } from 'discord.js';
3
- import { Style } from 'dumfunctions';
4
- import XernerxLog from '../tools/XernerxLog.js';
5
- export default class XernerxShardClient extends ShardingManager {
6
- constructor(file, discordOptions, xernerxOptions, data = {}) {
7
- super(file, discordOptions);
8
- this.stats = { guildCount: 0, userCount: 0, shardCount: 0, voteCount: 0, shards: {} };
9
- this.user = null;
10
- new XernerxLog(true).info('Starting sharding process...');
11
- this.on('shardCreate', async (shard) => {
12
- shard
13
- .on('ready', async () => {
14
- await new Promise((resolve) => setTimeout(resolve, 250));
15
- const stats = (await shard.fetchClientValue('stats'));
16
- this.stats.shards[String(shard.id)] = stats;
17
- this.user = (await shard.fetchClientValue('user'));
18
- this.stats.guildCount += stats.guildCount;
19
- this.stats.userCount += stats.userCount;
20
- this.stats.shardCount++;
21
- this.stats.voteCount = stats.voteCount;
22
- shard.send({ type: 'xernerx', data: { shardId: shard.id, sharded: true } });
23
- shard.send({ type: 'client', data });
24
- new XernerxLog({ settings: xernerxOptions }).info(`Launched shard ${Style.log(String(shard.id), { color: Style.TextColor.Cyan })} for ${Style.log(this.user?.tag, { color: Style.TextColor.Blue })}! ${xernerxOptions?.timeout ? `Automatically killing in ${Style.log(String(xernerxOptions.timeout), { color: Style.TextColor.Cyan })}ms.` : ''}`);
25
- })
26
- .on('error', (error) => {
27
- new XernerxLog({ settings: xernerxOptions }).info(`An error occurred in ${Style.log(String(shard.id), { color: Style.TextColor.Cyan })} for ${Style.log(String(this.user?.tag), { color: Style.TextColor.Blue })}! ${error}`);
28
- });
29
- if (xernerxOptions?.timeout)
30
- setTimeout(() => {
31
- new XernerxLog({ settings: xernerxOptions }).warn(`Automatically killing shard ${Style.log(String(shard.id), { color: Style.TextColor.Cyan })} on ${Style.log(String(shard.manager.user?.tag), {
32
- color: Style.TextColor.Blue,
33
- })}!`);
34
- shard.kill();
35
- }, xernerxOptions.timeout);
36
- });
37
- const spawn = this.spawn();
38
- this.spawner = spawn;
39
- spawn.then(async (shards) => {
40
- const collector = setInterval(() => {
41
- const index = shards.size - 1;
42
- if (shards.get(index)?.ready) {
43
- clearInterval(collector);
44
- new XernerxLog({ settings: xernerxOptions }).info(`All Shards launched for ${Style.log(String(this.user?.tag), {
45
- color: Style.TextColor.Blue,
46
- })} with a total of ${Style.log(String(this.stats.shardCount), { color: Style.TextColor.Cyan })} shard${this.stats.shardCount > 1 ? 's' : ''}, watching ${Style.log(String(this.stats.guildCount), {
47
- color: Style.TextColor.Cyan,
48
- })} guild${this.stats.guildCount > 1 ? 's' : ''}, and ${Style.log(String(this.stats.userCount), { color: Style.TextColor.Cyan })} user${this.stats.userCount > 1 ? 's' : ''}!`);
49
- }
50
- }, 1000);
51
- });
52
- return this;
53
- }
54
- }
@@ -1,3 +0,0 @@
1
- /** @format */
2
- import XernerxClient from '../client/XernerxClient.js';
3
- export default function deploy(client: XernerxClient): void;
@@ -1,63 +0,0 @@
1
- /** @format */
2
- import { GatewayVersion, REST, Routes } from 'discord.js';
3
- import { Style } from 'dumfunctions';
4
- import XernerxLog from '../tools/XernerxLog.js';
5
- import XernerxError from '../tools/XernerxError.js';
6
- const globalCommands = [];
7
- const localCommands = [];
8
- export default function deploy(client) {
9
- const commands = [];
10
- function stats() {
11
- client.stats.guildCount = client.guilds.cache.size;
12
- client.stats.userCount = client.guilds.cache.map((g) => g.memberCount || g.approximateMemberCount || 0).reduce((a, b) => (a += b), 0);
13
- }
14
- process.on('message', (message) => {
15
- if (message.type == 'xernerx')
16
- client.stats.shardId = message?.data?.shardId;
17
- if (message.type == 'client')
18
- client.data = message.data;
19
- });
20
- client.on('messageCreate', stats);
21
- client.on('interactionCreate', stats);
22
- client.once('ready', (client) => {
23
- stats();
24
- client.commands.slash.map((command) => commands.push(command));
25
- client.commands.context.map((command) => commands.push(command));
26
- client.commands.message.map((command) => commands.push(command));
27
- if (client.commands.slash.size)
28
- client.commands.slash.map((command) => (command.global ? globalCommands.push(command.data.toJSON()) : localCommands.push(command.data.toJSON())));
29
- if (client.commands.context.size)
30
- client.commands.context.map((command) => (command.global ? globalCommands.push(command.data.toJSON()) : localCommands.push(command.data.toJSON())));
31
- if (!globalCommands.length && !localCommands.length && !client.commands.message.size)
32
- return;
33
- try {
34
- if (client.settings.global) {
35
- put(client, client.settings.global, globalCommands);
36
- put(client, !client.settings.global, localCommands);
37
- }
38
- else {
39
- put(client, !client.settings.global, [...globalCommands, ...localCommands]);
40
- put(client, client.settings.global, []);
41
- }
42
- }
43
- catch (error) {
44
- new XernerxLog(client).error(`An error occurred while deploying the commands!`, error);
45
- }
46
- finally {
47
- new XernerxLog(client).info(`Deployed ${Style.log(String(commands.filter((command) => command.global).length), {
48
- color: Style.TextColor.Cyan,
49
- })} Commands ${client.settings.global
50
- ? Style.log('globally', { color: Style.TextColor.Green })
51
- : `${Style.log('locally', { color: Style.TextColor.Red })} in ${Style.log(client.guilds.cache.get(client.settings.local)?.name, { color: Style.TextColor.Blue })}`}.`);
52
- }
53
- });
54
- }
55
- function put(client, global, body) {
56
- const rest = new REST({ version: GatewayVersion }).setToken(client.token);
57
- if (!global && !client.settings?.local)
58
- throw new XernerxError(`No guild ID provided as local guild!`);
59
- if (!global && client.settings?.local)
60
- return rest.put(Routes.applicationGuildCommands(client.user?.id, client.settings.local), { body });
61
- else
62
- return rest.put(Routes.applicationCommands(client.user?.id), { body });
63
- }
@@ -1,4 +0,0 @@
1
- /** @format */
2
- import XernerxClient from '../client/XernerxClient.js';
3
- import { filetype } from '../types/types.js';
4
- export default function load(client: XernerxClient, path: string, type: filetype): Promise<any>;
@@ -1,35 +0,0 @@
1
- /** @format */
2
- import XernerxLog from '../tools/XernerxLog.js';
3
- export default async function load(client, path, type) {
4
- try {
5
- let file = new (await import(`file://${path}`)).default();
6
- file.filetype = type;
7
- file.filepath = path;
8
- file.client = client;
9
- file.util = {};
10
- fileSave(client, file, type);
11
- return file;
12
- }
13
- catch (error) {
14
- new XernerxLog(client).error(`Couldn't load ${type} ${path.match(/\w*\.js$/gim)?.at(0) || path}`, error);
15
- }
16
- }
17
- function fileSave(client, file, type) {
18
- switch (type) {
19
- case 'MessageCommand':
20
- client.commands.message.set(file.name, file);
21
- break;
22
- case 'SlashCommand':
23
- client.commands.slash.set(file.name, file);
24
- break;
25
- case 'ContextCommand':
26
- client.commands.context.set(file.name, file);
27
- break;
28
- case 'Inhibitor':
29
- client.inhibitors.set(file.name, file);
30
- break;
31
- case 'Event':
32
- client.events.set(file.name, file);
33
- break;
34
- }
35
- }
@@ -1,3 +0,0 @@
1
- /** @format */
2
- import XernerxClient from '../client/XernerxClient.js';
3
- export default function reload(client: XernerxClient, type: 'commands' | 'context' | 'message' | 'slash' | 'events' | 'inhibitors'): Promise<true | void | null>;
@@ -1,30 +0,0 @@
1
- /** @format */
2
- import * as path from 'path';
3
- import * as fs from 'fs';
4
- import load from './load.js';
5
- export default async function reload(client, type) {
6
- switch (type) {
7
- case 'message': {
8
- client.commands.message.clear();
9
- if (!client.modules.options.message)
10
- return null;
11
- const directory = path.resolve(client.modules.options.message?.directory);
12
- for (const file of fs.readdirSync(directory)) {
13
- load(client, `${directory}\\${file}`, 'MessageCommand');
14
- }
15
- return true;
16
- }
17
- case 'slash': {
18
- return client.commands.slash.clear();
19
- }
20
- case 'context': {
21
- return client.commands.context.clear();
22
- }
23
- case 'events': {
24
- return client.events.clear();
25
- }
26
- case 'inhibitors': {
27
- return client.inhibitors.clear();
28
- }
29
- }
30
- }
@@ -1,4 +0,0 @@
1
- /** @format */
2
- import XernerxClient from '../client/XernerxClient.js';
3
- import { PresenceOptions } from '../types/interfaces.js';
4
- export default function setPresence(client: XernerxClient, options: PresenceOptions): import("discord.js").ClientPresence | undefined;
@@ -1,21 +0,0 @@
1
- /** @format */
2
- import { ActivityType } from 'discord.js';
3
- import { Style } from 'dumfunctions';
4
- export default function setPresence(client, options) {
5
- const presence = () => client.user?.setPresence({
6
- activities: [
7
- {
8
- name: options.text,
9
- type: ActivityType[Style.titleCase(options.type || 'Custom')],
10
- url: options.url,
11
- },
12
- ],
13
- status: options.status,
14
- });
15
- let response = presence();
16
- if (options.interval)
17
- setInterval(() => {
18
- response = presence();
19
- }, options.interval);
20
- return response;
21
- }
@@ -1,16 +0,0 @@
1
- /** @format */
2
- import XernerxClient from '../client/XernerxClient.js';
3
- import { ContextHandlerOptions, MessageHandlerOptions, SlashHandlerOptions } from '../types/interfaces.js';
4
- import Handler from './Handler.js';
5
- export default class CommandHandler extends Handler {
6
- readonly readyTimestamp: number;
7
- constructor(client: XernerxClient);
8
- loadMessageCommands(options: MessageHandlerOptions): Promise<void>;
9
- loadSlashCommands(options: SlashHandlerOptions): Promise<void>;
10
- loadContextCommands(options: ContextHandlerOptions): Promise<void>;
11
- private messageCommandRun;
12
- private slashCommandRun;
13
- private contextCommandRun;
14
- private exec;
15
- private _checks;
16
- }