rubjs 2.7.8 → 2.8.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/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 +24 -1
- package/rubjs/session/index.d.ts +9 -9
- package/rubjs/session/index.js +45 -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.1",
|
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,9 @@ class Network {
|
|
216
236
|
}
|
217
237
|
return false;
|
218
238
|
});
|
239
|
+
if (isMUp && (messageData === null || messageData === void 0 ? void 0 : messageData.message)) {
|
240
|
+
messageData.message.author_title = username;
|
241
|
+
}
|
219
242
|
if (isValid)
|
220
243
|
yield callback(new types_1.Message(this.client, messageData));
|
221
244
|
}
|
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
@@ -3,55 +3,55 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
const
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
this.
|
11
|
-
this.
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
8
|
+
class SessionManager {
|
9
|
+
constructor(filename) {
|
10
|
+
this.secretKey = "12345678901234567890123456789012";
|
11
|
+
this.iv = crypto_1.default.randomBytes(16);
|
12
|
+
this.filename = filename + ".json";
|
12
13
|
}
|
13
|
-
|
14
|
+
encrypt(sessionData) {
|
15
|
+
const cipher = crypto_1.default.createCipheriv("aes-256-cbc", Buffer.from(this.secretKey), this.iv);
|
16
|
+
let encrypted = cipher.update(JSON.stringify(sessionData), "utf8", "hex");
|
17
|
+
encrypted += cipher.final("hex");
|
18
|
+
return encrypted;
|
19
|
+
}
|
20
|
+
decrypt(encryptedData, iv) {
|
21
|
+
const decipher = crypto_1.default.createDecipheriv("aes-256-cbc", Buffer.from(this.secretKey), iv);
|
22
|
+
let decrypted = decipher.update(encryptedData, "hex", "utf8");
|
23
|
+
decrypted += decipher.final("utf8");
|
24
|
+
return JSON.parse(decrypted);
|
25
|
+
}
|
26
|
+
saveSession(sessionData) {
|
27
|
+
const encryptedData = this.encrypt(sessionData);
|
28
|
+
const dataToWrite = {
|
29
|
+
iv: this.iv.toString("hex"),
|
30
|
+
encryptedData: encryptedData,
|
31
|
+
};
|
32
|
+
fs_1.default.writeFileSync(this.filename, JSON.stringify(dataToWrite, null, 2));
|
33
|
+
}
|
34
|
+
getSession() {
|
14
35
|
try {
|
15
|
-
|
36
|
+
if (!fs_1.default.existsSync(this.filename)) {
|
37
|
+
const defaultSessionData = {
|
38
|
+
phone: "",
|
39
|
+
auth: "",
|
40
|
+
guid: "",
|
41
|
+
agent: "",
|
42
|
+
private_key: "",
|
43
|
+
};
|
44
|
+
this.saveSession(defaultSessionData);
|
45
|
+
return defaultSessionData;
|
46
|
+
}
|
47
|
+
const rawData = fs_1.default.readFileSync(this.filename, "utf8");
|
48
|
+
const parsedData = JSON.parse(rawData);
|
49
|
+
return this.decrypt(parsedData.encryptedData, Buffer.from(parsedData.iv, "hex"));
|
16
50
|
}
|
17
51
|
catch (error) {
|
18
|
-
console.error(
|
19
|
-
|
52
|
+
console.error("Error reading or decrypting session data:", error);
|
53
|
+
return null;
|
20
54
|
}
|
21
55
|
}
|
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
56
|
}
|
57
|
-
exports.default =
|
57
|
+
exports.default = SessionManager;
|
@@ -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;
|