rubjs 2.7.8 → 2.8.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/package.json +2 -3
- package/rubjs/client.d.ts +2 -2
- package/rubjs/client.js +0 -8
- package/rubjs/methods/utilities/start.js +15 -1
- package/rubjs/network/index.js +23 -1
- package/rubjs/session/index.d.ts +9 -9
- package/rubjs/session/index.js +152 -45
- package/rubjs/types/decorators.d.ts +1 -0
- package/rubjs/methods/messages/sendLive.d.ts +0 -3
- package/rubjs/methods/messages/sendLive.js +0 -17
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "rubjs",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.8.0",
|
4
4
|
"main": "rubjs/index.js",
|
5
5
|
"types": "rubjs/index.d.ts",
|
6
6
|
"keywords": [
|
@@ -25,7 +25,6 @@
|
|
25
25
|
},
|
26
26
|
"dependencies": {
|
27
27
|
"axios": "^1.7.9",
|
28
|
-
"better-sqlite3": "^11.8.1",
|
29
28
|
"input": "^1.0.1",
|
30
29
|
"node-rsa": "^1.1.1",
|
31
30
|
"optional-require": "^1.1.8",
|
@@ -41,4 +40,4 @@
|
|
41
40
|
"rubjs/",
|
42
41
|
"README.md"
|
43
42
|
]
|
44
|
-
}
|
43
|
+
}
|
package/rubjs/client.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import Methods from "./methods";
|
2
2
|
import Network from "./network";
|
3
|
-
import
|
3
|
+
import SessionManager from "./session";
|
4
4
|
import { VoiceChatClient } from "./utils";
|
5
5
|
interface Platform {
|
6
6
|
app_name: string;
|
@@ -24,7 +24,7 @@ declare class Client extends Methods {
|
|
24
24
|
sessionFile: string;
|
25
25
|
platform: PlatformType;
|
26
26
|
userGuid: string | null;
|
27
|
-
sessionDb:
|
27
|
+
sessionDb: SessionManager;
|
28
28
|
initialize: boolean;
|
29
29
|
eventHandlers: {
|
30
30
|
callback: Function;
|
package/rubjs/client.js
CHANGED
@@ -34,14 +34,6 @@ class Client extends methods_1.default {
|
|
34
34
|
this.privateKey = null;
|
35
35
|
this.eventHandlers = [];
|
36
36
|
this.initialize = false;
|
37
|
-
const DBInformation = this.sessionDb.getSession();
|
38
|
-
if (DBInformation) {
|
39
|
-
this.auth = DBInformation.auth;
|
40
|
-
this.userGuid = DBInformation.guid;
|
41
|
-
this.privateKey = DBInformation.private_key;
|
42
|
-
if (typeof DBInformation.agent === "string")
|
43
|
-
this.userAgent = DBInformation.agent || this.userAgent;
|
44
|
-
}
|
45
37
|
this.start();
|
46
38
|
}
|
47
39
|
}
|
@@ -16,6 +16,14 @@ const crypto_1 = __importDefault(require("../../crypto"));
|
|
16
16
|
const input_1 = __importDefault(require("input"));
|
17
17
|
function start() {
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
19
|
+
const DBInformation = this.sessionDb.getSession();
|
20
|
+
if (DBInformation) {
|
21
|
+
this.auth = DBInformation.auth;
|
22
|
+
this.userGuid = DBInformation.guid;
|
23
|
+
this.privateKey = DBInformation.private_key;
|
24
|
+
if (typeof DBInformation.agent === "string")
|
25
|
+
this.userAgent = DBInformation.agent || this.userAgent;
|
26
|
+
}
|
19
27
|
try {
|
20
28
|
this.key = Buffer.from(crypto_1.default.passphrase(this.auth), "utf8");
|
21
29
|
this.decode_auth = crypto_1.default.decode_auth(this.auth);
|
@@ -56,7 +64,13 @@ function start() {
|
|
56
64
|
this.key = Buffer.from(crypto_1.default.passphrase(response.auth), "utf8");
|
57
65
|
this.auth = response.auth;
|
58
66
|
this.decode_auth = crypto_1.default.decode_auth(this.auth);
|
59
|
-
this.sessionDb.saveSession(
|
67
|
+
this.sessionDb.saveSession({
|
68
|
+
phone: response.user.phone,
|
69
|
+
auth: this.auth,
|
70
|
+
guid: response.user.user_guid,
|
71
|
+
agent: this.userAgent,
|
72
|
+
private_key: this.privateKey
|
73
|
+
});
|
60
74
|
yield this.registerDevice();
|
61
75
|
break;
|
62
76
|
}
|
package/rubjs/network/index.js
CHANGED
@@ -200,8 +200,28 @@ class Network {
|
|
200
200
|
return;
|
201
201
|
const update = JSON.parse(crypto_1.default.decrypt(data_enc, this.client.key));
|
202
202
|
this.client.eventHandlers.forEach((_a) => __awaiter(this, [_a], void 0, function* ({ callback, filters = [], updateType }) {
|
203
|
-
var _b;
|
203
|
+
var _b, _c, _d, _e, _f, _g, _h, _j;
|
204
204
|
if (((_b = update[updateType]) === null || _b === void 0 ? void 0 : _b.length) > 0) {
|
205
|
+
let username = null;
|
206
|
+
const isMUp = updateType === "message_updates";
|
207
|
+
if (isMUp) {
|
208
|
+
if (((_c = update === null || update === void 0 ? void 0 : update.show_notifications) === null || _c === void 0 ? void 0 : _c.length) > 0) {
|
209
|
+
const notification = (_d = update === null || update === void 0 ? void 0 : update.show_notifications) === null || _d === void 0 ? void 0 : _d[0];
|
210
|
+
const obg = (_e = notification === null || notification === void 0 ? void 0 : notification.message_data) === null || _e === void 0 ? void 0 : _e.object_guid;
|
211
|
+
if (obg === null || obg === void 0 ? void 0 : obg.startsWith("u0")) {
|
212
|
+
username = notification.title;
|
213
|
+
}
|
214
|
+
else if (obg === null || obg === void 0 ? void 0 : obg.startsWith("g0")) {
|
215
|
+
username = (_f = notification.text) === null || _f === void 0 ? void 0 : _f.split(":")[0];
|
216
|
+
}
|
217
|
+
}
|
218
|
+
else {
|
219
|
+
const chat_updates = (_g = update === null || update === void 0 ? void 0 : update.chat_updates) === null || _g === void 0 ? void 0 : _g[0];
|
220
|
+
username =
|
221
|
+
((_j = (_h = chat_updates === null || chat_updates === void 0 ? void 0 : chat_updates.chat) === null || _h === void 0 ? void 0 : _h.last_message) === null || _j === void 0 ? void 0 : _j.author_title) ||
|
222
|
+
"Unknown User";
|
223
|
+
}
|
224
|
+
}
|
205
225
|
for (let messageData of update[updateType]) {
|
206
226
|
if (!messageData)
|
207
227
|
return;
|
@@ -216,6 +236,8 @@ class Network {
|
|
216
236
|
}
|
217
237
|
return false;
|
218
238
|
});
|
239
|
+
if (isMUp)
|
240
|
+
messageData.message.author_title = username;
|
219
241
|
if (isValid)
|
220
242
|
yield callback(new types_1.Message(this.client, messageData));
|
221
243
|
}
|
package/rubjs/session/index.d.ts
CHANGED
@@ -5,14 +5,14 @@ interface SessionData {
|
|
5
5
|
agent: string;
|
6
6
|
private_key: string;
|
7
7
|
}
|
8
|
-
declare class
|
9
|
-
private
|
10
|
-
private
|
11
|
-
|
12
|
-
|
13
|
-
private
|
8
|
+
declare class SessionManager {
|
9
|
+
private secretKey;
|
10
|
+
private filename;
|
11
|
+
private iv;
|
12
|
+
constructor(filename: string);
|
13
|
+
private encrypt;
|
14
|
+
private decrypt;
|
15
|
+
saveSession(sessionData: SessionData): void;
|
14
16
|
getSession(): SessionData | null;
|
15
|
-
saveSession(phone: string, auth: string, guid: string, agent: string, privateKey: string): void;
|
16
|
-
closeDB(): void;
|
17
17
|
}
|
18
|
-
export default
|
18
|
+
export default SessionManager;
|
package/rubjs/session/index.js
CHANGED
@@ -1,57 +1,164 @@
|
|
1
1
|
"use strict";
|
2
|
+
// import sqlite3 from "sqlite3";
|
2
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
5
|
};
|
5
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
// interface SessionData {
|
8
|
+
// phone: string;
|
9
|
+
// auth: string;
|
10
|
+
// guid: string;
|
11
|
+
// agent: string;
|
12
|
+
// private_key: string;
|
13
|
+
// }
|
14
|
+
// class SQLiteSession {
|
15
|
+
// private dbFile: string;
|
16
|
+
// private db: sqlite3.Database;
|
17
|
+
// constructor(sessionName: string) {
|
18
|
+
// this.dbFile = sessionName.endsWith(".rp") ? sessionName : `${sessionName}.rp`;
|
19
|
+
// this.db = new sqlite3.Database(this.dbFile, (err) => {
|
20
|
+
// if (err) {
|
21
|
+
// console.error("Error opening database:", err);
|
22
|
+
// } else {
|
23
|
+
// this.initializeDB();
|
24
|
+
// }
|
25
|
+
// });
|
26
|
+
// }
|
27
|
+
// private handleError<T>(operation: string, callback: () => T): T | null {
|
28
|
+
// try {
|
29
|
+
// return callback();
|
30
|
+
// } catch (error) {
|
31
|
+
// console.error(`Error in ${operation}:`, error);
|
32
|
+
// console.warn(`Failed to execute ${operation}`);
|
33
|
+
// return null;
|
34
|
+
// }
|
35
|
+
// }
|
36
|
+
// private initializeDB(): void {
|
37
|
+
// this.handleError("initializeDB", () => {
|
38
|
+
// this.db.exec("PRAGMA journal_mode = DELETE");
|
39
|
+
// this.db.get(
|
40
|
+
// "SELECT name FROM sqlite_master WHERE type=? AND name=?",
|
41
|
+
// ["table", "session"],
|
42
|
+
// (err, row) => {
|
43
|
+
// if (!row) {
|
44
|
+
// this.db.run(
|
45
|
+
// `CREATE TABLE session (
|
46
|
+
// phone TEXT PRIMARY KEY,
|
47
|
+
// auth TEXT,
|
48
|
+
// guid TEXT,
|
49
|
+
// agent TEXT,
|
50
|
+
// private_key TEXT
|
51
|
+
// )`
|
52
|
+
// );
|
53
|
+
// }
|
54
|
+
// }
|
55
|
+
// );
|
56
|
+
// });
|
57
|
+
// }
|
58
|
+
// getSession(): SessionData | null {
|
59
|
+
// return this.handleError("getSession", () => {
|
60
|
+
// return new Promise<SessionData | null>((resolve) => {
|
61
|
+
// this.db.get("SELECT * FROM session", (err, row) => {
|
62
|
+
// if (err) {
|
63
|
+
// console.error("Error fetching session:", err);
|
64
|
+
// resolve(null);
|
65
|
+
// } else {
|
66
|
+
// resolve(row as SessionData || null);
|
67
|
+
// }
|
68
|
+
// });
|
69
|
+
// }) as unknown as SessionData | null;
|
70
|
+
// }) as SessionData | null;
|
71
|
+
// }
|
72
|
+
// saveSession(
|
73
|
+
// phone: string,
|
74
|
+
// auth: string,
|
75
|
+
// guid: string,
|
76
|
+
// agent: string,
|
77
|
+
// privateKey: string
|
78
|
+
// ): void {
|
79
|
+
// this.handleError("saveSession", () => {
|
80
|
+
// this.db.run(
|
81
|
+
// `INSERT OR REPLACE INTO session (phone, auth, guid, agent, private_key)
|
82
|
+
// VALUES (?, ?, ?, ?, ?)`,
|
83
|
+
// [phone, auth, guid, agent, privateKey]
|
84
|
+
// );
|
85
|
+
// });
|
86
|
+
// }
|
87
|
+
// closeDB(): void {
|
88
|
+
// this.handleError("closeDB", () => {
|
89
|
+
// this.db.close((err) => {
|
90
|
+
// if (err) {
|
91
|
+
// console.error("Error closing database:", err);
|
92
|
+
// }
|
93
|
+
// });
|
94
|
+
// });
|
95
|
+
// }
|
96
|
+
// }
|
97
|
+
// export default SQLiteSession;
|
98
|
+
const fs_1 = __importDefault(require("fs"));
|
99
|
+
const crypto_1 = __importDefault(require("crypto"));
|
100
|
+
class SessionManager {
|
101
|
+
constructor(filename) {
|
102
|
+
this.secretKey = "12345678901234567890123456789012";
|
103
|
+
this.iv = crypto_1.default.randomBytes(16);
|
104
|
+
this.filename = filename + ".json";
|
12
105
|
}
|
13
|
-
|
106
|
+
encrypt(sessionData) {
|
107
|
+
const cipher = crypto_1.default.createCipheriv("aes-256-cbc", Buffer.from(this.secretKey), this.iv);
|
108
|
+
let encrypted = cipher.update(JSON.stringify(sessionData), "utf8", "hex");
|
109
|
+
encrypted += cipher.final("hex");
|
110
|
+
return encrypted;
|
111
|
+
}
|
112
|
+
decrypt(encryptedData, iv) {
|
113
|
+
const decipher = crypto_1.default.createDecipheriv("aes-256-cbc", Buffer.from(this.secretKey), iv);
|
114
|
+
let decrypted = decipher.update(encryptedData, "hex", "utf8");
|
115
|
+
decrypted += decipher.final("utf8");
|
116
|
+
return JSON.parse(decrypted);
|
117
|
+
}
|
118
|
+
saveSession(sessionData) {
|
119
|
+
const encryptedData = this.encrypt(sessionData);
|
120
|
+
const dataToWrite = {
|
121
|
+
iv: this.iv.toString("hex"),
|
122
|
+
encryptedData: encryptedData,
|
123
|
+
};
|
124
|
+
fs_1.default.writeFileSync(this.filename, JSON.stringify(dataToWrite, null, 2));
|
125
|
+
}
|
126
|
+
getSession() {
|
14
127
|
try {
|
15
|
-
|
128
|
+
if (!fs_1.default.existsSync(this.filename)) {
|
129
|
+
const defaultSessionData = {
|
130
|
+
phone: "",
|
131
|
+
auth: "",
|
132
|
+
guid: "",
|
133
|
+
agent: "",
|
134
|
+
private_key: "",
|
135
|
+
};
|
136
|
+
this.saveSession(defaultSessionData);
|
137
|
+
return defaultSessionData;
|
138
|
+
}
|
139
|
+
const rawData = fs_1.default.readFileSync(this.filename, "utf8");
|
140
|
+
const parsedData = JSON.parse(rawData);
|
141
|
+
return this.decrypt(parsedData.encryptedData, Buffer.from(parsedData.iv, "hex"));
|
16
142
|
}
|
17
143
|
catch (error) {
|
18
|
-
console.error(
|
19
|
-
|
144
|
+
console.error("Error reading or decrypting session data:", error);
|
145
|
+
return null;
|
20
146
|
}
|
21
147
|
}
|
22
|
-
initializeDB() {
|
23
|
-
this.handleError("initializeDB", () => {
|
24
|
-
this.db.pragma("journal_mode = DELETE");
|
25
|
-
const sessionTable = this.db
|
26
|
-
.prepare("SELECT name FROM sqlite_master WHERE type=? AND name=?")
|
27
|
-
.get("table", "session");
|
28
|
-
if (!sessionTable) {
|
29
|
-
this.db.prepare(`CREATE TABLE session (
|
30
|
-
phone TEXT PRIMARY KEY,
|
31
|
-
auth TEXT,
|
32
|
-
guid TEXT,
|
33
|
-
agent TEXT,
|
34
|
-
private_key TEXT
|
35
|
-
)`).run();
|
36
|
-
}
|
37
|
-
});
|
38
|
-
}
|
39
|
-
getSession() {
|
40
|
-
return this.handleError("getSession", () => {
|
41
|
-
const result = this.db.prepare("SELECT * FROM session").get();
|
42
|
-
return result ? result : null;
|
43
|
-
});
|
44
|
-
}
|
45
|
-
saveSession(phone, auth, guid, agent, privateKey) {
|
46
|
-
this.handleError("saveSession", () => {
|
47
|
-
this.db.prepare(`INSERT OR REPLACE INTO session (phone, auth, guid, agent, private_key)
|
48
|
-
VALUES (?, ?, ?, ?, ?)`).run(phone, auth, guid, agent, privateKey);
|
49
|
-
});
|
50
|
-
}
|
51
|
-
closeDB() {
|
52
|
-
this.handleError("closeDB", () => {
|
53
|
-
this.db.close();
|
54
|
-
});
|
55
|
-
}
|
56
148
|
}
|
57
|
-
exports.default =
|
149
|
+
exports.default = SessionManager;
|
150
|
+
// // مثال استفاده از کلاس
|
151
|
+
// const secretKey = '12345678901234567890123456789012'; // کلید رمزنگاری 32 بایتی
|
152
|
+
// const sessionManager = new SessionManager(secretKey, 'session.json');
|
153
|
+
// const sessionData: SessionData = {
|
154
|
+
// phone: '1234567890',
|
155
|
+
// auth: 'auth-token',
|
156
|
+
// guid: 'unique-guid',
|
157
|
+
// agent: 'user-agent',
|
158
|
+
// private_key: 'private-key-example'
|
159
|
+
// };
|
160
|
+
// // ذخیره دادهها در فایل
|
161
|
+
// sessionManager.saveSession(sessionData);
|
162
|
+
// // خواندن دادهها از فایل
|
163
|
+
// const sessionFromFile = sessionManager.getSession();
|
164
|
+
// console.log('Decrypted session data:', sessionFromFile);
|
@@ -1,3 +0,0 @@
|
|
1
|
-
import Client from "../..";
|
2
|
-
declare function sendLive(this: Client, object_guid: string, music: string | Buffer<ArrayBufferLike>, caption?: string, reply_to_message_id?: string, is_spoil?: boolean, audio_info?: boolean, auto_delete?: number): Promise<import("../../types/messages").SendMessageResult>;
|
3
|
-
export default sendLive;
|
@@ -1,17 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
function sendLive(object_guid, music, caption, reply_to_message_id, is_spoil, audio_info, auto_delete) {
|
13
|
-
return __awaiter(this, void 0, void 0, function* () {
|
14
|
-
return yield this.sendMessage(object_guid, caption, reply_to_message_id, music, "Music", is_spoil, null, audio_info, auto_delete);
|
15
|
-
});
|
16
|
-
}
|
17
|
-
exports.default = sendLive;
|