@mtcute/dispatcher 0.16.9 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/context/message.d.ts +7 -1
- package/filters/message.d.ts +5 -0
- package/index.cjs +24 -0
- package/index.js +24 -0
- package/package.json +2 -2
package/context/message.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OmitInputMessageId, ParametersSkip1, Peer, Sticker, Message } from '@mtcute/core';
|
|
1
|
+
import { Chat, OmitInputMessageId, ParametersSkip1, Peer, Sticker, Message } from '@mtcute/core';
|
|
2
2
|
import { TelegramClient } from '@mtcute/core/client.js';
|
|
3
3
|
import { DeleteMessagesParams, ForwardMessageOptions, SendCopyGroupParams, SendCopyParams } from '@mtcute/core/methods.js';
|
|
4
4
|
import { UpdateContext } from './base.js';
|
|
@@ -29,6 +29,12 @@ export declare class MessageContext extends Message implements UpdateContext<Mes
|
|
|
29
29
|
* Learn more: [Incomplete peers](https://mtcute.dev/guide/topics/peers.html#incomplete-peers)
|
|
30
30
|
*/
|
|
31
31
|
getCompleteSender(): Promise<Peer>;
|
|
32
|
+
/**
|
|
33
|
+
* Get complete information about {@link chat}
|
|
34
|
+
*
|
|
35
|
+
* Learn more: [Incomplete peers](https://mtcute.dev/guide/topics/peers.html#incomplete-peers)
|
|
36
|
+
*/
|
|
37
|
+
getCompleteChat(): Promise<Chat>;
|
|
32
38
|
/** Get a message that this message is a reply to */
|
|
33
39
|
getReplyTo(): Promise<Message | null>;
|
|
34
40
|
/** If this is a channel post, get its automatic forward in the discussion group */
|
package/filters/message.d.ts
CHANGED
|
@@ -212,3 +212,8 @@ export declare function replyTo<Mod, State extends object>(filter?: UpdateFilter
|
|
|
212
212
|
* and make it available to further filters, as well as the handler itself.
|
|
213
213
|
*/
|
|
214
214
|
export declare function withCompleteSender<Mod, State extends object>(filter?: UpdateFilter<MessageContext, Mod, State>): UpdateFilter<MessageContext, Mod, State>;
|
|
215
|
+
/**
|
|
216
|
+
* Middleware-like filter that will fetch the chat of the message
|
|
217
|
+
* and make it available to further filters, as well as the handler itself.
|
|
218
|
+
*/
|
|
219
|
+
export declare function withCompleteChat<Mod, State extends object>(filter?: UpdateFilter<MessageContext, Mod, State>): UpdateFilter<MessageContext, Mod, State>;
|
package/index.cjs
CHANGED
|
@@ -429,6 +429,18 @@ class MessageContext extends core.Message {
|
|
|
429
429
|
Object.defineProperty(this, "sender", { value: res });
|
|
430
430
|
return res;
|
|
431
431
|
}
|
|
432
|
+
/**
|
|
433
|
+
* Get complete information about {@link chat}
|
|
434
|
+
*
|
|
435
|
+
* Learn more: [Incomplete peers](https://mtcute.dev/guide/topics/peers.html#incomplete-peers)
|
|
436
|
+
*/
|
|
437
|
+
async getCompleteChat() {
|
|
438
|
+
if (!this.chat.isMin) return this.chat;
|
|
439
|
+
const res = await this.client.getChat(this.chat);
|
|
440
|
+
if (!res) throw new core.MtPeerNotFoundError("Failed to fetch chat");
|
|
441
|
+
Object.defineProperty(this, "chat", { value: res });
|
|
442
|
+
return res;
|
|
443
|
+
}
|
|
432
444
|
/** Get a message that this message is a reply to */
|
|
433
445
|
getReplyTo() {
|
|
434
446
|
return this.client.getReplyTo(this);
|
|
@@ -2190,6 +2202,17 @@ function withCompleteSender(filter) {
|
|
|
2190
2202
|
return filter(msg, state2);
|
|
2191
2203
|
};
|
|
2192
2204
|
}
|
|
2205
|
+
function withCompleteChat(filter) {
|
|
2206
|
+
return async (msg, state2) => {
|
|
2207
|
+
try {
|
|
2208
|
+
await msg.getCompleteChat();
|
|
2209
|
+
} catch {
|
|
2210
|
+
return false;
|
|
2211
|
+
}
|
|
2212
|
+
if (!filter) return true;
|
|
2213
|
+
return filter(msg, state2);
|
|
2214
|
+
};
|
|
2215
|
+
}
|
|
2193
2216
|
const stateEmpty = async (upd, state2) => {
|
|
2194
2217
|
if (!state2) return false;
|
|
2195
2218
|
return !await state2.get();
|
|
@@ -2401,6 +2424,7 @@ const bundle = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProper
|
|
|
2401
2424
|
video,
|
|
2402
2425
|
voice,
|
|
2403
2426
|
webpage,
|
|
2427
|
+
withCompleteChat,
|
|
2404
2428
|
withCompleteSender
|
|
2405
2429
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
2406
2430
|
var PropagationAction = /* @__PURE__ */ ((PropagationAction2) => {
|
package/index.js
CHANGED
|
@@ -422,6 +422,18 @@ class MessageContext extends Message {
|
|
|
422
422
|
Object.defineProperty(this, "sender", { value: res });
|
|
423
423
|
return res;
|
|
424
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* Get complete information about {@link chat}
|
|
427
|
+
*
|
|
428
|
+
* Learn more: [Incomplete peers](https://mtcute.dev/guide/topics/peers.html#incomplete-peers)
|
|
429
|
+
*/
|
|
430
|
+
async getCompleteChat() {
|
|
431
|
+
if (!this.chat.isMin) return this.chat;
|
|
432
|
+
const res = await this.client.getChat(this.chat);
|
|
433
|
+
if (!res) throw new MtPeerNotFoundError("Failed to fetch chat");
|
|
434
|
+
Object.defineProperty(this, "chat", { value: res });
|
|
435
|
+
return res;
|
|
436
|
+
}
|
|
425
437
|
/** Get a message that this message is a reply to */
|
|
426
438
|
getReplyTo() {
|
|
427
439
|
return this.client.getReplyTo(this);
|
|
@@ -2183,6 +2195,17 @@ function withCompleteSender(filter) {
|
|
|
2183
2195
|
return filter(msg, state2);
|
|
2184
2196
|
};
|
|
2185
2197
|
}
|
|
2198
|
+
function withCompleteChat(filter) {
|
|
2199
|
+
return async (msg, state2) => {
|
|
2200
|
+
try {
|
|
2201
|
+
await msg.getCompleteChat();
|
|
2202
|
+
} catch {
|
|
2203
|
+
return false;
|
|
2204
|
+
}
|
|
2205
|
+
if (!filter) return true;
|
|
2206
|
+
return filter(msg, state2);
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2186
2209
|
const stateEmpty = async (upd, state2) => {
|
|
2187
2210
|
if (!state2) return false;
|
|
2188
2211
|
return !await state2.get();
|
|
@@ -2394,6 +2417,7 @@ const bundle = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProper
|
|
|
2394
2417
|
video,
|
|
2395
2418
|
voice,
|
|
2396
2419
|
webpage,
|
|
2420
|
+
withCompleteChat,
|
|
2397
2421
|
withCompleteSender
|
|
2398
2422
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
2399
2423
|
var PropagationAction = /* @__PURE__ */ ((PropagationAction2) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mtcute/dispatcher",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.17.0",
|
|
5
5
|
"description": "Updates dispatcher and bot framework for @mtcute/client",
|
|
6
6
|
"author": "alina sireneva <alina@tei.su>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"scripts": {},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@mtcute/core": "^0.
|
|
23
|
+
"@mtcute/core": "^0.17.0",
|
|
24
24
|
"events": "3.2.0"
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://mtcute.dev",
|