mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-09-30 20:31:21 +03:00
feat(sample): update sample
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
||||
import { TelegrafExecutionContext } from 'nestjs-telegraf';
|
||||
|
||||
export const From = createParamDecorator(
|
||||
export const UpdateType = createParamDecorator(
|
||||
(_, ctx: ExecutionContext) =>
|
||||
TelegrafExecutionContext.create(ctx).getContext().from,
|
||||
TelegrafExecutionContext.create(ctx).getContext().updateType,
|
||||
);
|
@@ -1,11 +1,13 @@
|
||||
import { ArgumentsHost, Catch, ExceptionFilter } from '@nestjs/common';
|
||||
import { TelegrafArgumentsHost } from 'nestjs-telegraf';
|
||||
import { Context } from '../../interfaces/context.interface';
|
||||
|
||||
@Catch()
|
||||
export class TelegrafExceptionFilter<T> implements ExceptionFilter {
|
||||
catch(exception: T, host: ArgumentsHost) {
|
||||
const tgHost = TelegrafArgumentsHost.create(host);
|
||||
console.log(tgHost);
|
||||
return exception;
|
||||
export class TelegrafExceptionFilter implements ExceptionFilter {
|
||||
async catch(exception: Error, host: ArgumentsHost): Promise<void> {
|
||||
const telegrafHost = TelegrafArgumentsHost.create(host);
|
||||
const ctx = telegrafHost.getContext<Context>();
|
||||
|
||||
await ctx.replyWithHTML(`<b>Error</b>: ${exception.message}`);
|
||||
}
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ export class AdminGuard implements CanActivate {
|
||||
|
||||
const isAdmin = this.ADMIN_IDS.includes(from.id);
|
||||
if (!isAdmin) {
|
||||
throw new TelegrafException('You are not admin >:(');
|
||||
throw new TelegrafException('You are not admin 😡');
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user