@tgify/tgify 0.1.0 → 0.1.4
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/LICENSE +23 -23
- package/README.md +356 -356
- package/lib/cli.mjs +9 -9
- package/package.json +1 -1
- package/src/button.ts +182 -182
- package/src/composer.ts +1008 -1008
- package/src/context.ts +1661 -1661
- package/src/core/helpers/args.ts +63 -63
- package/src/core/helpers/check.ts +71 -71
- package/src/core/helpers/compact.ts +18 -18
- package/src/core/helpers/deunionize.ts +26 -26
- package/src/core/helpers/formatting.ts +119 -119
- package/src/core/helpers/util.ts +96 -96
- package/src/core/network/client.ts +396 -396
- package/src/core/network/error.ts +29 -29
- package/src/core/network/multipart-stream.ts +45 -45
- package/src/core/network/polling.ts +94 -94
- package/src/core/network/webhook.ts +58 -58
- package/src/core/types/typegram.ts +54 -54
- package/src/filters.ts +109 -109
- package/src/format.ts +110 -110
- package/src/future.ts +213 -213
- package/src/index.ts +17 -17
- package/src/input.ts +59 -59
- package/src/markup.ts +142 -142
- package/src/middleware.ts +24 -24
- package/src/reactions.ts +118 -118
- package/src/router.ts +55 -55
- package/src/scenes/base.ts +52 -52
- package/src/scenes/context.ts +136 -136
- package/src/scenes/index.ts +21 -21
- package/src/scenes/stage.ts +71 -71
- package/src/scenes/wizard/context.ts +58 -58
- package/src/scenes/wizard/index.ts +63 -63
- package/src/scenes.ts +1 -1
- package/src/session.ts +204 -204
- package/src/telegraf.ts +354 -354
- package/src/telegram-types.ts +219 -219
- package/src/telegram.ts +1635 -1635
- package/src/types.ts +2 -2
- package/src/utils.ts +1 -1
- package/typings/telegraf.d.ts.map +1 -1
package/src/filters.ts
CHANGED
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CallbackQuery,
|
|
3
|
-
CommonMessageBundle,
|
|
4
|
-
Message,
|
|
5
|
-
Update,
|
|
6
|
-
} from '@telegraf/types'
|
|
7
|
-
import { DistinctKeys, KeyedDistinct, Guarded } from './core/helpers/util'
|
|
8
|
-
|
|
9
|
-
export type Filter<U extends Update> = (update: Update) => update is U
|
|
10
|
-
|
|
11
|
-
export { Guarded }
|
|
12
|
-
|
|
13
|
-
export type AllGuarded<Fs extends Filter<Update>[]> = Fs extends [
|
|
14
|
-
infer A,
|
|
15
|
-
...infer B,
|
|
16
|
-
]
|
|
17
|
-
? B extends []
|
|
18
|
-
? Guarded<A>
|
|
19
|
-
: // TS doesn't know otherwise that B is Filter[]
|
|
20
|
-
B extends Filter<Update>[]
|
|
21
|
-
? Guarded<A> & AllGuarded<B>
|
|
22
|
-
: never
|
|
23
|
-
: never
|
|
24
|
-
|
|
25
|
-
export const message =
|
|
26
|
-
<Ks extends DistinctKeys<Message>[]>(...keys: Ks) =>
|
|
27
|
-
(
|
|
28
|
-
update: Update
|
|
29
|
-
): update is Update.MessageUpdate<KeyedDistinct<Message, Ks[number]>> => {
|
|
30
|
-
if (!('message' in update)) return false
|
|
31
|
-
for (const key of keys) {
|
|
32
|
-
if (!(key in update.message)) return false
|
|
33
|
-
}
|
|
34
|
-
return true
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const editedMessage =
|
|
38
|
-
<Ks extends DistinctKeys<CommonMessageBundle>[]>(...keys: Ks) =>
|
|
39
|
-
(
|
|
40
|
-
update: Update
|
|
41
|
-
): update is Update.EditedMessageUpdate<
|
|
42
|
-
KeyedDistinct<CommonMessageBundle, Ks[number]>
|
|
43
|
-
> => {
|
|
44
|
-
if (!('edited_message' in update)) return false
|
|
45
|
-
for (const key of keys) {
|
|
46
|
-
if (!(key in update.edited_message)) return false
|
|
47
|
-
}
|
|
48
|
-
return true
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export const channelPost =
|
|
52
|
-
<Ks extends DistinctKeys<Message>[]>(...keys: Ks) =>
|
|
53
|
-
(
|
|
54
|
-
update: Update
|
|
55
|
-
): update is Update.ChannelPostUpdate<KeyedDistinct<Message, Ks[number]>> => {
|
|
56
|
-
if (!('channel_post' in update)) return false
|
|
57
|
-
for (const key of keys) {
|
|
58
|
-
if (!(key in update.channel_post)) return false
|
|
59
|
-
}
|
|
60
|
-
return true
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export const editedChannelPost =
|
|
64
|
-
<Ks extends DistinctKeys<CommonMessageBundle>[]>(...keys: Ks) =>
|
|
65
|
-
(
|
|
66
|
-
update: Update
|
|
67
|
-
): update is Update.EditedChannelPostUpdate<
|
|
68
|
-
KeyedDistinct<CommonMessageBundle, Ks[number]>
|
|
69
|
-
> => {
|
|
70
|
-
if (!('edited_channel_post' in update)) return false
|
|
71
|
-
for (const key of keys) {
|
|
72
|
-
if (!(key in update.edited_channel_post)) return false
|
|
73
|
-
}
|
|
74
|
-
return true
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export const callbackQuery =
|
|
78
|
-
<Ks extends DistinctKeys<CallbackQuery>[]>(...keys: Ks) =>
|
|
79
|
-
(
|
|
80
|
-
update: Update
|
|
81
|
-
): update is Update.CallbackQueryUpdate<
|
|
82
|
-
KeyedDistinct<CallbackQuery, Ks[number]>
|
|
83
|
-
> => {
|
|
84
|
-
if (!('callback_query' in update)) return false
|
|
85
|
-
for (const key of keys) {
|
|
86
|
-
if (!(key in update.callback_query)) return false
|
|
87
|
-
}
|
|
88
|
-
return true
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** Any of the provided filters must match */
|
|
92
|
-
export const anyOf =
|
|
93
|
-
<Us extends Update[]>(
|
|
94
|
-
...filters: {
|
|
95
|
-
[UIdx in keyof Us]: Filter<Us[UIdx]>
|
|
96
|
-
}
|
|
97
|
-
) =>
|
|
98
|
-
(update: Update): update is Us[number] => {
|
|
99
|
-
for (const filter of filters) if (filter(update)) return true
|
|
100
|
-
return false
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** All of the provided filters must match */
|
|
104
|
-
export const allOf =
|
|
105
|
-
<U extends Update, Fs extends Filter<U>[]>(...filters: Fs) =>
|
|
106
|
-
(update: Update): update is AllGuarded<Fs> => {
|
|
107
|
-
for (const filter of filters) if (!filter(update)) return false
|
|
108
|
-
return true
|
|
109
|
-
}
|
|
1
|
+
import type {
|
|
2
|
+
CallbackQuery,
|
|
3
|
+
CommonMessageBundle,
|
|
4
|
+
Message,
|
|
5
|
+
Update,
|
|
6
|
+
} from '@telegraf/types'
|
|
7
|
+
import { DistinctKeys, KeyedDistinct, Guarded } from './core/helpers/util'
|
|
8
|
+
|
|
9
|
+
export type Filter<U extends Update> = (update: Update) => update is U
|
|
10
|
+
|
|
11
|
+
export { Guarded }
|
|
12
|
+
|
|
13
|
+
export type AllGuarded<Fs extends Filter<Update>[]> = Fs extends [
|
|
14
|
+
infer A,
|
|
15
|
+
...infer B,
|
|
16
|
+
]
|
|
17
|
+
? B extends []
|
|
18
|
+
? Guarded<A>
|
|
19
|
+
: // TS doesn't know otherwise that B is Filter[]
|
|
20
|
+
B extends Filter<Update>[]
|
|
21
|
+
? Guarded<A> & AllGuarded<B>
|
|
22
|
+
: never
|
|
23
|
+
: never
|
|
24
|
+
|
|
25
|
+
export const message =
|
|
26
|
+
<Ks extends DistinctKeys<Message>[]>(...keys: Ks) =>
|
|
27
|
+
(
|
|
28
|
+
update: Update
|
|
29
|
+
): update is Update.MessageUpdate<KeyedDistinct<Message, Ks[number]>> => {
|
|
30
|
+
if (!('message' in update)) return false
|
|
31
|
+
for (const key of keys) {
|
|
32
|
+
if (!(key in update.message)) return false
|
|
33
|
+
}
|
|
34
|
+
return true
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const editedMessage =
|
|
38
|
+
<Ks extends DistinctKeys<CommonMessageBundle>[]>(...keys: Ks) =>
|
|
39
|
+
(
|
|
40
|
+
update: Update
|
|
41
|
+
): update is Update.EditedMessageUpdate<
|
|
42
|
+
KeyedDistinct<CommonMessageBundle, Ks[number]>
|
|
43
|
+
> => {
|
|
44
|
+
if (!('edited_message' in update)) return false
|
|
45
|
+
for (const key of keys) {
|
|
46
|
+
if (!(key in update.edited_message)) return false
|
|
47
|
+
}
|
|
48
|
+
return true
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const channelPost =
|
|
52
|
+
<Ks extends DistinctKeys<Message>[]>(...keys: Ks) =>
|
|
53
|
+
(
|
|
54
|
+
update: Update
|
|
55
|
+
): update is Update.ChannelPostUpdate<KeyedDistinct<Message, Ks[number]>> => {
|
|
56
|
+
if (!('channel_post' in update)) return false
|
|
57
|
+
for (const key of keys) {
|
|
58
|
+
if (!(key in update.channel_post)) return false
|
|
59
|
+
}
|
|
60
|
+
return true
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const editedChannelPost =
|
|
64
|
+
<Ks extends DistinctKeys<CommonMessageBundle>[]>(...keys: Ks) =>
|
|
65
|
+
(
|
|
66
|
+
update: Update
|
|
67
|
+
): update is Update.EditedChannelPostUpdate<
|
|
68
|
+
KeyedDistinct<CommonMessageBundle, Ks[number]>
|
|
69
|
+
> => {
|
|
70
|
+
if (!('edited_channel_post' in update)) return false
|
|
71
|
+
for (const key of keys) {
|
|
72
|
+
if (!(key in update.edited_channel_post)) return false
|
|
73
|
+
}
|
|
74
|
+
return true
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const callbackQuery =
|
|
78
|
+
<Ks extends DistinctKeys<CallbackQuery>[]>(...keys: Ks) =>
|
|
79
|
+
(
|
|
80
|
+
update: Update
|
|
81
|
+
): update is Update.CallbackQueryUpdate<
|
|
82
|
+
KeyedDistinct<CallbackQuery, Ks[number]>
|
|
83
|
+
> => {
|
|
84
|
+
if (!('callback_query' in update)) return false
|
|
85
|
+
for (const key of keys) {
|
|
86
|
+
if (!(key in update.callback_query)) return false
|
|
87
|
+
}
|
|
88
|
+
return true
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Any of the provided filters must match */
|
|
92
|
+
export const anyOf =
|
|
93
|
+
<Us extends Update[]>(
|
|
94
|
+
...filters: {
|
|
95
|
+
[UIdx in keyof Us]: Filter<Us[UIdx]>
|
|
96
|
+
}
|
|
97
|
+
) =>
|
|
98
|
+
(update: Update): update is Us[number] => {
|
|
99
|
+
for (const filter of filters) if (filter(update)) return true
|
|
100
|
+
return false
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** All of the provided filters must match */
|
|
104
|
+
export const allOf =
|
|
105
|
+
<U extends Update, Fs extends Filter<U>[]>(...filters: Fs) =>
|
|
106
|
+
(update: Update): update is AllGuarded<Fs> => {
|
|
107
|
+
for (const filter of filters) if (!filter(update)) return false
|
|
108
|
+
return true
|
|
109
|
+
}
|
package/src/format.ts
CHANGED
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
import { User } from '@telegraf/types'
|
|
2
|
-
import {
|
|
3
|
-
FmtString,
|
|
4
|
-
createFmt,
|
|
5
|
-
linkOrMention,
|
|
6
|
-
join as _join,
|
|
7
|
-
} from './core/helpers/formatting'
|
|
8
|
-
|
|
9
|
-
export { FmtString }
|
|
10
|
-
|
|
11
|
-
type Nestable<Kind extends string> = string | number | boolean | FmtString<Kind>
|
|
12
|
-
type Nesting<Kind extends string> = [
|
|
13
|
-
parts: Nestable<Kind> | readonly Nestable<Kind>[],
|
|
14
|
-
...items: Nestable<Kind>[],
|
|
15
|
-
]
|
|
16
|
-
type Nests<Is extends string, Kind extends string> = (
|
|
17
|
-
...args: Nesting<Kind>
|
|
18
|
-
) => FmtString<Is>
|
|
19
|
-
|
|
20
|
-
// Nests<A, B> means the function will return A, and it can nest B
|
|
21
|
-
// Nests<'fmt', string> means it will nest anything
|
|
22
|
-
// Nests<'code', never> means it will not nest anything
|
|
23
|
-
|
|
24
|
-
// Allowing everything to nest 'fmt' is a necessary evil; it allows to indirectly nest illegal entities
|
|
25
|
-
// Except for 'code' and 'pre', which don't nest anything anyway, so they only deal with strings
|
|
26
|
-
|
|
27
|
-
export const join = _join as Nests<'fmt', string>
|
|
28
|
-
|
|
29
|
-
export const fmt = createFmt() as Nests<'fmt', string>
|
|
30
|
-
|
|
31
|
-
export const bold = createFmt('bold') as Nests<
|
|
32
|
-
'bold',
|
|
33
|
-
'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
|
|
34
|
-
>
|
|
35
|
-
|
|
36
|
-
export const italic = createFmt('italic') as Nests<
|
|
37
|
-
'italic',
|
|
38
|
-
'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
|
|
39
|
-
>
|
|
40
|
-
|
|
41
|
-
export const spoiler = createFmt('spoiler') as Nests<
|
|
42
|
-
'spoiler',
|
|
43
|
-
'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
|
|
44
|
-
>
|
|
45
|
-
|
|
46
|
-
export const strikethrough =
|
|
47
|
-
//
|
|
48
|
-
createFmt('strikethrough') as Nests<
|
|
49
|
-
'strikethrough',
|
|
50
|
-
'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
|
|
51
|
-
>
|
|
52
|
-
|
|
53
|
-
export const underline =
|
|
54
|
-
//
|
|
55
|
-
createFmt('underline') as Nests<
|
|
56
|
-
'underline',
|
|
57
|
-
'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
|
|
58
|
-
>
|
|
59
|
-
|
|
60
|
-
export const quote =
|
|
61
|
-
//
|
|
62
|
-
createFmt('blockquote') as Nests<
|
|
63
|
-
'blockquote',
|
|
64
|
-
| 'fmt'
|
|
65
|
-
| 'bold'
|
|
66
|
-
| 'italic'
|
|
67
|
-
| 'underline'
|
|
68
|
-
| 'strikethrough'
|
|
69
|
-
| 'spoiler'
|
|
70
|
-
| 'code'
|
|
71
|
-
>
|
|
72
|
-
|
|
73
|
-
export const code = createFmt('code') as Nests<'code', never>
|
|
74
|
-
|
|
75
|
-
export const pre = (language: string) =>
|
|
76
|
-
createFmt('pre', { language }) as Nests<'pre', never>
|
|
77
|
-
|
|
78
|
-
export const link = (
|
|
79
|
-
content: Nestable<
|
|
80
|
-
| 'fmt'
|
|
81
|
-
| 'bold'
|
|
82
|
-
| 'italic'
|
|
83
|
-
| 'underline'
|
|
84
|
-
| 'strikethrough'
|
|
85
|
-
| 'spoiler'
|
|
86
|
-
| 'code'
|
|
87
|
-
>,
|
|
88
|
-
url: string
|
|
89
|
-
) =>
|
|
90
|
-
//
|
|
91
|
-
linkOrMention(content, { type: 'text_link', url }) as FmtString<'text_link'>
|
|
92
|
-
|
|
93
|
-
export const mention = (
|
|
94
|
-
name: Nestable<
|
|
95
|
-
| 'fmt'
|
|
96
|
-
| 'bold'
|
|
97
|
-
| 'italic'
|
|
98
|
-
| 'underline'
|
|
99
|
-
| 'strikethrough'
|
|
100
|
-
| 'spoiler'
|
|
101
|
-
| 'code'
|
|
102
|
-
>,
|
|
103
|
-
user: number | User
|
|
104
|
-
) =>
|
|
105
|
-
typeof user === 'number'
|
|
106
|
-
? link(name, 'tg://user?id=' + user)
|
|
107
|
-
: (linkOrMention(name, {
|
|
108
|
-
type: 'text_mention',
|
|
109
|
-
user,
|
|
110
|
-
}) as FmtString<'text_mention'>)
|
|
1
|
+
import { User } from '@telegraf/types'
|
|
2
|
+
import {
|
|
3
|
+
FmtString,
|
|
4
|
+
createFmt,
|
|
5
|
+
linkOrMention,
|
|
6
|
+
join as _join,
|
|
7
|
+
} from './core/helpers/formatting'
|
|
8
|
+
|
|
9
|
+
export { FmtString }
|
|
10
|
+
|
|
11
|
+
type Nestable<Kind extends string> = string | number | boolean | FmtString<Kind>
|
|
12
|
+
type Nesting<Kind extends string> = [
|
|
13
|
+
parts: Nestable<Kind> | readonly Nestable<Kind>[],
|
|
14
|
+
...items: Nestable<Kind>[],
|
|
15
|
+
]
|
|
16
|
+
type Nests<Is extends string, Kind extends string> = (
|
|
17
|
+
...args: Nesting<Kind>
|
|
18
|
+
) => FmtString<Is>
|
|
19
|
+
|
|
20
|
+
// Nests<A, B> means the function will return A, and it can nest B
|
|
21
|
+
// Nests<'fmt', string> means it will nest anything
|
|
22
|
+
// Nests<'code', never> means it will not nest anything
|
|
23
|
+
|
|
24
|
+
// Allowing everything to nest 'fmt' is a necessary evil; it allows to indirectly nest illegal entities
|
|
25
|
+
// Except for 'code' and 'pre', which don't nest anything anyway, so they only deal with strings
|
|
26
|
+
|
|
27
|
+
export const join = _join as Nests<'fmt', string>
|
|
28
|
+
|
|
29
|
+
export const fmt = createFmt() as Nests<'fmt', string>
|
|
30
|
+
|
|
31
|
+
export const bold = createFmt('bold') as Nests<
|
|
32
|
+
'bold',
|
|
33
|
+
'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
|
|
34
|
+
>
|
|
35
|
+
|
|
36
|
+
export const italic = createFmt('italic') as Nests<
|
|
37
|
+
'italic',
|
|
38
|
+
'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
|
|
39
|
+
>
|
|
40
|
+
|
|
41
|
+
export const spoiler = createFmt('spoiler') as Nests<
|
|
42
|
+
'spoiler',
|
|
43
|
+
'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
|
|
44
|
+
>
|
|
45
|
+
|
|
46
|
+
export const strikethrough =
|
|
47
|
+
//
|
|
48
|
+
createFmt('strikethrough') as Nests<
|
|
49
|
+
'strikethrough',
|
|
50
|
+
'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
|
|
51
|
+
>
|
|
52
|
+
|
|
53
|
+
export const underline =
|
|
54
|
+
//
|
|
55
|
+
createFmt('underline') as Nests<
|
|
56
|
+
'underline',
|
|
57
|
+
'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
|
|
58
|
+
>
|
|
59
|
+
|
|
60
|
+
export const quote =
|
|
61
|
+
//
|
|
62
|
+
createFmt('blockquote') as Nests<
|
|
63
|
+
'blockquote',
|
|
64
|
+
| 'fmt'
|
|
65
|
+
| 'bold'
|
|
66
|
+
| 'italic'
|
|
67
|
+
| 'underline'
|
|
68
|
+
| 'strikethrough'
|
|
69
|
+
| 'spoiler'
|
|
70
|
+
| 'code'
|
|
71
|
+
>
|
|
72
|
+
|
|
73
|
+
export const code = createFmt('code') as Nests<'code', never>
|
|
74
|
+
|
|
75
|
+
export const pre = (language: string) =>
|
|
76
|
+
createFmt('pre', { language }) as Nests<'pre', never>
|
|
77
|
+
|
|
78
|
+
export const link = (
|
|
79
|
+
content: Nestable<
|
|
80
|
+
| 'fmt'
|
|
81
|
+
| 'bold'
|
|
82
|
+
| 'italic'
|
|
83
|
+
| 'underline'
|
|
84
|
+
| 'strikethrough'
|
|
85
|
+
| 'spoiler'
|
|
86
|
+
| 'code'
|
|
87
|
+
>,
|
|
88
|
+
url: string
|
|
89
|
+
) =>
|
|
90
|
+
//
|
|
91
|
+
linkOrMention(content, { type: 'text_link', url }) as FmtString<'text_link'>
|
|
92
|
+
|
|
93
|
+
export const mention = (
|
|
94
|
+
name: Nestable<
|
|
95
|
+
| 'fmt'
|
|
96
|
+
| 'bold'
|
|
97
|
+
| 'italic'
|
|
98
|
+
| 'underline'
|
|
99
|
+
| 'strikethrough'
|
|
100
|
+
| 'spoiler'
|
|
101
|
+
| 'code'
|
|
102
|
+
>,
|
|
103
|
+
user: number | User
|
|
104
|
+
) =>
|
|
105
|
+
typeof user === 'number'
|
|
106
|
+
? link(name, 'tg://user?id=' + user)
|
|
107
|
+
: (linkOrMention(name, {
|
|
108
|
+
type: 'text_mention',
|
|
109
|
+
user,
|
|
110
|
+
}) as FmtString<'text_mention'>)
|