Skip to content

Commit

Permalink
feat: about scene
Browse files Browse the repository at this point in the history
  • Loading branch information
dodyagung committed Apr 8, 2024
1 parent d110e7f commit 80baaa3
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 21 deletions.
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2024 dodyagung.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13 changes: 4 additions & 9 deletions src/sale/sale.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@ const extra = (keyboard: HideableIKBtn[][]): ExtraEditMessageText => {
};
};

export const editMessage = async (
ctx: SceneContext,
message: string,
keyboard: HideableIKBtn[][],
): Promise<void> => {
await ctx.editMessageText(message, extra(keyboard));
};

export const sendMessage = async (
ctx: SceneContext,
message: string,
keyboard: HideableIKBtn[][],
new_message: boolean = false,
): Promise<void> => {
await ctx.reply(message, extra(keyboard));
(await new_message)
? ctx.reply(message, extra(keyboard))
: ctx.editMessageText(message, extra(keyboard));
};
3 changes: 2 additions & 1 deletion src/sale/sale.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { ConfigModule } from '@nestjs/config';
import { SaleService } from './sale.service';
import { SaleScene } from './scene/sale.scene';
import { WelcomeScene } from './scene/welcome.scene';
import { AboutScene } from './scene/about.scene';

@Module({
providers: [SaleUpdate, SaleService, SaleScene, WelcomeScene],
providers: [SaleUpdate, SaleService, SaleScene, WelcomeScene, AboutScene],
imports: [ConfigModule, PrismaModule],
})
export class SaleModule {}
38 changes: 38 additions & 0 deletions src/sale/scene/about.scene.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Scene, SceneEnter, Ctx, Action } from 'nestjs-telegraf';
import { SceneContext } from 'telegraf/scenes';
import { Markup } from 'telegraf';
import { sendMessage } from '../sale.common';

@Scene('ABOUT_SCENE')
export class AboutScene {
@SceneEnter()
async onSceneEnter(@Ctx() ctx: SceneContext): Promise<void> {
const keyboard = [[Markup.button.callback('🔙 Back', 'back')]];

let message = `*🤖 About*\n\n`;
message += `*telegram\\-sale\\-bot*\n`;
message += `I\\'m a bot to automate your scheduled\\-sale in Telegram group\\.\n`;
message += `Open\\-sourced at [GitHub](https://github.com/dodyagung/telegram-sale-bot)\\. Built with [NestJS](https://nestjs.com) and [Telegraf](https://telegraf.js.org)\\.\n`;
message += `Made with ♥ in Jakarta, Indonesia\\.\n\n`;

message += `*Contact Us*\n`;
message += `Found an error? Have a question? Open a [GitHub Issues](https://github.com/dodyagung/telegram-sale-bot/issues)\\.\n\n`;

message += `*Contribute*\n`;
message += `If you are developer, open a [GitHub Pull Request](https://github.com/dodyagung/telegram-sale-bot/pulls)\\.\n\n`;

message += `*Creator*\n`;
message += `Hi, I am Dody\\. A backend enthusiast\\. Loves Golang and Typescript\\.\n`;
message += `Visit my website at [dodyagung\\.com](https://dodyagung.com)\\.\n\n`;

message += `*License*\n`;
message += `This open\\-source project is licensed under [MIT license](https://github.com/dodyagung/telegram-sale-bot/blob/master/LICENSE.md)\\.`;

await sendMessage(ctx, message, keyboard);
}

@Action('back')
async onBack(@Ctx() ctx: SceneContext): Promise<void> {
await ctx.scene.enter('WELCOME_SCENE');
}
}
7 changes: 2 additions & 5 deletions src/sale/scene/sale.scene.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { Scene, SceneEnter, Ctx, Action } from 'nestjs-telegraf';
import { SceneContext } from 'telegraf/scenes';
import { Markup } from 'telegraf';
import { SaleUpdate } from '../sale.update';
import { editMessage } from '../sale.common';
import { sendMessage } from '../sale.common';

@Scene('SALE_SCENE')
export class SaleScene {
constructor(private saleUpdate: SaleUpdate) {}

@SceneEnter()
async onSceneEnter(@Ctx() ctx: SceneContext): Promise<void> {
const keyboard = [[Markup.button.callback('🔙 Back', 'back')]];
const message = ' sale scene';

await editMessage(ctx, message, keyboard);
await sendMessage(ctx, message, keyboard);
}

@Action('back')
Expand Down
13 changes: 7 additions & 6 deletions src/sale/scene/welcome.scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SceneContext } from 'telegraf/scenes';
import { Markup } from 'telegraf';
import { ConfigService } from '@nestjs/config';
import { RESET_DAY, SALE_DAY, TIMEZONE, TODAY } from '../sale.constant';
import { editMessage, sendMessage } from '../sale.common';
import { sendMessage } from '../sale.common';

@Scene('WELCOME_SCENE')
export class WelcomeScene {
Expand Down Expand Up @@ -52,15 +52,16 @@ export class WelcomeScene {
message += `├ Joined : \`${user_joined ? 'Yes' : 'No'}\`\n`;
message += `└ Link : [Click Here](${this.configService.get<string>('TELEGRAM_GROUP_LINK')})`;

if (ctx.callbackQuery) {
await editMessage(ctx, message, keyboard);
} else {
await sendMessage(ctx, message, keyboard);
}
await sendMessage(ctx, message, keyboard, !ctx.callbackQuery);
}

@Action('sale')
async onSaleAction(@Ctx() ctx: SceneContext): Promise<void> {
await ctx.scene.enter('SALE_SCENE');
}

@Action('about')
async onAboutAction(@Ctx() ctx: SceneContext): Promise<void> {
await ctx.scene.enter('ABOUT_SCENE');
}
}

0 comments on commit 80baaa3

Please sign in to comment.