xernerx 3.1.3 → 3.2.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/README.md CHANGED
@@ -13,7 +13,7 @@ Xernerx is a class based discord.js framework. \[BETA\]
13
13
  > - Message command handles
14
14
  > - Webhook handler for Top.gg
15
15
 
16
- You can checkout the docs [here](https://github.com/TheDummi/xernerx/blob/master/docs/docs.md)
16
+ You can checkout the docs [here](https://thedummi.github.io/xernerx/home.html)
17
17
 
18
18
  ## Notes
19
19
 
@@ -7,7 +7,6 @@ import { XernerxClient } from "../main.js";
7
7
  * @param {ContextCommandOptions} options - The command options.
8
8
  */
9
9
  export declare class ContextCommand {
10
- #private;
11
10
  id: string;
12
11
  data: ContextMenuCommandBuilder;
13
12
  description?: string;
@@ -1,5 +1,6 @@
1
1
  import { ContextMenuCommandBuilder, } from "discord.js";
2
2
  import { s } from "@sapphire/shapeshift";
3
+ import { XernerxClient } from "../main.js";
3
4
  /**
4
5
  * @description The command builder for context commands.
5
6
  * @param {String} id - The unique ID of the command.
@@ -27,7 +28,7 @@ export class ContextCommand {
27
28
  if (options.name)
28
29
  this.data.setName(options.name);
29
30
  if (options.type)
30
- this.data.setType(this.#types(options.type));
31
+ this.data.setType(options.type);
31
32
  if (options.defaultMemberPermissions)
32
33
  this.data.setDefaultMemberPermissions(options.defaultMemberPermissions);
33
34
  if (options.DMPermission)
@@ -66,7 +67,7 @@ export class ContextCommand {
66
67
  this.userPermissions = options.userPermissions;
67
68
  this.clientPermissions = options.clientPermissions;
68
69
  this.defer = options.defer;
69
- this.client = {};
70
+ this.client = XernerxClient;
70
71
  this.conditions = this.conditions;
71
72
  this.exec = this.exec;
72
73
  }
@@ -80,11 +81,4 @@ export class ContextCommand {
80
81
  * @description Make your custom command here.
81
82
  */
82
83
  async exec(interaction) { }
83
- #types(type) {
84
- if (String(type)?.toLowerCase() === "message")
85
- type = 3;
86
- if (String(type)?.toLowerCase() === "user")
87
- type = 2;
88
- return type;
89
- }
90
84
  }
@@ -1,4 +1,5 @@
1
1
  import { s } from "@sapphire/shapeshift";
2
+ import { XernerxClient } from "../main.js";
2
3
  /**
3
4
  * @description - The event builder for any events.
4
5
  * @param {String} id - The unique ID of the event.
@@ -23,7 +24,7 @@ export class Event {
23
24
  this.emitter = options.emitter || "client";
24
25
  this.type = options.type || "discord";
25
26
  this.once = options.once || false;
26
- this.client = {};
27
+ this.client = XernerxClient;
27
28
  this.run = this.run;
28
29
  }
29
30
  async run() {
@@ -1,4 +1,5 @@
1
1
  import { s } from "@sapphire/shapeshift";
2
+ import { XernerxClient } from "../main.js";
2
3
  /**
3
4
  * @description - The inhibitor builder for inhibitors.
4
5
  * @param {String} id - The unique ID of the inhibitor.
@@ -17,7 +18,7 @@ export class Inhibitor {
17
18
  }).parse(options);
18
19
  this.name = options.name;
19
20
  this.type = options.type;
20
- this.client = {};
21
+ this.client = XernerxClient;
21
22
  this.check = this.check;
22
23
  }
23
24
  async check() { }
@@ -1,4 +1,5 @@
1
1
  import { s } from "@sapphire/shapeshift";
2
+ import { XernerxClient } from "../main.js";
2
3
  /**
3
4
  * @description - The command builder for message commands.
4
5
  * @param {String} id - The unique ID of the command.
@@ -62,7 +63,7 @@ export class MessageCommand {
62
63
  this.userPermissions = options.userPermissions || [];
63
64
  this.clientPermissions = options.clientPermissions || [];
64
65
  this.args = options.args;
65
- this.client = {};
66
+ this.client = XernerxClient;
66
67
  this.conditions = this.conditions;
67
68
  this.exec = this.exec;
68
69
  }
@@ -1,5 +1,6 @@
1
1
  import { SlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, } from "discord.js";
2
2
  import { s } from "@sapphire/shapeshift";
3
+ import { XernerxClient } from "../main.js";
3
4
  import XernerxError from "../tools/XernerxError.js";
4
5
  /**
5
6
  * @description - The command builder for slash commands.
@@ -69,7 +70,7 @@ export class SlashCommand {
69
70
  this.userPermissions = options.userPermissions;
70
71
  this.clientPermissions = options.clientPermissions;
71
72
  this.defer = options.defer;
72
- this.client = {};
73
+ this.client = XernerxClient;
73
74
  this.conditions = this.conditions;
74
75
  this.exec = this.exec;
75
76
  }
@@ -1,6 +1,6 @@
1
1
  import { Client, Collection } from "discord.js";
2
2
  import { ClientUtil } from "../utils/ClientUtil.js";
3
- import { DiscordOptions, ClientOptions, Commands, Cache, Modules, HandlerOptions } from "../interfaces/ClientInterfaces.js";
3
+ import { DiscordOptions, ClientOptions, Commands, Cache, Modules, HandlerOptions, ExtensionOptions } from "../interfaces/ClientInterfaces.js";
4
4
  /**
5
5
  * @description - The Client.
6
6
  * @param {DiscordOptions} discordOptions - The options for discord.js.
@@ -15,8 +15,10 @@ export default class XernerxClient extends Client {
15
15
  util: ClientUtil;
16
16
  handlerOptions: HandlerOptions;
17
17
  events: Collection<string, object>;
18
+ extensions: Record<string, object>;
18
19
  inhibitors: Collection<string, object>;
19
20
  config: object;
20
21
  constructor(discordOptions: DiscordOptions, clientOptions: ClientOptions, config?: object);
21
22
  register(token: string): void;
23
+ loadExtensions(options: ExtensionOptions): Promise<void>;
22
24
  }
@@ -6,6 +6,7 @@ import InhibitorHandler from "../handlers/InhibitorHandler.js";
6
6
  import { ClientUtil } from "../utils/ClientUtil.js";
7
7
  import { Style } from "dumfunctions";
8
8
  import WebhookHandler from "../handlers/WebhookHandler.js";
9
+ import Extensions from "../models/Extensions.js";
9
10
  /**
10
11
  * @description - The Client.
11
12
  * @param {DiscordOptions} discordOptions - The options for discord.js.
@@ -20,6 +21,7 @@ export default class XernerxClient extends Client {
20
21
  util;
21
22
  handlerOptions;
22
23
  events;
24
+ extensions;
23
25
  inhibitors;
24
26
  config;
25
27
  constructor(discordOptions, clientOptions, config) {
@@ -59,6 +61,7 @@ export default class XernerxClient extends Client {
59
61
  inhibitorHandler: new InhibitorHandler(this),
60
62
  webhookHandler: new WebhookHandler(this),
61
63
  };
64
+ this.extensions = {};
62
65
  this.util = new ClientUtil(this);
63
66
  this.handlerOptions = {};
64
67
  if (this.settings.logging) {
@@ -67,8 +70,13 @@ export default class XernerxClient extends Client {
67
70
  console.info(Style.log(`Xernerx | ${client.user.tag} signed in watching ${size} server${size > 1 ? "s" : ""}. ${(this.handlerOptions.slash || this.handlerOptions.context)?.guildId ? `Using ${(await this.guilds.fetch((this.handlerOptions.slash || this.handlerOptions.context)?.guildId || "0")).name} as local guild.` : ""}`, { color: Style.TextColor.Purple }));
68
71
  });
69
72
  }
73
+ this.register = this.register;
70
74
  }
71
75
  register(token) {
72
76
  this.login(token);
73
77
  }
78
+ loadExtensions(options) {
79
+ const extensions = new Extensions(this);
80
+ return extensions.load(options.extensions, options.logging || false);
81
+ }
74
82
  }
@@ -58,3 +58,7 @@ export interface Modules {
58
58
  inhibitorHandler: InhibitorHandler;
59
59
  webhookHandler: WebhookHandler;
60
60
  }
61
+ export interface ExtensionOptions {
62
+ extensions: Array<any>;
63
+ logging?: boolean;
64
+ }
@@ -1,4 +1,5 @@
1
1
  import { ChannelType, ContextMenuCommandType } from "discord.js";
2
+ import { ContextCommandType } from "../types/Types.js";
2
3
  export interface MessageCommandOptions {
3
4
  name: string;
4
5
  regex?: string;
@@ -21,13 +22,12 @@ export interface MessageCommandOptions {
21
22
  }
22
23
  export interface ContextCommandOptions {
23
24
  name: string;
24
- type: ContextMenuCommandType | number;
25
+ type: ContextMenuCommandType | number | ContextCommandType;
25
26
  description?: string;
26
27
  info?: string;
27
28
  category?: string;
28
29
  owner?: boolean;
29
30
  channelType?: ChannelType;
30
- separator?: string;
31
31
  cooldown?: number;
32
32
  ignoreOwner?: boolean;
33
33
  channels?: string[];
package/dist/main.d.ts CHANGED
@@ -6,7 +6,7 @@ import { Inhibitor } from "./build/Inhibitor.js";
6
6
  import { MessageCommand } from "./build/MessageCommand.js";
7
7
  import { ContextCommand } from "./build/ContextCommand.js";
8
8
  import { SlashCommand } from "./build/SlashCommand.js";
9
- import { CommandType, EventEmitterType } from "./types/Types.js";
9
+ import { CommandType, EventEmitterType, ContextCommandType } from "./types/Types.js";
10
10
  import { InhibitorType } from "./types/InhibitorTypes.js";
11
11
  declare const version: string;
12
12
  declare const _default: {
@@ -81,6 +81,7 @@ declare const _default: {
81
81
  CommandType: typeof CommandType;
82
82
  EventEmitterType: typeof EventEmitterType;
83
83
  InhibitorType: typeof InhibitorType;
84
+ ContextCommandType: typeof ContextCommandType;
84
85
  Event: typeof Event;
85
86
  MessageCommand: typeof MessageCommand;
86
87
  ContextCommand: typeof ContextCommand;
@@ -89,4 +90,4 @@ declare const _default: {
89
90
  version: string;
90
91
  };
91
92
  export default _default;
92
- export { Discord, DumFunctions, XernerxClient, CommandType, EventEmitterType, InhibitorType, Event, MessageCommand, ContextCommand, SlashCommand, Inhibitor, version, };
93
+ export { Discord, DumFunctions, XernerxClient, CommandType, EventEmitterType, InhibitorType, ContextCommandType, Event, MessageCommand, ContextCommand, SlashCommand, Inhibitor, version, };
package/dist/main.js CHANGED
@@ -6,9 +6,9 @@ import { Inhibitor } from "./build/Inhibitor.js";
6
6
  import { MessageCommand } from "./build/MessageCommand.js";
7
7
  import { ContextCommand } from "./build/ContextCommand.js";
8
8
  import { SlashCommand } from "./build/SlashCommand.js";
9
- import { CommandType, EventEmitterType } from "./types/Types.js";
9
+ import { CommandType, EventEmitterType, ContextCommandType } from "./types/Types.js";
10
10
  import { InhibitorType } from "./types/InhibitorTypes.js";
11
- const version = "3.1.1";
11
+ const version = "3.1.4";
12
12
  export default {
13
13
  // Imported methods
14
14
  Discord,
@@ -20,6 +20,7 @@ export default {
20
20
  CommandType,
21
21
  EventEmitterType,
22
22
  InhibitorType,
23
+ ContextCommandType,
23
24
  // Builds
24
25
  Event,
25
26
  MessageCommand,
@@ -35,7 +36,7 @@ Discord, DumFunctions,
35
36
  // Client
36
37
  XernerxClient,
37
38
  // Types
38
- CommandType, EventEmitterType, InhibitorType,
39
+ CommandType, EventEmitterType, InhibitorType, ContextCommandType,
39
40
  // Builds
40
41
  Event, MessageCommand, ContextCommand, SlashCommand, Inhibitor,
41
42
  // Constants
@@ -15,25 +15,25 @@ export default function commandValidation(action, command, client, res = false)
15
15
  return true;
16
16
  else if (command.owner && !client.util.isOwner(user.id)) {
17
17
  res = true;
18
- emit(client, action, "Not an owner", client.settings.ownerId);
18
+ emit(client, action, command, "Not an owner", client.settings.ownerId);
19
19
  }
20
20
  else if (command.channelType?.length > 0 || command.channelType) {
21
21
  if (!Array.isArray(command.channelType))
22
22
  command.channelType = [command.channelType];
23
23
  if (!command?.channelType?.includes(action.channel?.type)) {
24
24
  res = true;
25
- emit(client, action, "Not the correct channel", command.channelType);
25
+ emit(client, action, command, "Not the correct channel", command.channelType);
26
26
  }
27
27
  }
28
28
  else if (command.channels?.length > 0 &&
29
29
  !command.channels.includes(action.channel?.id)) {
30
30
  res = true;
31
- emit(client, action, "Not a whitelisted channel", command.channels);
31
+ emit(client, action, command, "Not a whitelisted channel", command.channels);
32
32
  }
33
33
  else if (command.guilds?.length > 0 &&
34
34
  !command.guilds.includes(action.guild?.id)) {
35
35
  res = true;
36
- emit(client, action, "Not a whitelisted guild", command.guilds);
36
+ emit(client, action, command, "Not a whitelisted guild", command.guilds);
37
37
  }
38
38
  else if (action?.guild &&
39
39
  (command.userPermissions || client.settings.userPermissions)) {
@@ -47,7 +47,7 @@ export default function commandValidation(action, command, client, res = false)
47
47
  });
48
48
  if (missing.length > 0) {
49
49
  res = true;
50
- emit(client, action, "Missing User Permissions", missing);
50
+ emit(client, action, command, "Missing User Permissions", missing);
51
51
  }
52
52
  }
53
53
  else if (action?.guild &&
@@ -62,13 +62,13 @@ export default function commandValidation(action, command, client, res = false)
62
62
  });
63
63
  if (missing.length > 0) {
64
64
  res = true;
65
- emit(client, action, "Missing Client Permissions", missing);
65
+ emit(client, action, command, "Missing Client Permissions", missing);
66
66
  }
67
67
  }
68
68
  return res;
69
69
  }
70
- function emit(client, action, reason, extra) {
71
- return client.emit("commandBlock", action, reason, extra);
70
+ function emit(client, action, command, reason, extra) {
71
+ return client.emit("commandBlock", action, command, reason, extra);
72
72
  }
73
73
  function inCooldown(user, client, command, action) {
74
74
  let res = false, downs = {};
@@ -77,7 +77,7 @@ export class MessageCommandEvents {
77
77
  this.client.emit("commandRun", message, cmd);
78
78
  }
79
79
  catch (error) {
80
- return this.client.emit("commandError", message, error);
80
+ return this.client.emit("commandError", message, error, cmd);
81
81
  }
82
82
  }
83
83
  });
@@ -154,7 +154,7 @@ export class MessageCommandEvents {
154
154
  this.client.emit("commandRun", message, cmd);
155
155
  }
156
156
  catch (error) {
157
- return this.client.emit("commandError", message, error);
157
+ return this.client.emit("commandError", message, error, cmd);
158
158
  }
159
159
  }
160
160
  });
@@ -223,7 +223,7 @@ export class SlashCommandEvents {
223
223
  this.client.emit("commandRun", interaction, command);
224
224
  }
225
225
  catch (error) {
226
- this.client.emit("commandError", interaction, error);
226
+ this.client.emit("commandError", interaction, error, command);
227
227
  }
228
228
  }
229
229
  }
@@ -268,7 +268,7 @@ export class ContextCommandEvents {
268
268
  this.client.emit("commandRun", interaction, command);
269
269
  }
270
270
  catch (error) {
271
- this.client.emit("commandError", interaction, error);
271
+ this.client.emit("commandError", interaction, error, command);
272
272
  }
273
273
  }
274
274
  }
@@ -0,0 +1,6 @@
1
+ import { XernerxClient } from "../main.js";
2
+ export default class Extensions {
3
+ client: XernerxClient;
4
+ constructor(client: XernerxClient);
5
+ load(extensions: Array<any>, logging?: boolean): Promise<void>;
6
+ }
@@ -0,0 +1,16 @@
1
+ import { Style } from "dumfunctions";
2
+ export default class Extensions {
3
+ client;
4
+ constructor(client) {
5
+ this.client = client;
6
+ }
7
+ async load(extensions, logging = false) {
8
+ const exts = [];
9
+ extensions.map(extension => {
10
+ this.client.extensions[extension.name] = new extension(this.client, logging);
11
+ exts.push(extension.name);
12
+ });
13
+ if (logging)
14
+ console.info(Style.log(`Xernerx | Loaded ${exts.length} extensions: ${exts.join(', ')}`, { color: Style.TextColor.Cyan }));
15
+ }
16
+ }
@@ -1 +1 @@
1
- export declare function logStyle(text: string, type: string, color: string): string | undefined;
1
+ export {};
@@ -1,30 +1 @@
1
- export function logStyle(text, type, color) {
2
- if (type.toLowerCase() == "text") {
3
- if (color.toLowerCase() == "red")
4
- return `\u001b[0;31m${text}\u001b[0;0m`;
5
- if (color.toLowerCase() == "green")
6
- return `\u001b[0;32m${text}\u001b[0;0m`;
7
- if (color.toLowerCase() == "yellow")
8
- return `\u001b[0;33m${text}\u001b[0;0m`;
9
- if (color.toLowerCase() == "blue")
10
- return `\u001b[0;34m${text}\u001b[0;0m`;
11
- if (color.toLowerCase() == "purple")
12
- return `\u001b[0;35m${text}\u001b[0;0m`;
13
- if (color.toLowerCase() == "cyan")
14
- return `\u001b[0;36m${text}\u001b[0;0m`;
15
- }
16
- if (type.toLowerCase() == `background`) {
17
- if (color.toLowerCase() == "red")
18
- return `\u001b[0;41m${text}\u001b[0;0m`;
19
- if (color.toLowerCase() == "green")
20
- return `\u001b[0;42m${text}\u001b[0;0m`;
21
- if (color.toLowerCase() == "yellow")
22
- return `\u001b[0;43m${text}\u001b[0;0m`;
23
- if (color.toLowerCase() == "blue")
24
- return `\u001b[0;44m${text}\u001b[0;0m`;
25
- if (color.toLowerCase() == "purple")
26
- return `\u001b[0;45m${text}\u001b[0;0m`;
27
- if (color.toLowerCase() == "cyan")
28
- return `\u001b[0;46m${text}\u001b[0;0m`;
29
- }
30
- }
1
+ export {};
@@ -9,6 +9,10 @@ export declare enum CommandType {
9
9
  SlashCommand = "SlashCommand",
10
10
  ContextCommand = "ContextCommand"
11
11
  }
12
+ export declare enum ContextCommandType {
13
+ Message = 3,
14
+ User = 2
15
+ }
12
16
  export declare enum EventEmitterType {
13
17
  Client = "client",
14
18
  Rest = "rest",
@@ -9,6 +9,11 @@ export var CommandType;
9
9
  CommandType["SlashCommand"] = "SlashCommand";
10
10
  CommandType["ContextCommand"] = "ContextCommand";
11
11
  })(CommandType = CommandType || (CommandType = {}));
12
+ export var ContextCommandType;
13
+ (function (ContextCommandType) {
14
+ ContextCommandType[ContextCommandType["Message"] = 3] = "Message";
15
+ ContextCommandType[ContextCommandType["User"] = 2] = "User";
16
+ })(ContextCommandType = ContextCommandType || (ContextCommandType = {}));
12
17
  export var EventEmitterType;
13
18
  (function (EventEmitterType) {
14
19
  EventEmitterType["Client"] = "client";
@@ -3,6 +3,17 @@ export class ClientUtil {
3
3
  client;
4
4
  constructor(client) {
5
5
  this.client = client;
6
+ this.uptime = this.uptime;
7
+ this.getSubcommands = this.getSubcommands;
8
+ this.isOwner = this.isOwner;
9
+ this.getAllCommands = this.getAllCommands;
10
+ this.getAllMessageCommands = this.getAllMessageCommands;
11
+ this.getAllSlashCommands = this.getAllSlashCommands;
12
+ this.getAllContextCommands = this.getAllContextCommands;
13
+ this.setPresence = this.setPresence;
14
+ this.getCooldowns = this.getCooldowns;
15
+ this.getCooldownTimers = this.getCooldownTimers;
16
+ this.defer = this.defer;
6
17
  }
7
18
  uptime(timestamp) {
8
19
  if (!timestamp)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "xernerx",
4
- "version": "3.1.3",
4
+ "version": "3.2.0",
5
5
  "description": "A bot framework for discord.js. [BETA]",
6
6
  "main": "dist/main.js",
7
7
  "scripts": {