diff --git a/telegram/ext/filters.py b/telegram/ext/filters.py index eb965e108..67e5d435d 100644 --- a/telegram/ext/filters.py +++ b/telegram/ext/filters.py @@ -215,7 +215,7 @@ class Filters(object): 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 diff --git a/telegram/inlinequeryresultgif.py b/telegram/inlinequeryresultgif.py index e5f8961a7..427986b2a 100644 --- a/telegram/inlinequeryresultgif.py +++ b/telegram/inlinequeryresultgif.py @@ -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 @@ -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`]): @@ -63,6 +65,7 @@ class InlineQueryResultGif(InlineQueryResult): caption=None, reply_markup=None, input_message_content=None, + gif_duration=None, **kwargs): # Required @@ -75,6 +78,8 @@ class InlineQueryResultGif(InlineQueryResult): 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: diff --git a/telegram/inlinequeryresultmpeg4gif.py b/telegram/inlinequeryresultmpeg4gif.py index 3656a7b37..228079d10 100644 --- a/telegram/inlinequeryresultmpeg4gif.py +++ b/telegram/inlinequeryresultmpeg4gif.py @@ -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 @@ -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 @@ -64,6 +66,7 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): caption=None, reply_markup=None, input_message_content=None, + mpeg4_duration=None, **kwargs): # Required @@ -76,6 +79,8 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): 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: diff --git a/telegram/message.py b/telegram/message.py index a2dde4bcb..f63fbf644 100644 --- a/telegram/message.py +++ b/telegram/message.py @@ -24,6 +24,7 @@ from time import mktime 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 @@ -130,6 +131,7 @@ class Message(TelegramObject): location=None, venue=None, new_chat_member=None, + new_chat_members=None, left_chat_member=None, new_chat_title=None, new_chat_photo=None, @@ -167,7 +169,8 @@ class Message(TelegramObject): 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 @@ -224,6 +227,7 @@ class Message(TelegramObject): 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) @@ -257,6 +261,9 @@ class Message(TelegramObject): 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 @@ -712,3 +719,8 @@ class Message(TelegramObject): 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 diff --git a/telegram/user.py b/telegram/user.py index df924751a..e269ae3c7 100644 --- a/telegram/user.py +++ b/telegram/user.py @@ -99,3 +99,22 @@ class User(TelegramObject): 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): + """ + Args: + data (list): + bot (telegram.Bot): + + Returns: + List: + """ + if not data: + return [] + + users = list() + for user in data: + users.append(User.de_json(user, bot)) + + return users diff --git a/telegram/utils/deprecate.py b/telegram/utils/deprecate.py index af06e1b02..5cbec860e 100644 --- a/telegram/utils/deprecate.py +++ b/telegram/utils/deprecate.py @@ -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): diff --git a/tests/test_filters.py b/tests/test_filters.py index ecb173791..bb41e514b 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -121,9 +121,9 @@ class FiltersTest(BaseTest, unittest.TestCase): 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)) diff --git a/tests/test_inlinequeryresultgif.py b/tests/test_inlinequeryresultgif.py index 1d2d6dc48..4c7cf82c1 100644 --- a/tests/test_inlinequeryresultgif.py +++ b/tests/test_inlinequeryresultgif.py @@ -37,6 +37,7 @@ class InlineQueryResultGifTest(BaseTest, unittest.TestCase): 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' @@ -50,6 +51,7 @@ class InlineQueryResultGifTest(BaseTest, unittest.TestCase): '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, @@ -65,6 +67,7 @@ class InlineQueryResultGifTest(BaseTest, unittest.TestCase): 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) diff --git a/tests/test_inlinequeryresultmpeg4gif.py b/tests/test_inlinequeryresultmpeg4gif.py index c0d1d20b5..a9420f99f 100644 --- a/tests/test_inlinequeryresultmpeg4gif.py +++ b/tests/test_inlinequeryresultmpeg4gif.py @@ -37,6 +37,7 @@ class InlineQueryResultMpeg4GifTest(BaseTest, unittest.TestCase): 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' @@ -50,6 +51,7 @@ class InlineQueryResultMpeg4GifTest(BaseTest, unittest.TestCase): '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, @@ -65,6 +67,7 @@ class InlineQueryResultMpeg4GifTest(BaseTest, unittest.TestCase): 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)