-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(monitor): define decorators * docs: add param definitions * chore: update lock file * chore: remove @skyra/decorators * chore: enable const enum preservation * feat: optional status
- Loading branch information
1 parent
88afac3
commit 5d3accd
Showing
11 changed files
with
217 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import type { Constructor } from '@klasa/core'; | ||
import { createClassDecorator, createProxy } from './skyra-decorators-utils'; | ||
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<Monitor>) => | ||
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 | ||
* @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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* 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<TFunction extends (...args: any[]) => 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 | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
export function createProxy<T extends object>(target: T, handler: Omit<ProxyHandler<T>, '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; | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.