X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ break the API classes. For example:
.. code-block:: python
# GOOD
def __init__(self, id, name, last_name='', **kwargs):
def __init__(self, id, name, last_name=None, **kwargs):
self.last_name = last_name
# BAD
def __init__(self, id, name, last_name=''):
def __init__(self, id, name, last_name=None):
self.last_name = last_name
Expand Down
16 changes: 11 additions & 5 deletions telegram/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ class Animation(TelegramObject):

"""

def __init__(self, file_id, **kwargs):
def __init__(self,
file_id,
thumb=None,
file_name=None,
mime_type=None,
file_size=None,
**kwargs):
self.file_id = file_id
self.thumb = kwargs.get('thumb')
self.file_name = kwargs.get('file_name')
self.mime_type = kwargs.get('mime_type')
self.file_size = kwargs.get('file_size')
self.thumb = thumb
self.file_name = file_name
self.mime_type = mime_type
self.file_size = file_size

@staticmethod
def de_json(data, bot):
Expand Down
12 changes: 6 additions & 6 deletions telegram/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ class Audio(TelegramObject):
def __init__(self,
file_id,
duration,
performer='',
title='',
mime_type='',
file_size=0,
performer=None,
title=None,
mime_type=None,
file_size=None,
**kwargs):
# Required
self.file_id = str(file_id)
self.duration = int(duration)
# Optionals
self.performer = performer
self.title = title
self.mime_type = str(mime_type)
self.file_size = int(file_size)
self.mime_type = mime_type
self.file_size = file_size

@staticmethod
def de_json(data, bot):
Expand Down
9 changes: 8 additions & 1 deletion telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,14 @@ def sendContact(self,

@log
@message
def sendGame(self, chat_id, game_short_name, **kwargs):
def sendGame(self,
chat_id,
game_short_name,
disable_notification=False,
reply_to_message_id=None,
reply_markup=None,
timeout=None,
**kwargs):
"""Use this method to send a game.

Args:
Expand Down
10 changes: 5 additions & 5 deletions telegram/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class Chat(TelegramObject):
def __init__(self,
id,
type,
title='',
username='',
first_name='',
last_name='',
all_members_are_admins=False,
title=None,
username=None,
first_name=None,
last_name=None,
all_members_are_admins=None,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API of Chat calls this var as all_members_are_administrators, here we use admins. Is there anything that translates admins. I think we actually have a bug here, or telegram might have silently changed the API.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm about 90% sure they changed their API... so should we change it, or like keep both, or?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should follow their official API.
We can do bkwd-compat for a while using **kwargs.
@jh0ker What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say we keep bkwd-compat

bot=None,
**kwargs):
# Required
Expand Down
4 changes: 2 additions & 2 deletions telegram/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class Contact(TelegramObject):

"""

def __init__(self, phone_number, first_name, last_name='', user_id=0, **kwargs):
def __init__(self, phone_number, first_name, last_name=None, user_id=None, **kwargs):
# Required
self.phone_number = str(phone_number)
self.first_name = first_name
# Optionals
self.last_name = last_name
self.user_id = int(user_id)
self.user_id = user_id

@staticmethod
def de_json(data, bot):
Expand Down
12 changes: 9 additions & 3 deletions telegram/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,20 @@ class Document(TelegramObject):

"""

def __init__(self, file_id, thumb=None, file_name='', mime_type='', file_size=0, **kwargs):
def __init__(self,
file_id,
thumb=None,
file_name=None,
mime_type=None,
file_size=None,
**kwargs):
# Required
self.file_id = str(file_id)
# Optionals
self.thumb = thumb
self.file_name = file_name
self.mime_type = str(mime_type)
self.file_size = int(file_size)
self.mime_type = mime_type
self.file_size = file_size

@staticmethod
def de_json(data, bot):
Expand Down
7 changes: 4 additions & 3 deletions telegram/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ class File(TelegramObject):

"""

def __init__(self, file_id, bot, file_size=0, file_path='', **kwargs):
def __init__(self, file_id, bot, file_size=None, file_path=None, **kwargs):
# Required
self.file_id = str(file_id)

# Optionals
self.file_size = int(file_size)
self.file_path = str(file_path)
self.file_size = file_size
if file_path:
self.file_path = str(file_path)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just do
self.file_path = file_path
The if statement should not be there.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, whoops. I removed the other ones. Seems like I missed these.


self.bot = bot

Expand Down
2 changes: 1 addition & 1 deletion telegram/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self,
title,
description,
photo,
text='',
text=None,
text_entities=None,
animation=None,
**kwargs):
Expand Down
13 changes: 10 additions & 3 deletions telegram/inlinekeyboardbutton.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,23 @@ class InlineKeyboardButton(TelegramObject):

"""

def __init__(self, text, url=None, callback_data=None, switch_inline_query=None, **kwargs):
def __init__(self,
text,
url=None,
callback_data=None,
switch_inline_query=None,
switch_inline_query_current_chat=None,
callback_game=None,
**kwargs):
# Required
self.text = text

# Optionals
self.url = url
self.callback_data = callback_data
self.switch_inline_query = switch_inline_query
self.switch_inline_query_current_chat = kwargs.get('switch_inline_query_current_chat')
self.callback_game = kwargs.get('callback_game')
self.switch_inline_query_current_chat = switch_inline_query_current_chat
self.callback_game = callback_game

@staticmethod
def de_json(data, bot):
Expand Down
6 changes: 2 additions & 4 deletions telegram/keyboardbutton.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ def __init__(self, text, request_contact=None, request_location=None, **kwargs):
# Required
self.text = text
# Optionals
if request_contact:
self.request_contact = request_contact
if request_location:
self.request_location = request_location
self.request_contact = request_contact
self.request_location = request_location

@staticmethod
def de_json(data, bot):
Expand Down
14 changes: 7 additions & 7 deletions telegram/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,27 @@ def __init__(self,
forward_date=None,
reply_to_message=None,
edit_date=None,
text='',
text=None,
entities=None,
audio=None,
document=None,
photo=None,
sticker=None,
video=None,
voice=None,
caption='',
caption=None,
contact=None,
location=None,
venue=None,
new_chat_member=None,
left_chat_member=None,
new_chat_title='',
new_chat_title=None,
new_chat_photo=None,
delete_chat_photo=False,
group_chat_created=False,
supergroup_chat_created=False,
migrate_to_chat_id=0,
migrate_from_chat_id=0,
migrate_to_chat_id=None,
migrate_from_chat_id=None,
channel_chat_created=False,
pinned_message=None,
forward_from_message_id=None,
Expand Down Expand Up @@ -174,8 +174,8 @@ def __init__(self,
self.delete_chat_photo = bool(delete_chat_photo)
self.group_chat_created = bool(group_chat_created)
self.supergroup_chat_created = bool(supergroup_chat_created)
self.migrate_to_chat_id = int(migrate_to_chat_id)
self.migrate_from_chat_id = int(migrate_from_chat_id)
self.migrate_to_chat_id = migrate_to_chat_id
self.migrate_from_chat_id = migrate_from_chat_id
self.channel_chat_created = bool(channel_chat_created)
self.pinned_message = pinned_message
self.forward_from_message_id = forward_from_message_id
Expand Down
4 changes: 2 additions & 2 deletions telegram/photosize.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ class PhotoSize(TelegramObject):
file_size (Optional[int]):
"""

def __init__(self, file_id, width, height, file_size=0, **kwargs):
def __init__(self, file_id, width, height, file_size=None, **kwargs):
# Required
self.file_id = str(file_id)
self.width = int(width)
self.height = int(height)
# Optionals
self.file_size = int(file_size)
self.file_size = file_size

def __eq__(self, other):
if not isinstance(other, self.__class__):
Expand Down
4 changes: 2 additions & 2 deletions telegram/sticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ class Sticker(TelegramObject):
file_size (Optional[int]):
"""

def __init__(self, file_id, width, height, thumb=None, emoji='', file_size=0, **kwargs):
def __init__(self, file_id, width, height, thumb=None, emoji=None, file_size=None, **kwargs):
# Required
self.file_id = str(file_id)
self.width = int(width)
self.height = int(height)
# Optionals
self.thumb = thumb
self.emoji = emoji
self.file_size = int(file_size)
self.file_size = file_size

@staticmethod
def de_json(data, bot):
Expand Down
9 changes: 8 additions & 1 deletion telegram/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ class User(TelegramObject):
bot (Optional[Bot]): The Bot to use for instance methods
"""

def __init__(self, id, first_name, type='', last_name='', username='', bot=None, **kwargs):
def __init__(self,
id,
first_name,
type=None,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the type attribute in documentation. I think we should remove it too.
I can only guess it's something Telegram had obsoleted.
You should leave it at the prototype until ver. 7 I guess, and put a deprecation warning if it specified.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. I don't think it's ever been there tbh.. I might be us who made an error and confused User for Chat or something.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Telegram removed it.
@jh0ker what do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I remember it from the official docs as well, but I could be wrong...

last_name=None,
username=None,
bot=None,
**kwargs):
# Required
self.id = int(id)
self.first_name = first_name
Expand Down
8 changes: 4 additions & 4 deletions telegram/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def __init__(self,
height,
duration,
thumb=None,
mime_type='',
file_size=0,
mime_type=None,
file_size=None,
**kwargs):
# Required
self.file_id = str(file_id)
Expand All @@ -62,8 +62,8 @@ def __init__(self,
self.duration = int(duration)
# Optionals
self.thumb = thumb
self.mime_type = str(mime_type)
self.file_size = int(file_size)
self.mime_type = mime_type
self.file_size = file_size

@staticmethod
def de_json(data, bot):
Expand Down
6 changes: 3 additions & 3 deletions telegram/voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ class Voice(TelegramObject):
file_size (Optional[int]):
"""

def __init__(self, file_id, duration, mime_type='', file_size=0, **kwargs):
def __init__(self, file_id, duration, mime_type=None, file_size=None, **kwargs):
# Required
self.file_id = str(file_id)
self.duration = int(duration)
# Optionals
self.mime_type = str(mime_type)
self.file_size = int(file_size)
self.mime_type = mime_type
self.file_size = file_size

@staticmethod
def de_json(data, bot):
Expand Down
13 changes: 10 additions & 3 deletions telegram/webhookinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ class WebhookInfo(TelegramObject):

"""

def __init__(self, url, has_custom_certificate, pending_update_count, **kwargs):
def __init__(self,
url,
has_custom_certificate,
pending_update_count,
last_error_date=None,
last_error_message=None,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're missing optionals: max_connections (int) & allowed_updates (List[str])

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed but I thought @jh0ker was working on that?
Now that I look at it, it doesn't seem to be in our PR list... (I think I confused it for #483)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that too, so I checked the official December 4th release notes and it wasn't there, so lets fix it here while we're at it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait no... it totally is part of #483 isn't it, @jh0ker?

**kwargs):
# Required
self.url = url
self.has_custom_certificate = has_custom_certificate
self.pending_update_count = pending_update_count
self.last_error_date = kwargs.get('last_error_date', '')
self.last_error_message = kwargs.get('last_error_message', '')
# Optional
self.last_error_date = last_error_date
self.last_error_message = last_error_message

@staticmethod
def de_json(data, bot):
Expand Down
X Tutup