mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Add more filters.
This commit is contained in:
parent
e1b60dfe57
commit
8b28ba8fc4
3 changed files with 89 additions and 15 deletions
|
|
@ -121,6 +121,62 @@ class ChatType(helper.Helper):
|
|||
SUPER_GROUP = helper.Item() # supergroup
|
||||
CHANNEL = helper.Item() # channel
|
||||
|
||||
@staticmethod
|
||||
def _check(obj, chat_types) -> bool:
|
||||
if not hasattr(obj, 'chat'):
|
||||
return False
|
||||
return obj.chat.type in chat_types
|
||||
|
||||
@classmethod
|
||||
def is_private(cls, obj) -> bool:
|
||||
"""
|
||||
Check chat is private
|
||||
|
||||
:param obj:
|
||||
:return:
|
||||
"""
|
||||
return cls._check(obj, [cls.PRIVATE])
|
||||
|
||||
@classmethod
|
||||
def is_group(cls, obj) -> bool:
|
||||
"""
|
||||
Check chat is group
|
||||
|
||||
:param obj:
|
||||
:return:
|
||||
"""
|
||||
return cls._check(obj, [cls.GROUP])
|
||||
|
||||
@classmethod
|
||||
def is_super_group(cls, obj) -> bool:
|
||||
"""
|
||||
Check chat is super-group
|
||||
|
||||
:param obj:
|
||||
:return:
|
||||
"""
|
||||
return cls._check(obj, [cls.SUPER_GROUP])
|
||||
|
||||
@classmethod
|
||||
def is_group_or_super_group(cls, obj) -> bool:
|
||||
"""
|
||||
Check chat is group or super-group
|
||||
|
||||
:param obj:
|
||||
:return:
|
||||
"""
|
||||
return cls._check(obj, [cls.GROUP, cls.SUPER_GROUP])
|
||||
|
||||
@classmethod
|
||||
def is_channel(cls, obj) -> bool:
|
||||
"""
|
||||
Check chat is channel
|
||||
|
||||
:param obj:
|
||||
:return:
|
||||
"""
|
||||
return cls._check(obj, [cls.CHANNEL])
|
||||
|
||||
|
||||
class ChatActions(helper.Helper):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue