19
19
from ..exceptions .propagations import BreakPropagation , ContinuePropagation
20
20
from ..general import TUpdate
21
21
from ..key_resolvers .key_resolver import AbstractKeyResolver
22
+ from ..key_resolvers import (
23
+ MessageSenderId ,
24
+ CallbackQueryMessageId ,
25
+ CallbackQuerySenderId ,
26
+ )
22
27
from ..filters import Filter
23
28
24
29
if TYPE_CHECKING :
@@ -67,12 +72,85 @@ def decorator(
67
72
_tag = tag or _function .__name__
68
73
if not self ._context .dp .handler_tag_exists (_tag , CallbackQuery ):
69
74
self ._context .dp .add .handlers .callback_query (
70
- _tag , _function , filter , [self .handler_tag ] # type: ignore
75
+ _tag , _function , filter , [self ._context . handler_tag ]
71
76
)
72
77
self ._context .continue_with .callback_query (_tag , keys , * args , ** kwargs )
73
78
74
79
return decorator
75
80
81
+ def callback_query_form (
82
+ self ,
83
+ user_id : int ,
84
+ filter : Filter [CallbackQuery ],
85
+ tag : Optional [str ] = None ,
86
+ * args : Any ,
87
+ ** kwargs : Any ,
88
+ ):
89
+ def decorator (
90
+ _function : Callable [["CallbackQueryContext" ], Coroutine [Any , Any , None ]]
91
+ ):
92
+ _tag = tag or _function .__name__
93
+ if not self ._context .dp .handler_tag_exists (_tag , CallbackQuery ):
94
+ self ._context .dp .add .handlers .callback_query (
95
+ _tag , _function , filter , [self ._context .handler_tag ]
96
+ )
97
+ self ._context .continue_with .callback_query (
98
+ _tag , [CallbackQuerySenderId (user_id )], * args , ** kwargs
99
+ )
100
+
101
+ return decorator
102
+
103
+ def callback_query_same_message_form (
104
+ self ,
105
+ message_id : int ,
106
+ user_id : int ,
107
+ filter : Filter [CallbackQuery ],
108
+ tag : Optional [str ] = None ,
109
+ * args : Any ,
110
+ ** kwargs : Any ,
111
+ ):
112
+ def decorator (
113
+ _function : Callable [["CallbackQueryContext" ], Coroutine [Any , Any , None ]]
114
+ ):
115
+ _tag = tag or _function .__name__
116
+ if not self ._context .dp .handler_tag_exists (_tag , CallbackQuery ):
117
+ self ._context .dp .add .handlers .callback_query (
118
+ _tag , _function , filter , [self ._context .handler_tag ]
119
+ )
120
+ self ._context .continue_with .callback_query (
121
+ _tag ,
122
+ [CallbackQuerySenderId (user_id ), CallbackQueryMessageId (message_id )],
123
+ * args ,
124
+ ** kwargs ,
125
+ )
126
+
127
+ return decorator
128
+
129
+ def callback_query_same_message (
130
+ self ,
131
+ message_id : int ,
132
+ filter : Filter [CallbackQuery ],
133
+ tag : Optional [str ] = None ,
134
+ * args : Any ,
135
+ ** kwargs : Any ,
136
+ ):
137
+ def decorator (
138
+ _function : Callable [["CallbackQueryContext" ], Coroutine [Any , Any , None ]]
139
+ ):
140
+ _tag = tag or _function .__name__
141
+ if not self ._context .dp .handler_tag_exists (_tag , CallbackQuery ):
142
+ self ._context .dp .add .handlers .callback_query (
143
+ _tag , _function , filter , [self ._context .handler_tag ]
144
+ )
145
+ self ._context .continue_with .callback_query (
146
+ _tag ,
147
+ [CallbackQueryMessageId (message_id )],
148
+ * args ,
149
+ ** kwargs ,
150
+ )
151
+
152
+ return decorator
153
+
76
154
def message (
77
155
self ,
78
156
keys : list [AbstractKeyResolver [Message , Any ]],
@@ -86,11 +164,35 @@ def decorator(
86
164
):
87
165
_tag = tag or _function .__name__
88
166
if not self ._context .dp .handler_tag_exists (_tag , Message ):
89
- self ._context .dp .add .handlers .message (_tag , _function , filter , [self .handler_tag ]) # type: ignore
167
+ self ._context .dp .add .handlers .message (
168
+ _tag , _function , filter , [self ._context .handler_tag ]
169
+ )
90
170
self ._context .continue_with .message (_tag , keys , * args , ** kwargs )
91
171
92
172
return decorator
93
173
174
+ def message_from (
175
+ self ,
176
+ user_id : int ,
177
+ filter : "Filter[Message]" ,
178
+ tag : Optional [str ] = None ,
179
+ * args : Any ,
180
+ ** kwargs : Any ,
181
+ ):
182
+ def decorator (
183
+ _function : Callable [["MessageContext" ], Coroutine [Any , Any , None ]]
184
+ ):
185
+ _tag = tag or _function .__name__
186
+ if not self ._context .dp .handler_tag_exists (_tag , Message ):
187
+ self ._context .dp .add .handlers .message (
188
+ _tag , _function , filter , [self ._context .handler_tag ]
189
+ )
190
+ self ._context .continue_with .message (
191
+ _tag , [MessageSenderId (user_id )], * args , ** kwargs
192
+ )
193
+
194
+ return decorator
195
+
94
196
95
197
class ContinueWithExtensions (ContextExtensions ):
96
198
def __init__ (self , context : "ContextTemplate" ) -> None :
0 commit comments