@mtcute/dispatcher 0.6.0 → 0.7.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/cjs/callback-data-builder.d.ts +1 -1
- package/cjs/callback-data-builder.js +5 -5
- package/cjs/callback-data-builder.js.map +1 -1
- package/cjs/callback-data-builder.test.js +8 -8
- package/cjs/callback-data-builder.test.js.map +1 -1
- package/cjs/context/base.d.ts +1 -1
- package/cjs/context/base.js.map +1 -1
- package/cjs/context/callback-query.d.ts +2 -2
- package/cjs/context/callback-query.js +3 -3
- package/cjs/context/callback-query.js.map +1 -1
- package/cjs/context/chat-join-request.d.ts +1 -1
- package/cjs/context/chat-join-request.js +2 -2
- package/cjs/context/chat-join-request.js.map +1 -1
- package/cjs/context/chosen-inline-result.d.ts +1 -1
- package/cjs/context/chosen-inline-result.js +3 -3
- package/cjs/context/chosen-inline-result.js.map +1 -1
- package/cjs/context/inline-query.d.ts +1 -1
- package/cjs/context/inline-query.js +2 -2
- package/cjs/context/inline-query.js.map +1 -1
- package/cjs/context/message.d.ts +6 -6
- package/cjs/context/message.js +3 -3
- package/cjs/context/message.js.map +1 -1
- package/cjs/context/parse.js.map +1 -1
- package/cjs/context/pre-checkout-query.d.ts +1 -1
- package/cjs/context/pre-checkout-query.js +2 -2
- package/cjs/context/pre-checkout-query.js.map +1 -1
- package/cjs/dispatcher.d.ts +14 -9
- package/cjs/dispatcher.js +41 -78
- package/cjs/dispatcher.js.map +1 -1
- package/cjs/filters/bots.d.ts +6 -6
- package/cjs/filters/bots.js +2 -2
- package/cjs/filters/bots.js.map +1 -1
- package/cjs/filters/bots.test.js +6 -5
- package/cjs/filters/bots.test.js.map +1 -1
- package/cjs/filters/chat.d.ts +1 -1
- package/cjs/filters/chat.js +1 -1
- package/cjs/filters/chat.js.map +1 -1
- package/cjs/filters/group.d.ts +1 -1
- package/cjs/filters/group.js.map +1 -1
- package/cjs/filters/logic.js.map +1 -1
- package/cjs/filters/message.d.ts +75 -67
- package/cjs/filters/message.js +3 -3
- package/cjs/filters/message.js.map +1 -1
- package/cjs/filters/state.d.ts +2 -2
- package/cjs/filters/state.js.map +1 -1
- package/cjs/filters/text.d.ts +1 -1
- package/cjs/filters/text.js.map +1 -1
- package/cjs/filters/types.d.ts +2 -2
- package/cjs/filters/types.js.map +1 -1
- package/cjs/filters/updates.d.ts +1 -1
- package/cjs/filters/updates.js.map +1 -1
- package/cjs/filters/user.d.ts +1 -1
- package/cjs/filters/user.js +4 -4
- package/cjs/filters/user.js.map +1 -1
- package/cjs/handler.d.ts +3 -3
- package/cjs/handler.js.map +1 -1
- package/cjs/propagation.js +1 -1
- package/cjs/propagation.js.map +1 -1
- package/cjs/state/index.d.ts +3 -1
- package/cjs/state/index.js +3 -1
- package/cjs/state/index.js.map +1 -1
- package/cjs/state/key.d.ts +2 -2
- package/cjs/state/key.js +2 -2
- package/cjs/state/key.js.map +1 -1
- package/cjs/state/provider.d.ts +5 -0
- package/cjs/state/provider.js +3 -0
- package/cjs/state/provider.js.map +1 -0
- package/cjs/state/providers/index.d.ts +2 -0
- package/cjs/state/providers/index.js +19 -0
- package/cjs/state/providers/index.js.map +1 -0
- package/cjs/state/providers/memory.d.ts +29 -0
- package/cjs/state/providers/memory.js +76 -0
- package/cjs/state/providers/memory.js.map +1 -0
- package/cjs/state/providers/sqlite.d.ts +29 -0
- package/cjs/state/providers/sqlite.js +89 -0
- package/cjs/state/providers/sqlite.js.map +1 -0
- package/cjs/state/repository.d.ts +62 -0
- package/cjs/state/repository.js +3 -0
- package/cjs/state/repository.js.map +1 -0
- package/cjs/state/service.d.ts +19 -0
- package/cjs/state/service.js +68 -0
- package/cjs/state/service.js.map +1 -0
- package/cjs/state/update-state.d.ts +3 -3
- package/cjs/state/update-state.js +7 -7
- package/cjs/state/update-state.js.map +1 -1
- package/cjs/wizard.d.ts +2 -2
- package/cjs/wizard.js +1 -1
- package/cjs/wizard.js.map +1 -1
- package/esm/callback-data-builder.d.ts +1 -1
- package/esm/callback-data-builder.js +1 -1
- package/esm/callback-data-builder.js.map +1 -1
- package/esm/callback-data-builder.test.js +2 -2
- package/esm/callback-data-builder.test.js.map +1 -1
- package/esm/context/base.d.ts +1 -1
- package/esm/context/base.js.map +1 -1
- package/esm/context/callback-query.d.ts +2 -2
- package/esm/context/callback-query.js +1 -1
- package/esm/context/callback-query.js.map +1 -1
- package/esm/context/chat-join-request.d.ts +1 -1
- package/esm/context/chat-join-request.js +1 -1
- package/esm/context/chat-join-request.js.map +1 -1
- package/esm/context/chosen-inline-result.d.ts +1 -1
- package/esm/context/chosen-inline-result.js +1 -1
- package/esm/context/chosen-inline-result.js.map +1 -1
- package/esm/context/inline-query.d.ts +1 -1
- package/esm/context/inline-query.js +1 -1
- package/esm/context/inline-query.js.map +1 -1
- package/esm/context/message.d.ts +6 -6
- package/esm/context/message.js +1 -1
- package/esm/context/message.js.map +1 -1
- package/esm/context/parse.js.map +1 -1
- package/esm/context/pre-checkout-query.d.ts +1 -1
- package/esm/context/pre-checkout-query.js +1 -1
- package/esm/context/pre-checkout-query.js.map +1 -1
- package/esm/dispatcher.d.ts +14 -9
- package/esm/dispatcher.js +29 -66
- package/esm/dispatcher.js.map +1 -1
- package/esm/filters/bots.d.ts +6 -6
- package/esm/filters/bots.js +2 -2
- package/esm/filters/bots.js.map +1 -1
- package/esm/filters/bots.test.js +4 -3
- package/esm/filters/bots.test.js.map +1 -1
- package/esm/filters/chat.d.ts +2 -2
- package/esm/filters/chat.js +1 -1
- package/esm/filters/chat.js.map +1 -1
- package/esm/filters/group.d.ts +1 -1
- package/esm/filters/group.js.map +1 -1
- package/esm/filters/logic.js.map +1 -1
- package/esm/filters/message.d.ts +77 -69
- package/esm/filters/message.js +1 -1
- package/esm/filters/message.js.map +1 -1
- package/esm/filters/state.d.ts +2 -2
- package/esm/filters/state.js.map +1 -1
- package/esm/filters/text.d.ts +1 -1
- package/esm/filters/text.js.map +1 -1
- package/esm/filters/types.d.ts +2 -2
- package/esm/filters/types.js.map +1 -1
- package/esm/filters/updates.d.ts +1 -1
- package/esm/filters/updates.js.map +1 -1
- package/esm/filters/user.d.ts +1 -1
- package/esm/filters/user.js +3 -3
- package/esm/filters/user.js.map +1 -1
- package/esm/handler.d.ts +3 -3
- package/esm/handler.js.map +1 -1
- package/esm/propagation.js +1 -1
- package/esm/propagation.js.map +1 -1
- package/esm/state/index.d.ts +3 -1
- package/esm/state/index.js +3 -1
- package/esm/state/index.js.map +1 -1
- package/esm/state/key.d.ts +2 -2
- package/esm/state/key.js +1 -1
- package/esm/state/key.js.map +1 -1
- package/esm/state/provider.d.ts +5 -0
- package/esm/state/provider.js +2 -0
- package/esm/state/provider.js.map +1 -0
- package/esm/state/providers/index.d.ts +2 -0
- package/esm/state/providers/index.js +3 -0
- package/esm/state/providers/index.js.map +1 -0
- package/esm/state/providers/memory.d.ts +29 -0
- package/esm/state/providers/memory.js +72 -0
- package/esm/state/providers/memory.js.map +1 -0
- package/esm/state/providers/sqlite.d.ts +29 -0
- package/esm/state/providers/sqlite.js +85 -0
- package/esm/state/providers/sqlite.js.map +1 -0
- package/esm/state/repository.d.ts +62 -0
- package/esm/state/repository.js +2 -0
- package/esm/state/repository.js.map +1 -0
- package/esm/state/service.d.ts +19 -0
- package/esm/state/service.js +64 -0
- package/esm/state/service.js.map +1 -0
- package/esm/state/update-state.d.ts +3 -3
- package/esm/state/update-state.js +2 -2
- package/esm/state/update-state.js.map +1 -1
- package/esm/wizard.d.ts +2 -2
- package/esm/wizard.js +1 -1
- package/esm/wizard.js.map +1 -1
- package/package.json +10 -3
- package/cjs/state/storage.d.ts +0 -96
- package/cjs/state/storage.js +0 -17
- package/cjs/state/storage.js.map +0 -1
- package/esm/state/storage.d.ts +0 -96
- package/esm/state/storage.js +0 -13
- package/esm/state/storage.js.map +0 -1
package/cjs/filters/chat.js
CHANGED
|
@@ -42,7 +42,7 @@ const chatId = (id) => {
|
|
|
42
42
|
case 'history_read':
|
|
43
43
|
case 'user_typing': {
|
|
44
44
|
const id = upd.chatId;
|
|
45
|
-
return (matchSelf && id === upd.client.
|
|
45
|
+
return (matchSelf && id === upd.client.storage.self.getCached()?.userId) || indexId.has(id);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
const chat = upd.chat;
|
package/cjs/filters/chat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../../src/filters/chat.ts"],"names":[],"mappings":";;;AAgBA;;GAEG;AACI,MAAM,IAAI,GACb,CACI,IAAO,EAYT,EAAE,CACA,CAAC,GAAG,EAAE,EAAE,CACJ,GAAG,CAAC,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAA;AAhBzB,QAAA,IAAI,QAgBqB;AAEtC,kBAAkB;AAClB;;;;;;;GAOG;AACI,MAAM,MAAM,GAef,CAAC,EAAE,EAAE,EAAE;IACP,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;IACjC,MAAM,aAAa,GAAG,IAAI,GAAG,EAAU,CAAA;IACvC,IAAI,SAAS,GAAG,KAAK,CAAA;IAErB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QAAE,EAAE,GAAG,CAAC,EAAE,CAAC,CAAA;IACjC,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;QACd,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,MAAM,EAAE;YAC9B,SAAS,GAAG,IAAI,CAAA;SACnB;aAAM,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE;YAC/B,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;SAClB;aAAM;YACH,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;SACxB;IACL,CAAC,CAAC,CAAA;IAEF,OAAO,CAAC,GAAG,EAAE,EAAE;QACX,QAAQ,GAAG,CAAC,KAAK,EAAE;YACf,KAAK,WAAW,CAAC,CAAC;gBACd,MAAM,IAAI,GAA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,\n Chat,\n ChatMemberUpdate,\n ChatType,\n HistoryReadUpdate,\n MaybeArray,\n Message,\n PollVoteUpdate,\n User,\n UserTypingUpdate,\n} from '@mtcute/core'\n\nimport { UpdateContextDistributed } from '../context/base.js'\nimport { EmptyObject, Modify, UpdateFilter } from './types.js'\n\n/**\n * Filter updates by type of the chat where they happened\n */\nexport const chat =\n <T extends ChatType, Obj extends { chat: Chat }>(\n type: T,\n ): UpdateFilter<\n Obj,\n {\n chat: Modify<Chat, { chatType: T }>\n } & (Obj extends Message\n ? T extends 'private' | 'bot' | 'group'\n ? {\n sender: User\n }\n : EmptyObject\n : EmptyObject)\n > =>\n (msg) =>\n msg.chat.chatType === type\n\n// prettier-ignore\n/**\n * Filter updates by marked chat ID(s) or username(s)\n *\n * Note that only some updates support filtering by username.\n *\n * For messages, this filter checks for chat where the message\n * was sent to, NOT the chat sender.\n */\nexport const chatId: {\n (id: MaybeArray<number>): UpdateFilter<UpdateContextDistributed<\n | Message\n | ChatMemberUpdate\n | PollVoteUpdate\n | BotChatJoinRequestUpdate\n >>\n (id: MaybeArray<number | string>): UpdateFilter<UpdateContextDistributed<\n | Message\n | ChatMemberUpdate\n | UserTypingUpdate\n | HistoryReadUpdate\n | PollVoteUpdate\n | BotChatJoinRequestUpdate\n >>\n} = (id) => {\n const indexId = new Set<number>()\n const indexUsername = new Set<string>()\n let matchSelf = false\n\n if (!Array.isArray(id)) id = [id]\n id.forEach((id) => {\n if (id === 'me' || id === 'self') {\n matchSelf = true\n } else if (typeof id === 'number') {\n indexId.add(id)\n } else {\n indexUsername.add(id)\n }\n })\n\n return (upd) => {\n switch (upd._name) {\n case 'poll_vote': {\n const peer = upd.peer\n\n return peer.type === 'chat' && (\n indexId.has(peer.id) ||\n Boolean(peer.usernames?.some((u) => indexUsername.has(u.username)))\n )\n }\n case 'history_read':\n case 'user_typing': {\n const id = upd.chatId\n\n return (matchSelf && id === upd.client.storage.self.getCached()?.userId) || indexId.has(id)\n }\n }\n\n const chat = upd.chat\n\n return (matchSelf && chat.isSelf) ||\n indexId.has(chat.id) ||\n Boolean(chat.usernames?.some((u) => indexUsername.has(u.username)))\n }\n}\n"]}
|
package/cjs/filters/group.d.ts
CHANGED
package/cjs/filters/group.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group.js","sourceRoot":"","sources":["../../../src/filters/group.ts"],"names":[],"mappings":";;;AAKA;;;;;;;;GAQG;AACH,SAAgB,KAAK,CACjB,MAAyC;IAQzC,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAClB,IAAI,CAAC,GAAG,CAAC,CAAA;QACT,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAA;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAA;QAEvB,MAAM,IAAI,GAAG,
|
|
1
|
+
{"version":3,"file":"group.js","sourceRoot":"","sources":["../../../src/filters/group.ts"],"names":[],"mappings":";;;AAKA;;;;;;;;GAQG;AACH,SAAgB,KAAK,CACjB,MAAyC;IAQzC,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAClB,IAAI,CAAC,GAAG,CAAC,CAAA;QACT,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAA;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAA;QAEvB,MAAM,IAAI,GAAG,GAA0B,EAAE;YACrC,IAAI,CAAC,KAAK,GAAG;gBAAE,OAAO,IAAI,CAAA;YAE1B,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAA;YAEpC,IAAI,OAAO,GAAG,KAAK,SAAS,EAAE;gBAC1B,IAAI,CAAC,GAAG;oBAAE,OAAO,KAAK,CAAA;gBAEtB,OAAO,IAAI,EAAE,CAAA;aAChB;YAED,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAAU,EAAE,EAAE;gBAC3B,IAAI,CAAC,CAAC;oBAAE,OAAO,KAAK,CAAA;gBAEpB,OAAO,IAAI,EAAE,CAAA;YACjB,CAAC,CAAC,CAAA;QACN,CAAC,CAAA;QAED,OAAO,IAAI,EAAE,CAAA;IACjB,CAAC,CAAA;AACL,CAAC;AAlCD,sBAkCC;AAED;;;;;;;;GAQG;AACH,SAAgB,IAAI;AAChB,2BAA2B;AAC3B,MAAyC;IAGzC,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAClB,IAAI,CAAC,GAAG,CAAC,CAAA;QACT,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAA;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAA;QAEvB,MAAM,IAAI,GAAG,GAA0B,EAAE;YACrC,IAAI,CAAC,KAAK,GAAG;gBAAE,OAAO,KAAK,CAAA;YAE3B,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAA;YAEpC,IAAI,OAAO,GAAG,KAAK,SAAS,EAAE;gBAC1B,IAAI,GAAG;oBAAE,OAAO,IAAI,CAAA;gBAEpB,OAAO,IAAI,EAAE,CAAA;aAChB;YAED,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAAU,EAAE,EAAE;gBAC3B,IAAI,CAAC;oBAAE,OAAO,IAAI,CAAA;gBAElB,OAAO,IAAI,EAAE,CAAA;YACjB,CAAC,CAAC,CAAA;QACN,CAAC,CAAA;QAED,OAAO,IAAI,EAAE,CAAA;IACjB,CAAC,CAAA;AACL,CAAC;AA9BD,oBA8BC","sourcesContent":["import { MaybePromise, Message } from '@mtcute/core'\n\nimport { MessageContext } from '../context/message.js'\nimport { Modify, UpdateFilter } from './types.js'\n\n/**\n * For message groups, apply a filter to every message in the group.\n * Filter will match if **all** messages match.\n *\n * > **Note**: This also applies type modification to every message in the group\n *\n * @param filter\n * @returns\n */\nexport function every<Mod, State extends object>(\n filter: UpdateFilter<Message, Mod, State>,\n): UpdateFilter<\n MessageContext,\n Mod & {\n messages: Modify<MessageContext, Mod>[]\n },\n State\n> {\n return (ctx, state) => {\n let i = 0\n const upds = ctx.messages\n const max = upds.length\n\n const next = (): MaybePromise<boolean> => {\n if (i === max) return true\n\n const res = filter(upds[i++], state)\n\n if (typeof res === 'boolean') {\n if (!res) return false\n\n return next()\n }\n\n return res.then((r: boolean) => {\n if (!r) return false\n\n return next()\n })\n }\n\n return next()\n }\n}\n\n/**\n * For message groups, apply a filter to every message in the group.\n * Filter will match if **any** message matches.\n *\n * > **Note**: This *does not* apply type modification to any message\n *\n * @param filter\n * @returns\n */\nexport function some<State extends object>(\n // eslint-disable-next-line\n filter: UpdateFilter<Message, any, State>,\n // eslint-disable-next-line\n): UpdateFilter<MessageContext, {}, State> {\n return (ctx, state) => {\n let i = 0\n const upds = ctx.messages\n const max = upds.length\n\n const next = (): MaybePromise<boolean> => {\n if (i === max) return false\n\n const res = filter(upds[i++], state)\n\n if (typeof res === 'boolean') {\n if (res) return true\n\n return next()\n }\n\n return res.then((r: boolean) => {\n if (r) return true\n\n return next()\n })\n }\n\n return next()\n }\n}\n"]}
|
package/cjs/filters/logic.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logic.js","sourceRoot":"","sources":["../../../src/filters/logic.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,mCAAmC;;;AAMnC;;GAEG;AACI,MAAM,GAAG,GAAsB,GAAG,EAAE,CAAC,IAAI,CAAA;AAAnC,QAAA,GAAG,OAAgC;AAEhD;;;;;;;;;;;GAWG;AACH,SAAgB,GAAG,CACf,EAAkC;IAElC,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAClB,MAAM,GAAG,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QAE1B,IAAI,OAAO,GAAG,KAAK,SAAS;YAAE,OAAO,CAAC,GAAG,CAAA;QAEzC,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAA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AE,KAAK,CAAC,CAAA;YAEhC,IAAI,OAAO,GAAG,KAAK,SAAS,EAAE;gBAC1B,IAAI,GAAG;oBAAE,OAAO,IAAI,CAAA;gBAEpB,OAAO,IAAI,EAAE,CAAA;aAChB;YAED,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAAU,EAAE,EAAE;gBAC3B,IAAI,CAAC;oBAAE,OAAO,IAAI,CAAA;gBAElB,OAAO,IAAI,EAAE,CAAA;YACjB,CAAC,CAAC,CAAA;QACN,CAAC,CAAA;QAED,OAAO,IAAI,EAAE,CAAA;IACjB,CAAC,CAAA;AACL,CAAC;AAzBD,gBAyBC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n// ^^ will be looked into in MTQ-29\n\nimport { MaybeAsync } from '@mtcute/client'\n\nimport { ExtractBaseMany, ExtractMod, Invert, UnionToIntersection, UpdateFilter } from './types.js'\n\n/**\n * Filter that matches any update\n */\nexport const any: UpdateFilter<any> = () => true\n\n/**\n * Invert a filter by applying a NOT logical operation:\n * `not(fn) = NOT fn`\n *\n * > **Note**: This also inverts type modification, i.e.\n * > if the base is `{ field: string | number | null }`\n * > and the modification is `{ field: string }`,\n * > then the negated filter will have\n * > inverted modification `{ field: number | null }`\n *\n * @param fn Filter to negate\n */\nexport function not<Base, Mod, State extends object>(\n fn: UpdateFilter<Base, Mod, State>,\n): UpdateFilter<Base, Invert<Base, Mod>, State> {\n return (upd, state) => {\n const res = fn(upd, state)\n\n if (typeof res === 'boolean') return !res\n\n return res.then((r) => !r)\n }\n}\n\n// i couldn't come up with proper types for these 😭\n// if you know how to do this better - PRs are welcome!\n\nexport function and<Base1, Mod1, State1 extends object, Base2, Mod2, State2 extends object>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n): UpdateFilter<Base1 & Base2, Mod1 & Mod2, State1 | State2>\nexport function and<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n): UpdateFilter<Base1 & Base2 & Base3, Mod1 & Mod2 & Mod3, State1 | State2 | State3>\nexport function and<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n): UpdateFilter<Base1 & Base2 & Base3 & Base4, Mod1 & Mod2 & Mod3 & Mod4, State1 | State2 | State3 | State4>\nexport function and<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n Base5,\n Mod5,\n State5 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n fn5: UpdateFilter<Base5, Mod5, State5>,\n): UpdateFilter<\n Base1 & Base2 & Base3 & Base4 & Base5,\n Mod1 & Mod2 & Mod3 & Mod4 & Mod5,\n State1 | State2 | State3 | State4 | State5\n>\nexport function and<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n Base5,\n Mod5,\n State5 extends object,\n Base6,\n Mod6,\n State6 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n fn5: UpdateFilter<Base5, Mod5, State5>,\n fn6: UpdateFilter<Base6, Mod6, State6>,\n): UpdateFilter<\n Base1 & Base2 & Base3 & Base4 & Base5 & Base6,\n Mod1 & Mod2 & Mod3 & Mod4 & Mod5 & Mod6,\n State1 | State2 | State3 | State4 | State5 | State6\n>\nexport function and<Filters extends UpdateFilter<any, any>[]>(\n ...fns: Filters\n): UpdateFilter<ExtractBaseMany<Filters>, UnionToIntersection<ExtractMod<Filters[number]>>>\n\n/**\n * Combine multiple filters by applying an AND logical\n * operation between every one of them:\n * `and(fn1, fn2, ..., fnN) = fn1 AND fn2 AND ... AND fnN`\n *\n * > **Note**: This also combines type modifications, i.e.\n * > if the 1st has modification `{ field1: string }`\n * > and the 2nd has modification `{ field2: number }`,\n * > then the combined filter will have\n * > combined modification `{ field1: string, field2: number }`\n *\n * > **Note**: Due to TypeScript limitations (or more likely my lack of brain cells),\n * > state type is only correctly inferred for up to 6 filters.\n * > If you need more, either provide type explicitly (e.g. `filters.state<SomeState>(...)`),\n * > or combine multiple `and` calls.\n *\n * @param fns Filters to combine\n */\nexport function and(...fns: UpdateFilter<any, any, any>[]): UpdateFilter<any, any, any> {\n return (upd, state) => {\n let i = 0\n const max = fns.length\n\n const next = (): MaybeAsync<boolean> => {\n if (i === max) return true\n\n const res = fns[i++](upd, state)\n\n if (typeof res === 'boolean') {\n if (!res) return false\n\n return next()\n }\n\n return res.then((r: boolean) => {\n if (!r) return false\n\n return next()\n })\n }\n\n return next()\n }\n}\n\nexport function or<Base1, Mod1, State1 extends object, Base2, Mod2, State2 extends object>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n): UpdateFilter<Base1 & Base2, Mod1 | Mod2, State1 | State2>\n\nexport function or<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n): UpdateFilter<Base1 & Base2 & Base3, Mod1 | Mod2 | Mod3, State1 | State2 | State3>\n\nexport function or<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n): UpdateFilter<Base1 & Base2 & Base3 & Base4, Mod1 | Mod2 | Mod3 | Mod4, State1 | State2 | State3 | State4>\n\nexport function or<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n Base5,\n Mod5,\n State5 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n fn5: UpdateFilter<Base5, Mod5, State5>,\n): UpdateFilter<\n Base1 & Base2 & Base3 & Base4 & Base5,\n Mod1 | Mod2 | Mod3 | Mod4 | Mod5,\n State1 | State2 | State3 | State4 | State5\n>\n\nexport function or<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n Base5,\n Mod5,\n State5 extends object,\n Base6,\n Mod6,\n State6 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n fn5: UpdateFilter<Base5, Mod5, State5>,\n fn6: UpdateFilter<Base6, Mod6, State6>,\n): UpdateFilter<\n Base1 & Base2 & Base3 & Base4 & Base5 & Base6,\n Mod1 | Mod2 | Mod3 | Mod4 | Mod5 | Mod6,\n State1 | State2 | State3 | State4 | State5 | State6\n>\n\n/**\n * Combine multiple filters by applying an OR logical\n * operation between every one of them:\n * `or(fn1, fn2, ..., fnN) = fn1 OR fn2 OR ... OR fnN`\n *\n * > **Note**: This also combines type modifications in a union, i.e.\n * > if the 1st has modification `{ field1: string }`\n * > and the 2nd has modification `{ field2: number }`,\n * > then the combined filter will have\n * > modification `{ field1: string } | { field2: number }`.\n *\n * > **Note**: Due to TypeScript limitations (or more likely my lack of brain cells),\n * > state type is only correctly inferred for up to 6 filters.\n * > If you need more, either provide type explicitly (e.g. `filters.state<SomeState>(...)`),\n * > or combine multiple `and` calls.\n *\n * @param fns Filters to combine\n */\nexport function or(...fns: UpdateFilter<any, any, any>[]): UpdateFilter<any, any, any> {\n return (upd, state) => {\n let i = 0\n const max = fns.length\n\n const next = (): MaybeAsync<boolean> => {\n if (i === max) return false\n\n const res = fns[i++](upd, state)\n\n if (typeof res === 'boolean') {\n if (res) return true\n\n return next()\n }\n\n return res.then((r: boolean) => {\n if (r) return true\n\n return next()\n })\n }\n\n return next()\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"logic.js","sourceRoot":"","sources":["../../../src/filters/logic.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,mCAAmC;;;AAMnC;;GAEG;AACI,MAAM,GAAG,GAAsB,GAAG,EAAE,CAAC,IAAI,CAAA;AAAnC,QAAA,GAAG,OAAgC;AAEhD;;;;;;;;;;;GAWG;AACH,SAAgB,GAAG,CACf,EAAkC;IAElC,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAClB,MAAM,GAAG,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QAE1B,IAAI,OAAO,GAAG,KAAK,SAAS;YAAE,OAAO,CAAC,GAAG,CAAA;QAEzC,OAAO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C,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;YAEhC,IAAI,OAAO,GAAG,KAAK,SAAS,EAAE;gBAC1B,IAAI,GAAG;oBAAE,OAAO,IAAI,CAAA;gBAEpB,OAAO,IAAI,EAAE,CAAA;aAChB;YAED,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAAU,EAAE,EAAE;gBAC3B,IAAI,CAAC;oBAAE,OAAO,IAAI,CAAA;gBAElB,OAAO,IAAI,EAAE,CAAA;YACjB,CAAC,CAAC,CAAA;QACN,CAAC,CAAA;QAED,OAAO,IAAI,EAAE,CAAA;IACjB,CAAC,CAAA;AACL,CAAC;AAzBD,gBAyBC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n// ^^ will be looked into in MTQ-29\n\nimport { MaybePromise } from '@mtcute/core'\n\nimport { ExtractBaseMany, ExtractMod, Invert, UnionToIntersection, UpdateFilter } from './types.js'\n\n/**\n * Filter that matches any update\n */\nexport const any: UpdateFilter<any> = () => true\n\n/**\n * Invert a filter by applying a NOT logical operation:\n * `not(fn) = NOT fn`\n *\n * > **Note**: This also inverts type modification, i.e.\n * > if the base is `{ field: string | number | null }`\n * > and the modification is `{ field: string }`,\n * > then the negated filter will have\n * > inverted modification `{ field: number | null }`\n *\n * @param fn Filter to negate\n */\nexport function not<Base, Mod, State extends object>(\n fn: UpdateFilter<Base, Mod, State>,\n): UpdateFilter<Base, Invert<Base, Mod>, State> {\n return (upd, state) => {\n const res = fn(upd, state)\n\n if (typeof res === 'boolean') return !res\n\n return res.then((r) => !r)\n }\n}\n\n// i couldn't come up with proper types for these 😭\n// if you know how to do this better - PRs are welcome!\n\nexport function and<Base1, Mod1, State1 extends object, Base2, Mod2, State2 extends object>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n): UpdateFilter<Base1 & Base2, Mod1 & Mod2, State1 | State2>\nexport function and<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n): UpdateFilter<Base1 & Base2 & Base3, Mod1 & Mod2 & Mod3, State1 | State2 | State3>\nexport function and<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n): UpdateFilter<Base1 & Base2 & Base3 & Base4, Mod1 & Mod2 & Mod3 & Mod4, State1 | State2 | State3 | State4>\nexport function and<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n Base5,\n Mod5,\n State5 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n fn5: UpdateFilter<Base5, Mod5, State5>,\n): UpdateFilter<\n Base1 & Base2 & Base3 & Base4 & Base5,\n Mod1 & Mod2 & Mod3 & Mod4 & Mod5,\n State1 | State2 | State3 | State4 | State5\n>\nexport function and<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n Base5,\n Mod5,\n State5 extends object,\n Base6,\n Mod6,\n State6 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n fn5: UpdateFilter<Base5, Mod5, State5>,\n fn6: UpdateFilter<Base6, Mod6, State6>,\n): UpdateFilter<\n Base1 & Base2 & Base3 & Base4 & Base5 & Base6,\n Mod1 & Mod2 & Mod3 & Mod4 & Mod5 & Mod6,\n State1 | State2 | State3 | State4 | State5 | State6\n>\nexport function and<Filters extends UpdateFilter<any, any>[]>(\n ...fns: Filters\n): UpdateFilter<ExtractBaseMany<Filters>, UnionToIntersection<ExtractMod<Filters[number]>>>\n\n/**\n * Combine multiple filters by applying an AND logical\n * operation between every one of them:\n * `and(fn1, fn2, ..., fnN) = fn1 AND fn2 AND ... AND fnN`\n *\n * > **Note**: This also combines type modifications, i.e.\n * > if the 1st has modification `{ field1: string }`\n * > and the 2nd has modification `{ field2: number }`,\n * > then the combined filter will have\n * > combined modification `{ field1: string, field2: number }`\n *\n * > **Note**: Due to TypeScript limitations (or more likely my lack of brain cells),\n * > state type is only correctly inferred for up to 6 filters.\n * > If you need more, either provide type explicitly (e.g. `filters.state<SomeState>(...)`),\n * > or combine multiple `and` calls.\n *\n * @param fns Filters to combine\n */\nexport function and(...fns: UpdateFilter<any, any, any>[]): UpdateFilter<any, any, any> {\n return (upd, state) => {\n let i = 0\n const max = fns.length\n\n const next = (): MaybePromise<boolean> => {\n if (i === max) return true\n\n const res = fns[i++](upd, state)\n\n if (typeof res === 'boolean') {\n if (!res) return false\n\n return next()\n }\n\n return res.then((r: boolean) => {\n if (!r) return false\n\n return next()\n })\n }\n\n return next()\n }\n}\n\nexport function or<Base1, Mod1, State1 extends object, Base2, Mod2, State2 extends object>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n): UpdateFilter<Base1 & Base2, Mod1 | Mod2, State1 | State2>\n\nexport function or<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n): UpdateFilter<Base1 & Base2 & Base3, Mod1 | Mod2 | Mod3, State1 | State2 | State3>\n\nexport function or<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n): UpdateFilter<Base1 & Base2 & Base3 & Base4, Mod1 | Mod2 | Mod3 | Mod4, State1 | State2 | State3 | State4>\n\nexport function or<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n Base5,\n Mod5,\n State5 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n fn5: UpdateFilter<Base5, Mod5, State5>,\n): UpdateFilter<\n Base1 & Base2 & Base3 & Base4 & Base5,\n Mod1 | Mod2 | Mod3 | Mod4 | Mod5,\n State1 | State2 | State3 | State4 | State5\n>\n\nexport function or<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n Base5,\n Mod5,\n State5 extends object,\n Base6,\n Mod6,\n State6 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n fn5: UpdateFilter<Base5, Mod5, State5>,\n fn6: UpdateFilter<Base6, Mod6, State6>,\n): UpdateFilter<\n Base1 & Base2 & Base3 & Base4 & Base5 & Base6,\n Mod1 | Mod2 | Mod3 | Mod4 | Mod5 | Mod6,\n State1 | State2 | State3 | State4 | State5 | State6\n>\n\n/**\n * Combine multiple filters by applying an OR logical\n * operation between every one of them:\n * `or(fn1, fn2, ..., fnN) = fn1 OR fn2 OR ... OR fnN`\n *\n * > **Note**: This also combines type modifications in a union, i.e.\n * > if the 1st has modification `{ field1: string }`\n * > and the 2nd has modification `{ field2: number }`,\n * > then the combined filter will have\n * > modification `{ field1: string } | { field2: number }`.\n *\n * > **Note**: Due to TypeScript limitations (or more likely my lack of brain cells),\n * > state type is only correctly inferred for up to 6 filters.\n * > If you need more, either provide type explicitly (e.g. `filters.state<SomeState>(...)`),\n * > or combine multiple `and` calls.\n *\n * @param fns Filters to combine\n */\nexport function or(...fns: UpdateFilter<any, any, any>[]): UpdateFilter<any, any, any> {\n return (upd, state) => {\n let i = 0\n const max = fns.length\n\n const next = (): MaybePromise<boolean> => {\n if (i === max) return false\n\n const res = fns[i++](upd, state)\n\n if (typeof res === 'boolean') {\n if (res) return true\n\n return next()\n }\n\n return res.then((r: boolean) => {\n if (r) return true\n\n return next()\n })\n }\n\n return next()\n }\n}\n"]}
|
package/cjs/filters/message.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _RepliedMessageAssertionsByOrigin, MaybeArray, Message, MessageAction, Peer, RawDocument, RepliedMessageInfo, RepliedMessageOrigin, Sticker, StickerSourceType, StickerType, User, Video } from '@mtcute/
|
|
1
|
+
import { _RepliedMessageAssertionsByOrigin, MaybeArray, Message, MessageAction, Peer, RawDocument, RepliedMessageInfo, RepliedMessageOrigin, Sticker, StickerSourceType, StickerType, User, Video } from '@mtcute/core';
|
|
2
2
|
import { MessageContext } from '../index.js';
|
|
3
3
|
import { Modify, UpdateFilter } from './types.js';
|
|
4
4
|
/**
|
|
@@ -41,59 +41,59 @@ export declare const media: UpdateFilter<Message, {
|
|
|
41
41
|
* Filter messages containing media of given type
|
|
42
42
|
*/
|
|
43
43
|
export declare const mediaOf: <T extends "poll" | "story" | "contact" | "game" | "sticker" | "photo" | "location" | "dice" | "audio" | "voice" | "document" | "video" | "live_location" | "webpage" | "venue" | "invoice">(type: T) => UpdateFilter<Message, {
|
|
44
|
-
media: Extract<import("@mtcute/
|
|
44
|
+
media: Extract<import("@mtcute/core").Photo, {
|
|
45
45
|
type: T;
|
|
46
|
-
}> | Extract<import("@mtcute/
|
|
46
|
+
}> | Extract<import("@mtcute/core").Dice, {
|
|
47
47
|
type: T;
|
|
48
|
-
}> | Extract<import("@mtcute/
|
|
48
|
+
}> | Extract<import("@mtcute/core").Contact, {
|
|
49
49
|
type: T;
|
|
50
|
-
}> | Extract<import("@mtcute/
|
|
50
|
+
}> | Extract<import("@mtcute/core").Audio, {
|
|
51
51
|
type: T;
|
|
52
|
-
}> | Extract<import("@mtcute/
|
|
52
|
+
}> | Extract<import("@mtcute/core").Voice, {
|
|
53
53
|
type: T;
|
|
54
54
|
}> | Extract<Sticker, {
|
|
55
55
|
type: T;
|
|
56
|
-
}> | Extract<import("@mtcute/
|
|
56
|
+
}> | Extract<import("@mtcute/core").Document, {
|
|
57
57
|
type: T;
|
|
58
58
|
}> | Extract<Video, {
|
|
59
59
|
type: T;
|
|
60
|
-
}> | Extract<import("@mtcute/
|
|
60
|
+
}> | Extract<import("@mtcute/core").Location, {
|
|
61
61
|
type: T;
|
|
62
|
-
}> | Extract<import("@mtcute/
|
|
62
|
+
}> | Extract<import("@mtcute/core").LiveLocation, {
|
|
63
63
|
type: T;
|
|
64
|
-
}> | Extract<import("@mtcute/
|
|
64
|
+
}> | Extract<import("@mtcute/core").Game, {
|
|
65
65
|
type: T;
|
|
66
|
-
}> | Extract<import("@mtcute/
|
|
66
|
+
}> | Extract<import("@mtcute/core").WebPage, {
|
|
67
67
|
type: T;
|
|
68
|
-
}> | Extract<import("@mtcute/
|
|
68
|
+
}> | Extract<import("@mtcute/core").Venue, {
|
|
69
69
|
type: T;
|
|
70
|
-
}> | Extract<import("@mtcute/
|
|
70
|
+
}> | Extract<import("@mtcute/core").Poll, {
|
|
71
71
|
type: T;
|
|
72
|
-
}> | Extract<import("@mtcute/
|
|
72
|
+
}> | Extract<import("@mtcute/core").Invoice, {
|
|
73
73
|
type: T;
|
|
74
|
-
}> | Extract<import("@mtcute/
|
|
74
|
+
}> | Extract<import("@mtcute/core").MediaStory, {
|
|
75
75
|
type: T;
|
|
76
76
|
}>;
|
|
77
77
|
}>;
|
|
78
78
|
/** Filter messages containing a photo */
|
|
79
79
|
export declare const photo: UpdateFilter<Message, {
|
|
80
|
-
media: import("@mtcute/
|
|
80
|
+
media: import("@mtcute/core").Photo;
|
|
81
81
|
}>;
|
|
82
82
|
/** Filter messages containing a dice */
|
|
83
83
|
export declare const dice: UpdateFilter<Message, {
|
|
84
|
-
media: import("@mtcute/
|
|
84
|
+
media: import("@mtcute/core").Dice;
|
|
85
85
|
}>;
|
|
86
86
|
/** Filter messages containing a contact */
|
|
87
87
|
export declare const contact: UpdateFilter<Message, {
|
|
88
|
-
media: import("@mtcute/
|
|
88
|
+
media: import("@mtcute/core").Contact;
|
|
89
89
|
}>;
|
|
90
90
|
/** Filter messages containing an audio file */
|
|
91
91
|
export declare const audio: UpdateFilter<Message, {
|
|
92
|
-
media: import("@mtcute/
|
|
92
|
+
media: import("@mtcute/core").Audio;
|
|
93
93
|
}>;
|
|
94
94
|
/** Filter messages containing a voice message (audio-only) */
|
|
95
95
|
export declare const voice: UpdateFilter<Message, {
|
|
96
|
-
media: import("@mtcute/
|
|
96
|
+
media: import("@mtcute/core").Voice;
|
|
97
97
|
}>;
|
|
98
98
|
/** Filter messages containing a sticker */
|
|
99
99
|
export declare const sticker: UpdateFilter<Message, {
|
|
@@ -101,7 +101,7 @@ export declare const sticker: UpdateFilter<Message, {
|
|
|
101
101
|
}>;
|
|
102
102
|
/** Filter messages containing a document (a file) */
|
|
103
103
|
export declare const document: UpdateFilter<Message, {
|
|
104
|
-
media: import("@mtcute/
|
|
104
|
+
media: import("@mtcute/core").Document;
|
|
105
105
|
}>;
|
|
106
106
|
/** Filter messages containing any video (videos, round messages and animations) */
|
|
107
107
|
export declare const anyVideo: UpdateFilter<Message, {
|
|
@@ -109,31 +109,31 @@ export declare const anyVideo: UpdateFilter<Message, {
|
|
|
109
109
|
}>;
|
|
110
110
|
/** Filter messages containing a static location */
|
|
111
111
|
export declare const location: UpdateFilter<Message, {
|
|
112
|
-
media: import("@mtcute/
|
|
112
|
+
media: import("@mtcute/core").Location;
|
|
113
113
|
}>;
|
|
114
114
|
/** Filter messages containing a live location */
|
|
115
115
|
export declare const liveLocation: UpdateFilter<Message, {
|
|
116
|
-
media: import("@mtcute/
|
|
116
|
+
media: import("@mtcute/core").LiveLocation;
|
|
117
117
|
}>;
|
|
118
118
|
/** Filter messages containing a game */
|
|
119
119
|
export declare const game: UpdateFilter<Message, {
|
|
120
|
-
media: import("@mtcute/
|
|
120
|
+
media: import("@mtcute/core").Game;
|
|
121
121
|
}>;
|
|
122
122
|
/** Filter messages containing a web page */
|
|
123
123
|
export declare const webpage: UpdateFilter<Message, {
|
|
124
|
-
media: import("@mtcute/
|
|
124
|
+
media: import("@mtcute/core").WebPage;
|
|
125
125
|
}>;
|
|
126
126
|
/** Filter messages containing a venue */
|
|
127
127
|
export declare const venue: UpdateFilter<Message, {
|
|
128
|
-
media: import("@mtcute/
|
|
128
|
+
media: import("@mtcute/core").Venue;
|
|
129
129
|
}>;
|
|
130
130
|
/** Filter messages containing a poll */
|
|
131
131
|
export declare const poll: UpdateFilter<Message, {
|
|
132
|
-
media: import("@mtcute/
|
|
132
|
+
media: import("@mtcute/core").Poll;
|
|
133
133
|
}>;
|
|
134
134
|
/** Filter messages containing an invoice */
|
|
135
135
|
export declare const invoice: UpdateFilter<Message, {
|
|
136
|
-
media: import("@mtcute/
|
|
136
|
+
media: import("@mtcute/core").Invoice;
|
|
137
137
|
}>;
|
|
138
138
|
/**
|
|
139
139
|
* Filter messages containing any location (live or static).
|
|
@@ -210,80 +210,88 @@ export declare const service: UpdateFilter<Message, {
|
|
|
210
210
|
/**
|
|
211
211
|
* Filter service messages by action type
|
|
212
212
|
*/
|
|
213
|
-
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_chosen" | "wallpaper_changed">(type: MaybeArray<T>) => UpdateFilter<Message, {
|
|
214
|
-
action: Extract<import("@mtcute/
|
|
213
|
+
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_chosen" | "wallpaper_changed" | "gift_code" | "giveaway_started" | "giveaway_ended" | "boost_apply">(type: MaybeArray<T>) => UpdateFilter<Message, {
|
|
214
|
+
action: Extract<import("@mtcute/core").ActionChatCreated, {
|
|
215
215
|
type: T;
|
|
216
|
-
}> | Extract<import("@mtcute/
|
|
216
|
+
}> | Extract<import("@mtcute/core").ActionChannelCreated, {
|
|
217
217
|
type: T;
|
|
218
|
-
}> | Extract<import("@mtcute/
|
|
218
|
+
}> | Extract<import("@mtcute/core").ActionChatMigrateTo, {
|
|
219
219
|
type: T;
|
|
220
|
-
}> | Extract<import("@mtcute/
|
|
220
|
+
}> | Extract<import("@mtcute/core").ActionChannelMigrateFrom, {
|
|
221
221
|
type: T;
|
|
222
|
-
}> | Extract<import("@mtcute/
|
|
222
|
+
}> | Extract<import("@mtcute/core").ActionMessagePinned, {
|
|
223
223
|
type: T;
|
|
224
|
-
}> | Extract<import("@mtcute/
|
|
224
|
+
}> | Extract<import("@mtcute/core").ActionHistoryCleared, {
|
|
225
225
|
type: T;
|
|
226
|
-
}> | Extract<import("@mtcute/
|
|
226
|
+
}> | Extract<import("@mtcute/core").ActionGameScore, {
|
|
227
227
|
type: T;
|
|
228
|
-
}> | Extract<import("@mtcute/
|
|
228
|
+
}> | Extract<import("@mtcute/core").ActionContactJoined, {
|
|
229
229
|
type: T;
|
|
230
|
-
}> | Extract<import("@mtcute/
|
|
230
|
+
}> | Extract<import("@mtcute/core").ActionTitleChanged, {
|
|
231
231
|
type: T;
|
|
232
|
-
}> | Extract<import("@mtcute/
|
|
232
|
+
}> | Extract<import("@mtcute/core").ActionPhotoChanged, {
|
|
233
233
|
type: T;
|
|
234
|
-
}> | Extract<import("@mtcute/
|
|
234
|
+
}> | Extract<import("@mtcute/core").ActionPhotoDeleted, {
|
|
235
235
|
type: T;
|
|
236
|
-
}> | Extract<import("@mtcute/
|
|
236
|
+
}> | Extract<import("@mtcute/core").ActionUsersAdded, {
|
|
237
237
|
type: T;
|
|
238
|
-
}> | Extract<import("@mtcute/
|
|
238
|
+
}> | Extract<import("@mtcute/core").ActionUserLeft, {
|
|
239
239
|
type: T;
|
|
240
|
-
}> | Extract<import("@mtcute/
|
|
240
|
+
}> | Extract<import("@mtcute/core").ActionUserRemoved, {
|
|
241
241
|
type: T;
|
|
242
|
-
}> | Extract<import("@mtcute/
|
|
242
|
+
}> | Extract<import("@mtcute/core").ActionUserJoinedLink, {
|
|
243
243
|
type: T;
|
|
244
|
-
}> | Extract<import("@mtcute/
|
|
244
|
+
}> | Extract<import("@mtcute/core").ActionPaymentReceived, {
|
|
245
245
|
type: T;
|
|
246
|
-
}> | Extract<import("@mtcute/
|
|
246
|
+
}> | Extract<import("@mtcute/core").ActionPaymentSent, {
|
|
247
247
|
type: T;
|
|
248
|
-
}> | Extract<import("@mtcute/
|
|
248
|
+
}> | Extract<import("@mtcute/core").ActionCall, {
|
|
249
249
|
type: T;
|
|
250
|
-
}> | Extract<import("@mtcute/
|
|
250
|
+
}> | Extract<import("@mtcute/core").ActionScreenshotTaken, {
|
|
251
251
|
type: T;
|
|
252
|
-
}> | Extract<import("@mtcute/
|
|
252
|
+
}> | Extract<import("@mtcute/core").ActionBotAllowed, {
|
|
253
253
|
type: T;
|
|
254
|
-
}> | Extract<import("@mtcute/
|
|
254
|
+
}> | Extract<import("@mtcute/core").ActionGeoProximity, {
|
|
255
255
|
type: T;
|
|
256
|
-
}> | Extract<import("@mtcute/
|
|
256
|
+
}> | Extract<import("@mtcute/core").ActionGroupCallStarted, {
|
|
257
257
|
type: T;
|
|
258
|
-
}> | Extract<import("@mtcute/
|
|
258
|
+
}> | Extract<import("@mtcute/core").ActionGroupCallEnded, {
|
|
259
259
|
type: T;
|
|
260
|
-
}> | Extract<import("@mtcute/
|
|
260
|
+
}> | Extract<import("@mtcute/core").ActionGroupCallScheduled, {
|
|
261
261
|
type: T;
|
|
262
|
-
}> | Extract<import("@mtcute/
|
|
262
|
+
}> | Extract<import("@mtcute/core").ActionGroupInvite, {
|
|
263
263
|
type: T;
|
|
264
|
-
}> | Extract<import("@mtcute/
|
|
264
|
+
}> | Extract<import("@mtcute/core").ActionTtlChanged, {
|
|
265
265
|
type: T;
|
|
266
|
-
}> | Extract<import("@mtcute/
|
|
266
|
+
}> | Extract<import("@mtcute/core").ActionTopicCreated, {
|
|
267
267
|
type: T;
|
|
268
|
-
}> | Extract<import("@mtcute/
|
|
268
|
+
}> | Extract<import("@mtcute/core").ActionTopicEdited, {
|
|
269
269
|
type: T;
|
|
270
|
-
}> | Extract<import("@mtcute/
|
|
270
|
+
}> | Extract<import("@mtcute/core").ActionCustom, {
|
|
271
271
|
type: T;
|
|
272
|
-
}> | Extract<import("@mtcute/
|
|
272
|
+
}> | Extract<import("@mtcute/core").ActionThemeChanged, {
|
|
273
273
|
type: T;
|
|
274
|
-
}> | Extract<import("@mtcute/
|
|
274
|
+
}> | Extract<import("@mtcute/core").ActionUserJoinedApproved, {
|
|
275
275
|
type: T;
|
|
276
|
-
}> | Extract<import("@mtcute/
|
|
276
|
+
}> | Extract<import("@mtcute/core").ActionWebviewDataSent, {
|
|
277
277
|
type: T;
|
|
278
|
-
}> | Extract<import("@mtcute/
|
|
278
|
+
}> | Extract<import("@mtcute/core").ActionWebviewDataReceived, {
|
|
279
279
|
type: T;
|
|
280
|
-
}> | Extract<import("@mtcute/
|
|
280
|
+
}> | Extract<import("@mtcute/core").ActionPremiumGifted, {
|
|
281
281
|
type: T;
|
|
282
|
-
}> | Extract<import("@mtcute/
|
|
282
|
+
}> | Extract<import("@mtcute/core").ActionPhotoSuggested, {
|
|
283
283
|
type: T;
|
|
284
|
-
}> | Extract<import("@mtcute/
|
|
284
|
+
}> | Extract<import("@mtcute/core").ActionPeerChosen, {
|
|
285
285
|
type: T;
|
|
286
|
-
}> | Extract<import("@mtcute/
|
|
286
|
+
}> | Extract<import("@mtcute/core").ActionWallpaperChanged, {
|
|
287
|
+
type: T;
|
|
288
|
+
}> | Extract<import("@mtcute/core").ActionGiftCode, {
|
|
289
|
+
type: T;
|
|
290
|
+
}> | Extract<import("@mtcute/core").ActionGiveawayStarted, {
|
|
291
|
+
type: T;
|
|
292
|
+
}> | Extract<import("@mtcute/core").ActionGiveawayEnded, {
|
|
293
|
+
type: T;
|
|
294
|
+
}> | Extract<import("@mtcute/core").ActionBoostApply, {
|
|
287
295
|
type: T;
|
|
288
296
|
}>;
|
|
289
297
|
sender: T extends "history_cleared" | "contact_joined" | "user_removed" | "user_joined_link" | "bot_allowed" ? User : Peer;
|
|
@@ -291,7 +299,7 @@ export declare const action: <T extends "chat_created" | "channel_created" | "ch
|
|
|
291
299
|
export declare const sender: <T extends "user" | "chat">(type: T) => UpdateFilter<Message, {
|
|
292
300
|
sender: Extract<User, {
|
|
293
301
|
type: T;
|
|
294
|
-
}> | Extract<import("@mtcute/
|
|
302
|
+
}> | Extract<import("@mtcute/core").Chat, {
|
|
295
303
|
type: T;
|
|
296
304
|
}>;
|
|
297
305
|
}>;
|
package/cjs/filters/message.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
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.outgoing = exports.incoming = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
5
|
// ^^ will be looked into in MTQ-29
|
|
6
|
-
const
|
|
6
|
+
const core_1 = require("@mtcute/core");
|
|
7
7
|
/**
|
|
8
8
|
* Filter incoming messages.
|
|
9
9
|
*
|
|
@@ -71,7 +71,7 @@ exports.invoice = (0, exports.mediaOf)('invoice');
|
|
|
71
71
|
/**
|
|
72
72
|
* Filter messages containing any location (live or static).
|
|
73
73
|
*/
|
|
74
|
-
const anyLocation = (msg) => msg.media instanceof
|
|
74
|
+
const anyLocation = (msg) => msg.media instanceof core_1.RawLocation;
|
|
75
75
|
exports.anyLocation = anyLocation;
|
|
76
76
|
/**
|
|
77
77
|
* Filter messages containing a document
|
|
@@ -79,7 +79,7 @@ exports.anyLocation = anyLocation;
|
|
|
79
79
|
* This will also match media like audio, video, voice
|
|
80
80
|
* that also use Documents
|
|
81
81
|
*/
|
|
82
|
-
const anyDocument = (msg) => msg.media instanceof
|
|
82
|
+
const anyDocument = (msg) => msg.media instanceof core_1.RawDocument;
|
|
83
83
|
exports.anyDocument = anyDocument;
|
|
84
84
|
/**
|
|
85
85
|
* Filter messages containing a simple video.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/filters/message.ts"],"names":[],"mappings":";;;AAAA,uDAAuD;AACvD,mCAAmC;AACnC,2CAgBuB;AAKvB;;;;GAIG;AACI,MAAM,QAAQ,GAAiD,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAA;AAAjF,QAAA,QAAQ,YAAyE;AAE9F;;;;GAIG;AACI,MAAM,QAAQ,GAAgD,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAA;AAA/E,QAAA,QAAQ,YAAuE;AAE5F;;GAEG;AACI,MAAM,KAAK,GAAkE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,cAAc,KAAK,IAAI,CAAA;AAA3G,QAAA,KAAK,SAAsG;AAExH;;GAEG;AACI,MAAM,WAAW,GACpB,CACI,MAAS,EAMX,EAAE,CACA,CAAC,GAAG,EAAE,EAAE,CACJ,GAAG,CAAC,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,KAAK,CAAA,CAAC,kCAAkC;AAV/E,QAAA,WAAW,eAUiC;AAEzD;;GAEG;AACI,MAAM,KAAK,GAAsE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,KAAK,IAAI,CAAA;AAAtG,QAAA,KAAK,SAAiG;AAEnH;;GAEG;AACI,MAAM,OAAO,GAChB,CAA6B,IAAO,EAA4E,EAAE,CAC9G,CAAC,GAAG,EAAE,EAAE,CACJ,GAAG,CAAC,KAAK,EAAE,IAAI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AAK,CAAA;IAEzC,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,UAAU,EAAE,CAAA;IACpC,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IAExB,GAAG,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAE7C,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,OAAO,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AAC/B,CAAC,CAAA;AAfI,QAAA,OAAO,WAeX;AAET;;;GAGG;AACI,MAAM,kBAAkB,GAC3B,CACI,MAAiD,EACT,EAAE,CAC1C,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;IACjB,IAAI;QACA,MAAM,GAAG,CAAC,iBAAiB,EAAE,CAAA;KAChC;IAAC,OAAO,CAAC,EAAE;QACR,OAAO,KAAK,CAAA;KACf;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/client'\n\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 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, { getReplyTo: () => Promise<Message & Mod> }, State> =>\n async (msg, state) => {\n if (!msg.replyToMessage?.id) return false\n\n const reply = await msg.getReplyTo()\n if (!reply) return false\n\n msg.getReplyTo = () => Promise.resolve(reply)\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":";;;AAAA,uDAAuD;AACvD,mCAAmC;AACnC,uCAgBqB;AAKrB;;;;GAIG;AACI,MAAM,QAAQ,GAAiD,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAA;AAAjF,QAAA,QAAQ,YAAyE;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AAE,CAAA;KAChC;IAAC,OAAO,CAAC,EAAE;QACR,OAAO,KAAK,CAAA;KACf;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 { 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 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, { getReplyTo: () => Promise<Message & Mod> }, State> =>\n async (msg, state) => {\n if (!msg.replyToMessage?.id) return false\n\n const reply = await msg.getReplyTo()\n if (!reply) return false\n\n msg.getReplyTo = () => Promise.resolve(reply)\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"]}
|
package/cjs/filters/state.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MaybePromise } from '@mtcute/core';
|
|
2
2
|
import { UpdateFilter } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Create a filter for the cases when the state is empty
|
|
@@ -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) =>
|
|
15
|
+
export declare const state: <T extends object>(predicate: (state: T) => MaybePromise<boolean>) => UpdateFilter<any, {}, T>;
|
package/cjs/filters/state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/filters/state.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACI,MAAM,UAAU,GAAsB,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;IAC9D,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IAExB,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,GAAG,EAAE,CAAC,CAAA;AAC/B,CAAC,CAAA;AAJY,QAAA,UAAU,cAItB;AAED;;;;;;;GAOG;AACI,MAAM,KAAK,GAAG,CACjB,
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/filters/state.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACI,MAAM,UAAU,GAAsB,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;IAC9D,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IAExB,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,GAAG,EAAE,CAAC,CAAA;AAC/B,CAAC,CAAA;AAJY,QAAA,UAAU,cAItB;AAED;;;;;;;GAOG;AACI,MAAM,KAAK,GAAG,CACjB,SAA8C,EAEtB,EAAE;IAC1B,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QACxB,IAAI,CAAC,KAAK;YAAE,OAAO,KAAK,CAAA;QACxB,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,CAAA;QAC9B,IAAI,CAAC,IAAI;YAAE,OAAO,KAAK,CAAA;QAEvB,OAAO,SAAS,CAAC,IAAI,CAAC,CAAA;IAC1B,CAAC,CAAA;AACL,CAAC,CAAA;AAXY,QAAA,KAAK,SAWjB","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { MaybePromise } from '@mtcute/core'\n\nimport { UpdateFilter } from './types.js'\n\n/**\n * Create a filter for the cases when the state is empty\n */\nexport const stateEmpty: UpdateFilter<any> = async (upd, state) => {\n if (!state) return false\n\n return !(await state.get())\n}\n\n/**\n * Create a filter based on state predicate\n *\n * If state exists and matches `predicate`, update passes\n * this filter, otherwise it doesn't\n *\n * @param predicate State predicate\n */\nexport const state = <T extends object>(\n predicate: (state: T) => MaybePromise<boolean>,\n // eslint-disable-next-line @typescript-eslint/ban-types\n): UpdateFilter<any, {}, T> => {\n return async (upd, state) => {\n if (!state) return false\n const data = await state.get()\n if (!data) return false\n\n return predicate(data)\n }\n}\n"]}
|
package/cjs/filters/text.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CallbackQuery, ChosenInlineResult, InlineCallbackQuery, InlineQuery, Message } from '@mtcute/
|
|
1
|
+
import { CallbackQuery, ChosenInlineResult, InlineCallbackQuery, InlineQuery, Message } from '@mtcute/core';
|
|
2
2
|
import { UpdateContextDistributed } from '../context/base.js';
|
|
3
3
|
import { UpdateFilter } from './types.js';
|
|
4
4
|
type UpdatesWithText = UpdateContextDistributed<Message | InlineQuery | ChosenInlineResult | CallbackQuery | InlineCallbackQuery>;
|
package/cjs/filters/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/filters/text.ts"],"names":[],"mappings":";;;AASA,SAAS,WAAW,CAAC,GAAoB;IACrC,QAAQ,GAAG,CAAC,KAAK,EAAE;QACf,KAAK,aAAa;YACd,OAAO,GAAG,CAAC,IAAI,CAAA;QACnB,KAAK,cAAc;YACf,OAAO,GAAG,CAAC,KAAK,CAAA;QACpB,KAAK,sBAAsB;YACvB,OAAO,GAAG,CAAC,EAAE,CAAA;QACjB,KAAK,gBAAgB,CAAC;QACtB,KAAK,uBAAuB;YACxB,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI;gBAAE,OAAO,GAAG,CAAC,OAAO,CAAA;KAC3C;IAED,OAAO,IAAI,CAAA;AACf,CAAC;AAED;;;;;;;;;;;GAWG;AACI,MAAM,KAAK,GACd,CAAC,KAAa,EAA8D,EAAE,CAC1E,CAAC,GAAG,EAAE,EAAE;IACJ,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;IAC5B,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAA;IAEtB,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAE1B,IAAI,CAAC,EAAE;QACF,GAAgD,CAAC,KAAK,GAAG,CAAC,CAAA;QAE3D,OAAO,IAAI,CAAA;KACd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osenInlineResult, InlineCallbackQuery, InlineQuery, Message } from '@mtcute/
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/filters/text.ts"],"names":[],"mappings":";;;AASA,SAAS,WAAW,CAAC,GAAoB;IACrC,QAAQ,GAAG,CAAC,KAAK,EAAE;QACf,KAAK,aAAa;YACd,OAAO,GAAG,CAAC,IAAI,CAAA;QACnB,KAAK,cAAc;YACf,OAAO,GAAG,CAAC,KAAK,CAAA;QACpB,KAAK,sBAAsB;YACvB,OAAO,GAAG,CAAC,EAAE,CAAA;QACjB,KAAK,gBAAgB,CAAC;QACtB,KAAK,uBAAuB;YACxB,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI;gBAAE,OAAO,GAAG,CAAC,OAAO,CAAA;KAC3C;IAED,OAAO,IAAI,CAAA;AACf,CAAC;AAED;;;;;;;;;;;GAWG;AACI,MAAM,KAAK,GACd,CAAC,KAAa,EAA8D,EAAE,CAC1E,CAAC,GAAG,EAAE,EAAE;IACJ,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;IAC5B,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAA;IAEtB,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAE1B,IAAI,CAAC,EAAE;QACF,GAAgD,CAAC,KAAK,GAAG,CAAC,CAAA;QAE3D,OAAO,IAAI,CAAA;KACd;IAED,OAAO,KAAK,CAAA;AAChB,CAAC,CAAA;AAfI,QAAA,KAAK,SAeT;AAET;;;;;;;;;GASG;AACI,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,UAAU,GAAG,KAAK,EAAiC,EAAE;IACrF,IAAI,UAAU,EAAE;QACZ,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAA;QAEvB,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,KAAK,GAAG,CAAA;KAC1D;IAED,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;QAE5B,OAAO,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,CAAA;IAC9D,CAAC,CAAA;AACL,CAAC,CAAA;AAhBY,QAAA,UAAU,cAgBtB;AAED;;;;;;;;;GASG;AACI,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,UAAU,GAAG,KAAK,EAAiC,EAAE;IACvF,IAAI,UAAU,EAAE;QACZ,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAA;QAEvB,OAAO,CAAC,GAAG,EAAE,EAAE;YACX,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;YAE5B,OAAO,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,CAAA;QAC5E,CAAC,CAAA;KACJ;IAED,OAAO,CAAC,GAAG,EAAE,EAAE;QACX,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;QAE5B,OAAO,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,CAAA;IAC9D,CAAC,CAAA;AACL,CAAC,CAAA;AAhBY,QAAA,QAAQ,YAgBpB","sourcesContent":["import { CallbackQuery, ChosenInlineResult, InlineCallbackQuery, InlineQuery, Message } from '@mtcute/core'\n\nimport { UpdateContextDistributed } from '../context/base.js'\nimport { UpdateFilter } from './types.js'\n\ntype UpdatesWithText = UpdateContextDistributed<\n Message | InlineQuery | ChosenInlineResult | CallbackQuery | InlineCallbackQuery\n>\n\nfunction extractText(obj: UpdatesWithText): string | null {\n switch (obj._name) {\n case 'new_message':\n return obj.text\n case 'inline_query':\n return obj.query\n case 'chosen_inline_result':\n return obj.id\n case 'callback_query':\n case 'inline_callback_query':\n if (obj.raw.data) return obj.dataStr\n }\n\n return null\n}\n\n/**\n * Filter objects that match a given regular expression\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult#id} is used\n * - for `CallbackQuery`, `CallbackQuery.dataStr` is used\n *\n * When a regex matches, the match array is stored in a\n * type-safe extension field `.match` of the object\n *\n * @param regex Regex to be matched\n */\nexport const regex =\n (regex: RegExp): UpdateFilter<UpdatesWithText, { match: RegExpMatchArray }> =>\n (obj) => {\n const txt = extractText(obj)\n if (!txt) return false\n\n const m = txt.match(regex)\n\n if (m) {\n (obj as typeof obj & { match: RegExpMatchArray }).match = m\n\n return true\n }\n\n return false\n }\n\n/**\n * Filter objects which contain the exact text given\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for `CallbackQuery`, `CallbackQuery.dataStr` is used\n *\n * @param str String to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport const equals = (str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> => {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => extractText(obj)?.toLowerCase() === str\n }\n\n return (obj) => extractText(obj) === str\n}\n\n/**\n * Filter objects which contain the text given (as a substring)\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for `CallbackQuery`, `CallbackQuery.dataStr` is used\n *\n * @param str Substring to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport const contains = (str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> => {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.toLowerCase().includes(str)\n }\n }\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.includes(str)\n }\n}\n\n/**\n * Filter objects which contain the text starting with a given string\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for `CallbackQuery`, `CallbackQuery.dataStr` is used\n *\n * @param str Substring to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport const startsWith = (str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> => {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.toLowerCase().substring(0, str.length) === str\n }\n }\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.substring(0, str.length) === str\n }\n}\n\n/**\n * Filter objects which contain the text ending with a given string\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for `CallbackQuery`, `CallbackQuery.dataStr` is used\n *\n * @param str Substring to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport const endsWith = (str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> => {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.toLowerCase().substring(0, str.length) === str\n }\n }\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.substring(0, str.length) === str\n }\n}\n"]}
|
package/cjs/filters/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MaybePromise } from '@mtcute/core';
|
|
2
2
|
import { UpdateState } from '../state/update-state.js';
|
|
3
3
|
/**
|
|
4
4
|
* Type describing a primitive filter, which is a function taking some `Base`
|
|
@@ -68,7 +68,7 @@ import { UpdateState } from '../state/update-state.js';
|
|
|
68
68
|
* > **Warning!** Do not use the generics provided in functions
|
|
69
69
|
* > like `and`, `or`, etc. Those are meant to be inferred by the compiler!
|
|
70
70
|
*/
|
|
71
|
-
export type UpdateFilter<Base, Mod = {}, State extends object = never> = (update: Base, state?: UpdateState<State>) =>
|
|
71
|
+
export type UpdateFilter<Base, Mod = {}, State extends object = never> = (update: Base, state?: UpdateState<State>) => MaybePromise<boolean>;
|
|
72
72
|
export type Modify<Base, Mod> = Omit<Base, keyof Mod> & Mod;
|
|
73
73
|
export type Invert<Base, Mod> = {
|
|
74
74
|
[P in keyof Mod & keyof Base]: Exclude<Base[P], Mod[P]>;
|
package/cjs/filters/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/filters/types.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,uDAAuD;AACvD,mCAAmC","sourcesContent":["/* eslint-disable @typescript-eslint/ban-types */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n// ^^ will be looked into in MTQ-29\n\nimport {
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/filters/types.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,uDAAuD;AACvD,mCAAmC","sourcesContent":["/* eslint-disable @typescript-eslint/ban-types */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n// ^^ will be looked into in MTQ-29\n\nimport { MaybePromise } from '@mtcute/core'\n\nimport { UpdateState } from '../state/update-state.js'\n/**\n * Type describing a primitive filter, which is a function taking some `Base`\n * and a {@link TelegramClient}, checking it against some condition\n * and returning a boolean.\n *\n * If `true` is returned, the filter is considered\n * to be matched, and the appropriate update handler function is called,\n * otherwise next registered handler is checked.\n *\n * Additionally, filter might contain a type modification\n * to `Base` for better code insights. If it is present,\n * it is used to overwrite types (!) of some of the `Base` fields\n * to given (note that this is entirely compile-time! object is not modified)\n *\n * For parametrized filters (like {@link filters.regex}),\n * type modification can also be used to add additional fields\n * (in case of `regex`, its match array is added to `.match`)\n *\n * Example without type mod:\n * ```typescript\n *\n * const hasPhoto: UpdateFilter<Message> = msg => msg.media?.type === 'photo'\n *\n * // ..later..\n * tg.onNewMessage(hasPhoto, async (msg) => {\n * // `hasPhoto` filter matched, so we can safely assume\n * // that `msg.media` is a Photo.\n * //\n * // but it is very redundant, verbose and error-rome,\n * // wonder if we could make typescript do this automagically and safely...\n * await (msg.media as Photo).downloadToFile(`${msg.id}.jpg`)\n * })\n * ```\n *\n * Example with type mod:\n * ```typescript\n *\n * const hasPhoto: UpdateFilter<Message, { media: Photo }> = msg => msg.media?.type === 'photo'\n *\n * // ..later..\n * tg.onNewMessage(hasPhoto, async (msg) => {\n * // since `hasPhoto` filter matched,\n * // we have applied the modification to `msg`,\n * // and `msg.media` now has type `Photo`\n * //\n * // no more redundancy and type casts!\n * await msg.media.downloadToFile(`${msg.id}.jpg`)\n * })\n * ```\n *\n * > **Note**: Type modification can contain anything, even totally unrelated types\n * > and it is *your* task to keep track that everything is correct.\n * >\n * > Bad example:\n * > ```typescript\n * > // we check for `Photo`, but type contains `Audio`. this will be a problem!\n * > const hasPhoto: UpdateFilter<Message, { media: Audio }> = msg => msg.media?.type === 'photo'\n * >\n * > // ..later..\n * > tg.onNewMessage(hasPhoto, async (msg) => {\n * > // oops! `msg.media` is `Audio` and does not have `.width`!\n * > console.log(msg.media.width)\n * > })\n * > ```\n *\n * > **Warning!** Do not use the generics provided in functions\n * > like `and`, `or`, etc. Those are meant to be inferred by the compiler!\n */\n// we need the second parameter because it carries meta information\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport type UpdateFilter<Base, Mod = {}, State extends object = never> = (\n update: Base,\n state?: UpdateState<State>,\n) => MaybePromise<boolean>\n\nexport type Modify<Base, Mod> = Omit<Base, keyof Mod> & Mod\nexport type Invert<Base, Mod> = {\n [P in keyof Mod & keyof Base]: Exclude<Base[P], Mod[P]>\n}\n\nexport type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never\n\nexport type ExtractBase<Filter> = Filter extends UpdateFilter<infer I, any> ? I : never\n\nexport type ExtractMod<Filter> = Filter extends UpdateFilter<any, infer I> ? I : never\n\nexport type ExtractState<Filter> = Filter extends UpdateFilter<any, any, infer I> ? I : never\n\nexport type TupleKeys<T extends any[]> = Exclude<keyof T, keyof []>\nexport type WrapBase<T extends any[]> = {\n [K in TupleKeys<T>]: { base: ExtractBase<T[K]> }\n}\nexport type Values<T> = T[keyof T]\nexport type UnwrapBase<T> = T extends { base: any } ? T['base'] : never\nexport type ExtractBaseMany<Filters extends any[]> = UnwrapBase<UnionToIntersection<Values<WrapBase<Filters>>>>\n\nexport type EmptyObject = Record<never, never>\n"]}
|