evogram-gramjs 1.1.0 → 1.1.1
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/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 +95 -0
- package/lib/commands/AddAccount.command.d.ts +19 -0
- package/lib/commands/AddAccount.command.js +461 -0
- package/lib/commands/index.d.ts +2 -0
- package/lib/commands/index.js +5 -0
- package/lib/commands/managment/DeleteAccount.command.d.ts +0 -0
- package/{src/commands/managment/DeleteAccount.command.ts → lib/commands/managment/DeleteAccount.command.js} +1 -2
- 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 +72 -0
- package/lib/sessions/SessionAuth.js +327 -0
- package/lib/sessions/SessionLogger.d.ts +84 -0
- package/lib/sessions/SessionLogger.js +196 -0
- package/lib/sessions/SessionManager.d.ts +84 -0
- package/lib/sessions/SessionManager.js +198 -0
- package/lib/test.d.ts +1 -0
- package/lib/test.js +144 -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.json +1 -2
- package/src/EvogramGramJS.ts +0 -98
- package/src/commands/Accounts.command.ts +0 -89
- package/src/commands/AddAccount.command.ts +0 -449
- package/src/commands/index.ts +0 -2
- package/src/config/database.config.ts +0 -75
- package/src/entities/Session.entity.ts +0 -58
- package/src/entities/SessionEventLog.entity.ts +0 -41
- package/src/index.ts +0 -7
- package/src/services/DatabaseService.ts +0 -82
- package/src/services/ImageUploadService.ts +0 -49
- package/src/sessions/Session.ts +0 -21
- package/src/sessions/SessionAuth.ts +0 -356
- package/src/sessions/SessionLogger.ts +0 -208
- package/src/sessions/SessionManager.ts +0 -211
- package/src/types/auth.types.ts +0 -94
- package/src/types/session.types.ts +0 -96
- package/src/utils/Deferrer.ts +0 -12
|
@@ -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, page?: number): Promise<any>;
|
|
4
|
+
handleMessage(context: CommandContext, message: MessageContext): Promise<any>;
|
|
5
|
+
inlineExecute(context: InlineQueryContext): Promise<void>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
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, page) {
|
|
11
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
if (!sessionId) {
|
|
14
|
+
const sessions = yield EvogramGramJS_1.EvogramGramJS.sessionManager.getAllLoadedSessions();
|
|
15
|
+
//@ts-ignore
|
|
16
|
+
return (_a = context[context.callbackQuery ? 'edit' : 'send']) === null || _a === void 0 ? void 0 : _a.call(context, {
|
|
17
|
+
// prettier-ignore
|
|
18
|
+
text: '<blockquote><b>📊 Список аккаунтов</b></blockquote>\n\n' +
|
|
19
|
+
'<i>Панель управлениями Вашими аккаунтами</i>',
|
|
20
|
+
parse_mode: 'HTML',
|
|
21
|
+
reply_markup: {
|
|
22
|
+
inline_keyboard: [
|
|
23
|
+
[
|
|
24
|
+
{ text: '📋 Список аккаунтов', switch_inline_query_current_chat: ' ', command: AccountsCommand_1 },
|
|
25
|
+
{ text: '➕ Добавить аккаунт', command: AddAccount_command_1.AddAccountCommand },
|
|
26
|
+
],
|
|
27
|
+
...sessions.slice((Number(page) || 0) * 10, (Number(page) || 0) * 10 + 10).map((x) => { var _a, _b, _c; return [{ text: `[${((_a = x.db) === null || _a === void 0 ? void 0 : _a.error) ? '❌' : '✅'}] ${((_b = x.db) === null || _b === void 0 ? void 0 : _b.firstName) || ((_c = x.db) === null || _c === void 0 ? void 0 : _c.username) || 'Безымянный'}`, command: AccountsCommand_1, payload: { sessionId: x.sessionId } }]; }),
|
|
28
|
+
(0, evogram_1.Pagination)({ pages: Math.ceil(sessions.length / 10), currentPage: Number(page) || 0, command: AccountsCommand_1 }),
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
const session = EvogramGramJS_1.EvogramGramJS.sessionManager.getSession(sessionId);
|
|
34
|
+
const db = yield (session === null || session === void 0 ? void 0 : session.db());
|
|
35
|
+
const me = yield (session === null || session === void 0 ? void 0 : session.client.getMe().then((x) => x).catch(() => null));
|
|
36
|
+
//@ts-ignore
|
|
37
|
+
return (_b = context[context.callbackQuery ? 'edit' : 'send']) === null || _b === void 0 ? void 0 : _b.call(context, {
|
|
38
|
+
// prettier-ignore
|
|
39
|
+
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` +
|
|
40
|
+
`<i>— ID: ${db === null || db === void 0 ? void 0 : db.userId}</i>\n` +
|
|
41
|
+
`<i>— Phone: ${db === null || db === void 0 ? void 0 : db.phoneNumber}</i>\n\n` +
|
|
42
|
+
`<b>${me ? '✅ Активен и доступен к работе' : (db === null || db === void 0 ? void 0 : db.error) ? `❌ ${db === null || db === void 0 ? void 0 : db.error}` : '❌ Неавторизованный'}</b>`,
|
|
43
|
+
parse_mode: 'HTML',
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
handleMessage(context, message) {
|
|
48
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
if (!message.viaBot)
|
|
50
|
+
return;
|
|
51
|
+
message.delete().catch(() => null);
|
|
52
|
+
return context.redirect(AccountsCommand_1, { sessionId: message.text });
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
inlineExecute(context) {
|
|
56
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const accounts = EvogramGramJS_1.EvogramGramJS.sessionManager.getAllSessions();
|
|
58
|
+
context.answer(yield Promise.all(accounts.map((x) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const db = yield x.db();
|
|
60
|
+
return {
|
|
61
|
+
type: 'article',
|
|
62
|
+
id: x.sessionId,
|
|
63
|
+
title: db ? `${db === null || db === void 0 ? void 0 : db.firstName} ${(db === null || db === void 0 ? void 0 : db.lastName) || ''}` : 'Безымянный',
|
|
64
|
+
description: (db === null || db === void 0 ? void 0 : db.error) ? `❌ ${db === null || db === void 0 ? void 0 : db.error}` : db ? '✅ Аккаунт активен' : '❌ Неавторизованный',
|
|
65
|
+
thumbnail_url: (db === null || db === void 0 ? void 0 : db.avatarUrl) || undefined,
|
|
66
|
+
input_message_content: {
|
|
67
|
+
message_text: x.sessionId,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}))), {
|
|
71
|
+
switch_pm_text: accounts.length > 0 ? `Добавлено ${accounts.length} аккаунтов` : 'Нет доступных аккаунтов',
|
|
72
|
+
switch_pm_parameter: 'accounts',
|
|
73
|
+
cache_time: 0,
|
|
74
|
+
is_personal: true,
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
exports.AccountsCommand = AccountsCommand;
|
|
80
|
+
tslib_1.__decorate([
|
|
81
|
+
tslib_1.__param(1, (0, evogram_1.CommandArgument)('sessionId?')),
|
|
82
|
+
tslib_1.__param(2, (0, evogram_1.CommandArgument)('page?')),
|
|
83
|
+
tslib_1.__metadata("design:type", Function),
|
|
84
|
+
tslib_1.__metadata("design:paramtypes", [evogram_1.CommandContext, String, Number]),
|
|
85
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
86
|
+
], AccountsCommand.prototype, "execute", null);
|
|
87
|
+
tslib_1.__decorate([
|
|
88
|
+
(0, evogram_1.CommandUpdate)('message'),
|
|
89
|
+
tslib_1.__metadata("design:type", Function),
|
|
90
|
+
tslib_1.__metadata("design:paramtypes", [evogram_1.CommandContext, evogram_1.MessageContext]),
|
|
91
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
92
|
+
], AccountsCommand.prototype, "handleMessage", null);
|
|
93
|
+
exports.AccountsCommand = AccountsCommand = AccountsCommand_1 = tslib_1.__decorate([
|
|
94
|
+
(0, evogram_1.CommandD)({ name: 'accounts', backButton: 'Главное меню' })
|
|
95
|
+
], AccountsCommand);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Command, CommandContext, MessageContext } from 'evogram';
|
|
2
|
+
export declare class AddAccountCommand extends Command {
|
|
3
|
+
execute(context: CommandContext): Promise<void>;
|
|
4
|
+
}
|
|
5
|
+
export declare class AddAccountByCodeCommand extends Command {
|
|
6
|
+
execute(context: CommandContext, phone: string, code: string, password: string): Promise<void>;
|
|
7
|
+
handleMessage(context: CommandContext, message: MessageContext): Promise<void>;
|
|
8
|
+
onError(context: CommandContext, error: Error): void;
|
|
9
|
+
}
|
|
10
|
+
export declare class AddAccountByQRCodeCommand extends Command {
|
|
11
|
+
execute(context: CommandContext, qrcode: string, password: string): Promise<void>;
|
|
12
|
+
handleMessage(context: CommandContext, message: MessageContext): Promise<void>;
|
|
13
|
+
onError(context: CommandContext, error: Error): void;
|
|
14
|
+
}
|
|
15
|
+
export declare class AddAccountByStringSessionCommand extends Command {
|
|
16
|
+
execute(context: CommandContext, stringSession: string): Promise<void>;
|
|
17
|
+
handleMessage(context: CommandContext, message: MessageContext): Promise<void>;
|
|
18
|
+
onError(context: CommandContext, error: Error): void;
|
|
19
|
+
}
|