From 483cac05682b934785ebaa8a2a007cbdc4cc8319 Mon Sep 17 00:00:00 2001 From: QuantumlyTangled Date: Wed, 22 Jul 2020 01:49:29 +0200 Subject: [PATCH 1/6] feat(monitor): define decorators --- package.json | 1 + src/lib/structures/Monitor.ts | 80 ++++++++++++++++------------- src/lib/utils/decorators/monitor.ts | 61 ++++++++++++++++++++++ typedoc.json | 2 - yarn.lock | 43 +++++++++------- 5 files changed, 130 insertions(+), 57 deletions(-) create mode 100644 src/lib/utils/decorators/monitor.ts diff --git a/package.json b/package.json index 86e06a934..0d795507f 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "cz": "git-cz" }, "dependencies": { + "@skyra/decorators": "^2.2.0", "@klasa/ratelimits": "^0.1.0", "@klasa/utils": "^0.1.0" }, diff --git a/src/lib/structures/Monitor.ts b/src/lib/structures/Monitor.ts index 54b3f9497..c230ed3a7 100644 --- a/src/lib/structures/Monitor.ts +++ b/src/lib/structures/Monitor.ts @@ -4,42 +4,6 @@ import { Piece, PieceOptions, Message } from '@klasa/core'; import type { MonitorStore } from './MonitorStore'; export abstract class Monitor extends Piece { - /** - * Should this monitor ignore bots - * @default false - */ - public ignoreBots = false; - - /** - * Should this monitor ignore users - * @default false - */ - public ignoreUsers = false; - - /** - * Should this monitor ignore messages sent by the bot itself - * @default false - */ - public ignoreSelf = false; - - /** - * Should this monitor ignore everyone except itself - * @default false - */ - public ignoreOthers = false; - - /** - * Should this monitor ignore webhook messages - * @default false - */ - public ignoreWebhooks = false; - - /** - * Should this monitor ignore message edits - * @default false - */ - public ignoreEdits = false; - public constructor(store: MonitorStore, directory: string, file: string[], options: PieceOptions) { super(store, directory, file, options); } @@ -67,3 +31,47 @@ export abstract class Monitor extends Piece { } } } + +export interface Monitor { + /** + * Should this monitor ignore bots + * @since 1.0.0 + * @public + */ + ignoreBots: boolean; + + /** + * Should this monitor ignore users + * @since 1.0.0 + * @public + */ + ignoreUsers: boolean; + + /** + * Should this monitor ignore messages sent by the bot itself + * @since 1.0.0 + * @public + */ + ignoreSelf: boolean; + + /** + * Should this monitor ignore everyone except itself + * @since 1.0.0 + * @public + */ + ignoreOthers: boolean; + + /** + * Should this monitor ignore webhook messages + * @since 1.0.0 + * @public + */ + ignoreWebhooks: boolean; + + /** + * Should this monitor ignore message edits + * @since 1.0.0 + * @public + */ + ignoreEdits: boolean; +} diff --git a/src/lib/utils/decorators/monitor.ts b/src/lib/utils/decorators/monitor.ts new file mode 100644 index 000000000..d1a3e12d9 --- /dev/null +++ b/src/lib/utils/decorators/monitor.ts @@ -0,0 +1,61 @@ +import type { Constructor } from '@klasa/core'; +import { createClassDecorator, createProxy } from '@skyra/decorators'; +import type { Monitor } from '../../structures/Monitor'; + +/** + * @since 1.0.0 + * @param prop The property on which the status should be assigned. + * @param status Wheter the property should be ignored or not. + */ +export function monitorIgnoreOptions(prop: string, status?: boolean) { + return createClassDecorator((target: Constructor) => + createProxy(target, { + construct: (ctor, [store, directory, files, options]): Monitor => { + const command = new ctor(store, directory, files, options); + Reflect.defineProperty(command, prop, { + value: status ?? false, + enumerable: true, + configurable: true, + writable: true + }); + return command; + } + }) + ); +} + +/** + * Should the decorated monitor ignore bots. + * @since 1.0.0 + */ +export const ignoreBots = (status?: boolean) => monitorIgnoreOptions('ignoreBots', status); + +/** + * Should the decorated monitor ignore users. + * @since 1.0.0 + */ +export const ignoreUsers = (status?: boolean) => monitorIgnoreOptions('ignoreUsers', status); + +/** + * Should the decorated monitor ignore its self. + * @since 1.0.0 + */ +export const ignoreSelf = (status?: boolean) => monitorIgnoreOptions('ignoreSelf', status); + +/** + * Should the decorated monitor ignore others. + * @since 1.0.0 + */ +export const ignoreOthers = (status?: boolean) => monitorIgnoreOptions('ignoreOthers', status); + +/** + * Should the decorated monitor ignore webhooks. + * @since 1.0.0 + */ +export const ignoreWebhooks = (status?: boolean) => monitorIgnoreOptions('ignoreWebhooks', status); + +/** + * Should the decorated monitor ignore edits. + * @since 1.0.0 + */ +export const ignoreEdits = (status?: boolean) => monitorIgnoreOptions('ignoreEdits', status); diff --git a/typedoc.json b/typedoc.json index cde5f583c..9e93189f7 100644 --- a/typedoc.json +++ b/typedoc.json @@ -5,8 +5,6 @@ "exclude": ["**/node_modules/**", "tests/**"], "mode": "file", "excludeExternals": true, - "excludePrivate": true, - "excludeProtected": true, "excludeNotExported": true, "tsconfig": "./tsconfig.base.json" } diff --git a/yarn.lock b/yarn.lock index 4cb1ba9f1..f0a016c80 100644 --- a/yarn.lock +++ b/yarn.lock @@ -628,7 +628,7 @@ "@klasa/core@github:dirigeants/core#build": version "0.0.3" - resolved "https://codeload.github.com/dirigeants/core/tar.gz/3e2d9ea0c690df93541d1730a8ddfb767951dbda" + resolved "https://codeload.github.com/dirigeants/core/tar.gz/d35e31e175ad0ea330ceb3cb11268d914b5923bc" dependencies: "@klasa/bitfield" "^0.0.4" "@klasa/cache" "^0.0.3" @@ -639,7 +639,7 @@ "@klasa/timer-manager" "^0.0.1" "@klasa/utils" "^0.1.0" "@klasa/ws" "^0.0.14" - "@types/node" "^14.0.23" + "@types/node" "^14.0.24" "@types/node-fetch" "^2.5.7" fs-nextra "^0.5.1" @@ -723,6 +723,11 @@ dependencies: "@sinonjs/commons" "^1.7.0" +"@skyra/decorators@^2.2.0": + version "2.2.0" + resolved "https://registry.yarnpkg.com/@skyra/decorators/-/decorators-2.2.0.tgz#baf6feecf893fc972666ff626dec06c67eefa719" + integrity sha512-pUfcInGEv2cDctE1xRYJIxLHEks4aEe2OlR73DFsM2xGbNSoqVq85EZrAJCiuGJP/+UsPbmAYb4jpButeiwp+w== + "@skyra/eslint-config@^5.2.1": version "5.2.1" resolved "https://registry.yarnpkg.com/@skyra/eslint-config/-/eslint-config-5.2.1.tgz#c9444c578855f6511e0184956c8ea98161d8fb99" @@ -824,10 +829,10 @@ "@types/node" "*" form-data "^3.0.0" -"@types/node@*", "@types/node@^14.0.22", "@types/node@^14.0.23": - version "14.0.23" - resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.23.tgz#676fa0883450ed9da0bb24156213636290892806" - integrity sha512-Z4U8yDAl5TFkmYsZdFPdjeMa57NOvnaf1tljHzhouaPEp7LCj2JKkejpI1ODviIAQuW4CcQmxkQ77rnLsOOoKw== +"@types/node@*", "@types/node@^14.0.22", "@types/node@^14.0.24": + version "14.0.24" + resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.24.tgz#b0f86f58564fa02a28b68f8b55d4cdec42e3b9d6" + integrity sha512-btt/oNOiDWcSuI721MdL8VQGnjsKjlTMdrKyTcLCKeQp/n4AAMFJ961wMbp+09y8WuGPClDEv07RIItdXKIXAA== "@types/normalize-package-data@^2.4.0": version "2.4.0" @@ -861,7 +866,7 @@ dependencies: "@types/yargs-parser" "*" -"@typescript-eslint/eslint-plugin@^3.7.0": +"@typescript-eslint/eslint-plugin@^3.6.0": version "3.7.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.7.0.tgz#0f91aa3c83d019591719e597fbdb73a59595a263" integrity sha512-4OEcPON3QIx0ntsuiuFP/TkldmBGXf0uKxPQlGtS/W2F3ndYm8Vgdpj/woPJkzUc65gd3iR+qi3K8SDQP/obFg== @@ -884,7 +889,7 @@ eslint-scope "^5.0.0" eslint-utils "^2.0.0" -"@typescript-eslint/parser@^3.7.0": +"@typescript-eslint/parser@^3.6.0": version "3.7.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.7.0.tgz#3e9cd9df9ea644536feb6e5acdb8279ecff96ce9" integrity sha512-2LZauVUt7jAWkcIW7djUc3kyW+fSarNEuM3RF2JdLHR9BfX/nDEnyA4/uWz0wseoWVZbDXDF7iF9Jc342flNqQ== @@ -2923,7 +2928,7 @@ is-windows@^1.0.1, is-windows@^1.0.2: resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" integrity sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA== -is-wsl@^2.1.1: +is-wsl@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271" integrity sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww== @@ -3912,15 +3917,15 @@ node-modules-regexp@^1.0.0: integrity sha1-jZ2+KJZKSsVxLpExZCEHxx6Q7EA= node-notifier@^7.0.0: - version "7.0.1" - resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-7.0.1.tgz#a355e33e6bebacef9bf8562689aed0f4230ca6f9" - integrity sha512-VkzhierE7DBmQEElhTGJIoiZa1oqRijOtgOlsXg32KrJRXsPy0NXFBqWGW/wTswnJlDCs5viRYaqWguqzsKcmg== + version "7.0.2" + resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-7.0.2.tgz#3a70b1b70aca5e919d0b1b022530697466d9c675" + integrity sha512-ux+n4hPVETuTL8+daJXTOC6uKLgMsl1RYfFv7DKRzyvzBapqco0rZZ9g72ZN8VS6V+gvNYHYa/ofcCY8fkJWsA== dependencies: growly "^1.3.0" - is-wsl "^2.1.1" - semver "^7.2.1" + is-wsl "^2.2.0" + semver "^7.3.2" shellwords "^0.1.1" - uuid "^7.0.3" + uuid "^8.2.0" which "^2.0.2" normalize-package-data@^2.3.0, normalize-package-data@^2.3.2, normalize-package-data@^2.3.4, normalize-package-data@^2.3.5, normalize-package-data@^2.5.0: @@ -5369,10 +5374,10 @@ util-deprecate@^1.0.1, util-deprecate@~1.0.1: resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= -uuid@^7.0.3: - version "7.0.3" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-7.0.3.tgz#c5c9f2c8cf25dc0a372c4df1441c41f5bd0c680b" - integrity sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg== +uuid@^8.2.0: + version "8.2.0" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.2.0.tgz#cb10dd6b118e2dada7d0cd9730ba7417c93d920e" + integrity sha512-CYpGiFTUrmI6OBMkAdjSDM0k5h8SkkiTP4WAjQgDgNB1S3Ou9VBEvr6q0Kv2H1mMk7IWfxYGpMH5sd5AvcIV2Q== v8-compile-cache@^2.0.3: version "2.1.1" From e3dbed523b25a890a41faf2ebd143c2385ee1ce7 Mon Sep 17 00:00:00 2001 From: QuantumlyTangled Date: Wed, 22 Jul 2020 01:58:50 +0200 Subject: [PATCH 2/6] docs: add param definitions --- src/lib/structures/Monitor.ts | 4 ++++ src/lib/utils/decorators/monitor.ts | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/lib/structures/Monitor.ts b/src/lib/structures/Monitor.ts index c230ed3a7..8b242cd68 100644 --- a/src/lib/structures/Monitor.ts +++ b/src/lib/structures/Monitor.ts @@ -32,6 +32,10 @@ export abstract class Monitor extends Piece { } } +/** + * The Interface defining all ignore groups. + * @since 1.0.0 + */ export interface Monitor { /** * Should this monitor ignore bots diff --git a/src/lib/utils/decorators/monitor.ts b/src/lib/utils/decorators/monitor.ts index d1a3e12d9..523948990 100644 --- a/src/lib/utils/decorators/monitor.ts +++ b/src/lib/utils/decorators/monitor.ts @@ -6,6 +6,7 @@ import type { Monitor } from '../../structures/Monitor'; * @since 1.0.0 * @param prop The property on which the status should be assigned. * @param status Wheter the property should be ignored or not. + * @private */ export function monitorIgnoreOptions(prop: string, status?: boolean) { return createClassDecorator((target: Constructor) => @@ -27,35 +28,41 @@ export function monitorIgnoreOptions(prop: string, status?: boolean) { /** * Should the decorated monitor ignore bots. * @since 1.0.0 + * @param status Whether the given group should be ignored or not. */ export const ignoreBots = (status?: boolean) => monitorIgnoreOptions('ignoreBots', status); /** * Should the decorated monitor ignore users. * @since 1.0.0 + * @param status Whether the given group should be ignored or not. */ export const ignoreUsers = (status?: boolean) => monitorIgnoreOptions('ignoreUsers', status); /** * Should the decorated monitor ignore its self. * @since 1.0.0 + * @param status Whether the given group should be ignored or not. */ export const ignoreSelf = (status?: boolean) => monitorIgnoreOptions('ignoreSelf', status); /** * Should the decorated monitor ignore others. * @since 1.0.0 + * @param status Whether the given group should be ignored or not. */ export const ignoreOthers = (status?: boolean) => monitorIgnoreOptions('ignoreOthers', status); /** * Should the decorated monitor ignore webhooks. * @since 1.0.0 + * @param status Whether the given group should be ignored or not. */ export const ignoreWebhooks = (status?: boolean) => monitorIgnoreOptions('ignoreWebhooks', status); /** * Should the decorated monitor ignore edits. * @since 1.0.0 + * @param status Whether the given group should be ignored or not. */ export const ignoreEdits = (status?: boolean) => monitorIgnoreOptions('ignoreEdits', status); From 48e013310037bc2f09d4d2a27a209de51cfba4c4 Mon Sep 17 00:00:00 2001 From: QuantumlyTangled Date: Wed, 22 Jul 2020 09:20:15 +0200 Subject: [PATCH 3/6] chore: update lock file --- yarn.lock | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index f0a016c80..84cc7b81b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -866,7 +866,7 @@ dependencies: "@types/yargs-parser" "*" -"@typescript-eslint/eslint-plugin@^3.6.0": +"@typescript-eslint/eslint-plugin@^3.7.0": version "3.7.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.7.0.tgz#0f91aa3c83d019591719e597fbdb73a59595a263" integrity sha512-4OEcPON3QIx0ntsuiuFP/TkldmBGXf0uKxPQlGtS/W2F3ndYm8Vgdpj/woPJkzUc65gd3iR+qi3K8SDQP/obFg== @@ -889,7 +889,7 @@ eslint-scope "^5.0.0" eslint-utils "^2.0.0" -"@typescript-eslint/parser@^3.6.0": +"@typescript-eslint/parser@^3.7.0": version "3.7.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.7.0.tgz#3e9cd9df9ea644536feb6e5acdb8279ecff96ce9" integrity sha512-2LZauVUt7jAWkcIW7djUc3kyW+fSarNEuM3RF2JdLHR9BfX/nDEnyA4/uWz0wseoWVZbDXDF7iF9Jc342flNqQ== @@ -4459,11 +4459,16 @@ redent@^3.0.0: indent-string "^4.0.0" strip-indent "^3.0.0" -regenerator-runtime@0.13.5, regenerator-runtime@^0.13.4: +regenerator-runtime@0.13.5: version "0.13.5" resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz#d878a1d094b4306d10b9096484b33ebd55e26697" integrity sha512-ZS5w8CpKFinUzOwW3c83oPeVXoNsrLsaCoLtJvAClH135j/R77RuymhiSErhm2lKcwSCIpmvIWSbDkIfAqKQlA== +regenerator-runtime@^0.13.4: + version "0.13.6" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.6.tgz#d236043c46ffab2968c1ef651803d8acdea8ed65" + integrity sha512-GmwlGiazQEbOwQWDdbbaP10i15pGtScYWLbMZuu+RKRz0cZ+g8IUONazBnaZqe7j1670IV1HgE4/8iy7CQPf4Q== + regex-not@^1.0.0, regex-not@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/regex-not/-/regex-not-1.0.2.tgz#1f4ece27e00b0b65e0247a6810e6a85d83a5752c" From 109901af8c275a23910c7aee92902d6d42425204 Mon Sep 17 00:00:00 2001 From: QuantumlyTangled Date: Wed, 22 Jul 2020 09:57:53 +0200 Subject: [PATCH 4/6] chore: remove @skyra/decorators --- package.json | 1 - src/lib/structures/Command.ts | 38 ++++++------- src/lib/structures/CommandStore.ts | 4 +- src/lib/structures/MonitorStore.ts | 4 +- src/lib/{util => utils}/constants.ts | 0 src/lib/utils/decorators/monitor.ts | 2 +- .../decorators/skyra-decorators-utils.ts | 54 +++++++++++++++++++ yarn.lock | 5 -- 8 files changed, 78 insertions(+), 30 deletions(-) rename src/lib/{util => utils}/constants.ts (100%) create mode 100644 src/lib/utils/decorators/skyra-decorators-utils.ts diff --git a/package.json b/package.json index 0d795507f..86e06a934 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "cz": "git-cz" }, "dependencies": { - "@skyra/decorators": "^2.2.0", "@klasa/ratelimits": "^0.1.0", "@klasa/utils": "^0.1.0" }, diff --git a/src/lib/structures/Command.ts b/src/lib/structures/Command.ts index 550f36116..6b536a7c5 100644 --- a/src/lib/structures/Command.ts +++ b/src/lib/structures/Command.ts @@ -11,85 +11,85 @@ import { CooldownLevel } from '../types/Enums'; export abstract class Command extends AliasPiece { /** * Permissions required by the bot to run the command - * @since 0.0.1 + * @since 1.0.0 */ public requiredPermissions: Permissions; /** * Delete command's response if the trigger message was deleted - * @since 0.0.1 + * @since 1.0.0 */ public deletable: boolean; /** * A basic summary about the command - * @since 0.0.1 + * @since 1.0.0 */ public description: string; /** * Longer version of command's summary and how to use it - * @since 0.0.1 + * @since 1.0.0 */ public extendedHelp: string; /** * Full category name of the command - * @since 0.0.1 + * @since 1.0.0 */ public fullCategory: string[]; /** * Allow disabling of the command in a guild or not - * @since 0.0.1 + * @since 1.0.0 */ public guarded: boolean; /** * Whehter to show the command in the help message or not - * @since 0.0.1 + * @since 1.0.0 */ public hidden: boolean; /** * If the command will only work in NSFW channels - * @since 0.0.1 + * @since 1.0.0 */ public nsfw: boolean; /** * Required level of permission to use the command - * @since 0.0.1 + * @since 1.0.0 */ public permissionLevel: number; /** * Number of re-prompts of an argument - * @since 0.0.1 + * @since 1.0.0 */ public promptLimit: number; /** * Time allowed for re-prompts - * @since 0.0.1 + * @since 1.0.0 */ public promptTime: number; /** * Accepted flags for the command - * @since 0.0.1 + * @since 1.0.0 */ public flags: string[]; /** * Allow use of quoted strings for arguments - * @since 0.0.1 + * @since 1.0.0 */ public quotedStringSupport: boolean; /** * Which type of channel the command can execute in - * @since 0.0.1 + * @since 1.0.0 */ public runIn: ChannelType[]; @@ -97,18 +97,18 @@ export abstract class Command extends AliasPiece { /** * Whether the cooldown applies to author, channel or guild - * @since 0.0.1 + * @since 1.0.0 */ public cooldownLevel: CooldownLevel; /** * The time and limit for cooldown - * @since 0.0.1 + * @since 1.0.0 */ public cooldowns: RateLimitManager; /** - * @since 0.0.1 + * @since 1.0.0 * @param store The command store * @param directory The base directory to the pieces folder * @param file The path from the pieces folder to the command file @@ -144,7 +144,7 @@ export abstract class Command extends AliasPiece { /** * The main category for the command - * @since 0.0.1 + * @since 1.0.0 * @readonly */ public get category(): string { @@ -153,7 +153,7 @@ export abstract class Command extends AliasPiece { /** * The sub category for the command - * @since 0.0.1 + * @since 1.0.0 * @readonly */ public get subCategory(): string { diff --git a/src/lib/structures/CommandStore.ts b/src/lib/structures/CommandStore.ts index 2ea386faa..403897409 100644 --- a/src/lib/structures/CommandStore.ts +++ b/src/lib/structures/CommandStore.ts @@ -5,12 +5,12 @@ import { AliasStore, PieceConstructor, Client } from '@klasa/core'; /** * Stores all Command pieces - * @since 0.0.1 + * @since 1.0.0 */ export class CommandStore extends AliasStore { /** * Constructs the Command Store for use - * @since 0.0.1 + * @since 1.0.0 * @param client The framework client */ public constructor(client: Client) { diff --git a/src/lib/structures/MonitorStore.ts b/src/lib/structures/MonitorStore.ts index f23b37790..be57ad108 100644 --- a/src/lib/structures/MonitorStore.ts +++ b/src/lib/structures/MonitorStore.ts @@ -5,12 +5,12 @@ import { Monitor } from './Monitor'; /** * Stores all Monitor pieces - * @since 0.0.1 + * @since 1.0.0 */ export class MonitorStore extends Store { /** * Constructs the Monitor Store for use - * @since 0.0.1 + * @since 1.0.0 * @param client The framework client */ public constructor(client: Client) { diff --git a/src/lib/util/constants.ts b/src/lib/utils/constants.ts similarity index 100% rename from src/lib/util/constants.ts rename to src/lib/utils/constants.ts diff --git a/src/lib/utils/decorators/monitor.ts b/src/lib/utils/decorators/monitor.ts index 523948990..aefea2d57 100644 --- a/src/lib/utils/decorators/monitor.ts +++ b/src/lib/utils/decorators/monitor.ts @@ -1,5 +1,5 @@ import type { Constructor } from '@klasa/core'; -import { createClassDecorator, createProxy } from '@skyra/decorators'; +import { createClassDecorator, createProxy } from './skyra-decorators-utils'; import type { Monitor } from '../../structures/Monitor'; /** diff --git a/src/lib/utils/decorators/skyra-decorators-utils.ts b/src/lib/utils/decorators/skyra-decorators-utils.ts new file mode 100644 index 000000000..4eb93ab51 --- /dev/null +++ b/src/lib/utils/decorators/skyra-decorators-utils.ts @@ -0,0 +1,54 @@ +/** + * MIT License + * + * Copyright (c) 2018-2020 Kyra + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * Utility to make a class decorator with lighter syntax and inferred types. + * @since 1.0.0 + * @copyright 2018-2020 Kyra + * @license MIT + * @param fn The class to decorate + */ +export function createClassDecorator void>(fn: TFunction): ClassDecorator { + return fn; +} + +/** + * Creates a new proxy to efficiently add properties to class without creating subclasses + * @since 1.0.0 + * @copyright 2018-2020 Kyra + * @license MIT + * @param target The constructor of the class to modify + * @param handler The handler function to modify the constructor behaviour for the target + * @hidden + */ +// eslint-disable-next-line @typescript-eslint/ban-types +export function createProxy(target: T, handler: Omit, 'get'>): T { + return new Proxy(target, { + ...handler, + get: (target, property) => { + const value = Reflect.get(target, property); + return typeof value === 'function' ? (...args: readonly unknown[]) => value.apply(target, args) : value; + } + }); +} diff --git a/yarn.lock b/yarn.lock index 84cc7b81b..020d50bff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -723,11 +723,6 @@ dependencies: "@sinonjs/commons" "^1.7.0" -"@skyra/decorators@^2.2.0": - version "2.2.0" - resolved "https://registry.yarnpkg.com/@skyra/decorators/-/decorators-2.2.0.tgz#baf6feecf893fc972666ff626dec06c67eefa719" - integrity sha512-pUfcInGEv2cDctE1xRYJIxLHEks4aEe2OlR73DFsM2xGbNSoqVq85EZrAJCiuGJP/+UsPbmAYb4jpButeiwp+w== - "@skyra/eslint-config@^5.2.1": version "5.2.1" resolved "https://registry.yarnpkg.com/@skyra/eslint-config/-/eslint-config-5.2.1.tgz#c9444c578855f6511e0184956c8ea98161d8fb99" From bd081fcfa0ec152a36279fe80d39ca7115647346 Mon Sep 17 00:00:00 2001 From: QuantumlyTangled Date: Wed, 22 Jul 2020 11:16:55 +0200 Subject: [PATCH 5/6] chore: enable const enum preservation --- src/lib/types/{Enums.d.ts => Enums.ts} | 0 src/lib/utils/decorators/skyra-decorators-utils.ts | 1 - src/tsconfig.json | 3 ++- 3 files changed, 2 insertions(+), 2 deletions(-) rename src/lib/types/{Enums.d.ts => Enums.ts} (100%) diff --git a/src/lib/types/Enums.d.ts b/src/lib/types/Enums.ts similarity index 100% rename from src/lib/types/Enums.d.ts rename to src/lib/types/Enums.ts diff --git a/src/lib/utils/decorators/skyra-decorators-utils.ts b/src/lib/utils/decorators/skyra-decorators-utils.ts index 4eb93ab51..d2de9d115 100644 --- a/src/lib/utils/decorators/skyra-decorators-utils.ts +++ b/src/lib/utils/decorators/skyra-decorators-utils.ts @@ -40,7 +40,6 @@ export function createClassDecorator void> * @license MIT * @param target The constructor of the class to modify * @param handler The handler function to modify the constructor behaviour for the target - * @hidden */ // eslint-disable-next-line @typescript-eslint/ban-types export function createProxy(target: T, handler: Omit, 'get'>): T { diff --git a/src/tsconfig.json b/src/tsconfig.json index bdc402ffd..49d3da1e1 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -3,7 +3,8 @@ "compilerOptions": { "rootDir": "./", "outDir": "../dist", - "composite": true + "composite": true, + "preserveConstEnums": true }, "include": ["."] } From 53d4165d8dd9b440ab15e36735536c8edd24bbd3 Mon Sep 17 00:00:00 2001 From: QuantumlyTangled Date: Wed, 22 Jul 2020 12:47:38 +0200 Subject: [PATCH 6/6] feat: optional status --- src/lib/structures/Monitor.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/structures/Monitor.ts b/src/lib/structures/Monitor.ts index 8b242cd68..2d44f4d86 100644 --- a/src/lib/structures/Monitor.ts +++ b/src/lib/structures/Monitor.ts @@ -42,40 +42,40 @@ export interface Monitor { * @since 1.0.0 * @public */ - ignoreBots: boolean; + ignoreBots?: boolean; /** * Should this monitor ignore users * @since 1.0.0 * @public */ - ignoreUsers: boolean; + ignoreUsers?: boolean; /** * Should this monitor ignore messages sent by the bot itself * @since 1.0.0 * @public */ - ignoreSelf: boolean; + ignoreSelf?: boolean; /** * Should this monitor ignore everyone except itself * @since 1.0.0 * @public */ - ignoreOthers: boolean; + ignoreOthers?: boolean; /** * Should this monitor ignore webhook messages * @since 1.0.0 * @public */ - ignoreWebhooks: boolean; + ignoreWebhooks?: boolean; /** * Should this monitor ignore message edits * @since 1.0.0 * @public */ - ignoreEdits: boolean; + ignoreEdits?: boolean; }