@2byte/tgbot-framework 1.0.15 → 1.0.16
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.
package/package.json
CHANGED
|
@@ -33,57 +33,28 @@ export class Artisan {
|
|
|
33
33
|
// Создаем файл секции
|
|
34
34
|
fs.writeFileSync(sectionPath, template);
|
|
35
35
|
console.log(`✅ Created section ${sectionName} at ${sectionPath}`);
|
|
36
|
+
console.log('To enable the section, add key it to the sections array in ' + process.cwd() + '/sectionList.ts');
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
/**
|
|
39
40
|
* Форматирует имя секции (первая буква заглавная, остальные строчные)
|
|
40
41
|
*/
|
|
41
42
|
private formatSectionName(name: string): string {
|
|
42
|
-
return name.charAt(0).toUpperCase() + name.slice(1)
|
|
43
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
/**
|
|
46
47
|
* Возвращает шаблон для новой секции
|
|
47
48
|
*/
|
|
48
49
|
private getSectionTemplate(name: string): string {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"${name.toLowerCase()}.index": "index",
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
public sectionId = "${name.toLowerCase()}";
|
|
61
|
-
private mainInlineKeyboard: InlineKeyboard;
|
|
62
|
-
|
|
63
|
-
constructor(options: SectionOptions) {
|
|
64
|
-
super(options);
|
|
65
|
-
|
|
66
|
-
this.mainInlineKeyboard = this.makeInlineKeyboard([
|
|
67
|
-
[this.makeInlineButton("🏠 На главную", "home.index")],
|
|
68
|
-
]);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public async up(): Promise<void> {}
|
|
72
|
-
public async down(): Promise<void> {}
|
|
73
|
-
public async setup(): Promise<void> {}
|
|
74
|
-
public async unsetup(): Promise<void> {}
|
|
75
|
-
|
|
76
|
-
async index() {
|
|
77
|
-
const message = \`
|
|
78
|
-
👋 Welcome to ${name} Section
|
|
79
|
-
\`;
|
|
80
|
-
|
|
81
|
-
await this.message(message)
|
|
82
|
-
.inlineKeyboard(this.mainInlineKeyboard)
|
|
83
|
-
.send();
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
`;
|
|
50
|
+
const filePath = path.join(__dirname, '../../templates', 'TemplateSection.ts');
|
|
51
|
+
let template = fs.readFileSync(filePath, 'utf-8');
|
|
52
|
+
const nameCamelCase = name.charAt(0).toLowerCase() + name.slice(1);
|
|
53
|
+
|
|
54
|
+
template = template.replace(/\$\{name\}/g, nameCamelCase);
|
|
55
|
+
template = template.replace(/\$\{commandName\}/g, name.toLowerCase());
|
|
56
|
+
template = template.replace(/TemplateSection/g, `${name}Section`);
|
|
57
|
+
return template;
|
|
87
58
|
}
|
|
88
59
|
|
|
89
60
|
/**
|
package/src/types.ts
CHANGED
package/src/user/UserModel.ts
CHANGED
|
@@ -47,10 +47,18 @@ export class UserModel extends Model {
|
|
|
47
47
|
return this.attributes;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
get id(): number
|
|
50
|
+
get id(): number {
|
|
51
51
|
return this.attributes.id;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
get tgUsername(): string {
|
|
55
|
+
return this.attributes.tg_username;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get tgName(): string {
|
|
59
|
+
return this.attributes.tg_first_name + (this.attributes.tg_last_name ? " " + this.attributes.tg_last_name : "");
|
|
60
|
+
}
|
|
61
|
+
|
|
54
62
|
get lastMessageIds(): number[] {
|
|
55
63
|
return this.serviceAttributes.lastMessageIds;
|
|
56
64
|
}
|
|
@@ -153,6 +161,7 @@ export class UserModel extends Model {
|
|
|
153
161
|
|
|
154
162
|
const now = new Date().toISOString();
|
|
155
163
|
return UserModel.make({
|
|
164
|
+
id: 0,
|
|
156
165
|
tg_id: 0,
|
|
157
166
|
tg_username: tgUsername,
|
|
158
167
|
tg_first_name: tgUsername,
|
|
@@ -218,6 +227,10 @@ export class UserModel extends Model {
|
|
|
218
227
|
return this.attributes.role;
|
|
219
228
|
}
|
|
220
229
|
|
|
230
|
+
get roleIsAdmin(): boolean {
|
|
231
|
+
return this.attributes.role === 'admin';
|
|
232
|
+
}
|
|
233
|
+
|
|
221
234
|
get language(): string {
|
|
222
235
|
return this.attributes.language;
|
|
223
236
|
}
|
|
@@ -31,11 +31,10 @@ export class MassSendApiService extends ApiService<MassSendApiParams> {
|
|
|
31
31
|
this.app.debugLog("Received data for mass message:", receivedData);
|
|
32
32
|
|
|
33
33
|
let userIds: number[] = [];
|
|
34
|
-
let message: string = "Hello from MassSendApiService";
|
|
35
34
|
|
|
36
|
-
if (receivedData && typeof receivedData == "object") {
|
|
35
|
+
if (receivedData && typeof receivedData == "object" && receivedData.message) {
|
|
37
36
|
userIds = receivedData?.userIds || [];
|
|
38
|
-
message = receivedData?.message
|
|
37
|
+
const message = receivedData?.message;
|
|
39
38
|
|
|
40
39
|
this.sendMassMessage(userIds, message, receivedData.extra);
|
|
41
40
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Section } from "@2byte/tgbot-framework";
|
|
2
|
+
import { SectionOptions } from "@2byte/tgbot-framework";
|
|
3
|
+
import { InlineKeyboard } from "@2byte/tgbot-framework";
|
|
4
|
+
|
|
5
|
+
export default class TemplateSection extends Section {
|
|
6
|
+
static override command = "${commandName}";
|
|
7
|
+
static override description = "${name} section";
|
|
8
|
+
static override actionRoutes = {
|
|
9
|
+
"${name}.index": "index",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
public override sectionId = "${name}";
|
|
13
|
+
private mainInlineKeyboard: InlineKeyboard;
|
|
14
|
+
|
|
15
|
+
constructor(options: SectionOptions) {
|
|
16
|
+
super(options);
|
|
17
|
+
|
|
18
|
+
this.mainInlineKeyboard = this.makeInlineKeyboard().addFootFixedButtons(
|
|
19
|
+
this.makeInlineButton("🏠 На главную", "home.index")
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public override async up(): Promise<void> {}
|
|
24
|
+
public override async down(): Promise<void> {}
|
|
25
|
+
public override async setup(): Promise<void> {}
|
|
26
|
+
public override async unsetup(): Promise<void> {}
|
|
27
|
+
|
|
28
|
+
async index() {
|
|
29
|
+
const message = `
|
|
30
|
+
👋 Welcome to ${this.ctx.user.attributes.tg_username} Section
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
await this.message(message)
|
|
34
|
+
.inlineKeyboard(this.mainInlineKeyboard)
|
|
35
|
+
.send();
|
|
36
|
+
}
|
|
37
|
+
}
|