Skip to content

Commit

Permalink
add command decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
disizali committed Jun 1, 2021
1 parent aa1117e commit 35adfa0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/common/decorators/telegram/listeners/command.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { COMMAND_METADATA } from "../../../constants.ts";
import { parse } from "../../../../deps.ts";
export function Command(pattern: string): MethodDecorator {
return (
target: object,
key: string | symbol,
descriptor: PropertyDescriptor,
) => {
pattern = validatePattern(pattern);
const trigger = parse(pattern);
Reflect.defineMetadata(COMMAND_METADATA, trigger, descriptor.value);
};
}

const validatePattern = (pattern: string) =>
pattern.length ? (pattern[0] === "/" ? pattern.slice(1) : pattern) : pattern;

0 comments on commit 35adfa0

Please sign in to comment.