From 4783c4f268eaed456cca930309341a1a1abe5342 Mon Sep 17 00:00:00 2001 From: khamidov <63729380+amalkhamidov@users.noreply.github.com> Date: Sun, 8 Nov 2020 02:22:36 +0500 Subject: [PATCH 1/3] feat(InputFile): adding Pathlib to supporting types for files (#442) * feat(InputFile): adding Pathlib to supporting types for files * Resolve filename via pathlib Co-authored-by: Khamidov Amal Co-authored-by: Alex Root Junior --- aiogram/types/input_file.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/aiogram/types/input_file.py b/aiogram/types/input_file.py index 3c397395..3a78c499 100644 --- a/aiogram/types/input_file.py +++ b/aiogram/types/input_file.py @@ -4,6 +4,8 @@ import io import logging import os import secrets +from pathlib import Path +from typing import Union import aiohttp @@ -25,7 +27,7 @@ class InputFile(base.TelegramObject): https://core.telegram.org/bots/api#inputfile """ - def __init__(self, path_or_bytesio, filename=None, conf=None): + def __init__(self, path_or_bytesio: Union[str, io.IOBase, Path], filename=None, conf=None): """ :param path_or_bytesio: @@ -45,6 +47,12 @@ class InputFile(base.TelegramObject): elif isinstance(path_or_bytesio, _WebPipe): self._path = None self._file = path_or_bytesio + + elif isinstance(path_or_bytesio, Path): + self._file = path_or_bytesio.open("rb") + self._path = path_or_bytesio.resolve() + if filename is None: + filename = path_or_bytesio.name else: raise TypeError('Not supported file type.') From fc177b567fbb23c202643f377a20889291fa0758 Mon Sep 17 00:00:00 2001 From: Lamroy95 <50185460+Lamroy95@users.noreply.github.com> Date: Sun, 8 Nov 2020 18:45:39 +0300 Subject: [PATCH 2/3] Update quick_start.rst (#439) Handler without filters catches only text messages --- docs/source/quick_start.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/quick_start.rst b/docs/source/quick_start.rst index 319886ce..eb8551db 100644 --- a/docs/source/quick_start.rst +++ b/docs/source/quick_start.rst @@ -24,7 +24,7 @@ Next step: interaction with bots starts with one command. Register your first co :language: python :lines: 20-25 -If you want to handle all messages in the chat simply add handler without filters: +If you want to handle all text messages in the chat simply add handler without filters: .. literalinclude:: ../../examples/echo_bot.py :language: python From 8c43c209e07366dbe62e614d578458d7d7441dc5 Mon Sep 17 00:00:00 2001 From: Groosha Date: Sun, 8 Nov 2020 18:46:28 +0300 Subject: [PATCH 3/3] Added SUPERGROUP chat type (#438) * Added SUPERGROUP chat type, because SUPER_GROUP is incorrect and confusing. * Added deprecation warning to SUPER_GROUP value --- aiogram/types/chat.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/aiogram/types/chat.py b/aiogram/types/chat.py index 28cc5ed0..7fcea5ea 100644 --- a/aiogram/types/chat.py +++ b/aiogram/types/chat.py @@ -10,7 +10,7 @@ from .chat_member import ChatMember from .chat_permissions import ChatPermissions from .chat_photo import ChatPhoto from .input_file import InputFile -from ..utils.deprecated import deprecated +from ..utils.deprecated import deprecated, DeprecatedReadOnlyClassVar class Chat(base.TelegramObject): @@ -494,6 +494,7 @@ class ChatType(helper.Helper): :key: PRIVATE :key: GROUP :key: SUPER_GROUP + :key: SUPERGROUP :key: CHANNEL """ @@ -501,9 +502,14 @@ class ChatType(helper.Helper): PRIVATE = helper.Item() # private GROUP = helper.Item() # group - SUPER_GROUP = helper.Item() # supergroup + SUPERGROUP = helper.Item() # supergroup CHANNEL = helper.Item() # channel + SUPER_GROUP: DeprecatedReadOnlyClassVar[ChatType, helper.Item] \ + = DeprecatedReadOnlyClassVar( + "SUPER_GROUP chat type is deprecated, use SUPERGROUP instead.", + new_value_getter=lambda cls: cls.SUPERGROUP) + @staticmethod def _check(obj, chat_types) -> bool: if hasattr(obj, 'chat'): @@ -543,7 +549,7 @@ class ChatType(helper.Helper): :param obj: :return: """ - return cls._check(obj, [cls.SUPER_GROUP]) + return cls._check(obj, [cls.SUPER_GROUP, cls.SUPERGROUP]) @classmethod @deprecated("This filter was moved to ChatTypeFilter, and will be removed in aiogram v3.0") @@ -554,7 +560,7 @@ class ChatType(helper.Helper): :param obj: :return: """ - return cls._check(obj, [cls.GROUP, cls.SUPER_GROUP]) + return cls._check(obj, [cls.GROUP, cls.SUPER_GROUP, cls.SUPERGROUP]) @classmethod @deprecated("This filter was moved to ChatTypeFilter, and will be removed in aiogram v3.0")