@2byte/tgbot-framework 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +300 -300
  2. package/bin/2byte-cli.ts +97 -84
  3. package/package.json +6 -2
  4. package/src/cli/CreateBotCommand.ts +181 -181
  5. package/src/cli/GenerateCommand.ts +195 -111
  6. package/src/cli/InitCommand.ts +107 -107
  7. package/src/console/migrate.ts +82 -82
  8. package/src/core/ApiService.ts +21 -0
  9. package/src/core/ApiServiceManager.ts +63 -0
  10. package/src/core/App.ts +1113 -1042
  11. package/src/core/BotArtisan.ts +79 -79
  12. package/src/core/BotMigration.ts +30 -30
  13. package/src/core/BotSeeder.ts +66 -66
  14. package/src/core/Model.ts +84 -80
  15. package/src/core/utils.ts +2 -2
  16. package/src/illumination/Artisan.ts +149 -149
  17. package/src/illumination/InlineKeyboard.ts +61 -44
  18. package/src/illumination/Message2Byte.ts +255 -254
  19. package/src/illumination/Message2ByteLiveProgressive.ts +278 -278
  20. package/src/illumination/Message2bytePool.ts +107 -107
  21. package/src/illumination/Migration.ts +186 -186
  22. package/src/illumination/RunSectionRoute.ts +85 -85
  23. package/src/illumination/Section.ts +410 -430
  24. package/src/illumination/SectionComponent.ts +64 -64
  25. package/src/illumination/Telegraf2byteContext.ts +32 -32
  26. package/src/index.ts +35 -33
  27. package/src/libs/TelegramAccountControl.ts +738 -523
  28. package/src/types.ts +188 -186
  29. package/src/user/UserModel.ts +297 -288
  30. package/src/user/UserStore.ts +119 -119
  31. package/src/workflow/services/MassSendApiService.ts +80 -0
  32. package/templates/bot/.env.example +18 -17
  33. package/templates/bot/artisan.ts +8 -8
  34. package/templates/bot/bot.ts +79 -77
  35. package/templates/bot/database/dbConnector.ts +4 -4
  36. package/templates/bot/database/migrate.ts +9 -9
  37. package/templates/bot/database/migrations/001_create_users.sql +18 -18
  38. package/templates/bot/database/seed.ts +14 -14
  39. package/templates/bot/package.json +30 -30
  40. package/templates/bot/sectionList.ts +9 -7
  41. package/templates/bot/sections/ExampleInputSection.ts +85 -0
  42. package/templates/bot/sections/ExampleLiveTaskerSection.ts +60 -0
  43. package/templates/bot/sections/HomeSection.ts +63 -65
  44. package/templates/bot/workflow/services/ExampleServise.ts +24 -0
@@ -1,83 +1,83 @@
1
- #!/usr/bin/env bun
2
- import { Database } from 'bun:sqlite';
3
- import { Migration } from '../illumination/Migration';
4
- import path from 'path';
5
-
6
- type setupParams = {
7
- pathDatabase?: string;
8
- pathMigrations?: string;
9
- };
10
-
11
- async function main(params: setupParams = {}) {
12
-
13
- const MIGRATIONS_PATH = params.pathMigrations || path.join(__dirname, 'migrations');
14
-
15
- const command = process.argv[2];
16
- const args = process.argv.slice(3);
17
-
18
- if (!command) {
19
- showHelp();
20
- return;
21
- }
22
-
23
- const db = new Database(params.pathDatabase || __dirname + '/database/database.sqlite');
24
-
25
- const migration = new Migration(db, MIGRATIONS_PATH);
26
-
27
- try {
28
- switch (command) {
29
- case 'create':
30
- if (args.length === 0) {
31
- console.error('❌ Ошибка: Требуется имя миграции');
32
- console.log('Использование: migrate create migration_name');
33
- return;
34
- }
35
- await Migration.create(args[0], MIGRATIONS_PATH);
36
- break;
37
-
38
- case 'up':
39
- await migration.up();
40
- console.log('✅ Миграции выполнены');
41
- break;
42
-
43
- case 'down':
44
- const steps = args[0] ? parseInt(args[0]) : 1;
45
- await migration.down(steps);
46
- console.log('✅ Откат миграций выполнен');
47
- break;
48
-
49
- case 'status':
50
- migration.status();
51
- break;
52
-
53
- default:
54
- console.error(`❌ Неизвестная команда: ${command}`);
55
- showHelp();
56
- }
57
- } catch (error) {
58
- console.error('❌ Ошибка:', error);
59
- } finally {
60
- db.close();
61
- }
62
- }
63
-
64
- function showHelp() {
65
- console.log(`
66
- 🗃️ Migration CLI для SQLite
67
-
68
- Доступные команды:
69
- create <name> Создать новую миграцию
70
- up Выполнить все новые миграции
71
- down [steps] Откатить последние миграции (по умолчанию 1)
72
- status Показать статус миграций
73
-
74
- Примеры:
75
- migrate create create_users_table
76
- migrate up
77
- migrate down 2
78
- migrate status
79
- `);
80
- }
81
- export const setupMigrations = async (params: setupParams) => {
82
- return main(params).catch(console.error);
1
+ #!/usr/bin/env bun
2
+ import { Database } from 'bun:sqlite';
3
+ import { Migration } from '../illumination/Migration';
4
+ import path from 'path';
5
+
6
+ type setupParams = {
7
+ pathDatabase?: string;
8
+ pathMigrations?: string;
9
+ };
10
+
11
+ async function main(params: setupParams = {}) {
12
+
13
+ const MIGRATIONS_PATH = params.pathMigrations || path.join(__dirname, 'migrations');
14
+
15
+ const command = process.argv[2];
16
+ const args = process.argv.slice(3);
17
+
18
+ if (!command) {
19
+ showHelp();
20
+ return;
21
+ }
22
+
23
+ const db = new Database(params.pathDatabase || __dirname + '/database/database.sqlite');
24
+
25
+ const migration = new Migration(db, MIGRATIONS_PATH);
26
+
27
+ try {
28
+ switch (command) {
29
+ case 'create':
30
+ if (args.length === 0) {
31
+ console.error('❌ Ошибка: Требуется имя миграции');
32
+ console.log('Использование: migrate create migration_name');
33
+ return;
34
+ }
35
+ await Migration.create(args[0], MIGRATIONS_PATH);
36
+ break;
37
+
38
+ case 'up':
39
+ await migration.up();
40
+ console.log('✅ Миграции выполнены');
41
+ break;
42
+
43
+ case 'down':
44
+ const steps = args[0] ? parseInt(args[0]) : 1;
45
+ await migration.down(steps);
46
+ console.log('✅ Откат миграций выполнен');
47
+ break;
48
+
49
+ case 'status':
50
+ migration.status();
51
+ break;
52
+
53
+ default:
54
+ console.error(`❌ Неизвестная команда: ${command}`);
55
+ showHelp();
56
+ }
57
+ } catch (error) {
58
+ console.error('❌ Ошибка:', error);
59
+ } finally {
60
+ db.close();
61
+ }
62
+ }
63
+
64
+ function showHelp() {
65
+ console.log(`
66
+ 🗃️ Migration CLI для SQLite
67
+
68
+ Доступные команды:
69
+ create <name> Создать новую миграцию
70
+ up Выполнить все новые миграции
71
+ down [steps] Откатить последние миграции (по умолчанию 1)
72
+ status Показать статус миграций
73
+
74
+ Примеры:
75
+ migrate create create_users_table
76
+ migrate up
77
+ migrate down 2
78
+ migrate status
79
+ `);
80
+ }
81
+ export const setupMigrations = async (params: setupParams) => {
82
+ return main(params).catch(console.error);
83
83
  }
@@ -0,0 +1,21 @@
1
+ import { App } from "./App";
2
+
3
+ export abstract class ApiService {
4
+
5
+ constructor(
6
+ protected app: App,
7
+ public name: string
8
+ ) {}
9
+
10
+ async setup(): Promise<void> {
11
+ // Implement your API logic here
12
+ }
13
+
14
+ async unsetup(): Promise<void> {
15
+ // Implement your API logic here
16
+ }
17
+
18
+ async run(): Promise<void> {
19
+ // Implement your API logic here
20
+ }
21
+ }
@@ -0,0 +1,63 @@
1
+ import { App } from "./App";
2
+ import { ApiService } from "./ApiService";
3
+ import { readdirSync } from "fs";
4
+
5
+ export class ApiServiceManager {
6
+ private services: Map<string, ApiService> = new Map();
7
+
8
+ constructor(private app: App) {}
9
+
10
+ static init(app: App): ApiServiceManager {
11
+ return new ApiServiceManager(app);
12
+ }
13
+
14
+ async loadServicesFromDirectory(pathDirectory: string): Promise<void> {
15
+ for (const entry of readdirSync(pathDirectory, { withFileTypes: true })) {
16
+ if (entry.isFile() && entry.name.endsWith(".ts")) {
17
+ const serviceModule = await import(`${pathDirectory}/${entry.name}`);
18
+ const ServiceClass = serviceModule.default;
19
+ const serviceInstance = new ServiceClass(this.app);
20
+ this.registerService(entry.name.replace(".ts", ""), serviceInstance);
21
+ }
22
+ }
23
+ }
24
+
25
+ public registerService(name: string, service: ApiService): void {
26
+ this.services.set(name, service);
27
+ }
28
+
29
+ public getService(name: string): ApiService | undefined {
30
+ return this.services.get(name);
31
+ }
32
+
33
+ public async setupService(name: string): Promise<void> {
34
+ const service = this.getService(name);
35
+ if (service) {
36
+ await service.setup();
37
+ }
38
+ }
39
+
40
+ public async unsetupService(name: string): Promise<void> {
41
+ const service = this.getService(name);
42
+ if (service) {
43
+ await service.unsetup();
44
+ }
45
+ }
46
+
47
+ public async runService(name: string): Promise<void> {
48
+ const service = this.getService(name);
49
+ if (service) {
50
+ await service.run();
51
+ }
52
+ }
53
+
54
+ public getAll(): Map<string, ApiService> {
55
+ return this.services;
56
+ }
57
+
58
+ public async unsetupAllServices(): Promise<void> {
59
+ for (const [name, service] of this.services) {
60
+ await service.unsetup();
61
+ }
62
+ }
63
+ }