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
2 changes: 1 addition & 1 deletion telegram/ext/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def filter(self, message):
class _StatusUpdate(BaseFilter):

def filter(self, message):
return bool(message.new_chat_member or message.left_chat_member
return bool(message.new_chat_members or message.left_chat_member
or message.new_chat_title or message.new_chat_photo
or message.delete_chat_photo or message.group_chat_created
or message.supergroup_chat_created or message.channel_chat_created
Expand Down
5 changes: 5 additions & 0 deletions telegram/inlinequeryresultgif.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class InlineQueryResultGif(InlineQueryResult):
thumb_url (str): URL of the static thumbnail for the result (jpeg or gif).
gif_width (Optional[int]): Width of the GIF.
gif_height (Optional[int]): Height of the GIF.
gif_duration (Optional[int]): Duration of the GIF.
title (Optional[str]): Title for the result.
caption (Optional[str]): Caption of the GIF file to be sent, 0-200 characters.
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]): Inline keyboard attached
Expand All @@ -45,6 +46,7 @@ class InlineQueryResultGif(InlineQueryResult):
thumb_url (str):
gif_width (Optional[int]):
gif_height (Optional[int]):
gif_duration (Optional[int]):
title (Optional[str]):
caption (Optional[str]):
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]):
Expand All @@ -63,6 +65,7 @@ def __init__(self,
caption=None,
reply_markup=None,
input_message_content=None,
gif_duration=None,
**kwargs):

# Required
Expand All @@ -75,6 +78,8 @@ def __init__(self,
self.gif_width = gif_width
if gif_height:
self.gif_height = gif_height
if gif_duration:
self.gif_duration = gif_duration
if title:
self.title = title
if caption:
Expand Down
5 changes: 5 additions & 0 deletions telegram/inlinequeryresultmpeg4gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
thumb_url (str): URL of the static thumbnail (jpeg or gif) for the result.
mpeg4_width (Optional[int]): Video width.
mpeg4_height (Optional[int]): Video height.
mpeg4_duration (Optional[int]): Video duration
title (Optional[str]): Title for the result.
caption (Optional[str]): Caption of the MPEG-4 file to be sent, 0-200 characters.
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]): Inline keyboard attached
Expand All @@ -44,6 +45,7 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
thumb_url (str): URL of the static thumbnail (jpeg or gif) for the result.
mpeg4_width (Optional[int]): Video width.
mpeg4_height (Optional[int]): Video height.
mpeg4_duration (Optional[int]): Video duration
title (Optional[str]): Title for the result.
caption (Optional[str]): Caption of the MPEG-4 file to be sent, 0-200 characters.
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]): Inline keyboard attached
Expand All @@ -64,6 +66,7 @@ def __init__(self,
caption=None,
reply_markup=None,
input_message_content=None,
mpeg4_duration=None,
**kwargs):

# Required
Expand All @@ -76,6 +79,8 @@ def __init__(self,
self.mpeg4_width = mpeg4_width
if mpeg4_height:
self.mpeg4_height = mpeg4_height
if mpeg4_duration:
self.mpeg4_duration = mpeg4_duration
if title:
self.title = title
if caption:
Expand Down
14 changes: 13 additions & 1 deletion telegram/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from telegram import (Audio, Contact, Document, Chat, Location, PhotoSize, Sticker, TelegramObject,
User, Video, Voice, Venue, MessageEntity, Game)
from telegram.utils.deprecate import warn_deprecate_obj
from telegram.utils.helpers import escape_html, escape_markdown


Expand Down Expand Up @@ -130,6 +131,7 @@ def __init__(self,
location=None,
venue=None,
new_chat_member=None,
new_chat_members=None,
left_chat_member=None,
new_chat_title=None,
new_chat_photo=None,
Expand Down Expand Up @@ -167,7 +169,8 @@ def __init__(self,
self.contact = contact
self.location = location
self.venue = venue
self.new_chat_member = new_chat_member
self._new_chat_member = new_chat_member
self.new_chat_members = new_chat_members
self.left_chat_member = left_chat_member
self.new_chat_title = new_chat_title
self.new_chat_photo = new_chat_photo
Expand Down Expand Up @@ -224,6 +227,7 @@ def de_json(data, bot):
data['location'] = Location.de_json(data.get('location'), bot)
data['venue'] = Venue.de_json(data.get('venue'), bot)
data['new_chat_member'] = User.de_json(data.get('new_chat_member'), bot)
data['new_chat_members'] = User.de_list(data.get('new_chat_members'), bot)
data['left_chat_member'] = User.de_json(data.get('left_chat_member'), bot)
data['new_chat_photo'] = PhotoSize.de_list(data.get('new_chat_photo'), bot)
data['pinned_message'] = Message.de_json(data.get('pinned_message'), bot)
Expand Down Expand Up @@ -257,6 +261,9 @@ def to_dict(self):
data['entities'] = [e.to_dict() for e in self.entities]
if self.new_chat_photo:
data['new_chat_photo'] = [p.to_dict() for p in self.new_chat_photo]
data['new_chat_member'] = data.pop('_new_chat_member', None)
if self.new_chat_members:
data['new_chat_members'] = [u.to_dict() for u in self.new_chat_members]

return data

Expand Down Expand Up @@ -712,3 +719,8 @@ def text_markdown(self):
else:
markdown_text += escape_markdown(message_text[last_offset * 2:].decode('utf-16-le'))
return markdown_text

@property
def new_chat_member(self):
warn_deprecate_obj('new_chat_member', 'new_chat_members')
return self._new_chat_member
19 changes: 19 additions & 0 deletions telegram/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,22 @@ def get_profile_photos(self, *args, **kwargs):
Shortcut for ``bot.getUserProfilePhotos(update.message.from_user.id, *args, **kwargs)``
"""
return self.bot.getUserProfilePhotos(self.id, *args, **kwargs)

@staticmethod
def de_list(data, bot):
Copy link
Member

Choose a reason for hiding this comment

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

Just saying (don't think anything should be changed atm):
JSON can also be a list, so our notion of de_json & to_json should be fixed. (future todo?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, so you're saying we shouldn't both have a de_list and a de_json, but that de_json should do both?

Copy link
Member

Choose a reason for hiding this comment

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

yes. but not now. we need to open an issue so we won't forgot.

"""
Args:
data (list):
bot (telegram.Bot):

Returns:
List<telegram.User>:
"""
if not data:
return []

users = list()
for user in data:
users.append(User.de_json(user, bot))

return users
14 changes: 12 additions & 2 deletions telegram/utils/deprecate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@
import warnings


def warn_deprecate_obj(old, new):
warnings.warn('{0} is being deprecated, please use {1} from now on'.format(old, new))
# We use our own DeprecationWarning since they are muted by default and "UserWarning" makes it
# seem like it's the user that issued the warning
# We name it something else so that you don't get confused when you attempt to suppress it
class TelegramDeprecationWarning(Warning):
pass


def warn_deprecate_obj(old, new, stacklevel=3):
warnings.warn(
'{0} is being deprecated, please use {1} from now on.'.format(old, new),
category=TelegramDeprecationWarning,
stacklevel=stacklevel)


def deprecate(func, old, new):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def test_filters_game(self):
def test_filters_status_update(self):
self.assertFalse(Filters.status_update(self.message))

self.message.new_chat_member = 'test'
self.message.new_chat_members = ['test']
self.assertTrue(Filters.status_update(self.message))
self.message.new_chat_member = None
self.message.new_chat_members = None

self.message.left_chat_member = 'test'
self.assertTrue(Filters.status_update(self.message))
Expand Down
3 changes: 3 additions & 0 deletions tests/test_inlinequeryresultgif.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def setUp(self):
self.gif_url = 'gif url'
self.gif_width = 10
self.gif_height = 15
self.gif_duration = 1
self.thumb_url = 'thumb url'
self.title = 'title'
self.caption = 'caption'
Expand All @@ -50,6 +51,7 @@ def setUp(self):
'gif_url': self.gif_url,
'gif_width': self.gif_width,
'gif_height': self.gif_height,
'gif_duration': self.gif_duration,
'thumb_url': self.thumb_url,
'title': self.title,
'caption': self.caption,
Expand All @@ -65,6 +67,7 @@ def test_gif_de_json(self):
self.assertEqual(gif.gif_url, self.gif_url)
self.assertEqual(gif.gif_width, self.gif_width)
self.assertEqual(gif.gif_height, self.gif_height)
self.assertEqual(gif.gif_duration, self.gif_duration)
self.assertEqual(gif.thumb_url, self.thumb_url)
self.assertEqual(gif.title, self.title)
self.assertEqual(gif.caption, self.caption)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_inlinequeryresultmpeg4gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def setUp(self):
self.mpeg4_url = 'mpeg4 url'
self.mpeg4_width = 10
self.mpeg4_height = 15
self.mpeg4_duration = 1
self.thumb_url = 'thumb url'
self.title = 'title'
self.caption = 'caption'
Expand All @@ -50,6 +51,7 @@ def setUp(self):
'mpeg4_url': self.mpeg4_url,
'mpeg4_width': self.mpeg4_width,
'mpeg4_height': self.mpeg4_height,
'mpeg4_duration': self.mpeg4_duration,
'thumb_url': self.thumb_url,
'title': self.title,
'caption': self.caption,
Expand All @@ -65,6 +67,7 @@ def test_mpeg4_de_json(self):
self.assertEqual(mpeg4.mpeg4_url, self.mpeg4_url)
self.assertEqual(mpeg4.mpeg4_width, self.mpeg4_width)
self.assertEqual(mpeg4.mpeg4_height, self.mpeg4_height)
self.assertEqual(mpeg4.mpeg4_duration, self.mpeg4_duration)
self.assertEqual(mpeg4.thumb_url, self.thumb_url)
self.assertEqual(mpeg4.title, self.title)
self.assertEqual(mpeg4.caption, self.caption)
Expand Down