Refactor some redundant elifs

This commit is contained in:
Suren Khorenyan 2019-08-11 23:42:18 +03:00
parent 277eb8b701
commit be622ca559
4 changed files with 43 additions and 43 deletions

View file

@ -94,60 +94,60 @@ class Message(base.TelegramObject):
def content_type(self): def content_type(self):
if self.text: if self.text:
return ContentType.TEXT return ContentType.TEXT
elif self.audio: if self.audio:
return ContentType.AUDIO return ContentType.AUDIO
elif self.animation: if self.animation:
return ContentType.ANIMATION return ContentType.ANIMATION
elif self.document: if self.document:
return ContentType.DOCUMENT return ContentType.DOCUMENT
elif self.game: if self.game:
return ContentType.GAME return ContentType.GAME
elif self.photo: if self.photo:
return ContentType.PHOTO return ContentType.PHOTO
elif self.sticker: if self.sticker:
return ContentType.STICKER return ContentType.STICKER
elif self.video: if self.video:
return ContentType.VIDEO return ContentType.VIDEO
elif self.video_note: if self.video_note:
return ContentType.VIDEO_NOTE return ContentType.VIDEO_NOTE
elif self.voice: if self.voice:
return ContentType.VOICE return ContentType.VOICE
elif self.contact: if self.contact:
return ContentType.CONTACT return ContentType.CONTACT
elif self.venue: if self.venue:
return ContentType.VENUE return ContentType.VENUE
elif self.location: if self.location:
return ContentType.LOCATION return ContentType.LOCATION
elif self.new_chat_members: if self.new_chat_members:
return ContentType.NEW_CHAT_MEMBERS return ContentType.NEW_CHAT_MEMBERS
elif self.left_chat_member: if self.left_chat_member:
return ContentType.LEFT_CHAT_MEMBER return ContentType.LEFT_CHAT_MEMBER
elif self.invoice: if self.invoice:
return ContentType.INVOICE return ContentType.INVOICE
elif self.successful_payment: if self.successful_payment:
return ContentType.SUCCESSFUL_PAYMENT return ContentType.SUCCESSFUL_PAYMENT
elif self.connected_website: if self.connected_website:
return ContentType.CONNECTED_WEBSITE return ContentType.CONNECTED_WEBSITE
elif self.migrate_from_chat_id: if self.migrate_from_chat_id:
return ContentType.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 return ContentType.MIGRATE_TO_CHAT_ID
elif self.pinned_message: if self.pinned_message:
return ContentType.PINNED_MESSAGE return ContentType.PINNED_MESSAGE
elif self.new_chat_title: if self.new_chat_title:
return ContentType.NEW_CHAT_TITLE return ContentType.NEW_CHAT_TITLE
elif self.new_chat_photo: if self.new_chat_photo:
return ContentType.NEW_CHAT_PHOTO return ContentType.NEW_CHAT_PHOTO
elif self.delete_chat_photo: if self.delete_chat_photo:
return ContentType.DELETE_CHAT_PHOTO return ContentType.DELETE_CHAT_PHOTO
elif self.group_chat_created: if self.group_chat_created:
return ContentType.GROUP_CHAT_CREATED return ContentType.GROUP_CHAT_CREATED
elif self.passport_data: if self.passport_data:
return ContentType.PASSPORT_DATA return ContentType.PASSPORT_DATA
elif self.poll: if self.poll:
return ContentType.POLL return ContentType.POLL
else:
return ContentType.UNKNOWN return ContentType.UNKNOWN
def is_command(self): def is_command(self):
""" """

View file

@ -52,27 +52,27 @@ class MessageEntity(base.TelegramObject):
if as_html: if as_html:
return markdown.hbold(entity_text) return markdown.hbold(entity_text)
return markdown.bold(entity_text) return markdown.bold(entity_text)
elif self.type == MessageEntityType.ITALIC: if self.type == MessageEntityType.ITALIC:
if as_html: if as_html:
return markdown.hitalic(entity_text) return markdown.hitalic(entity_text)
return markdown.italic(entity_text) return markdown.italic(entity_text)
elif self.type == MessageEntityType.PRE: if self.type == MessageEntityType.PRE:
if as_html: if as_html:
return markdown.hpre(entity_text) return markdown.hpre(entity_text)
return markdown.pre(entity_text) return markdown.pre(entity_text)
elif self.type == MessageEntityType.CODE: if self.type == MessageEntityType.CODE:
if as_html: if as_html:
return markdown.hcode(entity_text) return markdown.hcode(entity_text)
return markdown.code(entity_text) return markdown.code(entity_text)
elif self.type == MessageEntityType.URL: if self.type == MessageEntityType.URL:
if as_html: if as_html:
return markdown.hlink(entity_text, entity_text) return markdown.hlink(entity_text, entity_text)
return markdown.link(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: if as_html:
return markdown.hlink(entity_text, self.url) return markdown.hlink(entity_text, self.url)
return markdown.link(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 self.user.get_mention(entity_text)
return entity_text return entity_text

View file

@ -120,15 +120,15 @@ class HelperMode(Helper):
""" """
if mode == cls.SCREAMING_SNAKE_CASE: if mode == cls.SCREAMING_SNAKE_CASE:
return cls._screaming_snake_case(text) return cls._screaming_snake_case(text)
elif mode == cls.snake_case: if mode == cls.snake_case:
return cls._snake_case(text) return cls._snake_case(text)
elif mode == cls.lowercase: if mode == cls.lowercase:
return cls._snake_case(text).replace('_', '') return cls._snake_case(text).replace('_', '')
elif mode == cls.lowerCamelCase: if mode == cls.lowerCamelCase:
return cls._camel_case(text) return cls._camel_case(text)
elif mode == cls.CamelCase: if mode == cls.CamelCase:
return cls._camel_case(text, True) return cls._camel_case(text, True)
elif callable(mode): if callable(mode):
return mode(text) return mode(text)
return text return text

View file

@ -52,14 +52,14 @@ def prepare_arg(value):
""" """
if value is None: if value is None:
return value 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)) return json.dumps(_normalize(value))
elif isinstance(value, datetime.timedelta): if isinstance(value, datetime.timedelta):
now = datetime.datetime.now() now = datetime.datetime.now()
return int((now + value).timestamp()) return int((now + value).timestamp())
elif isinstance(value, datetime.datetime): if isinstance(value, datetime.datetime):
return round(value.timestamp()) return round(value.timestamp())
elif isinstance(value, LazyProxy): if isinstance(value, LazyProxy):
return str(value) return str(value)
return value return value