Skip to content

Commit

Permalink
chore(release): v1.3.0 (#94)
Browse files Browse the repository at this point in the history
feat: decorators refactoring
  • Loading branch information
evilsprut authored Aug 14, 2020
2 parents 63bac9e + 8375d1a commit a9fcef0
Show file tree
Hide file tree
Showing 36 changed files with 387 additions and 273 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,31 @@ Now let's try to repeat the example from the Telegraf [documentation page](https

import { Injectable } from '@nestjs/common';
import {
TelegrafStart,
TelegrafHelp,
TelegrafOn,
TelegrafHears,
Start,
Help,
On,
Hears,
Context,
} from 'nestjs-telegraf';

@Injectable()
export class AppService {
@TelegrafStart()
@Start()
start(ctx: Context) {
ctx.reply('Welcome');
}

@TelegrafHelp()
@Help()
help(ctx: Context) {
ctx.reply('Send me a sticker');
}

@TelegrafOn('sticker')
@On('sticker')
on(ctx: Context) {
ctx.reply('👍');
}

@TelegrafHears('hi')
@Hears('hi')
hears(ctx: Context) {
ctx.reply('Hey there');
}
Expand Down Expand Up @@ -213,4 +213,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ import { Context } from '../interfaces';

export type TelegrafActionTriggers = HearsTriggers<Context>;

export interface TelegrafActionMetadata {
export interface ActionOptions {
triggers: TelegrafActionTriggers;
}

/**
* Registers middleware for handling callback_data actions with regular expressions.
* @param triggers Triggers
*
* https://telegraf.js.org/#/?id=action
* @see https://telegraf.js.org/#/?id=action
*/
export function TelegrafAction(
triggers: TelegrafActionTriggers,
): MethodDecorator {
export const Action = (triggers: TelegrafActionTriggers): MethodDecorator => {
return SetMetadata(DECORATORS.ACTION, { triggers });
}
};

/**
* Registers middleware for handling callback_data actions with regular expressions.
*
* @see https://telegraf.js.org/#/?id=action
* @deprecated since v2, use Action decorator instead.
*/
export const TelegrafAction = Action;
25 changes: 25 additions & 0 deletions lib/decorators/cashtag.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { SetMetadata } from '@nestjs/common';
import { DECORATORS } from '../telegraf.constants';

export type TelegrafCashtagCashtag = string | string[];

export interface CashtagOptions {
cashtag: TelegrafCashtagCashtag;
}

/**
* Cashtag handling.
*
* @see https://telegraf.js.org/#/?id=cashtag
*/
export const Cashtag = (cashtag: TelegrafCashtagCashtag): MethodDecorator => {
return SetMetadata(DECORATORS.CASHTAG, { cashtag });
};

/**
* Cashtag handling.
*
* @see https://telegraf.js.org/#/?id=cashtag
* @deprecated since v2, use Cashtag decorator instead.
*/
export const TelegrafCashtag = Cashtag;
25 changes: 25 additions & 0 deletions lib/decorators/command.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { SetMetadata } from '@nestjs/common';
import { DECORATORS } from '../telegraf.constants';

export type TelegrafCommandCommands = string | string[];

export interface CommandOptions {
commands: TelegrafCommandCommands;
}

/**
* Command handling.
*
* @see https://telegraf.js.org/#/?id=command
*/
export const Command = (commands: TelegrafCommandCommands): MethodDecorator => {
return SetMetadata(DECORATORS.COMMAND, { commands });
};

/**
* Command handling.
*
* @see https://telegraf.js.org/#/?id=command
* @deprecated since v2, use Command decorator instead.
*/
export const TelegrafCommand = Command;
30 changes: 30 additions & 0 deletions lib/decorators/entity.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { SetMetadata } from '@nestjs/common';
import { DECORATORS } from '../telegraf.constants';

export type TelegrafEntityEntity =
| string
| string[]
| RegExp
| RegExp[]
| Function;

export interface EntityOptions {
entity: TelegrafEntityEntity;
}

/**
* Entity handling.
*
* @see https://telegraf.js.org/#/?id=entity
*/
export const Entity = (entity: TelegrafEntityEntity): MethodDecorator => {
return SetMetadata(DECORATORS.ENTITY, { entity });
};

/**
* Entity handling.
*
* @see https://telegraf.js.org/#/?id=entity
* @deprecated since v2, use Entity decorator instead.
*/
export const TelegrafEntity = Entity;
19 changes: 19 additions & 0 deletions lib/decorators/game-query.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { SetMetadata } from '@nestjs/common';
import { DECORATORS } from '../telegraf.constants';

/**
* Registers middleware for handling callback_data actions with game query.
*
* @see https://telegraf.js.org/#/?id=inlinequery
*/
export const GameQuery = (): MethodDecorator => {
return SetMetadata(DECORATORS.GAME_QUERY, {});
};

/**
* Registers middleware for handling callback_data actions with game query.
*
* @see https://telegraf.js.org/#/?id=inlinequery
* @deprecated since v2, use Action decorator instead.
*/
export const TelegrafGameQuery = GameQuery;
25 changes: 25 additions & 0 deletions lib/decorators/hashtag.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { SetMetadata } from '@nestjs/common';
import { DECORATORS } from '../telegraf.constants';

export type TelegrafHashtagHashtag = string | string[];

export interface HashtagOptions {
hashtag: TelegrafHashtagHashtag;
}

/**
* Hashtag handling.
*
* @see https://telegraf.js.org/#/?id=hashtag
*/
export const Hashtag = (hashtag: TelegrafHashtagHashtag): MethodDecorator => {
return SetMetadata(DECORATORS.HASHTAG, { hashtag });
};

/**
* Hashtag handling.
*
* @see https://telegraf.js.org/#/?id=hashtag
* @deprecated since v2, use Hashtag decorator instead.
*/
export const TelegrafHashtag = Hashtag;
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ import { Context } from '../interfaces';

export type TelegrafHearsTriggers = HearsTriggers<Context>;

export interface TelegrafHearsMetadata {
export interface HearsOptions {
triggers: TelegrafHearsTriggers;
}

/**
* Registers middleware for handling text messages.
* @param triggers Triggers
*
* https://telegraf.js.org/#/?id=hears
* @see https://telegraf.js.org/#/?id=hears
*/
export function TelegrafHears(
triggers: TelegrafHearsTriggers,
): MethodDecorator {
export const Hears = (triggers: TelegrafHearsTriggers): MethodDecorator => {
return SetMetadata(DECORATORS.HEARS, { triggers: triggers });
}
};

/**
* Registers middleware for handling text messages.
*
* @see https://telegraf.js.org/#/?id=hears
* @deprecated since v2, use Hears decorator instead.
*/
export const TelegrafHears = Hears;
19 changes: 19 additions & 0 deletions lib/decorators/help.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { SetMetadata } from '@nestjs/common';
import { DECORATORS } from '../telegraf.constants';

/**
* Handler for /help command.
*
* @see https://telegraf.js.org/#/?id=help
*/
export const Help = (): MethodDecorator => {
return SetMetadata(DECORATORS.HELP, {});
};

/**
* Handler for /help command.
*
* @see https://telegraf.js.org/#/?id=help
* @deprecated since v2, use Help decorator instead.
*/
export const TelegrafHelp = Help;
31 changes: 16 additions & 15 deletions lib/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
export * from './action.decorator';
export * from './cashtag.decorator';
export * from './command.decorator';
export * from './entity.decorator';
export * from './game-query.decorator';
export * from './hashtag.decorator';
export * from './hears.decorator';
export * from './help.decorator';
export * from './inject-bot.decorator';
export * from './telegraf-use.decorator';
export * from './telegraf-on.decorator';
export * from './telegraf-hears.decorator';
export * from './telegraf-command.decorator';
export * from './telegraf-start.decorator';
export * from './telegraf-help.decorator';
export * from './telegraf-settings.decorator';
export * from './telegraf-entity.decorator';
export * from './telegraf-mention.decorator';
export * from './telegraf-phone.decorator';
export * from './telegraf-hashtag.decorator';
export * from './telegraf-cashtag.decorator';
export * from './telegraf-action.decorator';
export * from './telegraf-inline-query.decorator';
export * from './telegraf-game-query.decorator';
export * from './inline-query.decorator';
export * from './mention.decorator';
export * from './on.decorator';
export * from './phone.decorator';
export * from './settings.decorator';
export * from './start.decorator';
export * from './update.decorator';
export * from './use.decorator';
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@ import { DECORATORS } from '../telegraf.constants';

export type TelegrafInlineQueryTriggers = string | string[] | RegExp | RegExp[];

export interface TelegrafInlineQueryMetadata {
export interface InlineQueryOptions {
triggers: TelegrafInlineQueryTriggers;
}

/**
* Registers middleware for handling inline_query actions with regular expressions.
* @param triggers Triggers
*
* https://telegraf.js.org/#/?id=inlinequery
* @see https://telegraf.js.org/#/?id=inlinequery
*/
export function TelegrafInlineQuery(
export const InlineQuery = (
triggers: TelegrafInlineQueryTriggers,
): MethodDecorator {
): MethodDecorator => {
return SetMetadata(DECORATORS.INLINE_QUERY, { triggers });
}
};

/**
* Registers middleware for handling inline_query actions with regular expressions.
*
* @see https://telegraf.js.org/#/?id=inlinequery
* @deprecated since v2, use InlineQuery decorator instead.
*/
export const TelegrafInlineQuery = InlineQuery;
25 changes: 25 additions & 0 deletions lib/decorators/mention.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { SetMetadata } from '@nestjs/common';
import { DECORATORS } from '../telegraf.constants';

export type TelegrafMentionUsername = string | string[];

export interface MentionOptions {
username: TelegrafMentionUsername;
}

/**
* Mention handling.
*
* @see https://telegraf.js.org/#/?id=mention
*/
export const Mention = (username: TelegrafMentionUsername): MethodDecorator => {
return SetMetadata(DECORATORS.MENTION, { username });
};

/**
* Mention handling.
*
* @see https://telegraf.js.org/#/?id=mention
* @deprecated since v2, use Mention decorator instead.
*/
export const TelegrafMention = Mention;
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ export type TelegrafOnUpdateTypes =
| MessageSubTypes
| MessageSubTypes[];

export interface TelegrafOnMetadata {
export interface OnOptions {
updateTypes: TelegrafOnUpdateTypes;
}

/**
* Registers middleware for provided update type.
* @param updateTypes Update type
*
* https://telegraf.js.org/#/?id=on
* @see https://telegraf.js.org/#/?id=on
*/
export function TelegrafOn(
updateTypes: TelegrafOnUpdateTypes,
): MethodDecorator {
export const On = (updateTypes: TelegrafOnUpdateTypes): MethodDecorator => {
return SetMetadata(DECORATORS.ON, { updateTypes: updateTypes });
}
};

/**
* Registers middleware for provided update type.
*
* @see https://telegraf.js.org/#/?id=on
* @deprecated since v2, use On decorator instead.
*/
export const TelegrafOn = On;
Loading

0 comments on commit a9fcef0

Please sign in to comment.