Skip to content

New filters in builtin module #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
8 tasks done
JrooTJunior opened this issue Jul 8, 2019 · 10 comments
Closed
8 tasks done

New filters in builtin module #151

JrooTJunior opened this issue Jul 8, 2019 · 10 comments
Labels
enhancement Make it better! new feature Missing feature under discussion A subject of discussion

Comments

@JrooTJunior
Copy link
Member

JrooTJunior commented Jul 8, 2019

Next list of filters is planned for implementation in builtin module and registered in filters factory:

@JrooTJunior JrooTJunior added enhancement Make it better! new feature Missing feature labels Jul 8, 2019
@Birdi7
Copy link
Contributor

Birdi7 commented Jul 12, 2019

I would like to work on Multiple text filter. But I have a question regarding the key word. Should it be text for both single and muliple elements, text for single and texts for a list, or texts for both single and multiple elements(like it's done in commands filter)? @JrooTJunior what do you think about it?

@Forevka
Copy link
Contributor

Forevka commented Jul 16, 2019

Maybe it will be useful:

Checking if message from group

class IsGroup(Filter):
    """
        Check if chat is group
    """

    async def check(self, obj: Union[Message, CallbackQuery], *args):
        if isinstance(obj, Message):
            return obj.chat.id < 0
        return obj.message.chat.id < 0

Check if message from private

class IsPrivate(Filter):
    async def check(self, obj: Union[Message, CallbackQuery], *args):
        return obj.chat.id == obj.from_user.id

Check message text in list

class IsTextInList(Filter):
    def __init__(self, text_list):
        self.text_list = text_list

    async def check(self, obj: Union[Message, CallbackQuery], *args):
        return obj.text in self.text_list

@Birdi7 Birdi7 mentioned this issue Jul 22, 2019
7 tasks
@JrooTJunior
Copy link
Member Author

@Forevka69, filters for chat types is already implemented in types.ChatType object:

@staticmethod
def _check(obj, chat_types) -> bool:
if hasattr(obj, 'chat'):
obj = obj.chat
if not hasattr(obj, 'type'):
return False
return obj.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])

@JrooTJunior
Copy link
Member Author

But i think chat type filter can be also implemented (with deprecation of current filters)

For example implement next opportunity:

  • @dp.message_handler(chat_type=types.ChatType.PRIVATE)
  • @dp.message_handler(chat_type=[types.ChatType.GROUP, types.ChatType.SUPER_GROUP])

@JrooTJunior
Copy link
Member Author

About text in list...
I see no prerequisites for implementing separated filter. Maybe it can be added to Text filter.

@JrooTJunior JrooTJunior pinned this issue Jul 22, 2019
@Birdi7 Birdi7 mentioned this issue Jul 27, 2019
8 tasks
@riZZZhik
Copy link

riZZZhik commented Aug 2, 2019

  • reply_to=id
  • forward_from=id

@riZZZhik
Copy link

riZZZhik commented Aug 2, 2019

Maybe multiple all filters?

@JrooTJunior
Copy link
Member Author

multiple all filters?

What do you mean?

@riZZZhik
Copy link

riZZZhik commented Aug 2, 2019

What do you mean?

optimize custom_filter return with Any()

@JrooTJunior
Copy link
Member Author

optimize custom_filter return with Any()

I don't understand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Make it better! new feature Missing feature under discussion A subject of discussion
Projects
None yet
Development

No branches or pull requests

5 participants