@mtcute/dispatcher 0.16.0 → 0.16.7

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.
Files changed (162) hide show
  1. package/README.md +2 -2
  2. package/cjs/callback-data-builder.d.ts +2 -2
  3. package/cjs/callback-data-builder.js +8 -6
  4. package/cjs/callback-data-builder.js.map +1 -1
  5. package/cjs/context/base.d.ts +2 -2
  6. package/cjs/context/base.js.map +1 -1
  7. package/cjs/context/business-message.d.ts +20 -19
  8. package/cjs/context/business-message.js +3 -3
  9. package/cjs/context/business-message.js.map +1 -1
  10. package/cjs/context/callback-query.d.ts +4 -3
  11. package/cjs/context/callback-query.js.map +1 -1
  12. package/cjs/context/chat-join-request.d.ts +2 -2
  13. package/cjs/context/chat-join-request.js.map +1 -1
  14. package/cjs/context/chosen-inline-result.d.ts +2 -2
  15. package/cjs/context/chosen-inline-result.js.map +1 -1
  16. package/cjs/context/inline-query.d.ts +4 -3
  17. package/cjs/context/inline-query.js.map +1 -1
  18. package/cjs/context/message.d.ts +6 -5
  19. package/cjs/context/message.js +3 -3
  20. package/cjs/context/message.js.map +1 -1
  21. package/cjs/context/parse.d.ts +5 -5
  22. package/cjs/context/parse.js +1 -2
  23. package/cjs/context/parse.js.map +1 -1
  24. package/cjs/context/pre-checkout-query.d.ts +2 -2
  25. package/cjs/context/pre-checkout-query.js.map +1 -1
  26. package/cjs/context/scene-transition.d.ts +1 -1
  27. package/cjs/context/scene-transition.js.map +1 -1
  28. package/cjs/dispatcher.d.ts +10 -9
  29. package/cjs/dispatcher.js +34 -31
  30. package/cjs/dispatcher.js.map +1 -1
  31. package/cjs/filters/bots.d.ts +15 -25
  32. package/cjs/filters/bots.js +36 -34
  33. package/cjs/filters/bots.js.map +1 -1
  34. package/cjs/filters/chat.d.ts +5 -5
  35. package/cjs/filters/chat.js +10 -9
  36. package/cjs/filters/chat.js.map +1 -1
  37. package/cjs/filters/group.d.ts +4 -4
  38. package/cjs/filters/group.js +3 -6
  39. package/cjs/filters/group.js.map +1 -1
  40. package/cjs/filters/index.js.map +1 -1
  41. package/cjs/filters/logic.d.ts +1 -1
  42. package/cjs/filters/logic.js +5 -7
  43. package/cjs/filters/logic.js.map +1 -1
  44. package/cjs/filters/message.d.ts +29 -146
  45. package/cjs/filters/message.js +84 -72
  46. package/cjs/filters/message.js.map +1 -1
  47. package/cjs/filters/state.d.ts +3 -3
  48. package/cjs/filters/state.js +5 -4
  49. package/cjs/filters/state.js.map +1 -1
  50. package/cjs/filters/text.d.ts +8 -8
  51. package/cjs/filters/text.js +27 -26
  52. package/cjs/filters/text.js.map +1 -1
  53. package/cjs/filters/types.d.ts +2 -2
  54. package/cjs/filters/types.js +0 -3
  55. package/cjs/filters/types.js.map +1 -1
  56. package/cjs/filters/updates.d.ts +2 -2
  57. package/cjs/filters/updates.js +7 -7
  58. package/cjs/filters/updates.js.map +1 -1
  59. package/cjs/filters/user.d.ts +4 -3
  60. package/cjs/filters/user.js +15 -16
  61. package/cjs/filters/user.js.map +1 -1
  62. package/cjs/handler.d.ts +5 -5
  63. package/cjs/handler.js.map +1 -1
  64. package/cjs/state/key.d.ts +3 -3
  65. package/cjs/state/key.js.map +1 -1
  66. package/cjs/state/provider.d.ts +2 -2
  67. package/cjs/state/provider.js.map +1 -1
  68. package/cjs/state/providers/memory.d.ts +4 -3
  69. package/cjs/state/providers/memory.js.map +1 -1
  70. package/cjs/state/providers/sqlite.d.ts +3 -3
  71. package/cjs/state/providers/sqlite.js.map +1 -1
  72. package/cjs/state/repository.d.ts +7 -7
  73. package/cjs/state/repository.js.map +1 -1
  74. package/cjs/state/service.d.ts +4 -3
  75. package/cjs/state/service.js.map +1 -1
  76. package/cjs/state/update-state.d.ts +1 -1
  77. package/cjs/state/update-state.js +3 -4
  78. package/cjs/state/update-state.js.map +1 -1
  79. package/cjs/wizard.d.ts +8 -7
  80. package/cjs/wizard.js +3 -1
  81. package/cjs/wizard.js.map +1 -1
  82. package/esm/callback-data-builder.d.ts +2 -2
  83. package/esm/callback-data-builder.js +8 -6
  84. package/esm/callback-data-builder.js.map +1 -1
  85. package/esm/context/base.d.ts +2 -2
  86. package/esm/context/base.js.map +1 -1
  87. package/esm/context/business-message.d.ts +20 -19
  88. package/esm/context/business-message.js +3 -3
  89. package/esm/context/business-message.js.map +1 -1
  90. package/esm/context/callback-query.d.ts +4 -3
  91. package/esm/context/callback-query.js.map +1 -1
  92. package/esm/context/chat-join-request.d.ts +2 -2
  93. package/esm/context/chat-join-request.js.map +1 -1
  94. package/esm/context/chosen-inline-result.d.ts +2 -2
  95. package/esm/context/chosen-inline-result.js.map +1 -1
  96. package/esm/context/inline-query.d.ts +4 -3
  97. package/esm/context/inline-query.js.map +1 -1
  98. package/esm/context/message.d.ts +6 -5
  99. package/esm/context/message.js +3 -3
  100. package/esm/context/message.js.map +1 -1
  101. package/esm/context/parse.d.ts +5 -5
  102. package/esm/context/parse.js.map +1 -1
  103. package/esm/context/pre-checkout-query.d.ts +2 -2
  104. package/esm/context/pre-checkout-query.js.map +1 -1
  105. package/esm/context/scene-transition.d.ts +1 -1
  106. package/esm/context/scene-transition.js.map +1 -1
  107. package/esm/dispatcher.d.ts +10 -9
  108. package/esm/dispatcher.js +35 -32
  109. package/esm/dispatcher.js.map +1 -1
  110. package/esm/filters/bots.d.ts +15 -25
  111. package/esm/filters/bots.js +32 -30
  112. package/esm/filters/bots.js.map +1 -1
  113. package/esm/filters/chat.d.ts +5 -5
  114. package/esm/filters/chat.js +8 -7
  115. package/esm/filters/chat.js.map +1 -1
  116. package/esm/filters/group.d.ts +4 -4
  117. package/esm/filters/group.js +1 -3
  118. package/esm/filters/group.js.map +1 -1
  119. package/esm/filters/index.js.map +1 -1
  120. package/esm/filters/logic.d.ts +1 -1
  121. package/esm/filters/logic.js +1 -3
  122. package/esm/filters/logic.js.map +1 -1
  123. package/esm/filters/message.d.ts +29 -146
  124. package/esm/filters/message.js +60 -48
  125. package/esm/filters/message.js.map +1 -1
  126. package/esm/filters/state.d.ts +3 -3
  127. package/esm/filters/state.js +3 -2
  128. package/esm/filters/state.js.map +1 -1
  129. package/esm/filters/text.d.ts +8 -8
  130. package/esm/filters/text.js +22 -20
  131. package/esm/filters/text.js.map +1 -1
  132. package/esm/filters/types.d.ts +2 -2
  133. package/esm/filters/types.js +0 -3
  134. package/esm/filters/types.js.map +1 -1
  135. package/esm/filters/updates.d.ts +2 -2
  136. package/esm/filters/updates.js +7 -7
  137. package/esm/filters/updates.js.map +1 -1
  138. package/esm/filters/user.d.ts +4 -3
  139. package/esm/filters/user.js +15 -16
  140. package/esm/filters/user.js.map +1 -1
  141. package/esm/handler.d.ts +5 -5
  142. package/esm/handler.js.map +1 -1
  143. package/esm/state/key.d.ts +3 -3
  144. package/esm/state/key.js.map +1 -1
  145. package/esm/state/provider.d.ts +2 -2
  146. package/esm/state/provider.js.map +1 -1
  147. package/esm/state/providers/memory.d.ts +4 -3
  148. package/esm/state/providers/memory.js.map +1 -1
  149. package/esm/state/providers/sqlite.d.ts +3 -3
  150. package/esm/state/providers/sqlite.js.map +1 -1
  151. package/esm/state/repository.d.ts +7 -7
  152. package/esm/state/repository.js.map +1 -1
  153. package/esm/state/service.d.ts +4 -3
  154. package/esm/state/service.js +1 -1
  155. package/esm/state/service.js.map +1 -1
  156. package/esm/state/update-state.d.ts +1 -1
  157. package/esm/state/update-state.js +3 -4
  158. package/esm/state/update-state.js.map +1 -1
  159. package/esm/wizard.d.ts +8 -7
  160. package/esm/wizard.js +3 -1
  161. package/esm/wizard.js.map +1 -1
  162. package/package.json +3 -3
@@ -1,7 +1,8 @@
1
- import { _RepliedMessageAssertionsByOrigin, MaybeArray, Message, MessageAction, Peer, RawDocument, RepliedMessageInfo, RepliedMessageOrigin, Sticker, StickerSourceType, StickerType, User, Video } from '@mtcute/core';
2
- import { BusinessMessageContext } from '../context/business-message.js';
3
- import { MessageContext } from '../index.js';
4
- import { Modify, UpdateFilter } from './types.js';
1
+ import type { Audio, Contact, Dice, Document, Game, Invoice, LiveLocation, Location, MaybeArray, Message, MessageAction, MessageMediaType, Peer, Photo, Poll, RepliedMessageInfo, RepliedMessageOrigin, Sticker, StickerSourceType, StickerType, User, Venue, Video, Voice, WebPage, _RepliedMessageAssertionsByOrigin } from '@mtcute/core';
2
+ import { RawDocument } from '@mtcute/core';
3
+ import type { BusinessMessageContext } from '../context/business-message.js';
4
+ import type { MessageContext } from '../index.js';
5
+ import type { Modify, UpdateFilter } from './types.js';
5
6
  /**
6
7
  * Filter incoming messages.
7
8
  *
@@ -33,7 +34,7 @@ export declare const reply: UpdateFilter<Message, {
33
34
  /**
34
35
  * Filter messages that are replies with the given origin type
35
36
  */
36
- export declare const replyOrigin: <T extends RepliedMessageOrigin>(origin: T) => UpdateFilter<Message, {
37
+ export declare function replyOrigin<T extends RepliedMessageOrigin>(origin: T): UpdateFilter<Message, {
37
38
  replyToMessage: Modify<RepliedMessageInfo, _RepliedMessageAssertionsByOrigin[T] & {
38
39
  origin: T;
39
40
  }>;
@@ -47,62 +48,30 @@ export declare const media: UpdateFilter<Message, {
47
48
  /**
48
49
  * Filter messages containing media of given type
49
50
  */
50
- export declare const mediaOf: <T extends "photo" | "location" | "poll" | "story" | "contact" | "game" | "sticker" | "dice" | "audio" | "voice" | "document" | "video" | "live_location" | "webpage" | "venue" | "invoice" | "paid">(type: T) => UpdateFilter<Message, {
51
- media: Extract<Sticker, {
52
- type: T;
53
- }> | Extract<import("@mtcute/core").Photo, {
54
- type: T;
55
- }> | Extract<import("@mtcute/core").Dice, {
56
- type: T;
57
- }> | Extract<import("@mtcute/core").Contact, {
58
- type: T;
59
- }> | Extract<import("@mtcute/core").Audio, {
60
- type: T;
61
- }> | Extract<import("@mtcute/core").Voice, {
62
- type: T;
63
- }> | Extract<import("@mtcute/core").Document, {
64
- type: T;
65
- }> | Extract<Video, {
66
- type: T;
67
- }> | Extract<import("@mtcute/core").Location, {
68
- type: T;
69
- }> | Extract<import("@mtcute/core").LiveLocation, {
70
- type: T;
71
- }> | Extract<import("@mtcute/core").Game, {
72
- type: T;
73
- }> | Extract<import("@mtcute/core").WebPage, {
74
- type: T;
75
- }> | Extract<import("@mtcute/core").Venue, {
76
- type: T;
77
- }> | Extract<import("@mtcute/core").Poll, {
78
- type: T;
79
- }> | Extract<import("@mtcute/core").Invoice, {
80
- type: T;
81
- }> | Extract<import("@mtcute/core").MediaStory, {
82
- type: T;
83
- }> | Extract<import("@mtcute/core").PaidMedia, {
51
+ export declare function mediaOf<T extends MessageMediaType>(type: T): UpdateFilter<Message, {
52
+ media: Extract<Message['media'], {
84
53
  type: T;
85
54
  }>;
86
55
  }>;
87
56
  /** Filter messages containing a photo */
88
57
  export declare const photo: UpdateFilter<Message, {
89
- media: import("@mtcute/core").Photo;
58
+ media: Photo;
90
59
  }>;
91
60
  /** Filter messages containing a dice */
92
61
  export declare const dice: UpdateFilter<Message, {
93
- media: import("@mtcute/core").Dice;
62
+ media: Dice;
94
63
  }>;
95
64
  /** Filter messages containing a contact */
96
65
  export declare const contact: UpdateFilter<Message, {
97
- media: import("@mtcute/core").Contact;
66
+ media: Contact;
98
67
  }>;
99
68
  /** Filter messages containing an audio file */
100
69
  export declare const audio: UpdateFilter<Message, {
101
- media: import("@mtcute/core").Audio;
70
+ media: Audio;
102
71
  }>;
103
72
  /** Filter messages containing a voice message (audio-only) */
104
73
  export declare const voice: UpdateFilter<Message, {
105
- media: import("@mtcute/core").Voice;
74
+ media: Voice;
106
75
  }>;
107
76
  /** Filter messages containing a sticker */
108
77
  export declare const sticker: UpdateFilter<Message, {
@@ -110,7 +79,7 @@ export declare const sticker: UpdateFilter<Message, {
110
79
  }>;
111
80
  /** Filter messages containing a document (a file) */
112
81
  export declare const document: UpdateFilter<Message, {
113
- media: import("@mtcute/core").Document;
82
+ media: Document;
114
83
  }>;
115
84
  /** Filter messages containing any video (videos, round messages and animations) */
116
85
  export declare const anyVideo: UpdateFilter<Message, {
@@ -118,31 +87,31 @@ export declare const anyVideo: UpdateFilter<Message, {
118
87
  }>;
119
88
  /** Filter messages containing a static location */
120
89
  export declare const location: UpdateFilter<Message, {
121
- media: import("@mtcute/core").Location;
90
+ media: Location;
122
91
  }>;
123
92
  /** Filter messages containing a live location */
124
93
  export declare const liveLocation: UpdateFilter<Message, {
125
- media: import("@mtcute/core").LiveLocation;
94
+ media: LiveLocation;
126
95
  }>;
127
96
  /** Filter messages containing a game */
128
97
  export declare const game: UpdateFilter<Message, {
129
- media: import("@mtcute/core").Game;
98
+ media: Game;
130
99
  }>;
131
100
  /** Filter messages containing a web page */
132
101
  export declare const webpage: UpdateFilter<Message, {
133
- media: import("@mtcute/core").WebPage;
102
+ media: WebPage;
134
103
  }>;
135
104
  /** Filter messages containing a venue */
136
105
  export declare const venue: UpdateFilter<Message, {
137
- media: import("@mtcute/core").Venue;
106
+ media: Venue;
138
107
  }>;
139
108
  /** Filter messages containing a poll */
140
109
  export declare const poll: UpdateFilter<Message, {
141
- media: import("@mtcute/core").Poll;
110
+ media: Poll;
142
111
  }>;
143
112
  /** Filter messages containing an invoice */
144
113
  export declare const invoice: UpdateFilter<Message, {
145
- media: import("@mtcute/core").Invoice;
114
+ media: Invoice;
146
115
  }>;
147
116
  /**
148
117
  * Filter messages containing any location (live or static).
@@ -194,13 +163,13 @@ export declare const roundMessage: UpdateFilter<Message, {
194
163
  /**
195
164
  * Filter messages containing a sticker by its type
196
165
  */
197
- export declare const stickerByType: (type: StickerType) => UpdateFilter<Message, {
166
+ export declare function stickerByType(type: StickerType): UpdateFilter<Message, {
198
167
  media: Sticker;
199
168
  }>;
200
169
  /**
201
170
  * Filter messages containing a sticker by its source file type
202
171
  */
203
- export declare const stickerBySourceType: (type: StickerSourceType) => UpdateFilter<Message, {
172
+ export declare function stickerBySourceType(type: StickerSourceType): UpdateFilter<Message, {
204
173
  media: Sticker;
205
174
  }>;
206
175
  /**
@@ -219,100 +188,14 @@ export declare const service: UpdateFilter<Message, {
219
188
  /**
220
189
  * Filter service messages by action type
221
190
  */
222
- export declare const action: <T extends "chat_created" | "channel_created" | "chat_migrate_to" | "channel_migrate_from" | "message_pinned" | "history_cleared" | "game_score" | "contact_joined" | "title_changed" | "photo_changed" | "photo_deleted" | "users_added" | "user_left" | "user_removed" | "user_joined_link" | "payment_received" | "payment_sent" | "call" | "screenshot_taken" | "bot_allowed" | "geo_proximity" | "group_call_started" | "group_call_ended" | "group_call_scheduled" | "group_call_invite" | "ttl_changed" | "topic_created" | "topic_edited" | "custom" | "theme_changed" | "user_joined_approved" | "webview_sent" | "webview_received" | "premium_gifted" | "photo_suggested" | "peer_sent" | "peer_chosen" | "wallpaper_changed" | "gift_code" | "giveaway_started" | "giveaway_ended" | "boost_apply" | "payment_refunded">(type: MaybeArray<T>) => UpdateFilter<Message, {
223
- action: Extract<import("@mtcute/core").ActionChatCreated, {
224
- type: T;
225
- }> | Extract<import("@mtcute/core").ActionChannelCreated, {
226
- type: T;
227
- }> | Extract<import("@mtcute/core").ActionChatMigrateTo, {
228
- type: T;
229
- }> | Extract<import("@mtcute/core").ActionChannelMigrateFrom, {
230
- type: T;
231
- }> | Extract<import("@mtcute/core").ActionMessagePinned, {
232
- type: T;
233
- }> | Extract<import("@mtcute/core").ActionHistoryCleared, {
234
- type: T;
235
- }> | Extract<import("@mtcute/core").ActionGameScore, {
236
- type: T;
237
- }> | Extract<import("@mtcute/core").ActionContactJoined, {
238
- type: T;
239
- }> | Extract<import("@mtcute/core").ActionTitleChanged, {
240
- type: T;
241
- }> | Extract<import("@mtcute/core").ActionPhotoChanged, {
242
- type: T;
243
- }> | Extract<import("@mtcute/core").ActionPhotoDeleted, {
244
- type: T;
245
- }> | Extract<import("@mtcute/core").ActionUsersAdded, {
246
- type: T;
247
- }> | Extract<import("@mtcute/core").ActionUserLeft, {
248
- type: T;
249
- }> | Extract<import("@mtcute/core").ActionUserRemoved, {
250
- type: T;
251
- }> | Extract<import("@mtcute/core").ActionUserJoinedLink, {
252
- type: T;
253
- }> | Extract<import("@mtcute/core").ActionPaymentReceived, {
254
- type: T;
255
- }> | Extract<import("@mtcute/core").ActionPaymentSent, {
256
- type: T;
257
- }> | Extract<import("@mtcute/core").ActionCall, {
258
- type: T;
259
- }> | Extract<import("@mtcute/core").ActionScreenshotTaken, {
260
- type: T;
261
- }> | Extract<import("@mtcute/core").ActionBotAllowed, {
262
- type: T;
263
- }> | Extract<import("@mtcute/core").ActionGeoProximity, {
264
- type: T;
265
- }> | Extract<import("@mtcute/core").ActionGroupCallStarted, {
266
- type: T;
267
- }> | Extract<import("@mtcute/core").ActionGroupCallEnded, {
268
- type: T;
269
- }> | Extract<import("@mtcute/core").ActionGroupCallScheduled, {
270
- type: T;
271
- }> | Extract<import("@mtcute/core").ActionGroupInvite, {
272
- type: T;
273
- }> | Extract<import("@mtcute/core").ActionTtlChanged, {
274
- type: T;
275
- }> | Extract<import("@mtcute/core").ActionTopicCreated, {
276
- type: T;
277
- }> | Extract<import("@mtcute/core").ActionTopicEdited, {
278
- type: T;
279
- }> | Extract<import("@mtcute/core").ActionCustom, {
280
- type: T;
281
- }> | Extract<import("@mtcute/core").ActionThemeChanged, {
282
- type: T;
283
- }> | Extract<import("@mtcute/core").ActionUserJoinedApproved, {
284
- type: T;
285
- }> | Extract<import("@mtcute/core").ActionWebviewDataSent, {
286
- type: T;
287
- }> | Extract<import("@mtcute/core").ActionWebviewDataReceived, {
288
- type: T;
289
- }> | Extract<import("@mtcute/core").ActionPremiumGifted, {
290
- type: T;
291
- }> | Extract<import("@mtcute/core").ActionPhotoSuggested, {
292
- type: T;
293
- }> | Extract<import("@mtcute/core").ActionPeerSent, {
294
- type: T;
295
- }> | Extract<import("@mtcute/core").ActionPeerChosen, {
296
- type: T;
297
- }> | Extract<import("@mtcute/core").ActionWallpaperChanged, {
298
- type: T;
299
- }> | Extract<import("@mtcute/core").ActionGiftCode, {
300
- type: T;
301
- }> | Extract<import("@mtcute/core").ActionGiveawayStarted, {
302
- type: T;
303
- }> | Extract<import("@mtcute/core").ActionGiveawayEnded, {
304
- type: T;
305
- }> | Extract<import("@mtcute/core").ActionBoostApply, {
306
- type: T;
307
- }> | Extract<import("@mtcute/core").ActionPaymentRefunded, {
191
+ export declare function action<T extends Exclude<MessageAction, null>['type']>(type: MaybeArray<T>): UpdateFilter<Message, {
192
+ action: Extract<MessageAction, {
308
193
  type: T;
309
194
  }>;
310
195
  sender: T extends 'user_joined_link' | 'user_removed' | 'history_cleared' | 'contact_joined' | 'bot_allowed' ? User : Peer;
311
196
  }>;
312
- export declare const sender: <T extends "user" | "chat">(type: T) => UpdateFilter<Message, {
313
- sender: Extract<User, {
314
- type: T;
315
- }> | Extract<import("@mtcute/core").Chat, {
197
+ export declare function sender<T extends Message['sender']['type']>(type: T): UpdateFilter<Message, {
198
+ sender: Extract<Message['sender'], {
316
199
  type: T;
317
200
  }>;
318
201
  }>;
@@ -322,11 +205,11 @@ export declare const sender: <T extends "user" | "chat">(type: T) => UpdateFilte
322
205
  *
323
206
  * Optionally, you can pass a filter that will be applied to the replied message.
324
207
  */
325
- export declare const replyTo: <Mod, State extends object>(filter?: UpdateFilter<Message, Mod, State>) => UpdateFilter<MessageContext | BusinessMessageContext, {
208
+ export declare function replyTo<Mod, State extends object>(filter?: UpdateFilter<Message, Mod, State>): UpdateFilter<MessageContext | BusinessMessageContext, {
326
209
  getReplyTo: () => Promise<Message & Mod>;
327
210
  }, State>;
328
211
  /**
329
212
  * Middleware-like filter that will fetch the sender of the message
330
213
  * and make it available to further filters, as well as the handler itself.
331
214
  */
332
- export declare const withCompleteSender: <Mod, State extends object>(filter?: UpdateFilter<MessageContext, Mod, State>) => UpdateFilter<MessageContext, Mod, State>;
215
+ export declare function withCompleteSender<Mod, State extends object>(filter?: UpdateFilter<MessageContext, Mod, State>): UpdateFilter<MessageContext, Mod, State>;
@@ -1,82 +1,90 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withCompleteSender = exports.replyTo = exports.sender = exports.action = exports.service = exports.text = exports.stickerBySourceType = exports.stickerByType = exports.roundMessage = exports.animation = exports.video = exports.anyDocument = exports.anyLocation = exports.invoice = exports.poll = exports.venue = exports.webpage = exports.game = exports.liveLocation = exports.location = exports.anyVideo = exports.document = exports.sticker = exports.voice = exports.audio = exports.contact = exports.dice = exports.photo = exports.mediaOf = exports.media = exports.replyOrigin = exports.reply = exports.scheduled = exports.outgoing = exports.incoming = void 0;
4
- /* eslint-disable @typescript-eslint/no-explicit-any */
5
- // ^^ will be looked into in MTQ-29
3
+ exports.service = exports.text = exports.roundMessage = exports.animation = exports.video = exports.anyDocument = exports.anyLocation = exports.invoice = exports.poll = exports.venue = exports.webpage = exports.game = exports.liveLocation = exports.location = exports.anyVideo = exports.document = exports.sticker = exports.voice = exports.audio = exports.contact = exports.dice = exports.photo = exports.media = exports.reply = exports.scheduled = exports.outgoing = exports.incoming = void 0;
4
+ exports.replyOrigin = replyOrigin;
5
+ exports.mediaOf = mediaOf;
6
+ exports.stickerByType = stickerByType;
7
+ exports.stickerBySourceType = stickerBySourceType;
8
+ exports.action = action;
9
+ exports.sender = sender;
10
+ exports.replyTo = replyTo;
11
+ exports.withCompleteSender = withCompleteSender;
6
12
  const core_1 = require("@mtcute/core");
7
13
  /**
8
14
  * Filter incoming messages.
9
15
  *
10
16
  * Messages sent to yourself (i.e. Saved Messages) are also "incoming"
11
17
  */
12
- const incoming = (msg) => !msg.isOutgoing;
18
+ const incoming = msg => !msg.isOutgoing;
13
19
  exports.incoming = incoming;
14
20
  /**
15
21
  * Filter outgoing messages.
16
22
  *
17
23
  * Messages sent to yourself (i.e. Saved Messages) are **not** "outgoing"
18
24
  */
19
- const outgoing = (msg) => msg.isOutgoing;
25
+ const outgoing = msg => msg.isOutgoing;
20
26
  exports.outgoing = outgoing;
21
27
  /**
22
28
  * Filter for scheduled messages
23
29
  */
24
- const scheduled = (msg) => msg.isScheduled;
30
+ const scheduled = msg => msg.isScheduled;
25
31
  exports.scheduled = scheduled;
26
32
  /**
27
33
  * Filter messages that are replies to some other message
28
34
  */
29
- const reply = (msg) => msg.replyToMessage !== null;
35
+ const reply = msg => msg.replyToMessage !== null;
30
36
  exports.reply = reply;
31
37
  /**
32
38
  * Filter messages that are replies with the given origin type
33
39
  */
34
- const replyOrigin = (origin) => (msg) => msg.replyToMessage?.originIs(origin) ?? false; // originIs does additional checks
35
- exports.replyOrigin = replyOrigin;
40
+ function replyOrigin(origin) {
41
+ return msg => msg.replyToMessage?.originIs(origin) ?? false;
42
+ } // originIs does additional checks
36
43
  /**
37
44
  * Filter messages containing some media
38
45
  */
39
- const media = (msg) => msg.media !== null;
46
+ const media = msg => msg.media !== null;
40
47
  exports.media = media;
41
48
  /**
42
49
  * Filter messages containing media of given type
43
50
  */
44
- const mediaOf = (type) => (msg) => msg.media?.type === type;
45
- exports.mediaOf = mediaOf;
51
+ function mediaOf(type) {
52
+ return msg => msg.media?.type === type;
53
+ }
46
54
  /** Filter messages containing a photo */
47
- exports.photo = (0, exports.mediaOf)('photo');
55
+ exports.photo = mediaOf('photo');
48
56
  /** Filter messages containing a dice */
49
- exports.dice = (0, exports.mediaOf)('dice');
57
+ exports.dice = mediaOf('dice');
50
58
  /** Filter messages containing a contact */
51
- exports.contact = (0, exports.mediaOf)('contact');
59
+ exports.contact = mediaOf('contact');
52
60
  /** Filter messages containing an audio file */
53
- exports.audio = (0, exports.mediaOf)('audio');
61
+ exports.audio = mediaOf('audio');
54
62
  /** Filter messages containing a voice message (audio-only) */
55
- exports.voice = (0, exports.mediaOf)('voice');
63
+ exports.voice = mediaOf('voice');
56
64
  /** Filter messages containing a sticker */
57
- exports.sticker = (0, exports.mediaOf)('sticker');
65
+ exports.sticker = mediaOf('sticker');
58
66
  /** Filter messages containing a document (a file) */
59
- exports.document = (0, exports.mediaOf)('document');
67
+ exports.document = mediaOf('document');
60
68
  /** Filter messages containing any video (videos, round messages and animations) */
61
- exports.anyVideo = (0, exports.mediaOf)('video');
69
+ exports.anyVideo = mediaOf('video');
62
70
  /** Filter messages containing a static location */
63
- exports.location = (0, exports.mediaOf)('location');
71
+ exports.location = mediaOf('location');
64
72
  /** Filter messages containing a live location */
65
- exports.liveLocation = (0, exports.mediaOf)('live_location');
73
+ exports.liveLocation = mediaOf('live_location');
66
74
  /** Filter messages containing a game */
67
- exports.game = (0, exports.mediaOf)('game');
75
+ exports.game = mediaOf('game');
68
76
  /** Filter messages containing a web page */
69
- exports.webpage = (0, exports.mediaOf)('webpage');
77
+ exports.webpage = mediaOf('webpage');
70
78
  /** Filter messages containing a venue */
71
- exports.venue = (0, exports.mediaOf)('venue');
79
+ exports.venue = mediaOf('venue');
72
80
  /** Filter messages containing a poll */
73
- exports.poll = (0, exports.mediaOf)('poll');
81
+ exports.poll = mediaOf('poll');
74
82
  /** Filter messages containing an invoice */
75
- exports.invoice = (0, exports.mediaOf)('invoice');
83
+ exports.invoice = mediaOf('invoice');
76
84
  /**
77
85
  * Filter messages containing any location (live or static).
78
86
  */
79
- const anyLocation = (msg) => msg.media instanceof core_1.RawLocation;
87
+ const anyLocation = msg => msg.media instanceof core_1.RawLocation;
80
88
  exports.anyLocation = anyLocation;
81
89
  /**
82
90
  * Filter messages containing a document
@@ -84,14 +92,14 @@ exports.anyLocation = anyLocation;
84
92
  * This will also match media like audio, video, voice
85
93
  * that also use Documents
86
94
  */
87
- const anyDocument = (msg) => msg.media instanceof core_1.RawDocument;
95
+ const anyDocument = msg => msg.media instanceof core_1.RawDocument;
88
96
  exports.anyDocument = anyDocument;
89
97
  /**
90
98
  * Filter messages containing a simple video.
91
99
  *
92
100
  * This does not include round messages and animations
93
101
  */
94
- const video = (msg) => msg.media?.type === 'video' && !msg.media.isAnimation && !msg.media.isRound;
102
+ const video = msg => msg.media?.type === 'video' && !msg.media.isAnimation && !msg.media.isRound;
95
103
  exports.video = video;
96
104
  /**
97
105
  * Filter messages containing an animation.
@@ -99,81 +107,85 @@ exports.video = video;
99
107
  * > **Note**: Legacy GIFs (i.e. documents with `image/gif` MIME)
100
108
  * > are also considered animations.
101
109
  */
102
- const animation = (msg) => msg.media?.type === 'video' && msg.media.isAnimation && !msg.media.isRound;
110
+ const animation = msg => msg.media?.type === 'video' && msg.media.isAnimation && !msg.media.isRound;
103
111
  exports.animation = animation;
104
112
  /**
105
113
  * Filter messages containing a round message (aka video note).
106
114
  */
107
- const roundMessage = (msg) => msg.media?.type === 'video' && !msg.media.isAnimation && msg.media.isRound;
115
+ const roundMessage = msg => msg.media?.type === 'video' && !msg.media.isAnimation && msg.media.isRound;
108
116
  exports.roundMessage = roundMessage;
109
117
  /**
110
118
  * Filter messages containing a sticker by its type
111
119
  */
112
- const stickerByType = (type) => (msg) => msg.media?.type === 'sticker' && msg.media.stickerType === type;
113
- exports.stickerByType = stickerByType;
120
+ function stickerByType(type) {
121
+ return msg => msg.media?.type === 'sticker' && msg.media.stickerType === type;
122
+ }
114
123
  /**
115
124
  * Filter messages containing a sticker by its source file type
116
125
  */
117
- const stickerBySourceType = (type) => (msg) => msg.media?.type === 'sticker' && msg.media.sourceType === type;
118
- exports.stickerBySourceType = stickerBySourceType;
126
+ function stickerBySourceType(type) {
127
+ return msg => msg.media?.type === 'sticker' && msg.media.sourceType === type;
128
+ }
119
129
  /**
120
130
  * Filter text-only messages non-service messages
121
131
  */
122
- const text = (msg) => msg.media === null && !msg.isService;
132
+ const text = msg => msg.media === null && !msg.isService;
123
133
  exports.text = text;
124
134
  /**
125
135
  * Filter service messages
126
136
  */
127
- const service = (msg) => msg.isService;
137
+ const service = msg => msg.isService;
128
138
  exports.service = service;
129
139
  /**
130
140
  * Filter service messages by action type
131
141
  */
132
- const action = (type) => {
142
+ function action(type) {
133
143
  if (Array.isArray(type)) {
134
144
  const index = {};
135
- type.forEach((it) => (index[it] = true));
136
- return (msg) => msg.action?.type in index;
145
+ type.forEach(it => (index[it] = true));
146
+ return msg => msg.action?.type in index;
137
147
  }
138
- return (msg) => msg.action?.type === type;
139
- };
140
- exports.action = action;
141
- const sender = (type) => (msg) => msg.sender.type === type;
142
- exports.sender = sender;
148
+ return msg => msg.action?.type === type;
149
+ }
150
+ function sender(type) {
151
+ return msg => msg.sender.type === type;
152
+ }
143
153
  /**
144
154
  * Filter that matches messages that are replies to some other message that can be fetched
145
155
  * (i.e. not `private` origin, and has not been deleted)
146
156
  *
147
157
  * Optionally, you can pass a filter that will be applied to the replied message.
148
158
  */
149
- const replyTo = (filter) => async (msg, state) => {
150
- if (!msg.replyToMessage?.id)
151
- return false;
152
- const reply = msg._name === 'new_message' ? await msg.getReplyTo() : msg.replyTo;
153
- if (!reply)
154
- return false;
155
- if (msg._name === 'new_message') {
156
- msg.getReplyTo = () => Promise.resolve(reply);
157
- }
158
- if (!filter)
159
- return true;
160
- return filter(reply, state);
161
- };
162
- exports.replyTo = replyTo;
159
+ function replyTo(filter) {
160
+ return async (msg, state) => {
161
+ if (!msg.replyToMessage?.id)
162
+ return false;
163
+ const reply = msg._name === 'new_message' ? await msg.getReplyTo() : msg.replyTo;
164
+ if (!reply)
165
+ return false;
166
+ if (msg._name === 'new_message') {
167
+ msg.getReplyTo = () => Promise.resolve(reply);
168
+ }
169
+ if (!filter)
170
+ return true;
171
+ return filter(reply, state);
172
+ };
173
+ }
163
174
  /**
164
175
  * Middleware-like filter that will fetch the sender of the message
165
176
  * and make it available to further filters, as well as the handler itself.
166
177
  */
167
- const withCompleteSender = (filter) => async (msg, state) => {
168
- try {
169
- await msg.getCompleteSender();
170
- }
171
- catch (e) {
172
- return false;
173
- }
174
- if (!filter)
175
- return true;
176
- return filter(msg, state);
177
- };
178
- exports.withCompleteSender = withCompleteSender;
178
+ function withCompleteSender(filter) {
179
+ return async (msg, state) => {
180
+ try {
181
+ await msg.getCompleteSender();
182
+ }
183
+ catch {
184
+ return false;
185
+ }
186
+ if (!filter)
187
+ return true;
188
+ return filter(msg, state);
189
+ };
190
+ }
179
191
  //# sourceMappingURL=message.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/filters/message.ts"],"names":[],"mappings":";;;AAAA,uDAAuD;AACvD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C,KAAK,KAAK,aAAa,EAAE,CAAC;QAC9B,GAAG,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACjD,CAAC;IAED,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,OAAO,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AAC/B,CAAC,CAAA;AAjBI,QAAA,OAAO,WAiBX;AAET;;;GAGG;AACI,MAAM,kBAAkB,GAC3B,CACI,MAAiD,EACT,EAAE,CAC1C,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;IACjB,IAAI,CAAC;QACD,MAAM,GAAG,CAAC,iBAAiB,EAAE,CAAA;IACjC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,OAAO,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AAC7B,CAAC,CAAA;AAdI,QAAA,kBAAkB,sBActB","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n// ^^ will be looked into in MTQ-29\nimport {\n _RepliedMessageAssertionsByOrigin,\n MaybeArray,\n Message,\n MessageAction,\n MessageMediaType,\n Peer,\n RawDocument,\n RawLocation,\n RepliedMessageInfo,\n RepliedMessageOrigin,\n Sticker,\n StickerSourceType,\n StickerType,\n User,\n Video,\n} from '@mtcute/core'\n\nimport { BusinessMessageContext } from '../context/business-message.js'\nimport { MessageContext } from '../index.js'\nimport { Modify, UpdateFilter } from './types.js'\n\n/**\n * Filter incoming messages.\n *\n * Messages sent to yourself (i.e. Saved Messages) are also \"incoming\"\n */\nexport const incoming: UpdateFilter<Message, { isOutgoing: false }> = (msg) => !msg.isOutgoing\n\n/**\n * Filter outgoing messages.\n *\n * Messages sent to yourself (i.e. Saved Messages) are **not** \"outgoing\"\n */\nexport const outgoing: UpdateFilter<Message, { isOutgoing: true }> = (msg) => msg.isOutgoing\n\n/**\n * Filter for scheduled messages\n */\nexport const scheduled: UpdateFilter<Message, { isScheduled: true }> = (msg) => msg.isScheduled\n\n/**\n * Filter messages that are replies to some other message\n */\nexport const reply: UpdateFilter<Message, { replyToMessage: RepliedMessageInfo }> = (msg) => msg.replyToMessage !== null\n\n/**\n * Filter messages that are replies with the given origin type\n */\nexport const replyOrigin =\n <T extends RepliedMessageOrigin>(\n origin: T,\n ): UpdateFilter<\n Message,\n {\n replyToMessage: Modify<RepliedMessageInfo, _RepliedMessageAssertionsByOrigin[T] & { origin: T }>\n }\n > =>\n (msg) =>\n msg.replyToMessage?.originIs(origin) ?? false // originIs does additional checks\n\n/**\n * Filter messages containing some media\n */\nexport const media: UpdateFilter<Message, { media: Exclude<Message['media'], null> }> = (msg) => msg.media !== null\n\n/**\n * Filter messages containing media of given type\n */\nexport const mediaOf =\n <T extends MessageMediaType>(type: T): UpdateFilter<Message, { media: Extract<Message['media'], { type: T }> }> =>\n (msg) =>\n msg.media?.type === type\n\n/** Filter messages containing a photo */\nexport const photo = mediaOf('photo')\n/** Filter messages containing a dice */\nexport const dice = mediaOf('dice')\n/** Filter messages containing a contact */\nexport const contact = mediaOf('contact')\n/** Filter messages containing an audio file */\nexport const audio = mediaOf('audio')\n/** Filter messages containing a voice message (audio-only) */\nexport const voice = mediaOf('voice')\n/** Filter messages containing a sticker */\nexport const sticker = mediaOf('sticker')\n/** Filter messages containing a document (a file) */\nexport const document = mediaOf('document')\n/** Filter messages containing any video (videos, round messages and animations) */\nexport const anyVideo = mediaOf('video')\n/** Filter messages containing a static location */\nexport const location = mediaOf('location')\n/** Filter messages containing a live location */\nexport const liveLocation = mediaOf('live_location')\n/** Filter messages containing a game */\nexport const game = mediaOf('game')\n/** Filter messages containing a web page */\nexport const webpage = mediaOf('webpage')\n/** Filter messages containing a venue */\nexport const venue = mediaOf('venue')\n/** Filter messages containing a poll */\nexport const poll = mediaOf('poll')\n/** Filter messages containing an invoice */\nexport const invoice = mediaOf('invoice')\n\n/**\n * Filter messages containing any location (live or static).\n */\nexport const anyLocation: UpdateFilter<Message, { media: Location }> = (msg) => msg.media instanceof RawLocation\n\n/**\n * Filter messages containing a document\n *\n * This will also match media like audio, video, voice\n * that also use Documents\n */\nexport const anyDocument: UpdateFilter<Message, { media: RawDocument }> = (msg) => msg.media instanceof RawDocument\n\n/**\n * Filter messages containing a simple video.\n *\n * This does not include round messages and animations\n */\nexport const video: UpdateFilter<\n Message,\n {\n media: Modify<\n Video,\n {\n isRound: false\n isAnimation: false\n }\n >\n }\n> = (msg) => msg.media?.type === 'video' && !msg.media.isAnimation && !msg.media.isRound\n\n/**\n * Filter messages containing an animation.\n *\n * > **Note**: Legacy GIFs (i.e. documents with `image/gif` MIME)\n * > are also considered animations.\n */\nexport const animation: UpdateFilter<\n Message,\n {\n media: Modify<\n Video,\n {\n isRound: false\n isAnimation: true\n }\n >\n }\n> = (msg) => msg.media?.type === 'video' && msg.media.isAnimation && !msg.media.isRound\n\n/**\n * Filter messages containing a round message (aka video note).\n */\nexport const roundMessage: UpdateFilter<\n Message,\n {\n media: Modify<\n Video,\n {\n isRound: true\n isAnimation: false\n }\n >\n }\n> = (msg) => msg.media?.type === 'video' && !msg.media.isAnimation && msg.media.isRound\n\n/**\n * Filter messages containing a sticker by its type\n */\nexport const stickerByType =\n (type: StickerType): UpdateFilter<Message, { media: Sticker }> =>\n (msg) =>\n msg.media?.type === 'sticker' && msg.media.stickerType === type\n\n/**\n * Filter messages containing a sticker by its source file type\n */\nexport const stickerBySourceType =\n (type: StickerSourceType): UpdateFilter<Message, { media: Sticker }> =>\n (msg) =>\n msg.media?.type === 'sticker' && msg.media.sourceType === type\n\n/**\n * Filter text-only messages non-service messages\n */\nexport const text: UpdateFilter<\n Message,\n {\n media: null\n isService: false\n }\n> = (msg) => msg.media === null && !msg.isService\n\n/**\n * Filter service messages\n */\nexport const service: UpdateFilter<Message, { isService: true }> = (msg) => msg.isService\n\n/**\n * Filter service messages by action type\n */\nexport const action = <T extends Exclude<MessageAction, null>['type']>(\n type: MaybeArray<T>,\n): UpdateFilter<\n Message,\n {\n action: Extract<MessageAction, { type: T }>\n sender: T extends 'user_joined_link' | 'user_removed' | 'history_cleared' | 'contact_joined' | 'bot_allowed'\n ? User\n : Peer\n }\n> => {\n if (Array.isArray(type)) {\n const index: Partial<Record<T, true>> = {}\n type.forEach((it) => (index[it] = true))\n\n return (msg) => (msg.action?.type as any) in index\n }\n\n return (msg) => msg.action?.type === type\n}\n\nexport const sender =\n <T extends Message['sender']['type']>(\n type: T,\n ): UpdateFilter<Message, { sender: Extract<Message['sender'], { type: T }> }> =>\n (msg) =>\n msg.sender.type === type\n\n/**\n * Filter that matches messages that are replies to some other message that can be fetched\n * (i.e. not `private` origin, and has not been deleted)\n *\n * Optionally, you can pass a filter that will be applied to the replied message.\n */\nexport const replyTo =\n <Mod, State extends object>(\n filter?: UpdateFilter<Message, Mod, State>,\n ): UpdateFilter<MessageContext | BusinessMessageContext, { getReplyTo: () => Promise<Message & Mod> }, State> =>\n async (msg, state) => {\n if (!msg.replyToMessage?.id) return false\n\n const reply = msg._name === 'new_message' ? await msg.getReplyTo() : msg.replyTo\n if (!reply) return false\n\n if (msg._name === 'new_message') {\n msg.getReplyTo = () => Promise.resolve(reply)\n }\n\n if (!filter) return true\n\n return filter(reply, state)\n }\n\n/**\n * Middleware-like filter that will fetch the sender of the message\n * and make it available to further filters, as well as the handler itself.\n */\nexport const withCompleteSender =\n <Mod, State extends object>(\n filter?: UpdateFilter<MessageContext, Mod, State>,\n ): UpdateFilter<MessageContext, Mod, State> =>\n async (msg, state) => {\n try {\n await msg.getCompleteSender()\n } catch (e) {\n return false\n }\n\n if (!filter) return true\n\n return filter(msg, state)\n }\n"]}
1
+ {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/filters/message.ts"],"names":[],"mappings":";;;AAiEA,kCAQC;AAUD,0BAMC;AAsGD,sCAGC;AAKD,kDAGC;AAq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EAAE,KAAK,EAAE,EAAE;QACxB,IAAI,CAAC;YACD,MAAM,GAAG,CAAC,iBAAiB,EAAE,CAAA;QACjC,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,KAAK,CAAA;QAChB,CAAC;QAED,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAA;QAExB,OAAO,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IAC7B,CAAC,CAAA;AACL,CAAC","sourcesContent":["import type {\n Audio,\n Contact,\n Dice,\n Document,\n Game,\n Invoice,\n LiveLocation,\n Location,\n MaybeArray,\n Message,\n MessageAction,\n MessageMediaType,\n Peer,\n Photo,\n Poll,\n RepliedMessageInfo,\n RepliedMessageOrigin,\n Sticker,\n StickerSourceType,\n StickerType,\n User,\n Venue,\n Video,\n Voice,\n WebPage,\n _RepliedMessageAssertionsByOrigin,\n} from '@mtcute/core'\nimport {\n RawDocument,\n RawLocation,\n} from '@mtcute/core'\n\nimport type { BusinessMessageContext } from '../context/business-message.js'\nimport type { MessageContext } from '../index.js'\n\nimport type { Modify, UpdateFilter } from './types.js'\n\n/**\n * Filter incoming messages.\n *\n * Messages sent to yourself (i.e. Saved Messages) are also \"incoming\"\n */\nexport const incoming: UpdateFilter<Message, { isOutgoing: false }> = msg => !msg.isOutgoing\n\n/**\n * Filter outgoing messages.\n *\n * Messages sent to yourself (i.e. Saved Messages) are **not** \"outgoing\"\n */\nexport const outgoing: UpdateFilter<Message, { isOutgoing: true }> = msg => msg.isOutgoing\n\n/**\n * Filter for scheduled messages\n */\nexport const scheduled: UpdateFilter<Message, { isScheduled: true }> = msg => msg.isScheduled\n\n/**\n * Filter messages that are replies to some other message\n */\nexport const reply: UpdateFilter<Message, { replyToMessage: RepliedMessageInfo }> = msg => msg.replyToMessage !== null\n\n/**\n * Filter messages that are replies with the given origin type\n */\nexport function replyOrigin<T extends RepliedMessageOrigin>(origin: T): UpdateFilter<\n Message,\n {\n replyToMessage: Modify<RepliedMessageInfo, _RepliedMessageAssertionsByOrigin[T] & { origin: T }>\n }\n> {\n return msg =>\n msg.replyToMessage?.originIs(origin) ?? false\n} // originIs does additional checks\n\n/**\n * Filter messages containing some media\n */\nexport const media: UpdateFilter<Message, { media: Exclude<Message['media'], null> }> = msg => msg.media !== null\n\n/**\n * Filter messages containing media of given type\n */\nexport function mediaOf<T extends MessageMediaType>(type: T): UpdateFilter<\n Message,\n { media: Extract<Message['media'], { type: T }> }\n> {\n return msg =>\n msg.media?.type === type\n}\n\n/** Filter messages containing a photo */\nexport const photo: UpdateFilter<Message, { media: Photo }> = mediaOf('photo')\n/** Filter messages containing a dice */\nexport const dice: UpdateFilter<Message, { media: Dice }> = mediaOf('dice')\n/** Filter messages containing a contact */\nexport const contact: UpdateFilter<Message, { media: Contact }> = mediaOf('contact')\n/** Filter messages containing an audio file */\nexport const audio: UpdateFilter<Message, { media: Audio }> = mediaOf('audio')\n/** Filter messages containing a voice message (audio-only) */\nexport const voice: UpdateFilter<Message, { media: Voice }> = mediaOf('voice')\n/** Filter messages containing a sticker */\nexport const sticker: UpdateFilter<Message, { media: Sticker }> = mediaOf('sticker')\n/** Filter messages containing a document (a file) */\nexport const document: UpdateFilter<Message, { media: Document }> = mediaOf('document')\n/** Filter messages containing any video (videos, round messages and animations) */\nexport const anyVideo: UpdateFilter<Message, { media: Video }> = mediaOf('video')\n/** Filter messages containing a static location */\nexport const location: UpdateFilter<Message, { media: Location }> = mediaOf('location')\n/** Filter messages containing a live location */\nexport const liveLocation: UpdateFilter<Message, { media: LiveLocation }> = mediaOf('live_location')\n/** Filter messages containing a game */\nexport const game: UpdateFilter<Message, { media: Game }> = mediaOf('game')\n/** Filter messages containing a web page */\nexport const webpage: UpdateFilter<Message, { media: WebPage }> = mediaOf('webpage')\n/** Filter messages containing a venue */\nexport const venue: UpdateFilter<Message, { media: Venue }> = mediaOf('venue')\n/** Filter messages containing a poll */\nexport const poll: UpdateFilter<Message, { media: Poll }> = mediaOf('poll')\n/** Filter messages containing an invoice */\nexport const invoice: UpdateFilter<Message, { media: Invoice }> = mediaOf('invoice')\n\n/**\n * Filter messages containing any location (live or static).\n */\nexport const anyLocation: UpdateFilter<Message, { media: Location }> = msg => msg.media instanceof RawLocation\n\n/**\n * Filter messages containing a document\n *\n * This will also match media like audio, video, voice\n * that also use Documents\n */\nexport const anyDocument: UpdateFilter<Message, { media: RawDocument }> = msg => msg.media instanceof RawDocument\n\n/**\n * Filter messages containing a simple video.\n *\n * This does not include round messages and animations\n */\nexport const video: UpdateFilter<\n Message,\n {\n media: Modify<\n Video,\n {\n isRound: false\n isAnimation: false\n }\n >\n }\n> = msg => msg.media?.type === 'video' && !msg.media.isAnimation && !msg.media.isRound\n\n/**\n * Filter messages containing an animation.\n *\n * > **Note**: Legacy GIFs (i.e. documents with `image/gif` MIME)\n * > are also considered animations.\n */\nexport const animation: UpdateFilter<\n Message,\n {\n media: Modify<\n Video,\n {\n isRound: false\n isAnimation: true\n }\n >\n }\n> = msg => msg.media?.type === 'video' && msg.media.isAnimation && !msg.media.isRound\n\n/**\n * Filter messages containing a round message (aka video note).\n */\nexport const roundMessage: UpdateFilter<\n Message,\n {\n media: Modify<\n Video,\n {\n isRound: true\n isAnimation: false\n }\n >\n }\n> = msg => msg.media?.type === 'video' && !msg.media.isAnimation && msg.media.isRound\n\n/**\n * Filter messages containing a sticker by its type\n */\nexport function stickerByType(type: StickerType): UpdateFilter<Message, { media: Sticker }> {\n return msg =>\n msg.media?.type === 'sticker' && msg.media.stickerType === type\n}\n\n/**\n * Filter messages containing a sticker by its source file type\n */\nexport function stickerBySourceType(type: StickerSourceType): UpdateFilter<Message, { media: Sticker }> {\n return msg =>\n msg.media?.type === 'sticker' && msg.media.sourceType === type\n}\n\n/**\n * Filter text-only messages non-service messages\n */\nexport const text: UpdateFilter<\n Message,\n {\n media: null\n isService: false\n }\n> = msg => msg.media === null && !msg.isService\n\n/**\n * Filter service messages\n */\nexport const service: UpdateFilter<Message, { isService: true }> = msg => msg.isService\n\n/**\n * Filter service messages by action type\n */\nexport function action<T extends Exclude<MessageAction, null>['type']>(type: MaybeArray<T>): UpdateFilter<\n Message,\n {\n action: Extract<MessageAction, { type: T }>\n sender: T extends 'user_joined_link' | 'user_removed' | 'history_cleared' | 'contact_joined' | 'bot_allowed'\n ? User\n : Peer\n }\n> {\n if (Array.isArray(type)) {\n const index: Partial<Record<T, true>> = {}\n type.forEach(it => (index[it] = true))\n\n return msg => (msg.action?.type as any) in index\n }\n\n return msg => msg.action?.type === type\n}\n\nexport function sender<T extends Message['sender']['type']>(type: T): UpdateFilter<\n Message,\n { sender: Extract<Message['sender'], { type: T }> }\n> {\n return msg =>\n msg.sender.type === type\n}\n\n/**\n * Filter that matches messages that are replies to some other message that can be fetched\n * (i.e. not `private` origin, and has not been deleted)\n *\n * Optionally, you can pass a filter that will be applied to the replied message.\n */\nexport function replyTo<Mod, State extends object>(\n filter?: UpdateFilter<Message, Mod, State>,\n): UpdateFilter<\n MessageContext | BusinessMessageContext,\n { getReplyTo: () => Promise<Message & Mod> },\n State\n > {\n return async (msg, state) => {\n if (!msg.replyToMessage?.id) return false\n\n const reply = msg._name === 'new_message' ? await msg.getReplyTo() : msg.replyTo\n if (!reply) return false\n\n if (msg._name === 'new_message') {\n msg.getReplyTo = () => Promise.resolve(reply)\n }\n\n if (!filter) return true\n\n return filter(reply, state)\n }\n}\n\n/**\n * Middleware-like filter that will fetch the sender of the message\n * and make it available to further filters, as well as the handler itself.\n */\nexport function withCompleteSender<Mod, State extends object>(\n filter?: UpdateFilter<MessageContext, Mod, State>,\n): UpdateFilter<MessageContext, Mod, State> {\n return async (msg, state) => {\n try {\n await msg.getCompleteSender()\n } catch {\n return false\n }\n\n if (!filter) return true\n\n return filter(msg, state)\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
- import { MaybePromise } from '@mtcute/core';
2
- import { UpdateFilter } from './types.js';
1
+ import type { MaybePromise } from '@mtcute/core';
2
+ import type { UpdateFilter } from './types.js';
3
3
  /**
4
4
  * Create a filter for the cases when the state is empty
5
5
  */
@@ -12,4 +12,4 @@ export declare const stateEmpty: UpdateFilter<any>;
12
12
  *
13
13
  * @param predicate State predicate
14
14
  */
15
- export declare const state: <T extends object>(predicate: (state: T) => MaybePromise<boolean>) => UpdateFilter<any, {}, T>;
15
+ export declare function state<T extends object>(predicate: (state: T) => MaybePromise<boolean>): UpdateFilter<any, {}, T>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.state = exports.stateEmpty = void 0;
3
+ exports.stateEmpty = void 0;
4
+ exports.state = state;
4
5
  /**
5
6
  * Create a filter for the cases when the state is empty
6
7
  */
@@ -18,7 +19,8 @@ exports.stateEmpty = stateEmpty;
18
19
  *
19
20
  * @param predicate State predicate
20
21
  */
21
- const state = (predicate) => {
22
+ // eslint-disable-next-line ts/no-empty-object-type
23
+ function state(predicate) {
22
24
  return async (upd, state) => {
23
25
  if (!state)
24
26
  return false;
@@ -27,6 +29,5 @@ const state = (predicate) => {
27
29
  return false;
28
30
  return predicate(data);
29
31
  };
30
- };
31
- exports.state = state;
32
+ }
32
33
  //# sourceMappingURL=state.js.map