@mtkruto/node 0.0.993 → 0.0.994
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/esm/4_constants.d.ts +1 -1
- package/esm/4_constants.js +1 -1
- package/esm/5_client.d.ts +2 -1
- package/esm/5_client.js +2 -1
- package/esm/client/0_message.d.ts +3 -3
- package/esm/client/0_message.js +3 -3
- package/esm/client/0_utilities.d.ts +2 -0
- package/esm/client/0_utilities.js +1 -0
- package/esm/client/3_types.d.ts +221 -0
- package/esm/client/3_types.js +1 -0
- package/esm/client/4_composer.d.ts +13 -0
- package/esm/client/4_composer.js +80 -0
- package/esm/client/5_client.d.ts +207 -0
- package/esm/client/{3_client.js → 5_client.js} +92 -153
- package/esm/mod.d.ts +1 -1
- package/esm/mod.js +1 -1
- package/esm/tl/6_message.d.ts +2 -2
- package/esm/tl/6_message.js +2 -2
- package/esm/tl/7_message_container.d.ts +3 -3
- package/esm/tl/7_message_container.js +2 -2
- package/package.json +1 -1
- package/script/4_constants.d.ts +1 -1
- package/script/4_constants.js +1 -1
- package/script/5_client.d.ts +2 -1
- package/script/5_client.js +4 -1
- package/script/client/0_message.d.ts +3 -3
- package/script/client/0_message.js +2 -2
- package/script/client/0_utilities.d.ts +2 -0
- package/script/client/0_utilities.js +3 -1
- package/script/client/3_types.d.ts +221 -0
- package/script/client/3_types.js +2 -0
- package/script/client/4_composer.d.ts +13 -0
- package/script/client/4_composer.js +85 -0
- package/script/client/5_client.d.ts +207 -0
- package/script/client/{3_client.js → 5_client.js} +91 -151
- package/script/mod.d.ts +1 -1
- package/script/mod.js +2 -14
- package/script/tl/6_message.d.ts +2 -2
- package/script/tl/6_message.js +4 -4
- package/script/tl/7_message_container.d.ts +3 -3
- package/script/tl/7_message_container.js +1 -1
- package/esm/client/3_client.d.ts +0 -414
- package/script/client/3_client.d.ts +0 -414
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { debug, gunzip, Mutex } from "../0_deps.js";
|
|
2
2
|
import { bigIntFromBuffer, drop, getRandomBigInt, getRandomId, mustPrompt, mustPromptOneOf, Queue, sha1, UNREACHABLE } from "../1_utilities.js";
|
|
3
|
-
import { as, functions, getChannelChatId,
|
|
4
|
-
MessageContainer, peerToChatId, RPCResult, TLError, TLReader, types, } from "../2_tl.js";
|
|
3
|
+
import { as, functions, getChannelChatId, Message_, MessageContainer, peerToChatId, RPCResult, TLError, TLReader, types } from "../2_tl.js";
|
|
5
4
|
import { StorageMemory } from "../3_storage.js";
|
|
6
|
-
import { constructCallbackQuery, constructInlineQuery, constructMessage, constructUser, FileID, FileType, forceReplyToTlObject, inlineKeyboardMarkupToTlObject, messageEntityToTlObject, replyKeyboardMarkupToTlObject, replyKeyboardRemoveToTlObject, ThumbnailSource
|
|
5
|
+
import { constructCallbackQuery, constructInlineQuery, constructMessage, constructUser, FileID, FileType, forceReplyToTlObject, inlineKeyboardMarkupToTlObject, messageEntityToTlObject, replyKeyboardMarkupToTlObject, replyKeyboardRemoveToTlObject, ThumbnailSource } from "../3_types.js";
|
|
7
6
|
import { ACK_THRESHOLD, APP_VERSION, CHANNEL_DIFFERENCE_LIMIT_BOT, CHANNEL_DIFFERENCE_LIMIT_USER, DEVICE_MODEL, LANG_CODE, LANG_PACK, LAYER, MAX_CHANNEL_ID, MAX_CHAT_ID, STICKER_SET_NAME_TTL, SYSTEM_LANG_CODE, SYSTEM_VERSION, USERNAME_TTL, ZERO_CHANNEL_ID } from "../4_constants.js";
|
|
8
|
-
import { isChannelPtsUpdate, isPtsUpdate } from "./0_utilities.js";
|
|
7
|
+
import { isChannelPtsUpdate, isPtsUpdate, resolve } from "./0_utilities.js";
|
|
9
8
|
import { decryptMessage, encryptMessage, getMessageId } from "./0_message.js";
|
|
10
9
|
import { checkPassword } from "./0_password.js";
|
|
11
10
|
import { parseHtml } from "./0_html.js";
|
|
12
11
|
import { ClientPlain } from "./2_client_plain.js";
|
|
13
12
|
import { ClientAbstract } from "./1_client_abstract.js";
|
|
13
|
+
import { call } from "./4_composer.js";
|
|
14
14
|
const d = debug("Client");
|
|
15
15
|
const dGap = debug("Client/recoverUpdateGap");
|
|
16
16
|
const dGapC = debug("Client/recoverChannelUpdateGap");
|
|
@@ -21,11 +21,6 @@ export const getStickerSetName = Symbol();
|
|
|
21
21
|
export const handleMigrationError = Symbol();
|
|
22
22
|
export const getMessageWithReply = Symbol();
|
|
23
23
|
export const restartAuth = Symbol();
|
|
24
|
-
export var ParseMode;
|
|
25
|
-
(function (ParseMode) {
|
|
26
|
-
ParseMode["None"] = "none";
|
|
27
|
-
ParseMode["HTML"] = "html";
|
|
28
|
-
})(ParseMode || (ParseMode = {}));
|
|
29
24
|
export class Client extends ClientAbstract {
|
|
30
25
|
/**
|
|
31
26
|
* Constructs the client.
|
|
@@ -218,7 +213,7 @@ export class Client extends ClientAbstract {
|
|
|
218
213
|
writable: true,
|
|
219
214
|
value: new Queue("processUpdates")
|
|
220
215
|
});
|
|
221
|
-
Object.defineProperty(this, "
|
|
216
|
+
Object.defineProperty(this, "_handler", {
|
|
222
217
|
enumerable: true,
|
|
223
218
|
configurable: true,
|
|
224
219
|
writable: true,
|
|
@@ -226,7 +221,7 @@ export class Client extends ClientAbstract {
|
|
|
226
221
|
next();
|
|
227
222
|
}
|
|
228
223
|
});
|
|
229
|
-
this.parseMode = params?.parseMode ??
|
|
224
|
+
this.parseMode = params?.parseMode ?? "none";
|
|
230
225
|
this.appVersion = params?.appVersion ?? APP_VERSION;
|
|
231
226
|
this.deviceModel = params?.deviceModel ?? DEVICE_MODEL;
|
|
232
227
|
this.langCode = params?.langCode ?? LANG_CODE;
|
|
@@ -237,7 +232,7 @@ export class Client extends ClientAbstract {
|
|
|
237
232
|
this.autoStart = params?.autoStart ?? true;
|
|
238
233
|
}
|
|
239
234
|
propagateConnectionState(connectionState) {
|
|
240
|
-
return this.
|
|
235
|
+
return this._handler({ connectionState }, resolve);
|
|
241
236
|
}
|
|
242
237
|
/**
|
|
243
238
|
* Sets the DC and resets the auth key stored in the session provider
|
|
@@ -310,6 +305,16 @@ export class Client extends ClientAbstract {
|
|
|
310
305
|
release();
|
|
311
306
|
}
|
|
312
307
|
}
|
|
308
|
+
async assertUser(source) {
|
|
309
|
+
if (await this.storage.getAccountType() != "user") {
|
|
310
|
+
throw new Error(`${source}: not user a client`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
async assertBot(source) {
|
|
314
|
+
if (await this.storage.getAccountType() != "bot") {
|
|
315
|
+
throw new Error(`${source}: not a bot client`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
313
318
|
async fetchState(source) {
|
|
314
319
|
const state = await this.invoke(new functions.UpdatesGetState());
|
|
315
320
|
this.updateState = state;
|
|
@@ -354,7 +359,7 @@ export class Client extends ClientAbstract {
|
|
|
354
359
|
}
|
|
355
360
|
async propagateAuthorizationState(authorized) {
|
|
356
361
|
if (this.lastPropagatedAuthorizationState != authorized) {
|
|
357
|
-
await this.
|
|
362
|
+
await this._handler({ authorizationState: { authorized } }, resolve);
|
|
358
363
|
this.lastPropagatedAuthorizationState = authorized;
|
|
359
364
|
}
|
|
360
365
|
}
|
|
@@ -1174,6 +1179,10 @@ export class Client extends ClientAbstract {
|
|
|
1174
1179
|
}
|
|
1175
1180
|
return messages;
|
|
1176
1181
|
}
|
|
1182
|
+
async resolveSendAs(params) {
|
|
1183
|
+
await this.assertUser("sendAs");
|
|
1184
|
+
return params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined;
|
|
1185
|
+
}
|
|
1177
1186
|
/**
|
|
1178
1187
|
* Send a text message.
|
|
1179
1188
|
*
|
|
@@ -1181,50 +1190,16 @@ export class Client extends ClientAbstract {
|
|
|
1181
1190
|
* @param text The message's text.
|
|
1182
1191
|
*/
|
|
1183
1192
|
async sendMessage(chatId, text, params) {
|
|
1184
|
-
const
|
|
1185
|
-
const
|
|
1186
|
-
switch (parseMode) {
|
|
1187
|
-
case ParseMode.None:
|
|
1188
|
-
break;
|
|
1189
|
-
case ParseMode.HTML: {
|
|
1190
|
-
const [newText, entitiesToPush] = parseHtml(text);
|
|
1191
|
-
text = newText;
|
|
1192
|
-
for (const entity of entitiesToPush) {
|
|
1193
|
-
entities_.push(entity);
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
let replyMarkup = undefined;
|
|
1198
|
-
if (params?.replyMarkup) {
|
|
1199
|
-
if ("inlineKeyboard" in params.replyMarkup) {
|
|
1200
|
-
replyMarkup = await inlineKeyboardMarkupToTlObject(params.replyMarkup, async (v) => {
|
|
1201
|
-
const inputPeer = await this.getInputPeer(v).then((v) => v[as](types.InputPeerUser));
|
|
1202
|
-
return new types.InputUser({ userId: inputPeer.userId, accessHash: inputPeer.accessHash });
|
|
1203
|
-
});
|
|
1204
|
-
}
|
|
1205
|
-
else if ("keyboard" in params.replyMarkup) {
|
|
1206
|
-
replyMarkup = replyKeyboardMarkupToTlObject(params.replyMarkup);
|
|
1207
|
-
}
|
|
1208
|
-
else if ("removeKeyboard" in params.replyMarkup) {
|
|
1209
|
-
replyMarkup = replyKeyboardRemoveToTlObject(params.replyMarkup);
|
|
1210
|
-
}
|
|
1211
|
-
else if ("forceReply" in params.replyMarkup) {
|
|
1212
|
-
replyMarkup = forceReplyToTlObject(params.replyMarkup);
|
|
1213
|
-
}
|
|
1214
|
-
else {
|
|
1215
|
-
throw new Error("The replyMarkup parameter has an unexpected type");
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1193
|
+
const [message, entities] = this.parseText(text, params);
|
|
1194
|
+
const replyMarkup = await this.constructReplyMarkup(params);
|
|
1218
1195
|
const peer = await this.getInputPeer(chatId);
|
|
1219
1196
|
const randomId = getRandomId();
|
|
1220
|
-
const message = text;
|
|
1221
1197
|
const noWebpage = params?.disableWebPagePreview ? true : undefined;
|
|
1222
1198
|
const silent = params?.disableNotification ? true : undefined;
|
|
1223
1199
|
const noforwards = params?.protectContent ? true : undefined;
|
|
1224
1200
|
const replyToMsgId = params?.replyToMessageId;
|
|
1225
1201
|
const topMsgId = params?.messageThreadId;
|
|
1226
|
-
const sendAs =
|
|
1227
|
-
const entities = entities_?.length > 0 ? entities_.map((v) => messageEntityToTlObject(v)) : undefined;
|
|
1202
|
+
const sendAs = await this.resolveSendAs(params);
|
|
1228
1203
|
const result = await this.invoke(new functions.MessagesSendMessage({
|
|
1229
1204
|
peer,
|
|
1230
1205
|
randomId,
|
|
@@ -1237,56 +1212,46 @@ export class Client extends ClientAbstract {
|
|
|
1237
1212
|
entities,
|
|
1238
1213
|
replyMarkup,
|
|
1239
1214
|
}));
|
|
1240
|
-
|
|
1215
|
+
const message_ = await this.updatesToMessages(chatId, result).then((v) => v[0]);
|
|
1216
|
+
return Client.assertMsgHas(message_, "text");
|
|
1241
1217
|
}
|
|
1242
|
-
|
|
1243
|
-
* Edit a message's text.
|
|
1244
|
-
*
|
|
1245
|
-
* @param chatId The chat where the message is.
|
|
1246
|
-
* @param messageId The ID of the message.
|
|
1247
|
-
* @param text The new text of the message.
|
|
1248
|
-
*/
|
|
1249
|
-
async editMessageText(chatId, messageId, text, params) {
|
|
1218
|
+
parseText(text, params) {
|
|
1250
1219
|
const entities_ = params?.entities ?? [];
|
|
1251
1220
|
const parseMode = params?.parseMode ?? this.parseMode;
|
|
1252
1221
|
switch (parseMode) {
|
|
1253
|
-
case
|
|
1222
|
+
case "none":
|
|
1254
1223
|
break;
|
|
1255
|
-
case
|
|
1224
|
+
case "html": {
|
|
1256
1225
|
const [newText, entitiesToPush] = parseHtml(text);
|
|
1257
1226
|
text = newText;
|
|
1258
1227
|
for (const entity of entitiesToPush) {
|
|
1259
1228
|
entities_.push(entity);
|
|
1260
1229
|
}
|
|
1230
|
+
break;
|
|
1261
1231
|
}
|
|
1232
|
+
default:
|
|
1233
|
+
UNREACHABLE();
|
|
1262
1234
|
}
|
|
1263
|
-
let replyMarkup = undefined;
|
|
1264
|
-
if (params?.replyMarkup) {
|
|
1265
|
-
if ("inlineKeyboard" in params.replyMarkup) {
|
|
1266
|
-
replyMarkup = await inlineKeyboardMarkupToTlObject(params.replyMarkup, async (v) => {
|
|
1267
|
-
const inputPeer = await this.getInputPeer(v).then((v) => v[as](types.InputPeerUser));
|
|
1268
|
-
return new types.InputUser({ userId: inputPeer.userId, accessHash: inputPeer.accessHash });
|
|
1269
|
-
});
|
|
1270
|
-
}
|
|
1271
|
-
else if ("keyboard" in params.replyMarkup) {
|
|
1272
|
-
replyMarkup = replyKeyboardMarkupToTlObject(params.replyMarkup);
|
|
1273
|
-
}
|
|
1274
|
-
else if ("removeKeyboard" in params.replyMarkup) {
|
|
1275
|
-
replyMarkup = replyKeyboardRemoveToTlObject(params.replyMarkup);
|
|
1276
|
-
}
|
|
1277
|
-
else if ("forceReply" in params.replyMarkup) {
|
|
1278
|
-
replyMarkup = forceReplyToTlObject(params.replyMarkup);
|
|
1279
|
-
}
|
|
1280
|
-
else {
|
|
1281
|
-
throw new Error("The replyMarkup parameter has an unexpected type");
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
const id = messageId;
|
|
1285
|
-
const peer = await this.getInputPeer(chatId);
|
|
1286
1235
|
const entities = entities_?.length > 0 ? entities_.map((v) => messageEntityToTlObject(v)) : undefined;
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1236
|
+
return [text, entities];
|
|
1237
|
+
}
|
|
1238
|
+
/**
|
|
1239
|
+
* Edit a message's text.
|
|
1240
|
+
*
|
|
1241
|
+
* @param chatId The chat where the message is.
|
|
1242
|
+
* @param messageId The ID of the message.
|
|
1243
|
+
* @param text The new text of the message.
|
|
1244
|
+
*/
|
|
1245
|
+
async editMessageText(chatId, messageId, text, params) {
|
|
1246
|
+
const [message, entities] = this.parseText(text, params);
|
|
1247
|
+
await this.invoke(new functions.MessagesEditMessage({
|
|
1248
|
+
id: messageId,
|
|
1249
|
+
peer: await this.getInputPeer(chatId),
|
|
1250
|
+
entities,
|
|
1251
|
+
message,
|
|
1252
|
+
noWebpage: params?.disableWebPagePreview ? true : undefined,
|
|
1253
|
+
replyMarkup: await this.constructReplyMarkup(params),
|
|
1254
|
+
}));
|
|
1290
1255
|
}
|
|
1291
1256
|
async getMessagesInner(chatId_, messageIds) {
|
|
1292
1257
|
const peer = await this.getInputPeer(chatId_);
|
|
@@ -1485,7 +1450,7 @@ export class Client extends ClientAbstract {
|
|
|
1485
1450
|
update instanceof types.UpdateEditChannelMessage) {
|
|
1486
1451
|
const key = update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewChannelMessage ? "message" : "editedMessage";
|
|
1487
1452
|
const message = await constructMessage(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
|
|
1488
|
-
await this.
|
|
1453
|
+
await this._handler({ [key]: message }, resolve);
|
|
1489
1454
|
}
|
|
1490
1455
|
if (update instanceof types.UpdateDeleteMessages) {
|
|
1491
1456
|
const deletedMessages = new Array();
|
|
@@ -1500,7 +1465,7 @@ export class Client extends ClientAbstract {
|
|
|
1500
1465
|
}
|
|
1501
1466
|
}
|
|
1502
1467
|
if (deletedMessages.length > 0) {
|
|
1503
|
-
await this.
|
|
1468
|
+
await this._handler({ deletedMessages: deletedMessages }, resolve);
|
|
1504
1469
|
}
|
|
1505
1470
|
}
|
|
1506
1471
|
else if (update instanceof types.UpdateDeleteChannelMessages) {
|
|
@@ -1514,50 +1479,18 @@ export class Client extends ClientAbstract {
|
|
|
1514
1479
|
await this.storage.setMessage(chatId, messageId, null);
|
|
1515
1480
|
}
|
|
1516
1481
|
if (deletedMessages.length > 0) {
|
|
1517
|
-
await this.
|
|
1482
|
+
await this._handler({ deletedMessages: deletedMessages }, resolve);
|
|
1518
1483
|
}
|
|
1519
1484
|
}
|
|
1520
1485
|
if (update instanceof types.UpdateBotCallbackQuery || update instanceof types.UpdateInlineBotCallbackQuery) {
|
|
1521
|
-
await this.
|
|
1486
|
+
await this._handler({ callbackQuery: await constructCallbackQuery(update, this[getEntity].bind(this), this[getMessageWithReply].bind(this)) }, resolve);
|
|
1522
1487
|
}
|
|
1523
1488
|
else if (update instanceof types.UpdateBotInlineQuery) {
|
|
1524
|
-
await this.
|
|
1489
|
+
await this._handler({ inlineQuery: await constructInlineQuery(update, this[getEntity].bind(this)) }, resolve);
|
|
1525
1490
|
}
|
|
1526
1491
|
}
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
this.handler = async (upd, next) => {
|
|
1530
|
-
let called = false;
|
|
1531
|
-
await handler(upd, async () => {
|
|
1532
|
-
if (called)
|
|
1533
|
-
return;
|
|
1534
|
-
called = true;
|
|
1535
|
-
await middleware(upd, next);
|
|
1536
|
-
});
|
|
1537
|
-
};
|
|
1538
|
-
}
|
|
1539
|
-
on(filter, handler) {
|
|
1540
|
-
const type = typeof filter === "string" ? filter : filter[0];
|
|
1541
|
-
const keys = Array.isArray(filter) ? filter.slice(1) : [];
|
|
1542
|
-
this.use((update, next) => {
|
|
1543
|
-
if (type in update) {
|
|
1544
|
-
if (keys.length > 0) {
|
|
1545
|
-
for (const key of keys) {
|
|
1546
|
-
// deno-lint-ignore ban-ts-comment
|
|
1547
|
-
// @ts-ignore
|
|
1548
|
-
if (!(key in update[type])) {
|
|
1549
|
-
return next();
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
// deno-lint-ignore ban-ts-comment
|
|
1554
|
-
// @ts-ignore
|
|
1555
|
-
return handler(update, next);
|
|
1556
|
-
}
|
|
1557
|
-
else {
|
|
1558
|
-
return next();
|
|
1559
|
-
}
|
|
1560
|
-
});
|
|
1492
|
+
set handler(handler) {
|
|
1493
|
+
this._handler = call(handler);
|
|
1561
1494
|
}
|
|
1562
1495
|
/**
|
|
1563
1496
|
* Answer a callback query. Bot-only.
|
|
@@ -1565,6 +1498,7 @@ export class Client extends ClientAbstract {
|
|
|
1565
1498
|
* @param id ID of the callback query to answer.
|
|
1566
1499
|
*/
|
|
1567
1500
|
async answerCallbackQuery(id, params) {
|
|
1501
|
+
await this.assertBot("answerCallbackQuery");
|
|
1568
1502
|
await this.invoke(new functions.MessagesSetBotCallbackAnswer({
|
|
1569
1503
|
queryId: BigInt(id),
|
|
1570
1504
|
cacheTime: params?.cacheTime ?? 0,
|
|
@@ -1572,16 +1506,10 @@ export class Client extends ClientAbstract {
|
|
|
1572
1506
|
alert: params?.alert ? true : undefined,
|
|
1573
1507
|
}));
|
|
1574
1508
|
}
|
|
1575
|
-
async
|
|
1576
|
-
const peer = await this.getInputPeer(chatId);
|
|
1577
|
-
const randomId = getRandomId();
|
|
1578
|
-
const silent = params?.disableNotification ? true : undefined;
|
|
1579
|
-
const noforwards = params?.protectContent ? true : undefined;
|
|
1580
|
-
const replyToMsgId = params?.replyToMessageId;
|
|
1581
|
-
const topMsgId = params?.messageThreadId;
|
|
1582
|
-
const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined;
|
|
1509
|
+
async constructReplyMarkup(params) {
|
|
1583
1510
|
let replyMarkup = undefined;
|
|
1584
1511
|
if (params?.replyMarkup) {
|
|
1512
|
+
await this.assertBot("replyMarkup");
|
|
1585
1513
|
if ("inlineKeyboard" in params.replyMarkup) {
|
|
1586
1514
|
replyMarkup = await inlineKeyboardMarkupToTlObject(params.replyMarkup, async (v) => {
|
|
1587
1515
|
const inputPeer = await this.getInputPeer(v).then((v) => v[as](types.InputPeerUser));
|
|
@@ -1601,24 +1529,34 @@ export class Client extends ClientAbstract {
|
|
|
1601
1529
|
throw new Error("The replyMarkup parameter has an unexpected type");
|
|
1602
1530
|
}
|
|
1603
1531
|
}
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
case ParseMode.None:
|
|
1610
|
-
break;
|
|
1611
|
-
case ParseMode.HTML: {
|
|
1612
|
-
const [newText, entitiesToPush] = parseHtml(explanation);
|
|
1613
|
-
explanation = newText;
|
|
1614
|
-
for (const entity of entitiesToPush) {
|
|
1615
|
-
explanationEntities_.push(entity);
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
}
|
|
1532
|
+
return replyMarkup;
|
|
1533
|
+
}
|
|
1534
|
+
static assertMsgHas(message, key) {
|
|
1535
|
+
if (!(key in message) || message[key] === undefined) {
|
|
1536
|
+
UNREACHABLE();
|
|
1619
1537
|
}
|
|
1620
|
-
|
|
1621
|
-
|
|
1538
|
+
return message;
|
|
1539
|
+
}
|
|
1540
|
+
/**
|
|
1541
|
+
* Send a poll.
|
|
1542
|
+
*
|
|
1543
|
+
* @param chatId The chat to send the poll to.
|
|
1544
|
+
* @param question The poll's question.
|
|
1545
|
+
* @param options The poll's options.
|
|
1546
|
+
*/
|
|
1547
|
+
async sendPoll(chatId, question, options, params) {
|
|
1548
|
+
const peer = await this.getInputPeer(chatId);
|
|
1549
|
+
const randomId = getRandomId();
|
|
1550
|
+
const silent = params?.disableNotification ? true : undefined;
|
|
1551
|
+
const noforwards = params?.protectContent ? true : undefined;
|
|
1552
|
+
const replyToMsgId = params?.replyToMessageId;
|
|
1553
|
+
const topMsgId = params?.messageThreadId;
|
|
1554
|
+
const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
1555
|
+
const replyMarkup = await this.constructReplyMarkup(params);
|
|
1556
|
+
const explanation = params?.explanation;
|
|
1557
|
+
const parseResult = explanation !== undefined ? this.parseText(explanation, { parseMode: params?.explanationParseMode, entities: params?.explanationEntities }) : undefined;
|
|
1558
|
+
const solution = parseResult === undefined ? undefined : parseResult[0];
|
|
1559
|
+
const solutionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
1622
1560
|
const answers = options.map((v, i) => new types.PollAnswer({ option: new Uint8Array([i]), text: v }));
|
|
1623
1561
|
const poll = new types.Poll({
|
|
1624
1562
|
id: getRandomId(),
|
|
@@ -1637,7 +1575,7 @@ export class Client extends ClientAbstract {
|
|
|
1637
1575
|
solution,
|
|
1638
1576
|
solutionEntities,
|
|
1639
1577
|
});
|
|
1640
|
-
await this.invoke(new functions.MessagesSendMedia({
|
|
1578
|
+
const result = await this.invoke(new functions.MessagesSendMedia({
|
|
1641
1579
|
peer,
|
|
1642
1580
|
randomId,
|
|
1643
1581
|
silent,
|
|
@@ -1648,6 +1586,7 @@ export class Client extends ClientAbstract {
|
|
|
1648
1586
|
media,
|
|
1649
1587
|
message: "",
|
|
1650
1588
|
}));
|
|
1589
|
+
const message = await this.updatesToMessages(chatId, result).then((v) => v[0]);
|
|
1590
|
+
return Client.assertMsgHas(message, "poll");
|
|
1651
1591
|
}
|
|
1652
1592
|
}
|
|
1653
|
-
const resolve = () => Promise.resolve();
|
package/esm/mod.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare const utils: {
|
|
|
4
4
|
checkPassword: typeof checkPassword;
|
|
5
5
|
getRandomId: typeof getRandomId;
|
|
6
6
|
};
|
|
7
|
-
export *
|
|
7
|
+
export * from "./2_tl.js";
|
|
8
8
|
export * from "./2_connection.js";
|
|
9
9
|
export * from "./3_storage.js";
|
|
10
10
|
export * from "./3_transport.js";
|
package/esm/mod.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getRandomId } from "./1_utilities.js";
|
|
2
2
|
import { checkPassword } from "./client/0_password.js";
|
|
3
3
|
export const utils = { checkPassword, getRandomId };
|
|
4
|
-
export *
|
|
4
|
+
export * from "./2_tl.js";
|
|
5
5
|
export * from "./2_connection.js";
|
|
6
6
|
export * from "./3_storage.js";
|
|
7
7
|
export * from "./3_transport.js";
|
package/esm/tl/6_message.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ReadObject, TLReader } from "./3_tl_reader.js";
|
|
2
2
|
import { RPCResult } from "./5_rpc_result.js";
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class Message_ {
|
|
4
4
|
readonly id: bigint;
|
|
5
5
|
readonly seqNo: number;
|
|
6
6
|
readonly body: ReadObject | RPCResult;
|
|
7
7
|
constructor(id: bigint, seqNo: number, body: ReadObject | RPCResult);
|
|
8
8
|
serialize(): Uint8Array;
|
|
9
|
-
static deserialize(reader: TLReader):
|
|
9
|
+
static deserialize(reader: TLReader): Message_;
|
|
10
10
|
}
|
package/esm/tl/6_message.js
CHANGED
|
@@ -17,7 +17,7 @@ function calculateLength(object) {
|
|
|
17
17
|
}
|
|
18
18
|
return length;
|
|
19
19
|
}
|
|
20
|
-
export class
|
|
20
|
+
export class Message_ {
|
|
21
21
|
constructor(id, seqNo, body) {
|
|
22
22
|
Object.defineProperty(this, "id", {
|
|
23
23
|
enumerable: true,
|
|
@@ -64,6 +64,6 @@ export class Message {
|
|
|
64
64
|
body = reader.readObject(cid);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
return new
|
|
67
|
+
return new Message_(id_, seqNo, body);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { id } from "./1_tl_object.js";
|
|
2
|
-
import {
|
|
2
|
+
import { Message_ } from "./6_message.js";
|
|
3
3
|
export declare class MessageContainer {
|
|
4
|
-
messages:
|
|
4
|
+
messages: Message_[];
|
|
5
5
|
static get [id](): number;
|
|
6
|
-
constructor(messages:
|
|
6
|
+
constructor(messages: Message_[]);
|
|
7
7
|
serialize(): Uint8Array;
|
|
8
8
|
static deserialize(buffer: Uint8Array): MessageContainer;
|
|
9
9
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { id } from "./1_tl_object.js";
|
|
2
2
|
import { TLReader } from "./3_tl_reader.js";
|
|
3
3
|
import { TLWriter } from "./4_tl_writer.js";
|
|
4
|
-
import {
|
|
4
|
+
import { Message_ } from "./6_message.js";
|
|
5
5
|
export class MessageContainer {
|
|
6
6
|
static get [id]() {
|
|
7
7
|
return 0x73F1F8DC;
|
|
@@ -28,7 +28,7 @@ export class MessageContainer {
|
|
|
28
28
|
const length = reader.readInt32();
|
|
29
29
|
const messages = new Array();
|
|
30
30
|
for (let i = 0; i < length; i++) {
|
|
31
|
-
messages.push(
|
|
31
|
+
messages.push(Message_.deserialize(reader));
|
|
32
32
|
}
|
|
33
33
|
return new MessageContainer(messages);
|
|
34
34
|
}
|
package/package.json
CHANGED
package/script/4_constants.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
|
|
|
5
5
|
export declare const VECTOR_CONSTRUCTOR = 481674261;
|
|
6
6
|
export declare const INITIAL_DC: DC;
|
|
7
7
|
export declare const LAYER = 161;
|
|
8
|
-
export declare const APP_VERSION = "MTKruto 0.0.
|
|
8
|
+
export declare const APP_VERSION = "MTKruto 0.0.994";
|
|
9
9
|
export declare const DEVICE_MODEL: string;
|
|
10
10
|
export declare const LANG_CODE: string;
|
|
11
11
|
export declare const LANG_PACK = "";
|
package/script/4_constants.js
CHANGED
|
@@ -80,7 +80,7 @@ exports.PUBLIC_KEYS = Object.freeze([
|
|
|
80
80
|
exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
|
|
81
81
|
exports.INITIAL_DC = "2-test";
|
|
82
82
|
exports.LAYER = 161;
|
|
83
|
-
exports.APP_VERSION = "MTKruto 0.0.
|
|
83
|
+
exports.APP_VERSION = "MTKruto 0.0.994";
|
|
84
84
|
// @ts-ignore: lib
|
|
85
85
|
exports.DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
|
|
86
86
|
exports.LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
package/script/5_client.d.ts
CHANGED
package/script/5_client.js
CHANGED
|
@@ -14,5 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Composer = void 0;
|
|
17
18
|
__exportStar(require("./client/2_client_plain.js"), exports);
|
|
18
|
-
|
|
19
|
+
var _4_composer_js_1 = require("./client/4_composer.js");
|
|
20
|
+
Object.defineProperty(exports, "Composer", { enumerable: true, get: function () { return _4_composer_js_1.Composer; } });
|
|
21
|
+
__exportStar(require("./client/5_client.js"), exports);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Message_, MessageContainer } from "../2_tl.js";
|
|
2
2
|
export declare function getMessageId(lastMsgId: bigint): bigint;
|
|
3
3
|
export declare function packUnencryptedMessage(data: Uint8Array, messageId: bigint): Uint8Array;
|
|
4
4
|
export declare function unpackUnencryptedMessage(buffer: Uint8Array): {
|
|
5
5
|
messageId: bigint;
|
|
6
6
|
message: Uint8Array;
|
|
7
7
|
};
|
|
8
|
-
export declare function encryptMessage(message:
|
|
9
|
-
export declare function decryptMessage(buffer: Uint8Array, authKey: Uint8Array, authKeyId: bigint, _sessionId: bigint): Promise<
|
|
8
|
+
export declare function encryptMessage(message: Message_, authKey: Uint8Array, authKeyId: bigint, salt: bigint, sessionId: bigint): Promise<Uint8Array>;
|
|
9
|
+
export declare function decryptMessage(buffer: Uint8Array, authKey: Uint8Array, authKeyId: bigint, _sessionId: bigint): Promise<Message_ | MessageContainer>;
|
|
@@ -87,11 +87,11 @@ async function decryptMessage(buffer, authKey, authKeyId, _sessionId) {
|
|
|
87
87
|
}
|
|
88
88
|
else if (cid == _2_tl_js_1.RPCResult[_2_tl_js_1.id]) {
|
|
89
89
|
const body = _2_tl_js_1.RPCResult.deserialize(plainReader.buffer);
|
|
90
|
-
return new _2_tl_js_1.
|
|
90
|
+
return new _2_tl_js_1.Message_(mid, seqno, body);
|
|
91
91
|
}
|
|
92
92
|
else {
|
|
93
93
|
const body = plainReader.readObject(cid);
|
|
94
|
-
return new _2_tl_js_1.
|
|
94
|
+
return new _2_tl_js_1.Message_(mid, seqno, body);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
exports.decryptMessage = decryptMessage;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { types } from "../2_tl.js";
|
|
2
|
+
export declare const resolve: () => Promise<void>;
|
|
3
|
+
export type With<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
2
4
|
export declare function isPtsUpdate(v: types.TypeUpdate | types.TypeUpdates): v is types.UpdateShortMessage | types.UpdateShortChatMessage | types.UpdateShortSentMessage | types.UpdateNewMessage | types.UpdateDeleteMessages | types.UpdateReadHistoryInbox | types.UpdateReadHistoryOutbox | types.UpdatePinnedChannelMessages | types.UpdatePinnedMessages | types.UpdateFolderPeers | types.UpdateChannelWebPage | types.UpdateEditMessage | types.UpdateReadMessagesContents | types.UpdateWebPage;
|
|
3
5
|
export declare function isChannelPtsUpdate(v: types.TypeUpdate | types.TypeUpdates): v is types.UpdateNewChannelMessage | types.UpdateEditChannelMessage | types.UpdateDeleteChannelMessages | types.UpdateReadChannelInbox;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isChannelPtsUpdate = exports.isPtsUpdate = void 0;
|
|
3
|
+
exports.isChannelPtsUpdate = exports.isPtsUpdate = exports.resolve = void 0;
|
|
4
4
|
const _2_tl_js_1 = require("../2_tl.js");
|
|
5
|
+
const resolve = () => Promise.resolve();
|
|
6
|
+
exports.resolve = resolve;
|
|
5
7
|
function isPtsUpdate(v) {
|
|
6
8
|
return v instanceof _2_tl_js_1.types.UpdateShortMessage ||
|
|
7
9
|
v instanceof _2_tl_js_1.types.UpdateShortChatMessage ||
|