1616# You should have received a copy of the GNU Lesser General Public License
1717# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818
19+ import asyncio
20+
21+
1922class Filter :
2023 def __call__ (self , message ):
2124 raise NotImplementedError
@@ -34,23 +37,48 @@ class InvertFilter(Filter):
3437 def __init__ (self , base ):
3538 self .base = base
3639
37- def __call__ (self , message ):
38- return not self .base (message )
40+ async def __call__ (self , message ):
41+ if asyncio .iscoroutinefunction (self .base .__call__ ):
42+ x = await self .base (message )
43+ else :
44+ x = self .base (message )
45+
46+ return not x
3947
4048
4149class AndFilter (Filter ):
4250 def __init__ (self , base , other ):
4351 self .base = base
4452 self .other = other
4553
46- def __call__ (self , message ):
47- return self .base (message ) and self .other (message )
54+ async def __call__ (self , message ):
55+ if asyncio .iscoroutinefunction (self .base .__call__ ):
56+ x = await self .base (message )
57+ else :
58+ x = self .base (message )
59+
60+ if asyncio .iscoroutinefunction (self .other .__call__ ):
61+ y = await self .other (message )
62+ else :
63+ y = self .other (message )
64+
65+ return x and y
4866
4967
5068class OrFilter (Filter ):
5169 def __init__ (self , base , other ):
5270 self .base = base
5371 self .other = other
5472
55- def __call__ (self , message ):
56- return self .base (message ) or self .other (message )
73+ async def __call__ (self , message ):
74+ if asyncio .iscoroutinefunction (self .base .__call__ ):
75+ x = await self .base (message )
76+ else :
77+ x = self .base (message )
78+
79+ if asyncio .iscoroutinefunction (self .other .__call__ ):
80+ y = await self .other (message )
81+ else :
82+ y = self .other (message )
83+
84+ return x or y
0 commit comments