mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Refactor some redundant elifs
This commit is contained in:
parent
277eb8b701
commit
be622ca559
4 changed files with 43 additions and 43 deletions
|
|
@ -94,60 +94,60 @@ class Message(base.TelegramObject):
|
|||
def content_type(self):
|
||||
if self.text:
|
||||
return ContentType.TEXT
|
||||
elif self.audio:
|
||||
if self.audio:
|
||||
return ContentType.AUDIO
|
||||
elif self.animation:
|
||||
if self.animation:
|
||||
return ContentType.ANIMATION
|
||||
elif self.document:
|
||||
if self.document:
|
||||
return ContentType.DOCUMENT
|
||||
elif self.game:
|
||||
if self.game:
|
||||
return ContentType.GAME
|
||||
elif self.photo:
|
||||
if self.photo:
|
||||
return ContentType.PHOTO
|
||||
elif self.sticker:
|
||||
if self.sticker:
|
||||
return ContentType.STICKER
|
||||
elif self.video:
|
||||
if self.video:
|
||||
return ContentType.VIDEO
|
||||
elif self.video_note:
|
||||
if self.video_note:
|
||||
return ContentType.VIDEO_NOTE
|
||||
elif self.voice:
|
||||
if self.voice:
|
||||
return ContentType.VOICE
|
||||
elif self.contact:
|
||||
if self.contact:
|
||||
return ContentType.CONTACT
|
||||
elif self.venue:
|
||||
if self.venue:
|
||||
return ContentType.VENUE
|
||||
elif self.location:
|
||||
if self.location:
|
||||
return ContentType.LOCATION
|
||||
elif self.new_chat_members:
|
||||
if self.new_chat_members:
|
||||
return ContentType.NEW_CHAT_MEMBERS
|
||||
elif self.left_chat_member:
|
||||
if self.left_chat_member:
|
||||
return ContentType.LEFT_CHAT_MEMBER
|
||||
elif self.invoice:
|
||||
if self.invoice:
|
||||
return ContentType.INVOICE
|
||||
elif self.successful_payment:
|
||||
if self.successful_payment:
|
||||
return ContentType.SUCCESSFUL_PAYMENT
|
||||
elif self.connected_website:
|
||||
if self.connected_website:
|
||||
return ContentType.CONNECTED_WEBSITE
|
||||
elif self.migrate_from_chat_id:
|
||||
if self.migrate_from_chat_id:
|
||||
return ContentType.MIGRATE_FROM_CHAT_ID
|
||||
elif self.migrate_to_chat_id:
|
||||
if self.migrate_to_chat_id:
|
||||
return ContentType.MIGRATE_TO_CHAT_ID
|
||||
elif self.pinned_message:
|
||||
if self.pinned_message:
|
||||
return ContentType.PINNED_MESSAGE
|
||||
elif self.new_chat_title:
|
||||
if self.new_chat_title:
|
||||
return ContentType.NEW_CHAT_TITLE
|
||||
elif self.new_chat_photo:
|
||||
if self.new_chat_photo:
|
||||
return ContentType.NEW_CHAT_PHOTO
|
||||
elif self.delete_chat_photo:
|
||||
if self.delete_chat_photo:
|
||||
return ContentType.DELETE_CHAT_PHOTO
|
||||
elif self.group_chat_created:
|
||||
if self.group_chat_created:
|
||||
return ContentType.GROUP_CHAT_CREATED
|
||||
elif self.passport_data:
|
||||
if self.passport_data:
|
||||
return ContentType.PASSPORT_DATA
|
||||
elif self.poll:
|
||||
if self.poll:
|
||||
return ContentType.POLL
|
||||
else:
|
||||
return ContentType.UNKNOWN
|
||||
|
||||
return ContentType.UNKNOWN
|
||||
|
||||
def is_command(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -52,27 +52,27 @@ class MessageEntity(base.TelegramObject):
|
|||
if as_html:
|
||||
return markdown.hbold(entity_text)
|
||||
return markdown.bold(entity_text)
|
||||
elif self.type == MessageEntityType.ITALIC:
|
||||
if self.type == MessageEntityType.ITALIC:
|
||||
if as_html:
|
||||
return markdown.hitalic(entity_text)
|
||||
return markdown.italic(entity_text)
|
||||
elif self.type == MessageEntityType.PRE:
|
||||
if self.type == MessageEntityType.PRE:
|
||||
if as_html:
|
||||
return markdown.hpre(entity_text)
|
||||
return markdown.pre(entity_text)
|
||||
elif self.type == MessageEntityType.CODE:
|
||||
if self.type == MessageEntityType.CODE:
|
||||
if as_html:
|
||||
return markdown.hcode(entity_text)
|
||||
return markdown.code(entity_text)
|
||||
elif self.type == MessageEntityType.URL:
|
||||
if self.type == MessageEntityType.URL:
|
||||
if as_html:
|
||||
return markdown.hlink(entity_text, entity_text)
|
||||
return markdown.link(entity_text, entity_text)
|
||||
elif self.type == MessageEntityType.TEXT_LINK:
|
||||
if self.type == MessageEntityType.TEXT_LINK:
|
||||
if as_html:
|
||||
return markdown.hlink(entity_text, self.url)
|
||||
return markdown.link(entity_text, self.url)
|
||||
elif self.type == MessageEntityType.TEXT_MENTION and self.user:
|
||||
if self.type == MessageEntityType.TEXT_MENTION and self.user:
|
||||
return self.user.get_mention(entity_text)
|
||||
return entity_text
|
||||
|
||||
|
|
|
|||
|
|
@ -120,15 +120,15 @@ class HelperMode(Helper):
|
|||
"""
|
||||
if mode == cls.SCREAMING_SNAKE_CASE:
|
||||
return cls._screaming_snake_case(text)
|
||||
elif mode == cls.snake_case:
|
||||
if mode == cls.snake_case:
|
||||
return cls._snake_case(text)
|
||||
elif mode == cls.lowercase:
|
||||
if mode == cls.lowercase:
|
||||
return cls._snake_case(text).replace('_', '')
|
||||
elif mode == cls.lowerCamelCase:
|
||||
if mode == cls.lowerCamelCase:
|
||||
return cls._camel_case(text)
|
||||
elif mode == cls.CamelCase:
|
||||
if mode == cls.CamelCase:
|
||||
return cls._camel_case(text, True)
|
||||
elif callable(mode):
|
||||
if callable(mode):
|
||||
return mode(text)
|
||||
return text
|
||||
|
||||
|
|
|
|||
|
|
@ -52,14 +52,14 @@ def prepare_arg(value):
|
|||
"""
|
||||
if value is None:
|
||||
return value
|
||||
elif isinstance(value, (list, dict)) or hasattr(value, 'to_python'):
|
||||
if isinstance(value, (list, dict)) or hasattr(value, 'to_python'):
|
||||
return json.dumps(_normalize(value))
|
||||
elif isinstance(value, datetime.timedelta):
|
||||
if isinstance(value, datetime.timedelta):
|
||||
now = datetime.datetime.now()
|
||||
return int((now + value).timestamp())
|
||||
elif isinstance(value, datetime.datetime):
|
||||
if isinstance(value, datetime.datetime):
|
||||
return round(value.timestamp())
|
||||
elif isinstance(value, LazyProxy):
|
||||
if isinstance(value, LazyProxy):
|
||||
return str(value)
|
||||
return value
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue