Skip to content

Commit

Permalink
feat(wizards): add profiles wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
havrydotdev committed Oct 31, 2023
1 parent a0b07b8 commit b051f3d
Show file tree
Hide file tree
Showing 47 changed files with 54,496 additions and 188 deletions.
53,981 changes: 53,981 additions & 0 deletions migrations.sql

Large diffs are not rendered by default.

60 changes: 26 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"docs:dev": "vitepress dev",
"docs:build": "vitepress build",
"docs:preview": "vitepress preview",
"sessions:drop": "sqlite3 ./dev.db 'DROP TABLE \"telegraf-sessions\"'"
"sessions:drop": "sqlite3 ./dev.db 'DROP TABLE \"telegraf-sessions\"'",
"typeorm": "typeorm-ts-node-commonjs"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.436.0",
Expand All @@ -53,12 +54,15 @@
"@nestjs/typeorm": "^10.0.0",
"@telegraf/session": "^2.0.0-beta.6",
"better-sqlite3": "^8.7.0",
"dotenv": "^16.3.1",
"kysely": "^0.23.5",
"nestjs-i18n": "^10.3.6",
"nestjs-telegraf": "^2.7.0",
"pg": "^8.11.3",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"telegraf": "^4.14.0",
"telegraf-ratelimit": "^2.0.0",
"typeorm": "^0.3.17"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AppUpdate } from './controllers/updates';
import {
ChangeLangWizard,
NextActionWizard,
ProfilesWizard,
RegisterWizard,
} from './controllers/wizards';
import { GlobalFilter } from './core/filters';
Expand Down Expand Up @@ -49,6 +50,7 @@ import { UserUseCasesModule } from './use-cases/user';
RegisterWizard,
ChangeLangWizard,
NextActionWizard,
ProfilesWizard,
{
provide: APP_INTERCEPTOR,
useClass: I18nInterceptor,
Expand Down
77 changes: 51 additions & 26 deletions src/controllers/updates/app.update.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import { Logger } from '@nestjs/common';
import { Action, Command, Ctx, Help, On, Start, Update } from 'nestjs-telegraf';
import { CHANGE_LANG_WIZARD_ID } from 'src/core/constants';
import { Command, Ctx, Hears, Help, On, Start, Update } from 'nestjs-telegraf';
import {
CHANGE_LANG_WIZARD_ID,
COOP_CALLBACK,
HELP_CALLBACK,
LANG_CALLBACK,
LEAVE_PROFILES_CALLBACK,
LOOK_CALLBACK,
NEXT_PROFILE_CALLBACK,
PROFILES_WIZARD_ID,
PROFILE_CALLBACK,
} from 'src/core/constants';
import { Game } from 'src/core/entities';
import { getCaption } from 'src/core/utils';
import { MessageContext, MsgKey } from 'src/types';
import { MessageContext, MsgKey, MsgWithExtra } from 'src/types';
import { GameUseCases } from 'src/use-cases/game';
import { ReplyUseCases } from 'src/use-cases/reply';
import { Markup } from 'telegraf';
import { InlineQueryResult } from 'telegraf/typings/core/types/typegram';

@Update()
export class AppUpdate {
private readonly logger = new Logger(AppUpdate.name);

constructor(
private readonly replyUseCases: ReplyUseCases,
private readonly gameUseCases: GameUseCases,
) {}

@Start()
async onStart(@Ctx() ctx: MessageContext): Promise<MsgKey> {
this.logger.log(`/start ${ctx.from.username}`);

if (!ctx.session.user.profile) {
await this.replyUseCases.replyI18n(ctx, 'commands.start');

Expand All @@ -32,19 +38,15 @@ export class AppUpdate {
return 'commands.start';
}

@Action('language')
@Command('language')
@Hears(LANG_CALLBACK)
async onLanguage(@Ctx() ctx: MessageContext): Promise<void> {
this.logger.log(`/language ${ctx.from.username}`);

await ctx.scene.enter(CHANGE_LANG_WIZARD_ID);
}

@Action('me')
@Command('me')
@Hears(PROFILE_CALLBACK)
async onMe(@Ctx() ctx: MessageContext) {
this.logger.log(`/me ${ctx.from.username}`);

await ctx.replyWithPhoto(
{ url: ctx.session.user.profile.file.url },
{
Expand All @@ -53,11 +55,42 @@ export class AppUpdate {
);
}

@Help()
@Action('help')
async onHelp(@Ctx() ctx: MessageContext): Promise<MsgKey> {
this.logger.log(`/help ${ctx.from.username}`);
@Command('coop')
@Hears(COOP_CALLBACK)
async onCoop(): Promise<MsgWithExtra> {
return [
'commands.coop',
{
parse_mode: 'HTML',
},
];
}

@Command('profiles')
@Hears(LOOK_CALLBACK)
async onProfiles(@Ctx() ctx: MessageContext): Promise<void> {
await this.replyUseCases.replyI18n(ctx, 'messages.searching_teammates', {
reply_markup: Markup.removeKeyboard().reply_markup,
});

await this.replyUseCases.replyI18n(ctx, 'commands.profiles', {
reply_markup: Markup.keyboard([
[
Markup.button.callback(NEXT_PROFILE_CALLBACK, NEXT_PROFILE_CALLBACK),
Markup.button.callback(
LEAVE_PROFILES_CALLBACK,
LEAVE_PROFILES_CALLBACK,
),
],
]).resize(true).reply_markup,
});

await ctx.scene.enter(PROFILES_WIZARD_ID);
}

@Help()
@Hears(HELP_CALLBACK)
async onHelp(): Promise<MsgKey> {
return 'commands.help';
}

Expand All @@ -82,12 +115,4 @@ export class AppUpdate {
),
);
}

@Action('coop')
@Command('coop')
async onCoop(@Ctx() ctx: MessageContext): Promise<MsgKey> {
this.logger.log(`/coop ${ctx.from.username}`);

return 'commands.coop';
}
}
1 change: 1 addition & 0 deletions src/controllers/wizards/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './change-lang.wizard';
export * from './next.wizard';
export * from './profiles.wizard';
export * from './register.wizard';
7 changes: 2 additions & 5 deletions src/controllers/wizards/next.wizard.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { Ctx, Wizard, WizardStep } from 'nestjs-telegraf';
import { NEXT_WIZARD_ID } from 'src/core/constants';
import { MAIN_MENU_MARKUP, NEXT_WIZARD_ID } from 'src/core/constants';
import { MessageContext, MsgWithExtra } from 'src/types';
import { ReplyUseCases } from 'src/use-cases/reply';

@Wizard(NEXT_WIZARD_ID)
export class NextActionWizard {
constructor(private readonly replyUseCases: ReplyUseCases) {}

@WizardStep(1)
async onEnter(@Ctx() ctx: MessageContext): Promise<MsgWithExtra> {
await ctx.scene.leave();
return [
'messages.next_action',
{
reply_markup: await this.replyUseCases.getMainMenuMarkup(ctx),
reply_markup: MAIN_MENU_MARKUP,
},
];
}
Expand Down
Loading

0 comments on commit b051f3d

Please sign in to comment.