xernerx 4.17.5 → 4.17.7

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.
@@ -78,5 +78,5 @@ export default class XernerxContextCommand {
78
78
  * @param interaction - Interaction event emitted on command
79
79
  * @param args - The arguments parsed with the command, if any
80
80
  */
81
- exec(interaction: XernerxUserContextInteraction | XernerxMessageContextInteraction, args: ContextCommandArguments<'user' | 'message'>): Promise<any>;
81
+ exec<T = void>(interaction: XernerxUserContextInteraction | XernerxMessageContextInteraction, args: ContextCommandArguments<'user' | 'message'>): Promise<void | any | T>;
82
82
  }
@@ -17,5 +17,5 @@ export default class XernerxEvent<Event extends keyof XernerxClientEvents> {
17
17
  readonly filepath: string;
18
18
  readonly client: XernerxClientType;
19
19
  constructor(id: string, options: XernerxEventOptions);
20
- run(...args: XernerxClientEvents[Event]): Promise<Awaitable<any>>;
20
+ run<T = void>(...args: XernerxClientEvents[Event]): Promise<Awaitable<void | any | T>>;
21
21
  }
@@ -74,11 +74,11 @@ export default class XernerxMessageCommand {
74
74
  * @param message - The message event emitted on this command
75
75
  * @param options - The args and flags parsed on this command
76
76
  */
77
- conditions(message: XernerxMessage, { args, flags }: MessageCommandArguments): Promise<any>;
77
+ conditions<T = void>(message: XernerxMessage, { args, flags }: MessageCommandArguments): Promise<void | any | T>;
78
78
  /**
79
79
  * @description Runs the execution rule
80
80
  * @param message - The message event emitted on this command
81
81
  * @param options - The args and flags parsed on this command
82
82
  */
83
- exec(message: XernerxMessage, { args, flags }: MessageCommandArguments): Promise<any>;
83
+ exec<T = void>(message: XernerxMessage, { args, flags }: MessageCommandArguments): Promise<void | any | T>;
84
84
  }
@@ -1,5 +1,5 @@
1
1
  /** @format */
2
- import Discord from 'discord.js';
2
+ import Discord, { AutocompleteFocusedOption, AutocompleteInteraction } from 'discord.js';
3
3
  import { XernerxClientType, XernerxMessageContextInteraction, XernerxSlashInteraction, XernerxUserContextInteraction } from '../types/extenders.js';
4
4
  import { SlashCommandArguments, SlashCommandOptions } from '../types/interfaces.js';
5
5
  import { XernerxInteraction } from '../types/types.js';
@@ -79,13 +79,13 @@ export default class XernerxSlashCommand {
79
79
  * @param focused - The command option that is in focus
80
80
  * @param options - The full list of options on the command
81
81
  */
82
- autocomplete<T>(interaction: XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>, focused: T, options: T[]): Promise<void | any | T>;
82
+ autocomplete<T = void>(interaction: AutocompleteInteraction, focused: AutocompleteFocusedOption, options: any[]): Promise<void | any | T>;
83
83
  /**
84
84
  * @description Checks for conditions before running the command
85
85
  * @param interaction - The interaction event emitted on this command
86
86
  * @param options - The args, group and subcommand parsed on this command
87
87
  */
88
- conditions<T>(
88
+ conditions<T = void>(
89
89
  interaction: XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>,
90
90
  { args, subcommand, group }: SlashCommandArguments
91
91
  ): Promise<void | any | T>;
@@ -94,7 +94,7 @@ export default class XernerxSlashCommand {
94
94
  * @param interaction - The interaction event emitted on this command
95
95
  * @param options - The args, group and subcommand parsed on this command
96
96
  */
97
- exec<T>(
97
+ exec<T = void>(
98
98
  interaction: XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>,
99
99
  { args, subcommand, group }: SlashCommandArguments
100
100
  ): Promise<void | any | T>;
@@ -6,12 +6,17 @@ import ClientUtil from '../utils/ClientUtil.js';
6
6
  import XernerxInhibitor from '../build/XernerxInhibitor.js';
7
7
  import XernerxEvent from '../build/XernerxEvent.js';
8
8
  import Cooldowns from '../models/Cooldowns.js';
9
- export default class XernerxClient<T = unknown> extends Client {
9
+ export default class XernerxClient<
10
+ T extends object = {
11
+ [index: string | number]: any;
12
+ },
13
+ > extends Client {
10
14
  readonly settings: {
11
15
  ownerId: (string | string[]) & (string | string[] | undefined);
12
16
  local: string;
13
17
  ceaseless: boolean;
14
18
  global?: boolean | undefined;
19
+ debug?: boolean | undefined;
15
20
  permissions?:
16
21
  | {
17
22
  user: string[] | null;
@@ -61,5 +66,5 @@ export default class XernerxClient<T = unknown> extends Client {
61
66
  readonly dbl: any;
62
67
  readonly [index: string]: unknown;
63
68
  constructor(discordOptions: ClientOptions, xernerxOptions: XernerxOptions, config?: T);
64
- connect(token: string): Promise<string>;
69
+ connect(token: string): Promise<string | void>;
65
70
  }
@@ -1,6 +1,7 @@
1
1
  /** @format */
2
2
  import { Client, Collection } from 'discord.js';
3
3
  import { z } from 'zod';
4
+ import * as clack from '@clack/prompts';
4
5
  import CommandHandler from '../handlers/CommandHandler.js';
5
6
  import EventHandler from '../handlers/EventHandler.js';
6
7
  import InhibitorHandler from '../handlers/InhibitorHandler.js';
@@ -13,10 +14,12 @@ import Cooldowns from '../models/Cooldowns.js';
13
14
  export default class XernerxClient extends Client {
14
15
  constructor(discordOptions, xernerxOptions, config) {
15
16
  super(discordOptions);
17
+ clack.intro('Xernerx');
16
18
  this.settings = z
17
19
  .object({
18
20
  local: z.string(),
19
21
  global: z.boolean().default(false).optional(),
22
+ debug: z.boolean().default(false).optional(),
20
23
  ownerId: z.string().or(z.array(z.string())).default([]),
21
24
  ceaseless: z.boolean().default(false),
22
25
  permissions: z
@@ -89,9 +92,15 @@ export default class XernerxClient extends Client {
89
92
  };
90
93
  }
91
94
  async connect(token) {
92
- const login = this.login(token); // TODO add thing to catch and have better error message
95
+ if (this.settings.debug) new XernerxLog(this).debug(`Connecting to discord using token ${token}...`);
96
+ const login = await this.login(token).catch(() => {
97
+ new XernerxLog(this).error('An invalid token was provided. Please make sure to provide a valid Discord bot token.');
98
+ });
99
+ if (this.settings.debug) new XernerxLog(this).debug(`Connected to discord using token ${token}`);
93
100
  deploy(this);
94
101
  new XernerxLog(this).ready();
102
+ const spinner = clack.spinner();
103
+ spinner.start();
95
104
  return login;
96
105
  }
97
106
  }
@@ -6,7 +6,10 @@ import XernerxContextCommand from '../build/XernerxContextCommand.js';
6
6
  import { filetype } from '../types/types.js';
7
7
  import { XernerxClientEvents, XernerxEvent, XernerxInhibitor } from '../main.js';
8
8
  export default class Handler {
9
- readonly client: XernerxClient<unknown>;
9
+ readonly client: XernerxClient<{
10
+ [index: string]: any;
11
+ [index: number]: any;
12
+ }>;
10
13
  readonly files: Array<MessageCommandBuilder | XernerxSlashCommand | XernerxContextCommand>;
11
14
  constructor(client: XernerxClient);
12
15
  readdir(dir: string, type: string): Promise<string[]>;
@@ -14,16 +14,13 @@ export default class Handler {
14
14
  try {
15
15
  return fs.readdirSync(path.resolve(dir)).filter((file) => file.endsWith('.js'));
16
16
  } catch (error) {
17
- // const spinner = clack.spinner();
18
- // spinner.start();
19
17
  new XernerxLog(this.client).error(`Cannot load ${type.toLowerCase()}, there is no such directory ${Style.log(dir, { color: Style.BackgroundColor.Grey })}.`);
20
- // spinner.stop();
21
- // console.log(c);
22
18
  }
23
19
  return [];
24
20
  }
25
21
  async load(filepath, type) {
26
22
  const file = await load(this.client, filepath, type);
23
+ if (this.client.settings.debug) new XernerxLog(this.client).debug(`Loaded ${Style.log(type, { color: Style.TextColor.Blue })} ${Style.log(file.name, { color: Style.TextColor.Yellow })}`);
27
24
  this.files.push(file);
28
25
  return file;
29
26
  }
@@ -36,10 +33,13 @@ export default class Handler {
36
33
  if (file.filetype === 'Inhibitor') return;
37
34
  if (file.filetype === 'Event' && file.emitter) {
38
35
  if (file.emitter === 'client') {
36
+ if (this.client.settings.debug) new XernerxLog(this.client).debug(`Listening to client event ${Style.log(file.name, { color: Style.TextColor.Yellow })}`);
39
37
  this.client[file.once ? 'once' : 'on'](file.name, (...args) => file.run(...args));
40
38
  } else if (file.emitter === 'process') {
39
+ if (this.client.settings.debug) new XernerxLog(this.client).debug(`Listening to process event ${Style.log(file.name, { color: Style.TextColor.Yellow })}`);
41
40
  process[file.once ? 'once' : 'on'](file.name, (...args) => file.run(...args));
42
41
  } else if (file.emitter === 'rest') {
42
+ if (this.client.settings.debug) new XernerxLog(this.client).debug(`Listening to rest event ${Style.log(file.name, { color: Style.TextColor.Yellow })}`);
43
43
  this.client.rest[file.once ? 'once' : 'on'](file.name, (...args) => file.run(...args));
44
44
  } else {
45
45
  // @ts-expect-error
@@ -17,6 +17,7 @@ export default class XernerxLog {
17
17
  constructor(client: XernerxClient | XernerxClientType | true);
18
18
  info(message: string, force?: boolean): void | null;
19
19
  warn(message: string): void | null;
20
+ debug(message: string): void;
20
21
  update(version: string, url: string): Promise<void>;
21
22
  error(message: string, error?: XernerxError | unknown): void | null;
22
23
  ready(): void;
@@ -26,4 +27,5 @@ export default class XernerxLog {
26
27
  private purple;
27
28
  private red;
28
29
  private green;
30
+ private turquoise;
29
31
  }
@@ -43,7 +43,15 @@ export default class XernerxLog {
43
43
  });
44
44
  this.base = (type, message) =>
45
45
  `${
46
- type == 'info' ? `✔️ | ${this.purple('Xernerx')}` : type == `error` ? `❗ | ${this.red('Xernerx')}` : type == `update` ? `⬆️ | ${this.blue('Xernerx')}` : `⚠️ | ${this.yellow('Xernerx')}`
46
+ type == 'info'
47
+ ? `✔️ | ${this.purple('Xernerx')}`
48
+ : type == `error`
49
+ ? `❗ | ${this.red('Xernerx')}`
50
+ : type == `update`
51
+ ? `⬆️ | ${this.blue('Xernerx')}`
52
+ : type == `debug`
53
+ ? `🐛 | ${this.turquoise('Xernerx')}`
54
+ : `⚠️ | ${this.yellow('Xernerx')}`
47
55
  } | ${this.format
48
56
  ?.map((c) => (typeof format[c] == 'function' ? format[c]() : format[c]) || null)
49
57
  .filter((x) => x)
@@ -55,6 +63,9 @@ export default class XernerxLog {
55
63
  warn(message) {
56
64
  return this.warnLog ? console.warn(this.base('warn', message)) : null;
57
65
  }
66
+ debug(message) {
67
+ return console.debug(this.base('debug', message));
68
+ }
58
69
  async update(version, url) {
59
70
  try {
60
71
  const pkg = await fetch(url)
@@ -131,4 +142,7 @@ export default class XernerxLog {
131
142
  green(string) {
132
143
  return Style.log(String(string), { color: Style.TextColor.Green });
133
144
  }
145
+ turquoise(string) {
146
+ return Style.log(String(string), { color: Style.TextColor.Turquoise });
147
+ }
134
148
  }
@@ -13,6 +13,7 @@ import { XernerxClientEvents, XernerxMessage, XernerxUser } from './extenders.js
13
13
  export interface XernerxOptions {
14
14
  local: string;
15
15
  global?: boolean;
16
+ debug?: boolean;
16
17
  ownerId?: string | Array<string>;
17
18
  ceaseless?: boolean;
18
19
  permissions?: {
@@ -29,14 +30,16 @@ export interface XernerxOptions {
29
30
  channels?: Array<string>;
30
31
  guilds?: Array<string>;
31
32
  };
32
- log?: {
33
- ready?: boolean;
34
- info?: boolean;
35
- warn?: boolean;
36
- error?: boolean;
37
- table?: Array<'name' | 'aliases' | 'description' | 'filetype' | 'category'>;
38
- format?: Array<'name' | 'node' | 'xernerx' | 'discordjs' | 'platform' | 'time' | 'date' | 'ram' | 'version' | 'author' | 'shard' | 'index'>;
39
- };
33
+ log?:
34
+ | {
35
+ ready?: boolean;
36
+ info?: boolean;
37
+ warn?: boolean;
38
+ error?: boolean;
39
+ table?: Array<'name' | 'aliases' | 'description' | 'filetype' | 'category'>;
40
+ format?: Array<'name' | 'node' | 'xernerx' | 'discordjs' | 'platform' | 'time' | 'date' | 'ram' | 'version' | 'author' | 'shard' | 'index'>;
41
+ }
42
+ | boolean;
40
43
  cooldown?: {
41
44
  command?: number;
42
45
  cache?: number;
@@ -2,7 +2,10 @@
2
2
  import XernerxClient from '../client/XernerxClient.js';
3
3
  import XernerxText from '../tools/XernerxText.js';
4
4
  export default class Util {
5
- readonly client: XernerxClient<unknown>;
5
+ readonly client: XernerxClient<{
6
+ [index: string]: any;
7
+ [index: number]: any;
8
+ }>;
6
9
  readonly text: XernerxText;
7
10
  constructor(client: XernerxClient);
8
11
  delay(time: number): Promise<unknown>;
@@ -122,7 +122,7 @@ export default async function commandValidation(event, command) {
122
122
  );
123
123
  if (userPermissions.length) {
124
124
  const missing = [];
125
- userPermissions.map((permission) => (event.guild?.members.me?.permissionsIn(event.channel?.id).has(Style.pascalCase(permission, true)) ? null : missing.push(permission)));
125
+ userPermissions.map((permission) => ((event.member?.permissions).toArray().includes(Style.pascalCase(permission, true)) ? null : missing.push(permission)));
126
126
  if (missing.length)
127
127
  return await emit(
128
128
  event,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xernerx",
3
- "version": "4.17.5",
3
+ "version": "4.17.7",
4
4
  "description": "A bot framework for discord.js.",
5
5
  "main": "dist/main.js",
6
6
  "type": "module",
@@ -21,6 +21,7 @@
21
21
  "node": ">=16.11.0"
22
22
  },
23
23
  "scripts": {
24
+ "cover": "jest",
24
25
  "start": "npm i && npm fund && npm audit fix --force && npm link && tsc -w",
25
26
  "commit": "npm run write && git add . && node ./.github/scripts/message.js",
26
27
  "tag": "node ./.github/scripts/tag.js",
@@ -50,7 +51,9 @@
50
51
  "zod": "^3.22.4"
51
52
  },
52
53
  "devDependencies": {
54
+ "jest": "^29.7.0",
53
55
  "prettier": "3.0.0",
56
+ "ts-node": "^10.9.2",
54
57
  "typescript": "^5.5.2"
55
58
  }
56
59
  }