@mtkruto/node 0.0.992 → 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/{3_client.d.ts → 5_client.d.ts} +20 -165
- package/esm/client/{3_client.js → 5_client.js} +143 -127
- package/esm/mod.d.ts +1 -0
- package/esm/mod.js +1 -0
- 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/{3_client.d.ts → 5_client.d.ts} +20 -165
- package/script/client/{3_client.js → 5_client.js} +142 -125
- package/script/mod.d.ts +1 -0
- package/script/mod.js +1 -0
- 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/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/esm/4_constants.js
CHANGED
|
@@ -54,7 +54,7 @@ export const PUBLIC_KEYS = Object.freeze([
|
|
|
54
54
|
export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
|
|
55
55
|
export const INITIAL_DC = "2-test";
|
|
56
56
|
export const LAYER = 161;
|
|
57
|
-
export const APP_VERSION = "MTKruto 0.0.
|
|
57
|
+
export const APP_VERSION = "MTKruto 0.0.994";
|
|
58
58
|
// @ts-ignore: lib
|
|
59
59
|
export const 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;
|
|
60
60
|
export const LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
package/esm/5_client.d.ts
CHANGED
package/esm/5_client.js
CHANGED
|
@@ -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>;
|
package/esm/client/0_message.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assertEquals, ige256Decrypt, ige256Encrypt } from "../0_deps.js";
|
|
2
2
|
import { bufferFromBigInt, concat, sha256 } from "../1_utilities.js";
|
|
3
|
-
import { id,
|
|
3
|
+
import { id, Message_, MessageContainer, RPCResult, serialize, TLReader, TLWriter } from "../2_tl.js";
|
|
4
4
|
export function getMessageId(lastMsgId) {
|
|
5
5
|
const now = new Date().getTime() / 1000 + 0;
|
|
6
6
|
const nanoseconds = Math.floor((now - Math.floor(now)) * 1e9);
|
|
@@ -80,10 +80,10 @@ export async function decryptMessage(buffer, authKey, authKeyId, _sessionId) {
|
|
|
80
80
|
}
|
|
81
81
|
else if (cid == RPCResult[id]) {
|
|
82
82
|
const body = RPCResult.deserialize(plainReader.buffer);
|
|
83
|
-
return new
|
|
83
|
+
return new Message_(mid, seqno, body);
|
|
84
84
|
}
|
|
85
85
|
else {
|
|
86
86
|
const body = plainReader.readObject(cid);
|
|
87
|
-
return new
|
|
87
|
+
return new Message_(mid, seqno, body);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -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;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { MaybePromise } from "../1_utilities.js";
|
|
2
|
+
import { CallbackQuery, ForceReply, InlineKeyboardMarkup, InlineQuery, Message, MessageEntity, ReplyKeyboardMarkup, ReplyKeyboardRemove } from "../3_types.js";
|
|
3
|
+
import { With } from "./0_utilities.js";
|
|
4
|
+
import { ClientPlainParams } from "./2_client_plain.js";
|
|
5
|
+
export type ParseMode = "html" | "none";
|
|
6
|
+
export interface ClientParams extends ClientPlainParams {
|
|
7
|
+
/**
|
|
8
|
+
* A parse mode to use when the `parseMode` parameter is not specified when sending or editing messages. Defauls to `ParseMode.None`.
|
|
9
|
+
*/
|
|
10
|
+
parseMode?: ParseMode;
|
|
11
|
+
/**
|
|
12
|
+
* The app_version parameter to be passed to initConnection when calling `authorize`. It is recommended that this parameter is changed if users are authorized. Defaults to "MTKruto" followed by this version of MTKruto.
|
|
13
|
+
*/
|
|
14
|
+
appVersion?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The device_version parameter to be passed to initConnection when calling `authorize`. The default varies by the current runtime.
|
|
17
|
+
*/
|
|
18
|
+
deviceModel?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The lang_code parameter to be passed to initConnection when calling `authorize`. Defaults to the runtime's language or `"en"`.
|
|
21
|
+
*/
|
|
22
|
+
langCode?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The lang_pack parameter to be passed to initConnection when calling `authorize`. Defaults to an empty string.
|
|
25
|
+
*/
|
|
26
|
+
langPack?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The system_lang_cde parameter to be passed to initConnection when calling `authorize`. Defaults to the runtime's language or `"en"`.
|
|
29
|
+
*/
|
|
30
|
+
systemLangCode?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The system_version parameter to be passed to initConnection when calling `authorize`. The default varies by the current runtime.
|
|
33
|
+
*/
|
|
34
|
+
systemVersion?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Whether to automatically call `start` with no parameters in the first `invoke` call. Defaults to `true`.
|
|
37
|
+
*/
|
|
38
|
+
autoStart?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface AnswerCallbackQueryParams {
|
|
41
|
+
/** Text of the answer */
|
|
42
|
+
text?: string;
|
|
43
|
+
/** Pass true to show an alert to the user instead of a toast notification */
|
|
44
|
+
alert?: boolean;
|
|
45
|
+
/** URL to be opened */
|
|
46
|
+
url?: string;
|
|
47
|
+
/** Time during which the result of the query can be cached, in seconds */
|
|
48
|
+
cacheTime?: number;
|
|
49
|
+
}
|
|
50
|
+
export interface AuthorizeUserParams<S = string> {
|
|
51
|
+
phone: S | (() => MaybePromise<S>);
|
|
52
|
+
code: S | (() => MaybePromise<S>);
|
|
53
|
+
password: S | ((hint: string | null) => MaybePromise<S>);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A chat identifier as provided by MTKruto or a string starting with a @ that is followed by a username.
|
|
57
|
+
*/
|
|
58
|
+
export type ChatID = number | string;
|
|
59
|
+
export interface SendMessagesParams {
|
|
60
|
+
/**
|
|
61
|
+
* The parse mode to use. If not provided, the default parse mode will be used.
|
|
62
|
+
*/
|
|
63
|
+
parseMode?: ParseMode;
|
|
64
|
+
/**
|
|
65
|
+
* The message's entities.
|
|
66
|
+
*/
|
|
67
|
+
entities?: MessageEntity[];
|
|
68
|
+
/**
|
|
69
|
+
* Whether to disable web page previews in the message that is to be sent.
|
|
70
|
+
*/
|
|
71
|
+
disableWebPagePreview?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Whether to send the message in a silent way without making a sound on the recipients' clients.
|
|
74
|
+
*/
|
|
75
|
+
disableNotification?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Whether to protect the contents of the message from copying and forwarding.
|
|
78
|
+
*/
|
|
79
|
+
protectContent?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* The identifier of a message to reply to.
|
|
82
|
+
*/
|
|
83
|
+
replyToMessageId?: number;
|
|
84
|
+
/**
|
|
85
|
+
* The identifier of a thread to send the message to.
|
|
86
|
+
*/
|
|
87
|
+
messageThreadId?: number;
|
|
88
|
+
/**
|
|
89
|
+
* The identifier of the chat to send the message on behalf of. User-only.
|
|
90
|
+
*/
|
|
91
|
+
sendAs?: ChatID;
|
|
92
|
+
/**
|
|
93
|
+
* The reply markup of the message. Bot-only.
|
|
94
|
+
*/
|
|
95
|
+
replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
|
|
96
|
+
}
|
|
97
|
+
export interface EditMessageParams {
|
|
98
|
+
/**
|
|
99
|
+
* The parse mode to use. If not provided, the default parse mode will be used.
|
|
100
|
+
*/
|
|
101
|
+
parseMode?: ParseMode;
|
|
102
|
+
/**
|
|
103
|
+
* The message's entities.
|
|
104
|
+
*/
|
|
105
|
+
entities?: MessageEntity[];
|
|
106
|
+
/**
|
|
107
|
+
* Whether to disable web page previews in the message that is to be edited.
|
|
108
|
+
*/
|
|
109
|
+
disableWebPagePreview?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* The reply markup of the message. Bot-only.
|
|
112
|
+
*/
|
|
113
|
+
replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
|
|
114
|
+
}
|
|
115
|
+
export interface ForwardMessagesParams {
|
|
116
|
+
messageThreadId?: number;
|
|
117
|
+
/**
|
|
118
|
+
* Whether to forward the message in a silent way without making a sound on the recipients' clients.
|
|
119
|
+
*/
|
|
120
|
+
disableNotification?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Whether to protect the contents of the forwarded message from copying and forwarding.
|
|
123
|
+
*/
|
|
124
|
+
protectContent?: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* The identifier of the chat to forward the message on behalf of. User-only.
|
|
127
|
+
*/
|
|
128
|
+
sendAs?: ChatID;
|
|
129
|
+
/**
|
|
130
|
+
* Whether to not include the original sender of the message that is going to be forwarded.
|
|
131
|
+
*/
|
|
132
|
+
dropSenderName?: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Whether to not include the original caption of the message that is going to be forwarded.
|
|
135
|
+
*/
|
|
136
|
+
dropCaption?: boolean;
|
|
137
|
+
}
|
|
138
|
+
export interface SendPollParams {
|
|
139
|
+
/**
|
|
140
|
+
* True, if the poll needs to be anonymous, defaults to True */
|
|
141
|
+
isAnonymous?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* The type of the poll. Defaults to regular. */
|
|
144
|
+
type?: "quiz" | "regular";
|
|
145
|
+
/**
|
|
146
|
+
* True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False */
|
|
147
|
+
allowMultipleAnswers?: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Index of the correct option. Required for quizzes. */
|
|
150
|
+
correctOptionIndex?: number;
|
|
151
|
+
/**
|
|
152
|
+
* Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing */
|
|
153
|
+
explanation?: string;
|
|
154
|
+
/**
|
|
155
|
+
* The parse mode to use for the explanation. If not provided, the default parse mode will be used.
|
|
156
|
+
*/
|
|
157
|
+
explanationParseMode?: ParseMode;
|
|
158
|
+
/**
|
|
159
|
+
* The explanation's entities.
|
|
160
|
+
*/
|
|
161
|
+
explanationEntities?: MessageEntity[];
|
|
162
|
+
/**
|
|
163
|
+
* Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with close_date.
|
|
164
|
+
*/
|
|
165
|
+
openPeriod?: number;
|
|
166
|
+
/**
|
|
167
|
+
* Point in time when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future. Can't be used together with open_period.
|
|
168
|
+
*/
|
|
169
|
+
closeDate?: Date;
|
|
170
|
+
/**
|
|
171
|
+
* Pass True if the poll needs to be immediately closed. This can be useful for poll preview.
|
|
172
|
+
*/
|
|
173
|
+
isClosed?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Whether to send the message in a silent way without making a sound on the recipients' clients.
|
|
176
|
+
*/
|
|
177
|
+
disableNotification?: boolean;
|
|
178
|
+
/**
|
|
179
|
+
* The identifier of a message to reply to.
|
|
180
|
+
*/
|
|
181
|
+
replyToMessageId?: number;
|
|
182
|
+
/**
|
|
183
|
+
* The identifier of a thread to send the message to.
|
|
184
|
+
*/
|
|
185
|
+
messageThreadId?: number;
|
|
186
|
+
/**
|
|
187
|
+
* The identifier of the chat to send the message on behalf of. User-only.
|
|
188
|
+
*/
|
|
189
|
+
sendAs?: ChatID;
|
|
190
|
+
/**
|
|
191
|
+
* The reply markup of the message. Bot-only.
|
|
192
|
+
*/
|
|
193
|
+
replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
|
|
194
|
+
/**
|
|
195
|
+
* Whether to protect the contents of the message from copying and forwarding.
|
|
196
|
+
*/
|
|
197
|
+
protectContent?: boolean;
|
|
198
|
+
}
|
|
199
|
+
export type ConnectionState = "not-connected" | "updating" | "ready";
|
|
200
|
+
export type AuthorizationState = {
|
|
201
|
+
authorized: boolean;
|
|
202
|
+
};
|
|
203
|
+
export type FilterableUpdates = "message" | "editedMessage" | "callbackQuery";
|
|
204
|
+
export interface Update {
|
|
205
|
+
message?: Message;
|
|
206
|
+
editedMessage?: Message;
|
|
207
|
+
connectionState?: ConnectionState;
|
|
208
|
+
authorizationState?: AuthorizationState;
|
|
209
|
+
deletedMessages?: [Message, ...Message[]];
|
|
210
|
+
callbackQuery?: CallbackQuery;
|
|
211
|
+
inlineQuery?: InlineQuery;
|
|
212
|
+
}
|
|
213
|
+
export type NextFn = () => Promise<void>;
|
|
214
|
+
export interface HandlerObj<U extends Partial<Update> = Partial<Update>> {
|
|
215
|
+
handle(update: U, next: NextFn): MaybePromise<void>;
|
|
216
|
+
}
|
|
217
|
+
export type HandlerFn<U extends Partial<Update> = Partial<Update>> = HandlerObj<U>["handle"];
|
|
218
|
+
export type Handler<U extends Partial<Update> = Partial<Update>> = HandlerObj<U> | HandlerFn<U>;
|
|
219
|
+
export type FilterUpdate<U extends Update, T extends keyof U, F extends keyof NonNullable<U[T]>> = With<U, T> & Pick<{
|
|
220
|
+
[P in T]-?: With<NonNullable<U[T]>, F>;
|
|
221
|
+
}, T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MaybePromise } from "../1_utilities.js";
|
|
2
|
+
import { FilterableUpdates, FilterUpdate, Handler, HandlerFn, HandlerObj, Update } from "./3_types.js";
|
|
3
|
+
export declare function call(handler: Handler): HandlerFn;
|
|
4
|
+
export declare class Composer<U extends Update = Update> implements HandlerObj<U> {
|
|
5
|
+
constructor(...handlers: Handler<U>[]);
|
|
6
|
+
get handle(): HandlerFn;
|
|
7
|
+
private _handle;
|
|
8
|
+
use(...handlers: Handler<U>[]): this;
|
|
9
|
+
branch(predicate: (upd: U) => MaybePromise<boolean>, trueHandler: Handler<U>, falseHandler: Handler<U>): this;
|
|
10
|
+
filter<D extends U>(predicate: (ctx: U) => ctx is D, ...middleware: Handler<D>[]): Composer<D>;
|
|
11
|
+
filter(predicate: (ctx: U) => MaybePromise<boolean>, ...middleware: Handler<U>[]): Composer<U>;
|
|
12
|
+
on<T extends keyof U, F extends keyof NonNullable<U[T]>>(filter: T extends FilterableUpdates ? T | [T, F, ...F[]] : T, ...handlers: Handler<FilterUpdate<U, T, F>>[]): Composer<FilterUpdate<U, T, F>>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { resolve } from "./0_utilities.js";
|
|
2
|
+
export function call(handler) {
|
|
3
|
+
if ("handle" in handler) {
|
|
4
|
+
return handler.handle;
|
|
5
|
+
}
|
|
6
|
+
else {
|
|
7
|
+
return handler;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function concat(what, with_) {
|
|
11
|
+
return async (upd, next) => {
|
|
12
|
+
let called = false;
|
|
13
|
+
await call(what)(upd, async () => {
|
|
14
|
+
if (called)
|
|
15
|
+
return;
|
|
16
|
+
called = true;
|
|
17
|
+
await call(with_)(upd, next);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function reduce(...handlers) {
|
|
22
|
+
return handlers.reduce((a, b) => concat(a, b));
|
|
23
|
+
}
|
|
24
|
+
export class Composer {
|
|
25
|
+
constructor(...handlers) {
|
|
26
|
+
Object.defineProperty(this, "_handle", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: resolve
|
|
31
|
+
});
|
|
32
|
+
this.use(...handlers);
|
|
33
|
+
}
|
|
34
|
+
get handle() {
|
|
35
|
+
return this._handle;
|
|
36
|
+
}
|
|
37
|
+
use(...handlers) {
|
|
38
|
+
const handle = this.handle;
|
|
39
|
+
this._handle = concat(handle, reduce(...handlers));
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
branch(predicate, trueHandler, falseHandler) {
|
|
43
|
+
return this.use(async (upd, next) => {
|
|
44
|
+
if (await predicate(upd)) {
|
|
45
|
+
await call(trueHandler)(upd, next);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
await call(falseHandler)(upd, next);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
filter(predicate, ...middleware) {
|
|
53
|
+
const composer = new Composer(...middleware);
|
|
54
|
+
this.branch(predicate, composer, resolve);
|
|
55
|
+
return composer;
|
|
56
|
+
}
|
|
57
|
+
on(filter, ...handlers) {
|
|
58
|
+
// deno-lint-ignore ban-ts-comment
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
const type = typeof filter === "string" ? filter : filter[0];
|
|
61
|
+
const keys = Array.isArray(filter) ? filter.slice(1) : [];
|
|
62
|
+
return this.filter((update) => {
|
|
63
|
+
if (type in update) {
|
|
64
|
+
if (keys.length > 0) {
|
|
65
|
+
for (const key of keys) {
|
|
66
|
+
// deno-lint-ignore ban-ts-comment
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
if (!(key in update[type])) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}, ...handlers);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -1,152 +1,15 @@
|
|
|
1
|
-
import { MaybePromise } from "../1_utilities.js";
|
|
2
1
|
import { functions, ReadObject, types } from "../2_tl.js";
|
|
3
2
|
import { Storage } from "../3_storage.js";
|
|
4
3
|
import { DC } from "../3_transport.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { ClientPlainParams } from "./2_client_plain.js";
|
|
4
|
+
import { Message } from "../3_types.js";
|
|
5
|
+
import { With } from "./0_utilities.js";
|
|
8
6
|
import { ClientAbstract } from "./1_client_abstract.js";
|
|
7
|
+
import { AnswerCallbackQueryParams, AuthorizeUserParams, ChatID, ClientParams, EditMessageParams, ForwardMessagesParams, Handler, ParseMode, SendMessagesParams, SendPollParams } from "./3_types.js";
|
|
9
8
|
export declare const getEntity: unique symbol;
|
|
10
9
|
export declare const getStickerSetName: unique symbol;
|
|
11
10
|
export declare const handleMigrationError: unique symbol;
|
|
12
11
|
export declare const getMessageWithReply: unique symbol;
|
|
13
12
|
export declare const restartAuth: unique symbol;
|
|
14
|
-
export declare enum ParseMode {
|
|
15
|
-
None = "none",
|
|
16
|
-
HTML = "html"
|
|
17
|
-
}
|
|
18
|
-
export interface AuthorizeUserParams<S = string> {
|
|
19
|
-
phone: S | (() => MaybePromise<S>);
|
|
20
|
-
code: S | (() => MaybePromise<S>);
|
|
21
|
-
password: S | ((hint: string | null) => MaybePromise<S>);
|
|
22
|
-
}
|
|
23
|
-
export interface ClientParams extends ClientPlainParams {
|
|
24
|
-
/**
|
|
25
|
-
* A parse mode to use when the `parseMode` parameter is not specified when sending or editing messages. Defauls to `ParseMode.None`.
|
|
26
|
-
*/
|
|
27
|
-
parseMode?: ParseMode;
|
|
28
|
-
/**
|
|
29
|
-
* The app_version parameter to be passed to initConnection when calling `authorize`. It is recommended that this parameter is changed if users are authorized. Defaults to "MTKruto" followed by this version of MTKruto.
|
|
30
|
-
*/
|
|
31
|
-
appVersion?: string;
|
|
32
|
-
/**
|
|
33
|
-
* The device_version parameter to be passed to initConnection when calling `authorize`. The default varies by the current runtime.
|
|
34
|
-
*/
|
|
35
|
-
deviceModel?: string;
|
|
36
|
-
/**
|
|
37
|
-
* The lang_code parameter to be passed to initConnection when calling `authorize`. Defaults to the runtime's language or `"en"`.
|
|
38
|
-
*/
|
|
39
|
-
langCode?: string;
|
|
40
|
-
/**
|
|
41
|
-
* The lang_pack parameter to be passed to initConnection when calling `authorize`. Defaults to an empty string.
|
|
42
|
-
*/
|
|
43
|
-
langPack?: string;
|
|
44
|
-
/**
|
|
45
|
-
* The system_lang_cde parameter to be passed to initConnection when calling `authorize`. Defaults to the runtime's language or `"en"`.
|
|
46
|
-
*/
|
|
47
|
-
systemLangCode?: string;
|
|
48
|
-
/**
|
|
49
|
-
* The system_version parameter to be passed to initConnection when calling `authorize`. The default varies by the current runtime.
|
|
50
|
-
*/
|
|
51
|
-
systemVersion?: string;
|
|
52
|
-
/**
|
|
53
|
-
* Whether to automatically call `start` with no parameters in the first `invoke` call. Defaults to `true`.
|
|
54
|
-
*/
|
|
55
|
-
autoStart?: boolean;
|
|
56
|
-
}
|
|
57
|
-
export interface AnswerCallbackQueryParams {
|
|
58
|
-
/** Text of the answer */
|
|
59
|
-
text?: string;
|
|
60
|
-
/** Pass true to show an alert to the user instead of a toast notification */
|
|
61
|
-
alert?: boolean;
|
|
62
|
-
/** URL to be opened */
|
|
63
|
-
url?: string;
|
|
64
|
-
/** Time during which the result of the query can be cached, in seconds */
|
|
65
|
-
cacheTime?: number;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* A chat identifier as provided by MTKruto or a string starting with a @ that is followed by a username.
|
|
69
|
-
*/
|
|
70
|
-
export type ChatID = number | string;
|
|
71
|
-
export interface SendMessagesParams {
|
|
72
|
-
/**
|
|
73
|
-
* The parse mode to use. If not provided, the default parse mode will be used.
|
|
74
|
-
*/
|
|
75
|
-
parseMode?: ParseMode;
|
|
76
|
-
/**
|
|
77
|
-
* The message's entities.
|
|
78
|
-
*/
|
|
79
|
-
entities?: MessageEntity[];
|
|
80
|
-
/**
|
|
81
|
-
* Whether to disable web page previews in the message that is to be sent.
|
|
82
|
-
*/
|
|
83
|
-
disableWebPagePreview?: boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Whether to send the message in a silent way without making a sound on the recipients' clients.
|
|
86
|
-
*/
|
|
87
|
-
disableNotification?: boolean;
|
|
88
|
-
/**
|
|
89
|
-
* Whether to protect the contents of the message from copying and forwarding.
|
|
90
|
-
*/
|
|
91
|
-
protectContent?: boolean;
|
|
92
|
-
/**
|
|
93
|
-
* The identifier of a message to reply to.
|
|
94
|
-
*/
|
|
95
|
-
replyToMessageId?: number;
|
|
96
|
-
/**
|
|
97
|
-
* The identifier of a thread to send the message to.
|
|
98
|
-
*/
|
|
99
|
-
messageThreadId?: number;
|
|
100
|
-
/**
|
|
101
|
-
* The identifier of the chat to send the message on behalf of. User-only.
|
|
102
|
-
*/
|
|
103
|
-
sendAs?: ChatID;
|
|
104
|
-
/**
|
|
105
|
-
* The reply markup of the message. Bot-only.
|
|
106
|
-
*/
|
|
107
|
-
replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
|
|
108
|
-
}
|
|
109
|
-
export interface EditMessageParams {
|
|
110
|
-
/**
|
|
111
|
-
* The parse mode to use. If not provided, the default parse mode will be used.
|
|
112
|
-
*/
|
|
113
|
-
parseMode?: ParseMode;
|
|
114
|
-
/**
|
|
115
|
-
* The message's entities.
|
|
116
|
-
*/
|
|
117
|
-
entities?: MessageEntity[];
|
|
118
|
-
/**
|
|
119
|
-
* Whether to disable web page previews in the message that is to be edited.
|
|
120
|
-
*/
|
|
121
|
-
disableWebPagePreview?: boolean;
|
|
122
|
-
/**
|
|
123
|
-
* The reply markup of the message. Bot-only.
|
|
124
|
-
*/
|
|
125
|
-
replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
|
|
126
|
-
}
|
|
127
|
-
export interface ForwardMessagesParams {
|
|
128
|
-
messageThreadId?: number;
|
|
129
|
-
/**
|
|
130
|
-
* Whether to forward the message in a silent way without making a sound on the recipients' clients.
|
|
131
|
-
*/
|
|
132
|
-
disableNotification?: boolean;
|
|
133
|
-
/**
|
|
134
|
-
* Whether to protect the contents of the forwarded message from copying and forwarding.
|
|
135
|
-
*/
|
|
136
|
-
protectContent?: boolean;
|
|
137
|
-
/**
|
|
138
|
-
* The identifier of the chat to forward the message on behalf of. User-only.
|
|
139
|
-
*/
|
|
140
|
-
sendAs?: ChatID;
|
|
141
|
-
/**
|
|
142
|
-
* Whether to not include the original sender of the message that is going to be forwarded.
|
|
143
|
-
*/
|
|
144
|
-
dropSenderName?: boolean;
|
|
145
|
-
/**
|
|
146
|
-
* Whether to not include the original caption of the message that is going to be forwarded.
|
|
147
|
-
*/
|
|
148
|
-
dropCaption?: boolean;
|
|
149
|
-
}
|
|
150
13
|
export declare class Client extends ClientAbstract {
|
|
151
14
|
readonly storage: Storage;
|
|
152
15
|
readonly apiId: number | null;
|
|
@@ -194,6 +57,8 @@ export declare class Client extends ClientAbstract {
|
|
|
194
57
|
* Before establishing the connection, the session is saved.
|
|
195
58
|
*/
|
|
196
59
|
connect(): Promise<void>;
|
|
60
|
+
private assertUser;
|
|
61
|
+
private assertBot;
|
|
197
62
|
private fetchState;
|
|
198
63
|
[handleMigrationError](err: types.RPCError): Promise<void>;
|
|
199
64
|
private connectionInited;
|
|
@@ -259,13 +124,15 @@ export declare class Client extends ClientAbstract {
|
|
|
259
124
|
[getEntity](peer: types.PeerChannel): Promise<types.Channel | null>;
|
|
260
125
|
processResult(result: ReadObject): Promise<void>;
|
|
261
126
|
private updatesToMessages;
|
|
127
|
+
private resolveSendAs;
|
|
262
128
|
/**
|
|
263
129
|
* Send a text message.
|
|
264
130
|
*
|
|
265
131
|
* @param chatId The chat to send the message to.
|
|
266
132
|
* @param text The message's text.
|
|
267
133
|
*/
|
|
268
|
-
sendMessage(chatId: ChatID, text: string, params?: SendMessagesParams): Promise<Message
|
|
134
|
+
sendMessage(chatId: ChatID, text: string, params?: SendMessagesParams): Promise<With<Message, "text">>;
|
|
135
|
+
private parseText;
|
|
269
136
|
/**
|
|
270
137
|
* Edit a message's text.
|
|
271
138
|
*
|
|
@@ -319,34 +186,22 @@ export declare class Client extends ClientAbstract {
|
|
|
319
186
|
*/
|
|
320
187
|
getMe(): Promise<import("../3_types.js").User>;
|
|
321
188
|
private handleUpdate;
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
on<U extends keyof Update, K extends keyof Update[U]>(filter: U extends FilterableUpdates ? U | [U, K, ...K[]] : U, handler: Handler<Pick<{
|
|
325
|
-
[P in U]: With<Update[U], K>;
|
|
326
|
-
}, U>>): void;
|
|
189
|
+
private _handler;
|
|
190
|
+
set handler(handler: Handler);
|
|
327
191
|
/**
|
|
328
192
|
* Answer a callback query. Bot-only.
|
|
329
193
|
*
|
|
330
194
|
* @param id ID of the callback query to answer.
|
|
331
195
|
*/
|
|
332
196
|
answerCallbackQuery(id: string, params?: AnswerCallbackQueryParams): Promise<void>;
|
|
197
|
+
private constructReplyMarkup;
|
|
198
|
+
private static assertMsgHas;
|
|
199
|
+
/**
|
|
200
|
+
* Send a poll.
|
|
201
|
+
*
|
|
202
|
+
* @param chatId The chat to send the poll to.
|
|
203
|
+
* @param question The poll's question.
|
|
204
|
+
* @param options The poll's options.
|
|
205
|
+
*/
|
|
206
|
+
sendPoll(chatId: ChatID, question: string, options: [string, string, ...string[]], params?: SendPollParams): Promise<With<Message, "poll">>;
|
|
333
207
|
}
|
|
334
|
-
type With<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
335
|
-
export type ConnectionState = "not-connected" | "updating" | "ready";
|
|
336
|
-
export type AuthorizationState = {
|
|
337
|
-
authorized: boolean;
|
|
338
|
-
};
|
|
339
|
-
type FilterableUpdates = "message" | "editedMessage" | "callbackQuery";
|
|
340
|
-
export interface Update {
|
|
341
|
-
message: Message;
|
|
342
|
-
editedMessage: Message;
|
|
343
|
-
connectionState: ConnectionState;
|
|
344
|
-
authorizationState: AuthorizationState;
|
|
345
|
-
deletedMessages: [Message, ...Message[]];
|
|
346
|
-
callbackQuery: CallbackQuery;
|
|
347
|
-
inlineQuery: InlineQuery;
|
|
348
|
-
}
|
|
349
|
-
export interface Handler<U extends Partial<Update> = Partial<Update>> {
|
|
350
|
-
(update: U, next: () => Promise<void>): MaybePromise<void>;
|
|
351
|
-
}
|
|
352
|
-
export {};
|