From 0cc6a2c8f6e77b1a653d4fd6151164ee43892bd8 Mon Sep 17 00:00:00 2001 From: Ramzan Bekbulatov Date: Sun, 13 Sep 2020 22:15:07 +0300 Subject: [PATCH] Add is_forward method to Message (#390) * new: add is_forward method to Message * enh: add return types to Message methods * fix: docs typo * ref: make command methods closer --- aiogram/types/message.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/aiogram/types/message.py b/aiogram/types/message.py index 3540a736..f867a44a 100644 --- a/aiogram/types/message.py +++ b/aiogram/types/message.py @@ -153,7 +153,16 @@ class Message(base.TelegramObject): return ContentType.UNKNOWN - def is_command(self): + def is_forward(self) -> bool: + """ + Check that the message is forwarded. + Only `forward_date` is required to be in forwarded message. + + :return: bool + """ + return bool(self.forward_date) + + def is_command(self) -> bool: """ Check message text is command @@ -161,7 +170,7 @@ class Message(base.TelegramObject): """ return self.text and self.text.startswith("/") - def get_full_command(self): + def get_full_command(self) -> typing.Optional[typing.Tuple[str, str]]: """ Split command and args @@ -172,7 +181,7 @@ class Message(base.TelegramObject): args = args[-1] if args else "" return command, args - def get_command(self, pure=False): + def get_command(self, pure=False) -> typing.Optional[str]: """ Get command from message @@ -185,7 +194,7 @@ class Message(base.TelegramObject): command, _, _ = command[1:].partition("@") return command - def get_args(self): + def get_args(self) -> typing.Optional[str]: """ Get arguments @@ -195,7 +204,7 @@ class Message(base.TelegramObject): if command: return command[1] - def parse_entities(self, as_html=True): + def parse_entities(self, as_html=True) -> str: """ Text or caption formatted as HTML or Markdown.