evogram-gramjs 1.0.0
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/.evogram/7878190870/database.db +0 -0
- package/lib/EvogramGramJS.d.ts +51 -0
- package/lib/EvogramGramJS.js +99 -0
- package/lib/commands/Accounts.command.d.ts +6 -0
- package/lib/commands/Accounts.command.js +90 -0
- package/lib/commands/AddAccount.command.d.ts +6 -0
- package/lib/commands/AddAccount.command.js +170 -0
- package/lib/commands/index.d.ts +0 -0
- package/lib/commands/index.js +1 -0
- package/lib/commands/managment/DeleteAccount.command.d.ts +0 -0
- package/lib/commands/managment/DeleteAccount.command.js +12 -0
- package/lib/config/database.config.d.ts +26 -0
- package/lib/config/database.config.js +31 -0
- package/lib/entities/Session.entity.d.ts +28 -0
- package/lib/entities/Session.entity.js +71 -0
- package/lib/entities/SessionEventLog.entity.d.ts +22 -0
- package/lib/entities/SessionEventLog.entity.js +50 -0
- package/lib/examples/auth.example.d.ts +10 -0
- package/lib/examples/auth.example.js +126 -0
- package/lib/examples/database.example.d.ts +13 -0
- package/lib/examples/database.example.js +109 -0
- package/lib/examples/usage.example.d.ts +13 -0
- package/lib/examples/usage.example.js +127 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +10 -0
- package/lib/services/DatabaseService.d.ts +30 -0
- package/lib/services/DatabaseService.js +93 -0
- package/lib/services/ImageUploadService.d.ts +15 -0
- package/lib/services/ImageUploadService.js +56 -0
- package/lib/sessions/Session.d.ts +13 -0
- package/lib/sessions/Session.js +25 -0
- package/lib/sessions/SessionAuth.d.ts +62 -0
- package/lib/sessions/SessionAuth.js +165 -0
- package/lib/sessions/SessionLogger.d.ts +84 -0
- package/lib/sessions/SessionLogger.js +196 -0
- package/lib/sessions/SessionManager.d.ts +79 -0
- package/lib/sessions/SessionManager.js +184 -0
- package/lib/types/auth.types.d.ts +90 -0
- package/lib/types/auth.types.js +19 -0
- package/lib/types/session.types.d.ts +87 -0
- package/lib/types/session.types.js +21 -0
- package/lib/utils/Deferrer.d.ts +6 -0
- package/lib/utils/Deferrer.js +14 -0
- package/package-lock.json +6 -0
- package/package.json +27 -0
- package/src/EvogramGramJS.ts +98 -0
- package/src/commands/Accounts.command.ts +84 -0
- package/src/commands/AddAccount.command.ts +171 -0
- package/src/commands/index.ts +0 -0
- package/src/commands/managment/DeleteAccount.command.ts +13 -0
- package/src/config/database.config.ts +75 -0
- package/src/entities/Session.entity.ts +58 -0
- package/src/entities/SessionEventLog.entity.ts +41 -0
- package/src/index.ts +7 -0
- package/src/services/DatabaseService.ts +82 -0
- package/src/services/ImageUploadService.ts +49 -0
- package/src/sessions/Session.ts +21 -0
- package/src/sessions/SessionAuth.ts +173 -0
- package/src/sessions/SessionLogger.ts +208 -0
- package/src/sessions/SessionManager.ts +190 -0
- package/src/types/auth.types.ts +94 -0
- package/src/types/session.types.ts +96 -0
- package/src/utils/Deferrer.ts +12 -0
- package/tsconfig.json +17 -0
|
Binary file
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { DatabaseConfig } from './config/database.config';
|
|
2
|
+
import { DatabaseService } from './services/DatabaseService';
|
|
3
|
+
import { SessionManager } from './sessions/SessionManager';
|
|
4
|
+
/**
|
|
5
|
+
* Главный статический класс для работы с EvogramGramJS
|
|
6
|
+
* Управляет сессиями Telegram и базой данных
|
|
7
|
+
*/
|
|
8
|
+
export declare class EvogramGramJS {
|
|
9
|
+
private static _sessionManager;
|
|
10
|
+
private static _databaseService;
|
|
11
|
+
private static _telegramAppId;
|
|
12
|
+
private static _telegramAppHash;
|
|
13
|
+
/**
|
|
14
|
+
* Инициализирует EvogramGramJS
|
|
15
|
+
*
|
|
16
|
+
* @param telegramAppId API ID из Telegram
|
|
17
|
+
* @param telegramAppHash API Hash из Telegram
|
|
18
|
+
* @param databaseConfig Конфигурация базы данных (опционально)
|
|
19
|
+
*/
|
|
20
|
+
static initialize(telegramAppId: number, telegramAppHash: string, databaseConfig?: DatabaseConfig): void;
|
|
21
|
+
/**
|
|
22
|
+
* Получает менеджер сессий
|
|
23
|
+
*
|
|
24
|
+
* @returns SessionManager
|
|
25
|
+
* @throws Error если EvogramGramJS не инициализирован
|
|
26
|
+
*/
|
|
27
|
+
static get sessionManager(): SessionManager;
|
|
28
|
+
/**
|
|
29
|
+
* Получает сервис базы данных
|
|
30
|
+
*
|
|
31
|
+
* @returns DatabaseService
|
|
32
|
+
* @throws Error если EvogramGramJS не инициализирован
|
|
33
|
+
*/
|
|
34
|
+
static get databaseService(): DatabaseService;
|
|
35
|
+
/**
|
|
36
|
+
* Инициализирует базу данных
|
|
37
|
+
*
|
|
38
|
+
* @param config Конфигурация базы данных
|
|
39
|
+
*/
|
|
40
|
+
static initializeDatabase(config: DatabaseConfig): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Закрывает подключение к базе данных
|
|
43
|
+
*/
|
|
44
|
+
static closeDatabase(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Проверяет, инициализирован ли EvogramGramJS
|
|
47
|
+
*
|
|
48
|
+
* @returns true, если инициализирован
|
|
49
|
+
*/
|
|
50
|
+
static isInitialized(): boolean;
|
|
51
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EvogramGramJS = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const DatabaseService_1 = require("./services/DatabaseService");
|
|
6
|
+
const SessionManager_1 = require("./sessions/SessionManager");
|
|
7
|
+
/**
|
|
8
|
+
* Главный статический класс для работы с EvogramGramJS
|
|
9
|
+
* Управляет сессиями Telegram и базой данных
|
|
10
|
+
*/
|
|
11
|
+
class EvogramGramJS {
|
|
12
|
+
/**
|
|
13
|
+
* Инициализирует EvogramGramJS
|
|
14
|
+
*
|
|
15
|
+
* @param telegramAppId API ID из Telegram
|
|
16
|
+
* @param telegramAppHash API Hash из Telegram
|
|
17
|
+
* @param databaseConfig Конфигурация базы данных (опционально)
|
|
18
|
+
*/
|
|
19
|
+
static initialize(telegramAppId, telegramAppHash, databaseConfig) {
|
|
20
|
+
this._telegramAppId = telegramAppId;
|
|
21
|
+
this._telegramAppHash = telegramAppHash;
|
|
22
|
+
// Инициализируем сервис базы данных
|
|
23
|
+
this._databaseService = new DatabaseService_1.DatabaseService();
|
|
24
|
+
// Инициализируем менеджер сессий с поддержкой БД
|
|
25
|
+
this._sessionManager = new SessionManager_1.SessionManager(telegramAppId, telegramAppHash, this._databaseService);
|
|
26
|
+
// Инициализируем базу данных асинхронно
|
|
27
|
+
if (databaseConfig) {
|
|
28
|
+
this._databaseService
|
|
29
|
+
.initialize(databaseConfig)
|
|
30
|
+
.then(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
// Автоматически загружаем сессии из базы данных после инициализации
|
|
32
|
+
if (this._sessionManager)
|
|
33
|
+
yield this._sessionManager.initialize();
|
|
34
|
+
}))
|
|
35
|
+
.catch((error) => {
|
|
36
|
+
console.error('Ошибка инициализации базы данных:', error);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Получает менеджер сессий
|
|
42
|
+
*
|
|
43
|
+
* @returns SessionManager
|
|
44
|
+
* @throws Error если EvogramGramJS не инициализирован
|
|
45
|
+
*/
|
|
46
|
+
static get sessionManager() {
|
|
47
|
+
if (!this._sessionManager)
|
|
48
|
+
throw new Error('EvogramGramJS не инициализирован. Вызовите EvogramGramJS.initialize() сначала.');
|
|
49
|
+
return this._sessionManager;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Получает сервис базы данных
|
|
53
|
+
*
|
|
54
|
+
* @returns DatabaseService
|
|
55
|
+
* @throws Error если EvogramGramJS не инициализирован
|
|
56
|
+
*/
|
|
57
|
+
static get databaseService() {
|
|
58
|
+
if (!this._databaseService)
|
|
59
|
+
throw new Error('EvogramGramJS не инициализирован. Вызовите EvogramGramJS.initialize() сначала.');
|
|
60
|
+
return this._databaseService;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Инициализирует базу данных
|
|
64
|
+
*
|
|
65
|
+
* @param config Конфигурация базы данных
|
|
66
|
+
*/
|
|
67
|
+
static initializeDatabase(config) {
|
|
68
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
if (!this._databaseService)
|
|
70
|
+
throw new Error('EvogramGramJS не инициализирован. Вызовите EvogramGramJS.initialize() сначала.');
|
|
71
|
+
yield this._databaseService.initialize(config);
|
|
72
|
+
// Автоматически загружаем сессии из базы данных после инициализации
|
|
73
|
+
if (this._sessionManager)
|
|
74
|
+
yield this._sessionManager.initialize();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Закрывает подключение к базе данных
|
|
79
|
+
*/
|
|
80
|
+
static closeDatabase() {
|
|
81
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
if (this._databaseService)
|
|
83
|
+
yield this._databaseService.close();
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Проверяет, инициализирован ли EvogramGramJS
|
|
88
|
+
*
|
|
89
|
+
* @returns true, если инициализирован
|
|
90
|
+
*/
|
|
91
|
+
static isInitialized() {
|
|
92
|
+
return this._sessionManager !== null && this._databaseService !== null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.EvogramGramJS = EvogramGramJS;
|
|
96
|
+
EvogramGramJS._sessionManager = null;
|
|
97
|
+
EvogramGramJS._databaseService = null;
|
|
98
|
+
EvogramGramJS._telegramAppId = null;
|
|
99
|
+
EvogramGramJS._telegramAppHash = null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Command, CommandContext, InlineQueryContext, MessageContext } from 'evogram';
|
|
2
|
+
export declare class AccountsCommand extends Command {
|
|
3
|
+
execute(context: CommandContext, sessionId?: string): Promise<any>;
|
|
4
|
+
handleMessage(context: CommandContext, message: MessageContext): Promise<any>;
|
|
5
|
+
inlineExecute(context: InlineQueryContext): Promise<void>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var AccountsCommand_1;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.AccountsCommand = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const evogram_1 = require("evogram");
|
|
7
|
+
const EvogramGramJS_1 = require("../EvogramGramJS");
|
|
8
|
+
const AddAccount_command_1 = require("./AddAccount.command");
|
|
9
|
+
let AccountsCommand = AccountsCommand_1 = class AccountsCommand extends evogram_1.Command {
|
|
10
|
+
execute(context, sessionId) {
|
|
11
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
if (!sessionId)
|
|
14
|
+
//@ts-ignore
|
|
15
|
+
return (_a = context[context.callbackQuery ? 'edit' : 'send']) === null || _a === void 0 ? void 0 : _a.call(context, {
|
|
16
|
+
// prettier-ignore
|
|
17
|
+
text: '<blockquote><b>📊 Список аккаунтов</b></blockquote>\n\n' +
|
|
18
|
+
'<i>Панель управлениями Вашими аккаунтами</i>',
|
|
19
|
+
parse_mode: 'HTML',
|
|
20
|
+
reply_markup: {
|
|
21
|
+
inline_keyboard: [
|
|
22
|
+
[
|
|
23
|
+
{ text: 'Добавить', command: AddAccount_command_1.AddAccountCommand, payload: { phone: null, session: null, code: null, password: null } },
|
|
24
|
+
{ text: 'Список', command: AccountsCommand_1, switch_inline_query_current_chat: ' ' },
|
|
25
|
+
],
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
const session = EvogramGramJS_1.EvogramGramJS.sessionManager.getSession(sessionId);
|
|
30
|
+
const db = yield (session === null || session === void 0 ? void 0 : session.db());
|
|
31
|
+
const me = yield (session === null || session === void 0 ? void 0 : session.client.getMe().then((x) => x).catch(() => null));
|
|
32
|
+
//@ts-ignore
|
|
33
|
+
return (_b = context[context.callbackQuery ? 'edit' : 'send']) === null || _b === void 0 ? void 0 : _b.call(context, {
|
|
34
|
+
// prettier-ignore
|
|
35
|
+
text: `<blockquote><b>👤 Аккаунт <a href="tg://user?id=${db === null || db === void 0 ? void 0 : db.userId}">${db === null || db === void 0 ? void 0 : db.firstName}</a></b></blockquote>\n\n` +
|
|
36
|
+
`<i>— ID: ${db === null || db === void 0 ? void 0 : db.userId}</i>\n` +
|
|
37
|
+
`<i>— Phone: ${db === null || db === void 0 ? void 0 : db.phoneNumber}</i>\n\n` +
|
|
38
|
+
`<b>${me ? '✅ Активен и доступен к работе' : (db === null || db === void 0 ? void 0 : db.error) ? `❌ ${db === null || db === void 0 ? void 0 : db.error}` : '❌ Неавторизованный'}</b>`,
|
|
39
|
+
parse_mode: 'HTML',
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
handleMessage(context, message) {
|
|
44
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
if (!message.viaBot)
|
|
46
|
+
return;
|
|
47
|
+
message.delete().catch(() => null);
|
|
48
|
+
return context.redirect(AccountsCommand_1, { sessionId: message.text });
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
inlineExecute(context) {
|
|
52
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const accounts = EvogramGramJS_1.EvogramGramJS.sessionManager.getAllSessions();
|
|
54
|
+
context.answer(yield Promise.all(accounts.map((x) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const db = yield x.db();
|
|
56
|
+
return {
|
|
57
|
+
type: 'article',
|
|
58
|
+
id: x.sessionId,
|
|
59
|
+
title: db ? `${db === null || db === void 0 ? void 0 : db.firstName} ${(db === null || db === void 0 ? void 0 : db.lastName) || ''}` : 'Безымянный',
|
|
60
|
+
description: (db === null || db === void 0 ? void 0 : db.error) ? `❌ ${db === null || db === void 0 ? void 0 : db.error}` : db ? '✅ Аккаунт активен' : '❌ Неавторизованный',
|
|
61
|
+
thumbnail_url: (db === null || db === void 0 ? void 0 : db.avatarUrl) || undefined,
|
|
62
|
+
input_message_content: {
|
|
63
|
+
message_text: x.sessionId,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}))), {
|
|
67
|
+
switch_pm_text: accounts.length > 0 ? `Добавлено ${accounts.length} аккаунтов` : 'Нет доступных аккаунтов',
|
|
68
|
+
switch_pm_parameter: 'accounts',
|
|
69
|
+
cache_time: 0,
|
|
70
|
+
is_personal: true,
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.AccountsCommand = AccountsCommand;
|
|
76
|
+
tslib_1.__decorate([
|
|
77
|
+
tslib_1.__param(1, (0, evogram_1.CommandArgument)('sessionId?')),
|
|
78
|
+
tslib_1.__metadata("design:type", Function),
|
|
79
|
+
tslib_1.__metadata("design:paramtypes", [evogram_1.CommandContext, String]),
|
|
80
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
81
|
+
], AccountsCommand.prototype, "execute", null);
|
|
82
|
+
tslib_1.__decorate([
|
|
83
|
+
(0, evogram_1.CommandUpdate)('message'),
|
|
84
|
+
tslib_1.__metadata("design:type", Function),
|
|
85
|
+
tslib_1.__metadata("design:paramtypes", [evogram_1.CommandContext, evogram_1.MessageContext]),
|
|
86
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
87
|
+
], AccountsCommand.prototype, "handleMessage", null);
|
|
88
|
+
exports.AccountsCommand = AccountsCommand = AccountsCommand_1 = tslib_1.__decorate([
|
|
89
|
+
(0, evogram_1.CommandD)({ name: 'accounts' })
|
|
90
|
+
], AccountsCommand);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Command, CommandContext, MessageContext } from 'evogram';
|
|
2
|
+
export declare class AddAccountCommand extends Command {
|
|
3
|
+
execute(context: CommandContext, phone: string, code: string, password: string): Promise<void>;
|
|
4
|
+
handleMessage(context: CommandContext, message: MessageContext): Promise<void>;
|
|
5
|
+
onError(context: CommandContext, error: Error): void;
|
|
6
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var AddAccountCommand_1;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.AddAccountCommand = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const evogram_1 = require("evogram");
|
|
7
|
+
const EvogramGramJS_1 = require("../EvogramGramJS");
|
|
8
|
+
const auth_types_1 = require("../types/auth.types");
|
|
9
|
+
let AddAccountCommand = AddAccountCommand_1 = class AddAccountCommand extends evogram_1.Command {
|
|
10
|
+
execute(context, phone, code, password) {
|
|
11
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
const session = EvogramGramJS_1.EvogramGramJS.sessionManager.getSession(yield context.storage.get('session'));
|
|
13
|
+
context.send(`Вы успешно добавили аккаунт ${yield session.client
|
|
14
|
+
.getMe()
|
|
15
|
+
.then((user) => user.username)
|
|
16
|
+
.catch(() => 'unknown')}`);
|
|
17
|
+
yield context.storage.clearAll();
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
handleMessage(context, message) {
|
|
21
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
if (!(message === null || message === void 0 ? void 0 : message.text))
|
|
23
|
+
return;
|
|
24
|
+
console.log({ session: yield context.storage.get('session'), phone: yield context.storage.get('phone'), code: yield context.storage.get('code'), password: yield context.storage.get('password'), command: context.state.command, stage: yield context.storage.get('stage') });
|
|
25
|
+
yield context.edit('⏳').catch(() => { });
|
|
26
|
+
yield message.delete().catch(() => { });
|
|
27
|
+
if (!(yield context.storage.get('phone')))
|
|
28
|
+
context.redirect(AddAccountCommand_1, { phone: message.text });
|
|
29
|
+
else if ((yield context.storage.get('stage')) === 'code')
|
|
30
|
+
context.redirect(AddAccountCommand_1, { code: message.text });
|
|
31
|
+
else if ((yield context.storage.get('stage')) === 'password')
|
|
32
|
+
context.redirect(AddAccountCommand_1, { password: message.text });
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
onError(context, error) {
|
|
36
|
+
var _a;
|
|
37
|
+
//@ts-ignore
|
|
38
|
+
(_a = context[context.callbackQuery ? 'edit' : 'send']) === null || _a === void 0 ? void 0 : _a.call(context, {
|
|
39
|
+
// prettier-ignore
|
|
40
|
+
text: '<blockquote><b>❗️Произошла ошибка при добавлении аккаунта</b></blockquote>\n\n' +
|
|
41
|
+
error.message,
|
|
42
|
+
parse_mode: 'HTML',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.AddAccountCommand = AddAccountCommand;
|
|
47
|
+
tslib_1.__decorate([
|
|
48
|
+
tslib_1.__param(1, (0, evogram_1.CommandStorageArgument)('phone', (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ context, value }) {
|
|
49
|
+
var _b, _c;
|
|
50
|
+
if (value) {
|
|
51
|
+
if (!(yield context.storage.get('session'))) {
|
|
52
|
+
const session = yield EvogramGramJS_1.EvogramGramJS.sessionManager.addSession({
|
|
53
|
+
sessionId: value,
|
|
54
|
+
logging: {
|
|
55
|
+
enabled: true,
|
|
56
|
+
logsDirectory: './logs',
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
const result = yield session.auth.start(value);
|
|
60
|
+
if (result.success) {
|
|
61
|
+
yield context.storage.set('stage', 'code');
|
|
62
|
+
yield context.storage.set('session', session.sessionId);
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
context.state.command = undefined;
|
|
67
|
+
yield context.storage.clearAll();
|
|
68
|
+
//@ts-ignore
|
|
69
|
+
(_b = context[context.callbackQuery ? 'edit' : 'send']) === null || _b === void 0 ? void 0 : _b.call(context, {
|
|
70
|
+
// prettier-ignore
|
|
71
|
+
text: '<blockquote><b>❗️Произошла ошибка при добавлении аккаунта</b></blockquote>\n\n' +
|
|
72
|
+
result.error,
|
|
73
|
+
parse_mode: 'HTML',
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
//@ts-ignore
|
|
82
|
+
(_c = context[context.callbackQuery ? 'edit' : 'send']) === null || _c === void 0 ? void 0 : _c.call(context, {
|
|
83
|
+
// prettier-ignore
|
|
84
|
+
text: '<blockquote><b>➕ Добавление аккаунта</b></blockquote>\n\n' +
|
|
85
|
+
'<i>Отправьте номер телефона в следующем сообщении</i>',
|
|
86
|
+
parse_mode: 'HTML',
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}))),
|
|
90
|
+
tslib_1.__param(2, (0, evogram_1.CommandStorageArgument)('code', (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ context, value }) {
|
|
91
|
+
var _b, _c, _d;
|
|
92
|
+
if (value) {
|
|
93
|
+
const session = EvogramGramJS_1.EvogramGramJS.sessionManager.getSession(yield context.storage.get('session'));
|
|
94
|
+
if (((_b = session.auth.state) === null || _b === void 0 ? void 0 : _b.stage) !== auth_types_1.AuthState.WAITING_CODE)
|
|
95
|
+
return value;
|
|
96
|
+
const result = yield session.auth.setCode(value);
|
|
97
|
+
if (result.success) {
|
|
98
|
+
yield context.storage.set('stage', 'password');
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
//@ts-ignore
|
|
103
|
+
(_c = context[context.callbackQuery ? 'edit' : 'send']) === null || _c === void 0 ? void 0 : _c.call(context, {
|
|
104
|
+
// prettier-ignore
|
|
105
|
+
text: '<blockquote><b>➕ Добавление аккаунта</b></blockquote>\n\n' +
|
|
106
|
+
'<i>Отправьте код подтверждения, отправленный на аккаунт, в следующем сообщении</i>\n\n' +
|
|
107
|
+
`<blockquote><b>❗️Произошла ошибка</b></blockquote>\n\n` +
|
|
108
|
+
result.error,
|
|
109
|
+
parse_mode: 'HTML',
|
|
110
|
+
});
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
//@ts-ignore
|
|
116
|
+
(_d = context[context.callbackQuery ? 'edit' : 'send']) === null || _d === void 0 ? void 0 : _d.call(context, {
|
|
117
|
+
// prettier-ignore
|
|
118
|
+
text: '<blockquote><b>➕ Добавление аккаунта</b></blockquote>\n\n' +
|
|
119
|
+
'<i>Отправьте код подтверждения, отправленный на аккаунт, в следующем сообщении</i>',
|
|
120
|
+
parse_mode: 'HTML',
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}))),
|
|
124
|
+
tslib_1.__param(3, (0, evogram_1.CommandStorageArgument)('password', (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ context, value }) {
|
|
125
|
+
var _b, _c;
|
|
126
|
+
const session = EvogramGramJS_1.EvogramGramJS.sessionManager.getSession(yield context.storage.get('session'));
|
|
127
|
+
const isRequired = yield session.auth.isRequiredPassword();
|
|
128
|
+
if (!isRequired || value === 'none')
|
|
129
|
+
return 'none';
|
|
130
|
+
if (value) {
|
|
131
|
+
const session = EvogramGramJS_1.EvogramGramJS.sessionManager.getSession(yield context.storage.get('session'));
|
|
132
|
+
const result = yield session.auth.setPassword(value);
|
|
133
|
+
if (result.success) {
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
//@ts-ignore
|
|
138
|
+
(_b = context[context.callbackQuery ? 'edit' : 'send']) === null || _b === void 0 ? void 0 : _b.call(context, {
|
|
139
|
+
// prettier-ignore
|
|
140
|
+
text: '<blockquote><b>➕ Добавление аккаунта</b></blockquote>\n\n' +
|
|
141
|
+
'<i>На аккаунте включен 2FA. Отправьте пароль для 2FA в следующем сообщении</i>\n\n' +
|
|
142
|
+
`<blockquote><b>❗️Произошла ошибка</b></blockquote>\n\n` +
|
|
143
|
+
result.error,
|
|
144
|
+
parse_mode: 'HTML',
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
//@ts-ignore
|
|
150
|
+
(_c = context[context.callbackQuery ? 'edit' : 'send']) === null || _c === void 0 ? void 0 : _c.call(context, {
|
|
151
|
+
// prettier-ignore
|
|
152
|
+
text: '<blockquote><b>➕ Добавление аккаунта</b></blockquote>\n\n' +
|
|
153
|
+
'<i>На аккаунте включен 2FA. Отправьте пароль для 2FA в следующем сообщении</i>',
|
|
154
|
+
parse_mode: 'HTML',
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}))),
|
|
158
|
+
tslib_1.__metadata("design:type", Function),
|
|
159
|
+
tslib_1.__metadata("design:paramtypes", [evogram_1.CommandContext, String, String, String]),
|
|
160
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
161
|
+
], AddAccountCommand.prototype, "execute", null);
|
|
162
|
+
tslib_1.__decorate([
|
|
163
|
+
(0, evogram_1.CommandUpdate)('message'),
|
|
164
|
+
tslib_1.__metadata("design:type", Function),
|
|
165
|
+
tslib_1.__metadata("design:paramtypes", [evogram_1.CommandContext, evogram_1.MessageContext]),
|
|
166
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
167
|
+
], AddAccountCommand.prototype, "handleMessage", null);
|
|
168
|
+
exports.AddAccountCommand = AddAccountCommand = AddAccountCommand_1 = tslib_1.__decorate([
|
|
169
|
+
(0, evogram_1.CommandD)({ name: 'addaccount', argsMethod: 'parameterized', backButton: 'Список аккаунтов' })
|
|
170
|
+
], AddAccountCommand);
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import { Command, CommandArgument, CommandContext, CommandD } from 'evogram'
|
|
3
|
+
// import { EvogramGramJS } from '../../EvogramGramJS'
|
|
4
|
+
// @CommandD({ name: 'deleteaccount', argsMethod: 'parameterized' })
|
|
5
|
+
// export class DeleteAccountCommand extends Command {
|
|
6
|
+
// public async execute(context: CommandContext, @CommandArgument('sessionId') sessionId: string) {
|
|
7
|
+
// const session = EvogramGramJS.sessionManager.getSession(sessionId)
|
|
8
|
+
// if (!session) return context.send('Сессия не найдена')
|
|
9
|
+
// await EvogramGramJS.databaseService.deleteSession(sessionId)
|
|
10
|
+
// return context.send('Сессия успешно удалена')
|
|
11
|
+
// }
|
|
12
|
+
// }
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DataSourceOptions } from 'typeorm';
|
|
2
|
+
/**
|
|
3
|
+
* Конфигурация базы данных
|
|
4
|
+
*/
|
|
5
|
+
export interface DatabaseConfig {
|
|
6
|
+
/** Тип базы данных */
|
|
7
|
+
type?: 'sqlite' | 'postgres' | 'mysql' | 'mariadb';
|
|
8
|
+
/** Путь к файлу БД (для SQLite) или строка подключения */
|
|
9
|
+
database?: string;
|
|
10
|
+
/** Хост БД (для PostgreSQL/MySQL) */
|
|
11
|
+
host?: string;
|
|
12
|
+
/** Порт БД (для PostgreSQL/MySQL) */
|
|
13
|
+
port?: number;
|
|
14
|
+
/** Имя пользователя БД */
|
|
15
|
+
username?: string;
|
|
16
|
+
/** Пароль БД */
|
|
17
|
+
password?: string;
|
|
18
|
+
/** Включить синхронизацию схемы (только для разработки) */
|
|
19
|
+
synchronize?: boolean;
|
|
20
|
+
/** Включить логирование SQL запросов */
|
|
21
|
+
logging?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Создает конфигурацию DataSource для TypeORM
|
|
25
|
+
*/
|
|
26
|
+
export declare function createDataSourceOptions(config?: DatabaseConfig): DataSourceOptions;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDataSourceOptions = createDataSourceOptions;
|
|
4
|
+
const Session_entity_1 = require("../entities/Session.entity");
|
|
5
|
+
const SessionEventLog_entity_1 = require("../entities/SessionEventLog.entity");
|
|
6
|
+
/**
|
|
7
|
+
* Создает конфигурацию DataSource для TypeORM
|
|
8
|
+
*/
|
|
9
|
+
function createDataSourceOptions(config = {}) {
|
|
10
|
+
const { type = 'sqlite', database = './data/evogram.db', host, port, username, password, synchronize = false, logging = false } = config;
|
|
11
|
+
const baseOptions = {
|
|
12
|
+
type: type,
|
|
13
|
+
entities: [Session_entity_1.Session, SessionEventLog_entity_1.SessionEventLog],
|
|
14
|
+
synchronize,
|
|
15
|
+
logging,
|
|
16
|
+
};
|
|
17
|
+
if (type === 'sqlite') {
|
|
18
|
+
// Для SQLite используем специальную конфигурацию
|
|
19
|
+
const sqliteOptions = Object.assign(Object.assign({}, baseOptions), { type: 'better-sqlite3', database });
|
|
20
|
+
return sqliteOptions;
|
|
21
|
+
}
|
|
22
|
+
if (type === 'postgres') {
|
|
23
|
+
return Object.assign(Object.assign({}, baseOptions), { type: 'postgres', host: host || 'localhost', port: port || 5432, username,
|
|
24
|
+
password, database: database || 'evogram' });
|
|
25
|
+
}
|
|
26
|
+
if (type === 'mysql' || type === 'mariadb') {
|
|
27
|
+
return Object.assign(Object.assign({}, baseOptions), { type: type === 'mariadb' ? 'mariadb' : 'mysql', host: host || 'localhost', port: port || 3306, username,
|
|
28
|
+
password, database: database || 'evogram' });
|
|
29
|
+
}
|
|
30
|
+
return baseOptions;
|
|
31
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SessionEventLog } from './SessionEventLog.entity';
|
|
2
|
+
/**
|
|
3
|
+
* Сущность сессии Telegram в базе данных
|
|
4
|
+
*/
|
|
5
|
+
export declare class Session {
|
|
6
|
+
/** Уникальный идентификатор сессии */
|
|
7
|
+
sessionId: string;
|
|
8
|
+
/** API ID из Telegram */
|
|
9
|
+
apiId?: number;
|
|
10
|
+
/** API Hash из Telegram */
|
|
11
|
+
apiHash?: string;
|
|
12
|
+
userId: number;
|
|
13
|
+
username?: string;
|
|
14
|
+
firstName?: string;
|
|
15
|
+
lastName?: string;
|
|
16
|
+
phoneNumber?: string;
|
|
17
|
+
error?: string;
|
|
18
|
+
/** Строка сессии (зашифрованная) */
|
|
19
|
+
sessionString?: string;
|
|
20
|
+
/** Дополнительные опции клиента (JSON) */
|
|
21
|
+
clientOptions?: string;
|
|
22
|
+
/** URL аватарки пользователя */
|
|
23
|
+
avatarUrl?: string;
|
|
24
|
+
/** Связанные события сессии */
|
|
25
|
+
eventLogs: SessionEventLog[];
|
|
26
|
+
/** Время создания сессии */
|
|
27
|
+
createdAt: Date;
|
|
28
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Session = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
const SessionEventLog_entity_1 = require("./SessionEventLog.entity");
|
|
7
|
+
/**
|
|
8
|
+
* Сущность сессии Telegram в базе данных
|
|
9
|
+
*/
|
|
10
|
+
let Session = class Session {
|
|
11
|
+
};
|
|
12
|
+
exports.Session = Session;
|
|
13
|
+
tslib_1.__decorate([
|
|
14
|
+
(0, typeorm_1.PrimaryColumn)({ type: 'varchar', length: 255 }),
|
|
15
|
+
tslib_1.__metadata("design:type", String)
|
|
16
|
+
], Session.prototype, "sessionId", void 0);
|
|
17
|
+
tslib_1.__decorate([
|
|
18
|
+
(0, typeorm_1.Column)({ type: 'integer', nullable: true }),
|
|
19
|
+
tslib_1.__metadata("design:type", Number)
|
|
20
|
+
], Session.prototype, "apiId", void 0);
|
|
21
|
+
tslib_1.__decorate([
|
|
22
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 255, nullable: true }),
|
|
23
|
+
tslib_1.__metadata("design:type", String)
|
|
24
|
+
], Session.prototype, "apiHash", void 0);
|
|
25
|
+
tslib_1.__decorate([
|
|
26
|
+
(0, typeorm_1.Column)({ type: 'bigint' }),
|
|
27
|
+
tslib_1.__metadata("design:type", Number)
|
|
28
|
+
], Session.prototype, "userId", void 0);
|
|
29
|
+
tslib_1.__decorate([
|
|
30
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 255, nullable: true }),
|
|
31
|
+
tslib_1.__metadata("design:type", String)
|
|
32
|
+
], Session.prototype, "username", void 0);
|
|
33
|
+
tslib_1.__decorate([
|
|
34
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 255, nullable: true }),
|
|
35
|
+
tslib_1.__metadata("design:type", String)
|
|
36
|
+
], Session.prototype, "firstName", void 0);
|
|
37
|
+
tslib_1.__decorate([
|
|
38
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 255, nullable: true }),
|
|
39
|
+
tslib_1.__metadata("design:type", String)
|
|
40
|
+
], Session.prototype, "lastName", void 0);
|
|
41
|
+
tslib_1.__decorate([
|
|
42
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 255, nullable: true }),
|
|
43
|
+
tslib_1.__metadata("design:type", String)
|
|
44
|
+
], Session.prototype, "phoneNumber", void 0);
|
|
45
|
+
tslib_1.__decorate([
|
|
46
|
+
(0, typeorm_1.Column)({ type: 'text', nullable: true }),
|
|
47
|
+
tslib_1.__metadata("design:type", String)
|
|
48
|
+
], Session.prototype, "error", void 0);
|
|
49
|
+
tslib_1.__decorate([
|
|
50
|
+
(0, typeorm_1.Column)({ type: 'text', nullable: true }),
|
|
51
|
+
tslib_1.__metadata("design:type", String)
|
|
52
|
+
], Session.prototype, "sessionString", void 0);
|
|
53
|
+
tslib_1.__decorate([
|
|
54
|
+
(0, typeorm_1.Column)({ type: 'text', nullable: true }),
|
|
55
|
+
tslib_1.__metadata("design:type", String)
|
|
56
|
+
], Session.prototype, "clientOptions", void 0);
|
|
57
|
+
tslib_1.__decorate([
|
|
58
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 500, nullable: true }),
|
|
59
|
+
tslib_1.__metadata("design:type", String)
|
|
60
|
+
], Session.prototype, "avatarUrl", void 0);
|
|
61
|
+
tslib_1.__decorate([
|
|
62
|
+
(0, typeorm_1.OneToMany)(() => SessionEventLog_entity_1.SessionEventLog, (eventLog) => eventLog.session, { cascade: true }),
|
|
63
|
+
tslib_1.__metadata("design:type", Array)
|
|
64
|
+
], Session.prototype, "eventLogs", void 0);
|
|
65
|
+
tslib_1.__decorate([
|
|
66
|
+
(0, typeorm_1.CreateDateColumn)(),
|
|
67
|
+
tslib_1.__metadata("design:type", Date)
|
|
68
|
+
], Session.prototype, "createdAt", void 0);
|
|
69
|
+
exports.Session = Session = tslib_1.__decorate([
|
|
70
|
+
(0, typeorm_1.Entity)('sessions')
|
|
71
|
+
], Session);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Session } from './Session.entity';
|
|
2
|
+
/**
|
|
3
|
+
* Сущность для логирования событий сессии
|
|
4
|
+
*/
|
|
5
|
+
export declare class SessionEventLog {
|
|
6
|
+
/** Уникальный идентификатор записи */
|
|
7
|
+
id: number;
|
|
8
|
+
/** Идентификатор сессии */
|
|
9
|
+
sessionId: string;
|
|
10
|
+
/** Тип события */
|
|
11
|
+
eventType: string;
|
|
12
|
+
/** Уровень логирования */
|
|
13
|
+
level: string;
|
|
14
|
+
/** Сообщение события */
|
|
15
|
+
message: string;
|
|
16
|
+
/** Дополнительные данные события (JSON) */
|
|
17
|
+
data?: string;
|
|
18
|
+
/** Время создания события */
|
|
19
|
+
createdAt: Date;
|
|
20
|
+
/** Связь с сессией */
|
|
21
|
+
session: Session;
|
|
22
|
+
}
|