@mtkruto/node 0.1.128 → 0.1.130
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/0_deps.d.ts +1 -0
- package/esm/0_deps.js +9 -0
- package/esm/4_constants.d.ts +1 -1
- package/esm/4_constants.js +1 -1
- package/esm/client/5_client.d.ts +17 -3
- package/esm/client/5_client.js +310 -79
- package/esm/deps/deno.land/std@0.209.0/media_types/extension.d.ts +17 -0
- package/esm/deps/deno.land/std@0.209.0/media_types/extension.js +26 -0
- package/esm/deps/deno.land/std@0.209.0/media_types/extensions_by_type.d.ts +20 -0
- package/esm/deps/deno.land/std@0.209.0/media_types/extensions_by_type.js +31 -0
- package/esm/storage/0_storage.d.ts +8 -7
- package/esm/storage/0_storage.js +39 -9
- package/esm/tl/0_tl_raw_reader.js +1 -1
- package/esm/tl/3_utilities.d.ts +1 -0
- package/esm/tl/3_utilities.js +11 -0
- package/esm/types/1__getters.d.ts +3 -2
- package/esm/types/1_chat_p.d.ts +2 -2
- package/esm/types/1_chat_p.js +16 -4
- package/esm/types/1_sticker.js +5 -4
- package/esm/types/4_chat.d.ts +3 -2
- package/esm/types/4_chat.js +16 -27
- package/package.json +1 -1
- package/script/0_deps.d.ts +1 -0
- package/script/0_deps.js +11 -1
- package/script/4_constants.d.ts +1 -1
- package/script/4_constants.js +1 -1
- package/script/client/5_client.d.ts +17 -3
- package/script/client/5_client.js +307 -76
- package/script/deps/deno.land/std@0.209.0/media_types/extension.d.ts +17 -0
- package/script/deps/deno.land/std@0.209.0/media_types/extension.js +30 -0
- package/script/deps/deno.land/std@0.209.0/media_types/extensions_by_type.d.ts +20 -0
- package/script/deps/deno.land/std@0.209.0/media_types/extensions_by_type.js +35 -0
- package/script/storage/0_storage.d.ts +8 -7
- package/script/storage/0_storage.js +39 -9
- package/script/tl/0_tl_raw_reader.js +1 -1
- package/script/tl/3_utilities.d.ts +1 -0
- package/script/tl/3_utilities.js +13 -1
- package/script/types/1__getters.d.ts +3 -2
- package/script/types/1_chat_p.d.ts +2 -2
- package/script/types/1_chat_p.js +16 -4
- package/script/types/1_sticker.js +4 -3
- package/script/types/4_chat.d.ts +3 -2
- package/script/types/4_chat.js +17 -27
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* For a given media type, return the most relevant extension, or `undefined`
|
|
3
|
+
* if no extension can be found.
|
|
4
|
+
*
|
|
5
|
+
* Extensions are returned without a leading `.`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { extension } from "https://deno.land/std@$STD_VERSION/media_types/extension.ts";
|
|
10
|
+
*
|
|
11
|
+
* extension("text/plain"); // `txt`
|
|
12
|
+
* extension("application/json"); // `json`
|
|
13
|
+
* extension("text/html; charset=UTF-8"); // `html`
|
|
14
|
+
* extension("application/foo"); // undefined
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function extension(type: string): string | undefined;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
import { extensionsByType } from "./extensions_by_type.js";
|
|
4
|
+
/**
|
|
5
|
+
* For a given media type, return the most relevant extension, or `undefined`
|
|
6
|
+
* if no extension can be found.
|
|
7
|
+
*
|
|
8
|
+
* Extensions are returned without a leading `.`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { extension } from "https://deno.land/std@$STD_VERSION/media_types/extension.ts";
|
|
13
|
+
*
|
|
14
|
+
* extension("text/plain"); // `txt`
|
|
15
|
+
* extension("application/json"); // `json`
|
|
16
|
+
* extension("text/html; charset=UTF-8"); // `html`
|
|
17
|
+
* extension("application/foo"); // undefined
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function extension(type) {
|
|
21
|
+
const exts = extensionsByType(type);
|
|
22
|
+
if (exts) {
|
|
23
|
+
return exts[0];
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { extensions } from "./_util.js";
|
|
2
|
+
export { extensions };
|
|
3
|
+
/**
|
|
4
|
+
* Returns the extensions known to be associated with the media type `type`.
|
|
5
|
+
* The returned extensions will each begin with a leading dot, as in `.html`.
|
|
6
|
+
*
|
|
7
|
+
* When `type` has no associated extensions, the function returns `undefined`.
|
|
8
|
+
*
|
|
9
|
+
* Extensions are returned without a leading `.`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { extensionsByType } from "https://deno.land/std@$STD_VERSION/media_types/extensions_by_type.ts";
|
|
14
|
+
*
|
|
15
|
+
* extensionsByType("application/json"); // ["json", "map"]
|
|
16
|
+
* extensionsByType("text/html; charset=UTF-8"); // ["html", "htm", "shtml"]
|
|
17
|
+
* extensionsByType("application/foo"); // undefined
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function extensionsByType(type: string): string[] | undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
import { parseMediaType } from "./parse_media_type.js";
|
|
4
|
+
import { extensions } from "./_util.js";
|
|
5
|
+
export { extensions };
|
|
6
|
+
/**
|
|
7
|
+
* Returns the extensions known to be associated with the media type `type`.
|
|
8
|
+
* The returned extensions will each begin with a leading dot, as in `.html`.
|
|
9
|
+
*
|
|
10
|
+
* When `type` has no associated extensions, the function returns `undefined`.
|
|
11
|
+
*
|
|
12
|
+
* Extensions are returned without a leading `.`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { extensionsByType } from "https://deno.land/std@$STD_VERSION/media_types/extensions_by_type.ts";
|
|
17
|
+
*
|
|
18
|
+
* extensionsByType("application/json"); // ["json", "map"]
|
|
19
|
+
* extensionsByType("text/html; charset=UTF-8"); // ["html", "htm", "shtml"]
|
|
20
|
+
* extensionsByType("application/foo"); // undefined
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function extensionsByType(type) {
|
|
24
|
+
try {
|
|
25
|
+
const [mediaType] = parseMediaType(type);
|
|
26
|
+
return extensions.get(mediaType);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// just swallow errors, returning undefined
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -32,7 +32,7 @@ export declare abstract class Storage {
|
|
|
32
32
|
updateUsernames(type: "user" | "channel", id: bigint, usernames: string[]): Promise<void>;
|
|
33
33
|
getUsername(username: string): Promise<["channel" | "user", bigint, Date] | null>;
|
|
34
34
|
setTlObject(key: readonly StorageKeyPart[], value: TLObject | null): Promise<void>;
|
|
35
|
-
|
|
35
|
+
getTlObject(keyOrBuffer: Uint8Array | readonly StorageKeyPart[]): Promise<import("../2_tl.js").ReadObject | null>;
|
|
36
36
|
setState(state: enums.updates.State): Promise<void>;
|
|
37
37
|
getState(): Promise<import("../tl/2_types.js").updates_State_ | null>;
|
|
38
38
|
setMessage(chatId: number, messageId: number, message: enums.Message | null): Promise<void>;
|
|
@@ -42,13 +42,12 @@ export declare abstract class Storage {
|
|
|
42
42
|
getLastMessage(chatId: number): Promise<enums.Message | null>;
|
|
43
43
|
setChannelPts(channelId: bigint, pts: number): Promise<void>;
|
|
44
44
|
getChannelPts(channelId: bigint): MaybePromise<number | null>;
|
|
45
|
-
setEntity(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
getEntity(type: "
|
|
49
|
-
getEntity(type: "chat", id: bigint): Promise<types.Chat | null>;
|
|
45
|
+
setEntity(entity: types.User | types.Channel | types.ChannelForbidden | types.Chat | types.ChatForbidden): Promise<void>;
|
|
46
|
+
removeEntity(entity: types.User | types.Channel | types.ChannelForbidden | types.Chat | types.ChatForbidden): Promise<void>;
|
|
47
|
+
getEntity(type: "channel", id: bigint): Promise<types.Channel | types.ChannelForbidden | null>;
|
|
48
|
+
getEntity(type: "chat", id: bigint): Promise<types.Chat | types.ChatForbidden | null>;
|
|
50
49
|
getEntity(type: "user", id: bigint): Promise<types.User | null>;
|
|
51
|
-
getEntity(type: "channel" | "chat" | "user", id: bigint): Promise<types.Channel | types.Chat | types.User | null>;
|
|
50
|
+
getEntity(type: "channel" | "chat" | "user", id: bigint): Promise<types.Channel | types.ChannelForbidden | types.Chat | types.ChatForbidden | types.User | null>;
|
|
52
51
|
setAccountType(type: "user" | "bot"): Promise<void>;
|
|
53
52
|
getAccountType(): MaybePromise<"bot" | "user" | null>;
|
|
54
53
|
updateStickerSetName(id: bigint, accessHash: bigint, name: string): Promise<void>;
|
|
@@ -72,4 +71,6 @@ export declare abstract class Storage {
|
|
|
72
71
|
iterFileParts(id: bigint, partCount: number): AsyncGenerator<Uint8Array, void, unknown>;
|
|
73
72
|
saveFilePart(id: bigint, index: number, bytes: Uint8Array): Promise<void>;
|
|
74
73
|
setFilePartCount(id: bigint, partCount: number): Promise<void>;
|
|
74
|
+
setCustomEmojiDocument(id: bigint, document: types.Document): Promise<void>;
|
|
75
|
+
getCustomEmojiDocument(id: bigint): Promise<[import("../tl/2_types.js").Document_, Date] | null>;
|
|
75
76
|
}
|
package/esm/storage/0_storage.js
CHANGED
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _Storage_instances, _Storage__authKeyId, _Storage_resetAuthKeyId;
|
|
12
|
+
var _Storage_instances, _Storage__authKeyId, _Storage_resetAuthKeyId, _Storage_getEntityType;
|
|
13
13
|
import { bigIntFromBuffer, rleDecode, rleEncode, sha1, UNREACHABLE, ZERO_CHANNEL_ID } from "../1_utilities.js";
|
|
14
14
|
import { serialize, TLReader, types } from "../2_tl.js";
|
|
15
15
|
const KPARTS__DC = ["dc"];
|
|
@@ -32,6 +32,7 @@ const KPARTS_PINNED_CHATS = (listId) => ["pinnedChats", listId];
|
|
|
32
32
|
const KPARTS_SERVER_SALT = ["serverSalt"];
|
|
33
33
|
const KPARTS_FILE = (fileId) => ["files", fileId];
|
|
34
34
|
const KPARTS_FILE_PART = (fileId, n) => ["fileParts", fileId, n];
|
|
35
|
+
const KPARTS_CEMOJI = (id) => ["customEmojiDocuments", id];
|
|
35
36
|
export class Storage {
|
|
36
37
|
constructor() {
|
|
37
38
|
_Storage_instances.add(this);
|
|
@@ -85,7 +86,7 @@ export class Storage {
|
|
|
85
86
|
await this.set(key, rleEncode(value[serialize]()));
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
|
-
async
|
|
89
|
+
async getTlObject(keyOrBuffer) {
|
|
89
90
|
const buffer = keyOrBuffer instanceof Uint8Array ? keyOrBuffer : await this.get(keyOrBuffer);
|
|
90
91
|
if (buffer != null) {
|
|
91
92
|
return new TLReader(rleDecode(buffer)).readObject();
|
|
@@ -98,7 +99,7 @@ export class Storage {
|
|
|
98
99
|
await this.setTlObject(KPARTS__STATE, state);
|
|
99
100
|
}
|
|
100
101
|
async getState() {
|
|
101
|
-
return await this.
|
|
102
|
+
return await this.getTlObject(KPARTS__STATE);
|
|
102
103
|
}
|
|
103
104
|
async setMessage(chatId, messageId, message) {
|
|
104
105
|
if (chatId > ZERO_CHANNEL_ID) {
|
|
@@ -117,11 +118,11 @@ export class Storage {
|
|
|
117
118
|
return this.get(KPARTS_MESSAGE_REF(messageId));
|
|
118
119
|
}
|
|
119
120
|
async getMessage(chatId, messageId) {
|
|
120
|
-
return await this.
|
|
121
|
+
return await this.getTlObject(KPARTS_MESSAGE(chatId, messageId));
|
|
121
122
|
}
|
|
122
123
|
async getLastMessage(chatId) {
|
|
123
124
|
for await (const [_, buffer] of await this.getMany({ prefix: KPARTS_MESSAGES(chatId) }, { limit: 1, reverse: true })) {
|
|
124
|
-
return await this.
|
|
125
|
+
return await this.getTlObject(buffer);
|
|
125
126
|
}
|
|
126
127
|
return null;
|
|
127
128
|
}
|
|
@@ -131,9 +132,13 @@ export class Storage {
|
|
|
131
132
|
getChannelPts(channelId) {
|
|
132
133
|
return this.get(KPARTS__CHANNEL_PTS(channelId));
|
|
133
134
|
}
|
|
134
|
-
async setEntity(
|
|
135
|
-
const type =
|
|
136
|
-
await this.set(KPARTS__PEER(type,
|
|
135
|
+
async setEntity(entity) {
|
|
136
|
+
const type = __classPrivateFieldGet(this, _Storage_instances, "m", _Storage_getEntityType).call(this, entity);
|
|
137
|
+
await this.set(KPARTS__PEER(type, entity.id), rleEncode(entity[serialize]()));
|
|
138
|
+
}
|
|
139
|
+
async removeEntity(entity) {
|
|
140
|
+
const type = __classPrivateFieldGet(this, _Storage_instances, "m", _Storage_getEntityType).call(this, entity);
|
|
141
|
+
await this.set(KPARTS__PEER(type, entity.id), null);
|
|
137
142
|
}
|
|
138
143
|
async getEntity(type, id) {
|
|
139
144
|
const peer_ = await this.get(KPARTS__PEER(type, id));
|
|
@@ -213,7 +218,7 @@ export class Storage {
|
|
|
213
218
|
++limit;
|
|
214
219
|
const messages = new Array();
|
|
215
220
|
for await (const [_, buffer] of await this.getMany({ start: KPARTS_MESSAGE(chatId, 0), end: KPARTS_MESSAGE(chatId, offsetId) }, { limit, reverse: true })) {
|
|
216
|
-
const message = await this.
|
|
221
|
+
const message = await this.getTlObject(buffer);
|
|
217
222
|
if ("id" in message && message.id == offsetId) {
|
|
218
223
|
continue;
|
|
219
224
|
}
|
|
@@ -251,6 +256,18 @@ export class Storage {
|
|
|
251
256
|
}
|
|
252
257
|
await this.set(KPARTS_FILE(id), partCount);
|
|
253
258
|
}
|
|
259
|
+
async setCustomEmojiDocument(id, document) {
|
|
260
|
+
await this.set(KPARTS_CEMOJI(id), [rleEncode(document[serialize]()), new Date()]);
|
|
261
|
+
}
|
|
262
|
+
async getCustomEmojiDocument(id) {
|
|
263
|
+
const v = await this.get(KPARTS_CEMOJI(id));
|
|
264
|
+
if (v != null) {
|
|
265
|
+
return [await this.getTlObject([0]), v[1]];
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
254
271
|
}
|
|
255
272
|
_Storage__authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storage_resetAuthKeyId = async function _Storage_resetAuthKeyId(authKey) {
|
|
256
273
|
if (authKey != null) {
|
|
@@ -259,4 +276,17 @@ _Storage__authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storag
|
|
|
259
276
|
else {
|
|
260
277
|
__classPrivateFieldSet(this, _Storage__authKeyId, null, "f");
|
|
261
278
|
}
|
|
279
|
+
}, _Storage_getEntityType = function _Storage_getEntityType(entity) {
|
|
280
|
+
if (entity instanceof types.Channel || entity instanceof types.ChannelForbidden) {
|
|
281
|
+
return "channel";
|
|
282
|
+
}
|
|
283
|
+
else if (entity instanceof types.Chat || entity instanceof types.ChatForbidden) {
|
|
284
|
+
return "chat";
|
|
285
|
+
}
|
|
286
|
+
else if (entity instanceof types.User) {
|
|
287
|
+
return "user";
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
UNREACHABLE();
|
|
291
|
+
}
|
|
262
292
|
};
|
|
@@ -34,7 +34,7 @@ export class TLRawReader {
|
|
|
34
34
|
return bigIntFromBuffer(buffer, true, signed);
|
|
35
35
|
}
|
|
36
36
|
readDouble() {
|
|
37
|
-
return new DataView(this.read(8).buffer).getFloat64(0, true);
|
|
37
|
+
return new DataView(this.read(8).buffer).getFloat64(0, true);
|
|
38
38
|
}
|
|
39
39
|
readInt128(signed = true) {
|
|
40
40
|
const buffer = this.read(128 / 8);
|
package/esm/tl/3_utilities.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { enums } from "./2_types.js";
|
|
2
2
|
export declare function getChannelChatId(channelId: bigint): number;
|
|
3
3
|
export declare function peerToChatId(peer: enums.Peer | enums.InputPeer): number;
|
|
4
|
+
export declare function chatIdToPeer(chatId: number): import("./2_types.js").PeerUser_ | import("./2_types.js").PeerChat_ | import("./2_types.js").PeerChannel_;
|
package/esm/tl/3_utilities.js
CHANGED
|
@@ -17,3 +17,14 @@ export function peerToChatId(peer) {
|
|
|
17
17
|
UNREACHABLE();
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
export function chatIdToPeer(chatId) {
|
|
21
|
+
if (chatId > 0) {
|
|
22
|
+
return new types.PeerUser({ user_id: BigInt(chatId) });
|
|
23
|
+
}
|
|
24
|
+
else if (chatId > ZERO_CHANNEL_ID) {
|
|
25
|
+
return new types.PeerChat({ chat_id: BigInt(Math.abs(chatId)) });
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return new types.PeerChannel({ channel_id: BigInt(ZERO_CHANNEL_ID - chatId) });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -3,8 +3,9 @@ import { types } from "../2_tl.js";
|
|
|
3
3
|
import { ChatID } from "./0_chat_id.js";
|
|
4
4
|
export interface EntityGetter {
|
|
5
5
|
(peer: types.PeerUser): MaybePromise<types.User | null>;
|
|
6
|
-
(peer: types.PeerChat): MaybePromise<types.Chat | null>;
|
|
7
|
-
(peer: types.PeerChannel): MaybePromise<types.Channel | null>;
|
|
6
|
+
(peer: types.PeerChat): MaybePromise<types.Chat | types.ChatForbidden | null>;
|
|
7
|
+
(peer: types.PeerChannel): MaybePromise<types.Channel | types.ChannelForbidden | null>;
|
|
8
|
+
(peer: types.PeerUser | types.PeerChat | types.PeerChannel): MaybePromise<types.User | types.Chat | types.ChatForbidden | types.Channel | types.ChannelForbidden | null>;
|
|
8
9
|
}
|
|
9
10
|
export interface InputPeerGetter {
|
|
10
11
|
(id: ChatID): Promise<types.InputPeerUser | types.InputPeerChannel | types.InputPeerChat>;
|
package/esm/types/1_chat_p.d.ts
CHANGED
|
@@ -68,5 +68,5 @@ export declare namespace ChatP {
|
|
|
68
68
|
/** This object represents a chat. */
|
|
69
69
|
export type ChatP = ChatP.Private | ChatP.Group | ChatP.Supergroup | ChatP.Channel;
|
|
70
70
|
export declare function constructChatP(chat: types.User): ChatP.Private;
|
|
71
|
-
export declare function constructChatP(chat: types.Chat): ChatP.Group;
|
|
72
|
-
export declare function constructChatP(chat: types.Channel): ChatP.Supergroup | ChatP.Channel;
|
|
71
|
+
export declare function constructChatP(chat: types.Chat | types.ChatForbidden): ChatP.Group;
|
|
72
|
+
export declare function constructChatP(chat: types.Channel | types.ChannelForbidden): ChatP.Supergroup | ChatP.Channel;
|
package/esm/types/1_chat_p.js
CHANGED
|
@@ -22,21 +22,33 @@ export function constructChatP(chat) {
|
|
|
22
22
|
}
|
|
23
23
|
return cleanObject(chat_);
|
|
24
24
|
}
|
|
25
|
-
else if (chat instanceof types.Chat) {
|
|
25
|
+
else if (chat instanceof types.Chat || chat instanceof types.ChatForbidden) {
|
|
26
26
|
const id = Number(-chat.id);
|
|
27
27
|
const chat_ = {
|
|
28
28
|
id,
|
|
29
29
|
type: "group",
|
|
30
30
|
color: getColorFromPeerId(id),
|
|
31
31
|
title: chat.title,
|
|
32
|
-
isCreator:
|
|
32
|
+
isCreator: false,
|
|
33
33
|
};
|
|
34
|
+
if (chat instanceof types.Chat) {
|
|
35
|
+
chat_.isCreator = chat.creator || false;
|
|
36
|
+
}
|
|
34
37
|
return cleanObject(chat_);
|
|
35
38
|
}
|
|
36
|
-
else if (chat instanceof types.Channel) {
|
|
39
|
+
else if (chat instanceof types.Channel || types.ChannelForbidden) {
|
|
37
40
|
let chat_;
|
|
38
|
-
const { title, scam: isScam = false, fake: isFake = false, verified: isVerified = false, restricted: isRestricted = false, } = chat;
|
|
39
41
|
const id = ZERO_CHANNEL_ID + -Number(chat.id);
|
|
42
|
+
if (chat instanceof types.ChannelForbidden) {
|
|
43
|
+
const { title } = chat;
|
|
44
|
+
if (chat.megagroup) {
|
|
45
|
+
return { id, color: getColorFromPeerId(id), title, type: "supergroup", isScam: false, isFake: false, isVerified: false, isRestricted: false, isForum: false };
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return { id, color: getColorFromPeerId(id), title, type: "channel", isScam: false, isFake: false, isVerified: false, isRestricted: false };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const { title, scam: isScam = false, fake: isFake = false, verified: isVerified = false, restricted: isRestricted = false, } = chat;
|
|
40
52
|
if (chat.megagroup) {
|
|
41
53
|
chat_ = {
|
|
42
54
|
id,
|
package/esm/types/1_sticker.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cleanObject } from "../1_utilities.js";
|
|
2
|
+
import { types } from "../2_tl.js";
|
|
2
3
|
import { constructMaskPosition } from "./0_mask_position.js";
|
|
3
4
|
import { constructThumbnail } from "./0_thumbnail.js";
|
|
4
5
|
export async function constructSticker(document, fileId, fileUniqueId, getStickerSetName) {
|
|
5
6
|
const stickerAttribute = document.attributes.find((v) => v instanceof types.DocumentAttributeSticker);
|
|
6
7
|
const imageSizeAttribute = document.attributes.find((v) => v instanceof types.DocumentAttributeImageSize);
|
|
7
8
|
const videoAttribute = document.attributes.find((v) => v instanceof types.DocumentAttributeVideo);
|
|
8
|
-
const setName = await getStickerSetName(stickerAttribute.stickerset
|
|
9
|
-
return {
|
|
9
|
+
const setName = stickerAttribute.stickerset instanceof types.InputStickerSetID ? await getStickerSetName(stickerAttribute.stickerset) : undefined;
|
|
10
|
+
return cleanObject({
|
|
10
11
|
fileId,
|
|
11
12
|
fileUniqueId,
|
|
12
13
|
// TODO: custom emoji type?
|
|
@@ -23,5 +24,5 @@ export async function constructSticker(document, fileId, fileUniqueId, getSticke
|
|
|
23
24
|
customEmojiId: undefined,
|
|
24
25
|
needsRepainting: undefined,
|
|
25
26
|
fileSize: Number(document.size),
|
|
26
|
-
};
|
|
27
|
+
});
|
|
27
28
|
}
|
package/esm/types/4_chat.d.ts
CHANGED
|
@@ -29,5 +29,6 @@ export declare namespace Chat {
|
|
|
29
29
|
export type Chat = Chat.Channel | Chat.Supergroup | Chat.Group | Chat.Private;
|
|
30
30
|
export declare function getChatOrder(lastMessage: Message | undefined, pinned: number): string;
|
|
31
31
|
export declare function constructChat(dialog: enums.Dialog, dialogs: types.messages.Dialogs | types.messages.DialogsSlice, pinnedChats: number[], getEntity: EntityGetter, getMessage: MessageGetter<"replyToMessage">, getStickerSetName: StickerSetNameGetter): Promise<Chat>;
|
|
32
|
-
export declare function constructChat2(
|
|
33
|
-
export declare function constructChat3(chatId: number, pinned: number,
|
|
32
|
+
export declare function constructChat2(entity: types.User | types.Chat | types.ChatForbidden | types.Channel | types.ChannelForbidden, pinned: number, lastMessage: Message | undefined): Chat;
|
|
33
|
+
export declare function constructChat3(chatId: number, pinned: number, lastMessage: Message | undefined, getEntity: EntityGetter): Promise<Chat | null>;
|
|
34
|
+
export declare function constructChat4(chatId: number, pinned: number, lastMessageId: number, getEntity: EntityGetter, getMessage: MessageGetter<"replyToMessage">): Promise<Chat | null>;
|
package/esm/types/4_chat.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { cleanObject, UNREACHABLE
|
|
2
|
-
import { peerToChatId, types } from "../2_tl.js";
|
|
1
|
+
import { cleanObject, UNREACHABLE } from "../1_utilities.js";
|
|
2
|
+
import { chatIdToPeer, peerToChatId, types } from "../2_tl.js";
|
|
3
3
|
import { constructChatP } from "./1_chat_p.js";
|
|
4
4
|
import { constructChatPhoto } from "./0_chat_photo.js";
|
|
5
5
|
import { constructMessage } from "./3_message.js";
|
|
@@ -69,29 +69,8 @@ export async function constructChat(dialog, dialogs, pinnedChats, getEntity, get
|
|
|
69
69
|
UNREACHABLE();
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
export
|
|
73
|
-
|
|
74
|
-
if (chatId < ZERO_CHANNEL_ID) {
|
|
75
|
-
const entity = await getEntity(new types.PeerChannel({ channel_id: BigInt(Math.abs(chatId - ZERO_CHANNEL_ID)) }));
|
|
76
|
-
if (entity != null) {
|
|
77
|
-
chatPAlsoPhoto = getChatPAlsoPhoto(entity);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else if (chatId < 0) {
|
|
81
|
-
const entity = await getEntity(new types.PeerChat({ chat_id: BigInt(Math.abs(chatId)) }));
|
|
82
|
-
if (entity != null) {
|
|
83
|
-
chatPAlsoPhoto = getChatPAlsoPhoto(entity);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
const entity = await getEntity(new types.PeerUser({ user_id: BigInt(chatId) }));
|
|
88
|
-
if (entity != null) {
|
|
89
|
-
chatPAlsoPhoto = getChatPAlsoPhoto(entity);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (chatPAlsoPhoto == null) {
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
72
|
+
export function constructChat2(entity, pinned, lastMessage) {
|
|
73
|
+
const chatPAlsoPhoto = getChatPAlsoPhoto(entity);
|
|
95
74
|
const order = getChatOrder(lastMessage, pinned);
|
|
96
75
|
const { also, photo, chatP } = chatPAlsoPhoto;
|
|
97
76
|
if (chatP.type == "group") {
|
|
@@ -110,8 +89,18 @@ export async function constructChat2(chatId, pinned, lastMessage, getEntity) {
|
|
|
110
89
|
UNREACHABLE();
|
|
111
90
|
}
|
|
112
91
|
}
|
|
113
|
-
export async function constructChat3(chatId, pinned,
|
|
92
|
+
export async function constructChat3(chatId, pinned, lastMessage, getEntity) {
|
|
93
|
+
const peer = chatIdToPeer(chatId);
|
|
94
|
+
const entity = await getEntity(peer);
|
|
95
|
+
if (entity == null) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return constructChat2(entity, pinned, lastMessage);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export async function constructChat4(chatId, pinned, lastMessageId, getEntity, getMessage) {
|
|
114
103
|
const lastMessage_ = lastMessageId > 0 ? await getMessage(chatId, lastMessageId) : null;
|
|
115
104
|
const lastMessage = lastMessage_ == null ? undefined : lastMessage_;
|
|
116
|
-
return await
|
|
105
|
+
return await constructChat3(chatId, pinned, lastMessage, getEntity);
|
|
117
106
|
}
|
package/package.json
CHANGED
package/script/0_deps.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./deps/deno.land/std@0.209.0/assert/mod.js";
|
|
|
2
2
|
export * as path from "./deps/deno.land/std@0.209.0/path/mod.js";
|
|
3
3
|
export { decodeBase64, encodeBase64 } from "./deps/deno.land/std@0.209.0/encoding/base64.js";
|
|
4
4
|
export { contentType } from "./deps/deno.land/std@0.209.0/media_types/content_type.js";
|
|
5
|
+
export declare function extension(mimeType: string): string;
|
|
5
6
|
export { ctr256, factorize, ige256Decrypt, ige256Encrypt, init as initTgCrypto } from "./deps/deno.land/x/tgcrypto@0.3.3/mod.js";
|
|
6
7
|
export { gunzip, gzip } from "./deps/raw.githubusercontent.com/MTKruto/compress/main/gzip/gzip.js";
|
|
7
8
|
export { Mutex, type MutexInterface } from "async-mutex";
|
package/script/0_deps.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.debug = exports.Parser = exports.Mutex = exports.gzip = exports.gunzip = exports.initTgCrypto = exports.ige256Encrypt = exports.ige256Decrypt = exports.factorize = exports.ctr256 = exports.contentType = exports.encodeBase64 = exports.decodeBase64 = exports.path = void 0;
|
|
29
|
+
exports.debug = exports.Parser = exports.Mutex = exports.gzip = exports.gunzip = exports.initTgCrypto = exports.ige256Encrypt = exports.ige256Decrypt = exports.factorize = exports.ctr256 = exports.extension = exports.contentType = exports.encodeBase64 = exports.decodeBase64 = exports.path = void 0;
|
|
30
30
|
__exportStar(require("./deps/deno.land/std@0.209.0/assert/mod.js"), exports);
|
|
31
31
|
exports.path = __importStar(require("./deps/deno.land/std@0.209.0/path/mod.js"));
|
|
32
32
|
var base64_js_1 = require("./deps/deno.land/std@0.209.0/encoding/base64.js");
|
|
@@ -34,6 +34,16 @@ Object.defineProperty(exports, "decodeBase64", { enumerable: true, get: function
|
|
|
34
34
|
Object.defineProperty(exports, "encodeBase64", { enumerable: true, get: function () { return base64_js_1.encodeBase64; } });
|
|
35
35
|
var content_type_js_1 = require("./deps/deno.land/std@0.209.0/media_types/content_type.js");
|
|
36
36
|
Object.defineProperty(exports, "contentType", { enumerable: true, get: function () { return content_type_js_1.contentType; } });
|
|
37
|
+
const extension_js_1 = require("./deps/deno.land/std@0.209.0/media_types/extension.js");
|
|
38
|
+
function extension(mimeType) {
|
|
39
|
+
if (mimeType == "application/x-tgsticker") {
|
|
40
|
+
return "tgs";
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return (0, extension_js_1.extension)(mimeType) || "unknown";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.extension = extension;
|
|
37
47
|
var mod_js_1 = require("./deps/deno.land/x/tgcrypto@0.3.3/mod.js");
|
|
38
48
|
Object.defineProperty(exports, "ctr256", { enumerable: true, get: function () { return mod_js_1.ctr256; } });
|
|
39
49
|
Object.defineProperty(exports, "factorize", { enumerable: true, get: function () { return mod_js_1.factorize; } });
|
package/script/4_constants.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type PublicKeys = readonly [bigint, [bigint, bigint]][];
|
|
|
4
4
|
export declare const PUBLIC_KEYS: PublicKeys;
|
|
5
5
|
export declare const INITIAL_DC: DC;
|
|
6
6
|
export declare const LAYER = 167;
|
|
7
|
-
export declare const APP_VERSION = "MTKruto 0.1.
|
|
7
|
+
export declare const APP_VERSION = "MTKruto 0.1.130";
|
|
8
8
|
export declare const DEVICE_MODEL: string;
|
|
9
9
|
export declare const LANG_CODE: string;
|
|
10
10
|
export declare const LANG_PACK = "";
|
package/script/4_constants.js
CHANGED
|
@@ -79,7 +79,7 @@ exports.PUBLIC_KEYS = Object.freeze([
|
|
|
79
79
|
]);
|
|
80
80
|
exports.INITIAL_DC = "2";
|
|
81
81
|
exports.LAYER = 167;
|
|
82
|
-
exports.APP_VERSION = "MTKruto 0.1.
|
|
82
|
+
exports.APP_VERSION = "MTKruto 0.1.130";
|
|
83
83
|
// @ts-ignore: lib
|
|
84
84
|
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;
|
|
85
85
|
exports.LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
|
@@ -2,7 +2,7 @@ import { MaybePromise } from "../1_utilities.js";
|
|
|
2
2
|
import { functions, ReadObject, types } from "../2_tl.js";
|
|
3
3
|
import { Storage } from "../3_storage.js";
|
|
4
4
|
import { DC } from "../3_transport.js";
|
|
5
|
-
import { BotCommand, CallbackQuery, Chat, ChatAction, ChatID, InlineQuery, InlineQueryResult, Message, ParseMode, User } from "../3_types.js";
|
|
5
|
+
import { BotCommand, CallbackQuery, Chat, ChatAction, ChatID, Document, InlineQuery, InlineQueryResult, Message, ParseMode, User } from "../3_types.js";
|
|
6
6
|
import { Migrate } from "../4_errors.js";
|
|
7
7
|
import { FileSource, With } from "./0_utilities.js";
|
|
8
8
|
import { ClientAbstract } from "./1_client_abstract.js";
|
|
@@ -157,6 +157,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
|
|
|
157
157
|
private [getEntity];
|
|
158
158
|
private [getEntity];
|
|
159
159
|
private [getEntity];
|
|
160
|
+
private [getEntity];
|
|
160
161
|
processResult(result: ReadObject): Promise<void>;
|
|
161
162
|
/**
|
|
162
163
|
* Send a text message.
|
|
@@ -214,7 +215,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
|
|
|
214
215
|
* ```
|
|
215
216
|
* @returns A generator yielding the contents of the file.
|
|
216
217
|
*/
|
|
217
|
-
download(fileId: string, params?: DownloadParams):
|
|
218
|
+
download(fileId: string, params?: DownloadParams): AsyncGenerator<Uint8Array, void, unknown>;
|
|
218
219
|
private [getStickerSetName];
|
|
219
220
|
/**
|
|
220
221
|
* Forward multiple messages.
|
|
@@ -395,11 +396,17 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
|
|
|
395
396
|
*/
|
|
396
397
|
getNetworkStatistics(): Promise<NetworkStatistics>;
|
|
397
398
|
/**
|
|
398
|
-
* Get chats.
|
|
399
|
+
* Get chats from a chat list.
|
|
399
400
|
*
|
|
400
401
|
* @method
|
|
401
402
|
*/
|
|
402
403
|
getChats(params?: GetChatsParams): Promise<Chat[]>;
|
|
404
|
+
/**
|
|
405
|
+
* Get a chat.
|
|
406
|
+
*
|
|
407
|
+
* @method
|
|
408
|
+
*/
|
|
409
|
+
getChat(chatId: ChatID): Promise<Chat>;
|
|
403
410
|
/**
|
|
404
411
|
* Get chat history.
|
|
405
412
|
*
|
|
@@ -407,5 +414,12 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
|
|
|
407
414
|
* @method
|
|
408
415
|
*/
|
|
409
416
|
getHistory(chatId: ChatID, params?: GetHistoryParams): Promise<Message[]>;
|
|
417
|
+
/**
|
|
418
|
+
* Get custom emoji documents for download.
|
|
419
|
+
*
|
|
420
|
+
* @param id Identifier of one or more of custom emojis.
|
|
421
|
+
* @method
|
|
422
|
+
*/
|
|
423
|
+
getCustomEmojiDocuments(id: string | string[]): Promise<Document[]>;
|
|
410
424
|
}
|
|
411
425
|
export {};
|