Skip to content

Commit

Permalink
fix: isallowedtostart function
Browse files Browse the repository at this point in the history
  • Loading branch information
dodyagung committed May 6, 2024
1 parent c48903d commit 71685c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
10 changes: 7 additions & 3 deletions src/sale/sale.update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Start, Update, Ctx, InjectBot, Hears } from 'nestjs-telegraf';
import { SceneContext } from 'telegraf/scenes';
import { SaleService } from './sale.service';
import { Logger } from '@nestjs/common';
import { Cron, CronExpression, Interval } from '@nestjs/schedule';
import { Cron, CronExpression } from '@nestjs/schedule';
import {
RESET_DAY_MINUS_1_WEEK,
SALE_DAY,
Expand All @@ -13,9 +13,9 @@ import {
import { Context, Telegraf } from 'telegraf';
import { ConfigService } from '@nestjs/config';
import {
isAllowedToStart,
leaveScene,
sendMessageToGroup,
sendMessageWithoutKeyboard,
} from './sale.common';

@Update()
Expand All @@ -30,7 +30,11 @@ export class SaleUpdate {

@Start()
onStart(@Ctx() ctx: SceneContext): void {
ctx.scene.enter('WELCOME_SCENE');
if (isAllowedToStart(ctx)) {
ctx.scene.enter('WELCOME_SCENE');
} else {
leaveScene(ctx);
}
}

@Hears(/.+/)
Expand Down
11 changes: 1 addition & 10 deletions src/sale/scene/welcome.scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import { SceneContext } from 'telegraf/scenes';
import { Markup } from 'telegraf';
import { ConfigService } from '@nestjs/config';
import { RESET_DAY, SALE_DAY, TIMEZONE, TODAY_LONG } from '../sale.constant';
import {
isAllowedToStart,
leaveScene,
sendMessageWithKeyboard,
} from '../sale.common';
import { leaveScene, sendMessageWithKeyboard } from '../sale.common';
import { SaleService } from '../sale.service';

@Scene('WELCOME_SCENE')
Expand All @@ -33,11 +29,6 @@ export class WelcomeScene {
@Sender('first_name') firstName: string,
@Sender('last_name') lastName: string,
): Promise<void> {
if (!isAllowedToStart(ctx)) {
leaveScene(ctx);
return;
}

const keyboard = [
[
Markup.button.callback('💰 My Sale', 'sale'),
Expand Down

0 comments on commit 71685c0

Please sign in to comment.