Options
All
  • Public
  • Public/Protected
  • All
Menu

@skyra/decorators

Index

Functions

ApplyOptions

  • ApplyOptions<T>(optionsOrFn: T | ((client: KlasaClient) => T)): ClassDecorator
  • Decorator function that applies given options to any Klasa piece

        ApplyOptions<CommandOptions>({
            name: 'ping',
            cooldown: 10
        })
        export default class extends Command {}
    
    since

    1.0.0

    Type parameters

    • T: PieceOptions

    Parameters

    • optionsOrFn: T | ((client: KlasaClient) => T)

    Returns ClassDecorator

CreateResolver

  • CreateResolver(name: string, resolverFn: ArgResolverCustomMethod): ClassDecorator
  • Applies a single custom resolver to a command through a decorator

        CreateResolver('key', (arg, _possible, message, [action]) => {
            if (action === 'show' || arg) return arg || '';
            throw message.language.get('commandConfNoKey');
        })
    

    Parameters

    • name: string

      Name of the custom argument resolver

    • resolverFn: ArgResolverCustomMethod

      Function describing how to resolve the argument

    Returns ClassDecorator

CreateResolvers

  • CreateResolvers(resolvers: [string, ArgResolverCustomMethod][]): ClassDecorator
  • Applies a set of custom resolvers to a command through a decorator

        CreateResolvers([
            [
                'key',
                (arg, _possible, message, [action]) => {
                    if (action === 'show' || arg) return arg || '';
                    throw message.language.get('commandConfNoKey');
                }
            ]
        ])
    
    since

    2.1.0

    copyright

    2020 Gryffon Bellish

    license

    MIT

    Parameters

    • resolvers: [string, ArgResolverCustomMethod][]

      Array of custom resolvers to apply to a command

    Returns ClassDecorator

createClassDecorator

  • createClassDecorator<TFunction>(fn: TFunction): ClassDecorator
  • Utility to make a class decorator with lighter syntax and inferred types.

    since

    1.0.0

    see

    ApplyOptions

    Type parameters

    • TFunction: (...args: any[]) => void

    Parameters

    • fn: TFunction

      The class to decorate

    Returns ClassDecorator

createFunctionInhibitor

  • createFunctionInhibitor(inhibitor: Inhibitor, fallback?: Fallback): MethodDecorator
  • Utility to make function inhibitors.

        // No fallback (returns undefined)
        function requiresPermission(value: number) {
            return createFunctionInhibitor((message: KlasaMessage) =>
                message.hasAtLeastPermissionLevel(value));
        }
    
        // With fallback
        function requiresPermission(
            value: number,
            fallback: () => unknown = () => undefined
        ) {
            return createFunctionInhibitor((message: KlasaMessage) =>
                message.hasAtLeastPermissionLevel(value), fallback);
        }
    
    since

    1.0.0

    Parameters

    • inhibitor: Inhibitor

      The function that defines whether or not the function should be run, returning the returned value from fallback

    • fallback: Fallback = ...

      The fallback value that defines what the method should return in case the inhibitor fails

    Returns MethodDecorator

createMethodDecorator

  • createMethodDecorator(fn: MethodDecorator): MethodDecorator
  • Utility to make a method decorator with lighter syntax and inferred types.

    // Enumerable function
        function enumerable(value: boolean) {
            return createMethodDecorator((_target, _propertyKey, descriptor) => {
                descriptor.enumerable = value;
            });
        }
    
    since

    1.0.0

    Parameters

    • fn: MethodDecorator

      The method to decorate

    Returns MethodDecorator

Const requiredPermissions

  • requiredPermissions(permissionsResolvable: BitFieldResolvable<PermissionString>): MethodDecorator
  • Allows you to set permissions required for individual methods

    since

    2.1.0

    remark

    In particular useful for subcommand methods

    Parameters

    • permissionsResolvable: BitFieldResolvable<PermissionString>

      Permissions that the method should have

    Returns MethodDecorator

requiresDMContext

  • requiresDMContext(fallback?: Fallback): MethodDecorator
  • Requires the message to be run in a dm context, this decorator requires the first argument to be a KlasaMessage instance

    since

    1.0.0

    Parameters

    • fallback: Fallback = ...

      The fallback value passed to createFunctionInhibitor

    Returns MethodDecorator

requiresGuildContext

  • requiresGuildContext(fallback?: Fallback): MethodDecorator
  • Requires the message to be run in a guild context, this decorator requires the first argument to be a KlasaMessage instance

    since

    1.0.0

    Parameters

    • fallback: Fallback = ...

      The fallback value passed to createFunctionInhibitor

    Returns MethodDecorator

requiresPermission

  • requiresPermission(value: number, fallback?: Fallback): MethodDecorator
  • Requires a permission, this decorator requires the first argument to be a KlasaMessage instance

    since

    1.0.0

    Parameters

    • value: number

      The minimum permission level for this inhibitor to pass

    • fallback: Fallback = ...

      The fallback value passed to createFunctionInhibitor

    Returns MethodDecorator

Generated using TypeDoc