From ad347b5c02cb20dd676cfc2d2fb81b0ad89a910a Mon Sep 17 00:00:00 2001 From: Jacob Bom Date: Sun, 21 May 2017 14:32:36 +0200 Subject: [PATCH 1/2] new_chat_member -> new_chat_members Keep old for now... we can remove it in the future when telegram stops parsing it along. Also: TODO: write proper Message tests --- telegram/message.py | 5 +++++ telegram/user.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/telegram/message.py b/telegram/message.py index a2dde4bcb..8a3c95737 100644 --- a/telegram/message.py +++ b/telegram/message.py @@ -130,6 +130,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, @@ -168,6 +169,7 @@ class Message(TelegramObject): self.location = location self.venue = venue 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 +226,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 +260,8 @@ 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] + if self.new_chat_members: + data['new_chat_members'] = [u.to_dict() for u in self.new_chat_members] return data 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 From 5a15d1b5d6548c7bc156f10718090931ec80d2cb Mon Sep 17 00:00:00 2001 From: Jacob Bom Date: Sun, 21 May 2017 14:38:12 +0200 Subject: [PATCH 2/2] Add mpeg4_duration and gif_duration to inline gif and mpeg4gif --- telegram/inlinequeryresultgif.py | 5 +++++ telegram/inlinequeryresultmpeg4gif.py | 5 +++++ tests/test_inlinequeryresultgif.py | 3 +++ tests/test_inlinequeryresultmpeg4gif.py | 3 +++ 4 files changed, 16 insertions(+) diff --git a/telegram/inlinequeryresultgif.py b/telegram/inlinequeryresultgif.py index e5f8961a7..70a217e6d 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`]): @@ -59,6 +61,7 @@ class InlineQueryResultGif(InlineQueryResult): thumb_url, gif_width=None, gif_height=None, + gif_duration=None, title=None, caption=None, reply_markup=None, @@ -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..c195b4f37 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 @@ -60,6 +62,7 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): thumb_url, mpeg4_width=None, mpeg4_height=None, + mpeg4_duration=None, title=None, caption=None, reply_markup=None, @@ -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/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)