@2byte/tgbot-framework 1.0.2 → 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 -84
  15. package/src/core/utils.ts +2 -2
  16. package/src/illumination/Artisan.ts +149 -149
  17. package/src/illumination/InlineKeyboard.ts +61 -60
  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 -410
  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 -738
  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 -63
  44. package/templates/bot/workflow/services/ExampleServise.ts +24 -0
@@ -1,278 +1,278 @@
1
- import Message2byte from "./Message2Byte";
2
- import Message2bytePool from "./Message2bytePool";
3
-
4
- interface ProgressiveItem {
5
- id: number;
6
- text: string;
7
- status?: 'pending' | 'active' | 'completed' | 'error';
8
- caption?: string;
9
- progressBar?: {
10
- active: boolean;
11
- duration?: number;
12
- infinite?: boolean;
13
- };
14
- }
15
-
16
- export default class Message2ByteLiveProgressive {
17
- private message2byte: Message2byte;
18
- private message2bytePool: Message2bytePool;
19
- private items: Map<number, ProgressiveItem> = new Map();
20
- private baseMessage: string = '';
21
- private progressBarTimer?: NodeJS.Timeout;
22
- private progressBarIcons = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
23
- private progressBarIndex = 0;
24
- private activeProgressItem?: number;
25
-
26
- static init(message2byte: Message2byte, message2bytePool: Message2bytePool) {
27
- return new Message2ByteLiveProgressive(message2byte, message2bytePool);
28
- }
29
-
30
- constructor(message2byte: Message2byte, message2bytePool: Message2bytePool) {
31
- this.message2byte = message2byte;
32
- this.message2bytePool = message2bytePool;
33
- }
34
-
35
- /**
36
- * Устанавливает базовое сообщение
37
- */
38
- setBaseMessage(message: string): this {
39
- this.baseMessage = message;
40
- return this;
41
- }
42
-
43
- /**
44
- * Добавляет новый пункт
45
- */
46
- appendItem(id: number, text: string, status: 'pending' | 'active' | 'completed' | 'error' = 'pending'): this {
47
- this.items.set(id, {
48
- id,
49
- text,
50
- status
51
- });
52
- return this;
53
- }
54
-
55
- /**
56
- * Изменяет существующий пункт
57
- */
58
- changeItem(id: number, text: string, status?: 'pending' | 'active' | 'completed' | 'error'): this {
59
- const existingItem = this.items.get(id);
60
- if (existingItem) {
61
- this.items.set(id, {
62
- ...existingItem,
63
- text,
64
- status: status || existingItem.status
65
- });
66
- }
67
- return this;
68
- }
69
-
70
- setItemCaption(id: number, caption: string): this {
71
- const item = this.items.get(id);
72
- if (item) {
73
- item.caption = caption;
74
- }
75
- return this;
76
- }
77
-
78
- changeItemCaption(id: number, caption: string): this {
79
- const item = this.items.get(id);
80
- if (item) {
81
- item.caption = caption;
82
- }
83
- return this;
84
- }
85
-
86
- /**
87
- * Удаляет пункт по ID
88
- */
89
- removeItem(id: number): this {
90
- this.items.delete(id);
91
- return this;
92
- }
93
-
94
- /**
95
- * Изменяет статус пункта
96
- */
97
- setItemStatus(id: number, status: 'pending' | 'active' | 'completed' | 'error'): this {
98
- const item = this.items.get(id);
99
- if (item) {
100
- item.status = status;
101
- }
102
- return this;
103
- }
104
-
105
- setItemStatusError(id: number, errorText?: string): this {
106
- const item = this.items.get(id);
107
- if (item) {
108
- item.status = 'error';
109
- if (errorText) {
110
- item.text += ` - ${errorText}`;
111
- }
112
- }
113
- return this;
114
- }
115
-
116
- setItemStatusCompleted(id: number): this {
117
- const item = this.items.get(id);
118
- if (item) {
119
- item.status = 'completed';
120
- }
121
- return this;
122
- }
123
-
124
- /**
125
- * Запускает прогрессбар для конкретного пункта
126
- */
127
- sleepProgressBar(duration?: number, itemId?: number): this {
128
- if (!itemId) {
129
- itemId = this.items.size > 0 ? Array.from(this.items.keys())[this.items.size - 1] : undefined;
130
- }
131
- if (itemId) {
132
- this.activeProgressItem = itemId;
133
- const item = this.items.get(itemId);
134
- if (item) {
135
- item.progressBar = {
136
- active: true,
137
- duration,
138
- infinite: !duration
139
- };
140
- item.status = 'active';
141
- }
142
- }
143
-
144
- this.startProgressBar(duration);
145
- return this;
146
- }
147
-
148
- /**
149
- * Останавливает прогрессбар
150
- */
151
- stopSleepProgress(): this {
152
- if (this.progressBarTimer) {
153
- clearInterval(this.progressBarTimer);
154
- this.progressBarTimer = undefined;
155
- }
156
-
157
- if (this.activeProgressItem) {
158
- const item = this.items.get(this.activeProgressItem);
159
- if (item && item.progressBar) {
160
- item.progressBar.active = false;
161
- item.status = 'completed';
162
- }
163
- this.activeProgressItem = undefined;
164
- this.updateMessage();
165
- this.message2bytePool.send();
166
- }
167
-
168
- return this;
169
- }
170
-
171
- /**
172
- * Запускает анимацию прогрессбара
173
- */
174
- private startProgressBar(duration?: number): void {
175
- if (this.progressBarTimer) {
176
- clearInterval(this.progressBarTimer);
177
- }
178
-
179
- this.progressBarTimer = setInterval(() => {
180
- this.progressBarIndex = (this.progressBarIndex + 1) % this.progressBarIcons.length;
181
- this.updateMessage();
182
- this.message2bytePool.send();
183
- }, 200);
184
-
185
- if (duration) {
186
- setTimeout(() => {
187
- this.stopSleepProgress();
188
- }, duration);
189
- }
190
- }
191
-
192
- /**
193
- * Обновляет сообщение с текущими пунктами
194
- */
195
- private updateMessage(): void {
196
- let message = this.baseMessage;
197
-
198
- if (this.items.size > 0) {
199
- message += '\n\n';
200
-
201
- // Сортируем пункты по ID
202
- const sortedItems = Array.from(this.items.values()).sort((a, b) => a.id - b.id);
203
-
204
- sortedItems.forEach(item => {
205
- const statusIcon = this.getStatusIcon(item);
206
- const progressIcon = this.getProgressIcon(item);
207
-
208
- message += `${statusIcon} ${item.text}${progressIcon}\n`;
209
-
210
- if (item.caption) {
211
- if (this.message2byte.messageExtra && this.message2byte.messageExtra.parse_mode === 'html') {
212
- message += ` <i>${item.caption}</i>\n`;
213
- } else if (this.message2byte.messageExtra && this.message2byte.messageExtra.parse_mode === 'markdown') {
214
- message += ` _${item.caption}_\n`;
215
- } else {
216
- message += ` ${item.caption}\n`;
217
- }
218
- }
219
- });
220
- }
221
-
222
- this.message2bytePool.update(message.trim());
223
- }
224
-
225
- /**
226
- * Получает иконку статуса для пункта
227
- */
228
- private getStatusIcon(item: ProgressiveItem): string {
229
- switch (item.status) {
230
- case 'pending': return '⏳';
231
- case 'active': return '🔄';
232
- case 'completed': return '✅';
233
- case 'error': return '❌';
234
- default: return '⏳';
235
- }
236
- }
237
-
238
- /**
239
- * Получает иконку прогресса для пункта
240
- */
241
- private getProgressIcon(item: ProgressiveItem): string {
242
- if (item.progressBar?.active && item.id === this.activeProgressItem) {
243
- return ` ${this.progressBarIcons[this.progressBarIndex]}`;
244
- }
245
- return '';
246
- }
247
-
248
- /**
249
- * Очищает все пункты
250
- */
251
- clear(): this {
252
- this.items.clear();
253
- return this;
254
- }
255
-
256
- /**
257
- * Получает все пункты
258
- */
259
- getItems(): ProgressiveItem[] {
260
- return Array.from(this.items.values()).sort((a, b) => a.id - b.id);
261
- }
262
-
263
- /**
264
- * Получает пункт по ID
265
- */
266
- getItem(id: number): ProgressiveItem | undefined {
267
- return this.items.get(id);
268
- }
269
-
270
- /**
271
- * Отправляет сообщение
272
- */
273
- async send() {
274
- this.updateMessage();
275
- const entity = await this.message2bytePool.send();
276
- return entity;
277
- }
278
- }
1
+ import Message2byte from "./Message2Byte";
2
+ import Message2bytePool from "./Message2bytePool";
3
+
4
+ interface ProgressiveItem {
5
+ id: number;
6
+ text: string;
7
+ status?: 'pending' | 'active' | 'completed' | 'error';
8
+ caption?: string;
9
+ progressBar?: {
10
+ active: boolean;
11
+ duration?: number;
12
+ infinite?: boolean;
13
+ };
14
+ }
15
+
16
+ export default class Message2ByteLiveProgressive {
17
+ private message2byte: Message2byte;
18
+ private message2bytePool: Message2bytePool;
19
+ private items: Map<number, ProgressiveItem> = new Map();
20
+ private baseMessage: string = '';
21
+ private progressBarTimer?: NodeJS.Timeout;
22
+ private progressBarIcons = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
23
+ private progressBarIndex = 0;
24
+ private activeProgressItem?: number;
25
+
26
+ static init(message2byte: Message2byte, message2bytePool: Message2bytePool) {
27
+ return new Message2ByteLiveProgressive(message2byte, message2bytePool);
28
+ }
29
+
30
+ constructor(message2byte: Message2byte, message2bytePool: Message2bytePool) {
31
+ this.message2byte = message2byte;
32
+ this.message2bytePool = message2bytePool;
33
+ }
34
+
35
+ /**
36
+ * Устанавливает базовое сообщение
37
+ */
38
+ setBaseMessage(message: string): this {
39
+ this.baseMessage = message;
40
+ return this;
41
+ }
42
+
43
+ /**
44
+ * Добавляет новый пункт
45
+ */
46
+ appendItem(id: number, text: string, status: 'pending' | 'active' | 'completed' | 'error' = 'pending'): this {
47
+ this.items.set(id, {
48
+ id,
49
+ text,
50
+ status
51
+ });
52
+ return this;
53
+ }
54
+
55
+ /**
56
+ * Изменяет существующий пункт
57
+ */
58
+ changeItem(id: number, text: string, status?: 'pending' | 'active' | 'completed' | 'error'): this {
59
+ const existingItem = this.items.get(id);
60
+ if (existingItem) {
61
+ this.items.set(id, {
62
+ ...existingItem,
63
+ text,
64
+ status: status || existingItem.status
65
+ });
66
+ }
67
+ return this;
68
+ }
69
+
70
+ setItemCaption(id: number, caption: string): this {
71
+ const item = this.items.get(id);
72
+ if (item) {
73
+ item.caption = caption;
74
+ }
75
+ return this;
76
+ }
77
+
78
+ changeItemCaption(id: number, caption: string): this {
79
+ const item = this.items.get(id);
80
+ if (item) {
81
+ item.caption = caption;
82
+ }
83
+ return this;
84
+ }
85
+
86
+ /**
87
+ * Удаляет пункт по ID
88
+ */
89
+ removeItem(id: number): this {
90
+ this.items.delete(id);
91
+ return this;
92
+ }
93
+
94
+ /**
95
+ * Изменяет статус пункта
96
+ */
97
+ setItemStatus(id: number, status: 'pending' | 'active' | 'completed' | 'error'): this {
98
+ const item = this.items.get(id);
99
+ if (item) {
100
+ item.status = status;
101
+ }
102
+ return this;
103
+ }
104
+
105
+ setItemStatusError(id: number, errorText?: string): this {
106
+ const item = this.items.get(id);
107
+ if (item) {
108
+ item.status = 'error';
109
+ if (errorText) {
110
+ item.text += ` - ${errorText}`;
111
+ }
112
+ }
113
+ return this;
114
+ }
115
+
116
+ setItemStatusCompleted(id: number): this {
117
+ const item = this.items.get(id);
118
+ if (item) {
119
+ item.status = 'completed';
120
+ }
121
+ return this;
122
+ }
123
+
124
+ /**
125
+ * Запускает прогрессбар для конкретного пункта
126
+ */
127
+ sleepProgressBar(duration?: number, itemId?: number): this {
128
+ if (!itemId) {
129
+ itemId = this.items.size > 0 ? Array.from(this.items.keys())[this.items.size - 1] : undefined;
130
+ }
131
+ if (itemId) {
132
+ this.activeProgressItem = itemId;
133
+ const item = this.items.get(itemId);
134
+ if (item) {
135
+ item.progressBar = {
136
+ active: true,
137
+ duration,
138
+ infinite: !duration
139
+ };
140
+ item.status = 'active';
141
+ }
142
+ }
143
+
144
+ this.startProgressBar(duration);
145
+ return this;
146
+ }
147
+
148
+ /**
149
+ * Останавливает прогрессбар
150
+ */
151
+ async stopSleepProgress(): Promise<this> {
152
+ if (this.progressBarTimer) {
153
+ clearInterval(this.progressBarTimer);
154
+ this.progressBarTimer = undefined;
155
+ }
156
+
157
+ if (this.activeProgressItem) {
158
+ const item = this.items.get(this.activeProgressItem);
159
+ if (item && item.progressBar) {
160
+ item.progressBar.active = false;
161
+ item.status = 'completed';
162
+ }
163
+ this.activeProgressItem = undefined;
164
+ this.updateMessage();
165
+ await this.message2bytePool.send();
166
+ }
167
+
168
+ return this;
169
+ }
170
+
171
+ /**
172
+ * Запускает анимацию прогрессбара
173
+ */
174
+ private startProgressBar(duration?: number): void {
175
+ if (this.progressBarTimer) {
176
+ clearInterval(this.progressBarTimer);
177
+ }
178
+
179
+ this.progressBarTimer = setInterval(() => {
180
+ this.progressBarIndex = (this.progressBarIndex + 1) % this.progressBarIcons.length;
181
+ this.updateMessage();
182
+ this.message2bytePool.send();
183
+ }, 200);
184
+
185
+ if (duration) {
186
+ setTimeout(() => {
187
+ this.stopSleepProgress();
188
+ }, duration);
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Обновляет сообщение с текущими пунктами
194
+ */
195
+ private updateMessage(): void {
196
+ let message = this.baseMessage;
197
+
198
+ if (this.items.size > 0) {
199
+ message += '\n\n';
200
+
201
+ // Сортируем пункты по ID
202
+ const sortedItems = Array.from(this.items.values()).sort((a, b) => a.id - b.id);
203
+
204
+ sortedItems.forEach(item => {
205
+ const statusIcon = this.getStatusIcon(item);
206
+ const progressIcon = this.getProgressIcon(item);
207
+
208
+ message += `${statusIcon} ${item.text}${progressIcon}\n`;
209
+
210
+ if (item.caption) {
211
+ if (this.message2byte.messageExtra && this.message2byte.messageExtra.parse_mode === 'html') {
212
+ message += ` <i>${item.caption}</i>\n`;
213
+ } else if (this.message2byte.messageExtra && this.message2byte.messageExtra.parse_mode === 'markdown') {
214
+ message += ` _${item.caption}_\n`;
215
+ } else {
216
+ message += ` ${item.caption}\n`;
217
+ }
218
+ }
219
+ });
220
+ }
221
+
222
+ this.message2bytePool.update(message.trim());
223
+ }
224
+
225
+ /**
226
+ * Получает иконку статуса для пункта
227
+ */
228
+ private getStatusIcon(item: ProgressiveItem): string {
229
+ switch (item.status) {
230
+ case 'pending': return '⏳';
231
+ case 'active': return '🔄';
232
+ case 'completed': return '✅';
233
+ case 'error': return '❌';
234
+ default: return '⏳';
235
+ }
236
+ }
237
+
238
+ /**
239
+ * Получает иконку прогресса для пункта
240
+ */
241
+ private getProgressIcon(item: ProgressiveItem): string {
242
+ if (item.progressBar?.active && item.id === this.activeProgressItem) {
243
+ return ` ${this.progressBarIcons[this.progressBarIndex]}`;
244
+ }
245
+ return '';
246
+ }
247
+
248
+ /**
249
+ * Очищает все пункты
250
+ */
251
+ clear(): this {
252
+ this.items.clear();
253
+ return this;
254
+ }
255
+
256
+ /**
257
+ * Получает все пункты
258
+ */
259
+ getItems(): ProgressiveItem[] {
260
+ return Array.from(this.items.values()).sort((a, b) => a.id - b.id);
261
+ }
262
+
263
+ /**
264
+ * Получает пункт по ID
265
+ */
266
+ getItem(id: number): ProgressiveItem | undefined {
267
+ return this.items.get(id);
268
+ }
269
+
270
+ /**
271
+ * Отправляет сообщение
272
+ */
273
+ async send() {
274
+ this.updateMessage();
275
+ const entity = await this.message2bytePool.send();
276
+ return entity;
277
+ }
278
+ }