import { INIT_MAP } from './common' const DEFAULTS: Partial = { emitsEvent: false, resetStates: [], onlyFor: undefined, unauthorizedExecHandlerName: 'onUnauthorizedCommand', } /** * Marks the function as command function of the bot. * * When the user sends a command starting with / (slash) followed by the same * name of the function, the function is executed. * * @export * @param {ICommandDecoratorOpts} [opts] Options for the command decorator. * @returns Method Decorator */ export function command(opts?: ICommandDecoratorOpts) { return function any = (...args: any[]) => any>(target: any, propName: string, descriptor?: TypedPropertyDescriptor) { if (typeof opts !== 'object') { opts = { name: propName, ...DEFAULTS } } else { opts = { name: propName, ...DEFAULTS, ...opts } } const originalFunction = target[ propName ] let initArray = INIT_MAP.get(target) if (!initArray) { INIT_MAP.set(target, initArray = []) } initArray.push({ name: opts.name || propName, type: 'command', handler: originalFunction, opts }) return descriptor } }