anote
1import { Keywords } from "../flows/Keywords";
2import { Command } from "./Command";
3import { Delete } from "./Delete";
4import { Help } from "./Help";
5import { Ls } from "./Ls";
6import { Mkdir } from "./Mkdir";
7import { Error } from "./Error";
8import { Context } from "telegraf";
9import { Cat } from "./Cat";
10import { Echo } from "./Echo";
11import { Add } from "./Add";
12
13const commandsMap = {
14del: Delete,
15help: Help,
16ls: Ls,
17mkdir: Mkdir,
18cat: Cat,
19echo: Echo,
20add: Add
21};
22
23export type Keys = keyof typeof commandsMap;
24
25export class CommandFactory {
26ctx: Context;
27
28constructor(ctx: Context) {
29this.ctx = ctx;
30}
31
32getCommand(k: Keys): Command {
33switch(k) {
34case Keywords.HELP:
35return new Help(this.ctx);
36case Keywords.LIST:
37return new Ls(this.ctx);
38case Keywords.MKDIR:
39return new Mkdir(this.ctx);
40case Keywords.CAT:
41return new Cat(this.ctx);
42case Keywords.DELETE:
43return new Delete(this.ctx);
44case Keywords.ECHO:
45return new Echo(this.ctx);
46case Keywords.ADD:
47return new Add(this.ctx);
48default:
49return new Error(this.ctx);
50}
51}
52}