From 7f1dd6d67e340bdc99f159e7bbba11f0d29f333c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 17 Aug 2018 02:17:48 +0200 Subject: [PATCH] Rename "build" to "create" (friendlier name) --- pyrogram/client/filters/filters.py | 84 +++++++++++++++--------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 5c2538f4..92fb278e 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -22,7 +22,7 @@ from .filter import Filter from ..types.bots import InlineKeyboardMarkup, ReplyKeyboardMarkup -def build(name: str, func: callable, **kwargs) -> type: +def create(name: str, func: callable, **kwargs) -> type: d = {"__call__": func} d.update(kwargs) @@ -33,109 +33,109 @@ class Filters: """This class provides access to all Filters available in Pyrogram. Filters are intended to be used with the :obj:`MessageHandler `.""" - bot = build("Bot", lambda _, m: bool(m.from_user and m.from_user.is_bot)) + bot = create("Bot", lambda _, m: bool(m.from_user and m.from_user.is_bot)) """Filter messages coming from bots""" - incoming = build("Incoming", lambda _, m: not m.outgoing) + incoming = create("Incoming", lambda _, m: not m.outgoing) """Filter incoming messages.""" - outgoing = build("Outgoing", lambda _, m: m.outgoing) + outgoing = create("Outgoing", lambda _, m: m.outgoing) """Filter outgoing messages.""" - text = build("Text", lambda _, m: bool(m.text)) + text = create("Text", lambda _, m: bool(m.text)) """Filter text messages.""" - reply = build("Reply", lambda _, m: bool(m.reply_to_message)) + reply = create("Reply", lambda _, m: bool(m.reply_to_message)) """Filter messages that are replies to other messages.""" - forwarded = build("Forwarded", lambda _, m: bool(m.forward_date)) + forwarded = create("Forwarded", lambda _, m: bool(m.forward_date)) """Filter messages that are forwarded.""" - caption = build("Caption", lambda _, m: bool(m.caption)) + caption = create("Caption", lambda _, m: bool(m.caption)) """Filter media messages that contain captions.""" - edited = build("Edited", lambda _, m: bool(m.edit_date)) + edited = create("Edited", lambda _, m: bool(m.edit_date)) """Filter edited messages.""" - audio = build("Audio", lambda _, m: bool(m.audio)) + audio = create("Audio", lambda _, m: bool(m.audio)) """Filter messages that contain :obj:`Audio ` objects.""" - document = build("Document", lambda _, m: bool(m.document)) + document = create("Document", lambda _, m: bool(m.document)) """Filter messages that contain :obj:`Document ` objects.""" - photo = build("Photo", lambda _, m: bool(m.photo)) + photo = create("Photo", lambda _, m: bool(m.photo)) """Filter messages that contain :obj:`Photo ` objects.""" - sticker = build("Sticker", lambda _, m: bool(m.sticker)) + sticker = create("Sticker", lambda _, m: bool(m.sticker)) """Filter messages that contain :obj:`Sticker ` objects.""" - animation = build("GIF", lambda _, m: bool(m.animation)) + animation = create("GIF", lambda _, m: bool(m.animation)) """Filter messages that contain :obj:`Animation ` objects.""" - video = build("Video", lambda _, m: bool(m.video)) + video = create("Video", lambda _, m: bool(m.video)) """Filter messages that contain :obj:`Video ` objects.""" - voice = build("Voice", lambda _, m: bool(m.voice)) + voice = create("Voice", lambda _, m: bool(m.voice)) """Filter messages that contain :obj:`Voice ` note objects.""" - video_note = build("Voice", lambda _, m: bool(m.video_note)) + video_note = create("Voice", lambda _, m: bool(m.video_note)) """Filter messages that contain :obj:`VideoNote ` objects.""" - contact = build("Contact", lambda _, m: bool(m.contact)) + contact = create("Contact", lambda _, m: bool(m.contact)) """Filter messages that contain :obj:`Contact ` objects.""" - location = build("Location", lambda _, m: bool(m.location)) + location = create("Location", lambda _, m: bool(m.location)) """Filter messages that contain :obj:`Location ` objects.""" - venue = build("Venue", lambda _, m: bool(m.venue)) + venue = create("Venue", lambda _, m: bool(m.venue)) """Filter messages that contain :obj:`Venue ` objects.""" - private = build("Private", lambda _, m: bool(m.chat and m.chat.type == "private")) + private = create("Private", lambda _, m: bool(m.chat and m.chat.type == "private")) """Filter messages sent in private chats.""" - group = build("Group", lambda _, m: bool(m.chat and m.chat.type in {"group", "supergroup"})) + group = create("Group", lambda _, m: bool(m.chat and m.chat.type in {"group", "supergroup"})) """Filter messages sent in group or supergroup chats.""" - channel = build("Channel", lambda _, m: bool(m.chat and m.chat.type == "channel")) + channel = create("Channel", lambda _, m: bool(m.chat and m.chat.type == "channel")) """Filter messages sent in channels.""" - new_chat_members = build("NewChatMembers", lambda _, m: bool(m.new_chat_members)) + new_chat_members = create("NewChatMembers", lambda _, m: bool(m.new_chat_members)) """Filter service messages for new chat members.""" - left_chat_member = build("LeftChatMember", lambda _, m: bool(m.left_chat_member)) + left_chat_member = create("LeftChatMember", lambda _, m: bool(m.left_chat_member)) """Filter service messages for members that left the chat.""" - new_chat_title = build("NewChatTitle", lambda _, m: bool(m.new_chat_title)) + new_chat_title = create("NewChatTitle", lambda _, m: bool(m.new_chat_title)) """Filter service messages for new chat titles.""" - new_chat_photo = build("NewChatPhoto", lambda _, m: bool(m.new_chat_photo)) + new_chat_photo = create("NewChatPhoto", lambda _, m: bool(m.new_chat_photo)) """Filter service messages for new chat photos.""" - delete_chat_photo = build("DeleteChatPhoto", lambda _, m: bool(m.delete_chat_photo)) + delete_chat_photo = create("DeleteChatPhoto", lambda _, m: bool(m.delete_chat_photo)) """Filter service messages for deleted photos.""" - group_chat_created = build("GroupChatCreated", lambda _, m: bool(m.group_chat_created)) + group_chat_created = create("GroupChatCreated", lambda _, m: bool(m.group_chat_created)) """Filter service messages for group chat creations.""" - supergroup_chat_created = build("SupergroupChatCreated", lambda _, m: bool(m.supergroup_chat_created)) + supergroup_chat_created = create("SupergroupChatCreated", lambda _, m: bool(m.supergroup_chat_created)) """Filter service messages for supergroup chat creations.""" - channel_chat_created = build("ChannelChatCreated", lambda _, m: bool(m.channel_chat_created)) + channel_chat_created = create("ChannelChatCreated", lambda _, m: bool(m.channel_chat_created)) """Filter service messages for channel chat creations.""" - migrate_to_chat_id = build("MigrateToChatId", lambda _, m: bool(m.migrate_to_chat_id)) + migrate_to_chat_id = create("MigrateToChatId", lambda _, m: bool(m.migrate_to_chat_id)) """Filter service messages that contain migrate_to_chat_id.""" - migrate_from_chat_id = build("MigrateFromChatId", lambda _, m: bool(m.migrate_from_chat_id)) + migrate_from_chat_id = create("MigrateFromChatId", lambda _, m: bool(m.migrate_from_chat_id)) """Filter service messages that contain migrate_from_chat_id.""" - pinned_message = build("PinnedMessage", lambda _, m: bool(m.pinned_message)) + pinned_message = create("PinnedMessage", lambda _, m: bool(m.pinned_message)) """Filter service messages for pinned messages.""" - reply_keyboard = build("ReplyKeyboard", lambda _, m: isinstance(m.reply_markup, ReplyKeyboardMarkup)) + reply_keyboard = create("ReplyKeyboard", lambda _, m: isinstance(m.reply_markup, ReplyKeyboardMarkup)) """Filter messages containing reply keyboard markups""" - inline_keyboard = build("InlineKeyboard", lambda _, m: isinstance(m.reply_markup, InlineKeyboardMarkup)) + inline_keyboard = create("InlineKeyboard", lambda _, m: isinstance(m.reply_markup, InlineKeyboardMarkup)) """Filter messages containing inline keyboard markups""" @staticmethod @@ -174,7 +174,7 @@ class Filters: return bool(m.command) - return build( + return create( "Command", f, c={command if case_sensitive @@ -206,7 +206,7 @@ class Filters: m.matches = [i for i in _.p.finditer(m.text or "")] return bool(m.matches) - return build("Regex", f, p=re.compile(pattern, flags)) + return create("Regex", f, p=re.compile(pattern, flags)) @staticmethod def user(user: int or str or list): @@ -216,7 +216,7 @@ class Filters: user (``int`` | ``str`` | ``list``): The user or list of user IDs (int) or usernames (str) the filter should look for. """ - return build( + return create( "User", lambda _, m: bool(m.from_user and (m.from_user.id in _.u @@ -237,7 +237,7 @@ class Filters: chat (``int`` | ``str`` | ``list``): The chat or list of chat IDs (int) or usernames (str) the filter should look for. """ - return build( + return create( "Chat", lambda _, m: bool(m.chat and (m.chat.id in _.c @@ -250,7 +250,7 @@ class Filters: ) ) - service = build( + service = create( "Service", lambda _, m: bool( Filters.new_chat_members(m) @@ -268,7 +268,7 @@ class Filters: ) """Filter all service messages.""" - media = build( + media = create( "Media", lambda _, m: bool( Filters.audio(m)