Skip to content

Commit 858684a

Browse files
authored
Merge pull request python-telegram-bot#628 from python-telegram-bot/may18minor
May 18 minor changes
2 parents ff897ce + f4c6197 commit 858684a

File tree

9 files changed

+63
-6
lines changed

9 files changed

+63
-6
lines changed

telegram/ext/filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def filter(self, message):
215215
class _StatusUpdate(BaseFilter):
216216

217217
def filter(self, message):
218-
return bool(message.new_chat_member or message.left_chat_member
218+
return bool(message.new_chat_members or message.left_chat_member
219219
or message.new_chat_title or message.new_chat_photo
220220
or message.delete_chat_photo or message.group_chat_created
221221
or message.supergroup_chat_created or message.channel_chat_created

telegram/inlinequeryresultgif.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class InlineQueryResultGif(InlineQueryResult):
3232
thumb_url (str): URL of the static thumbnail for the result (jpeg or gif).
3333
gif_width (Optional[int]): Width of the GIF.
3434
gif_height (Optional[int]): Height of the GIF.
35+
gif_duration (Optional[int]): Duration of the GIF.
3536
title (Optional[str]): Title for the result.
3637
caption (Optional[str]): Caption of the GIF file to be sent, 0-200 characters.
3738
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]): Inline keyboard attached
@@ -45,6 +46,7 @@ class InlineQueryResultGif(InlineQueryResult):
4546
thumb_url (str):
4647
gif_width (Optional[int]):
4748
gif_height (Optional[int]):
49+
gif_duration (Optional[int]):
4850
title (Optional[str]):
4951
caption (Optional[str]):
5052
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]):
@@ -63,6 +65,7 @@ def __init__(self,
6365
caption=None,
6466
reply_markup=None,
6567
input_message_content=None,
68+
gif_duration=None,
6669
**kwargs):
6770

6871
# Required
@@ -75,6 +78,8 @@ def __init__(self,
7578
self.gif_width = gif_width
7679
if gif_height:
7780
self.gif_height = gif_height
81+
if gif_duration:
82+
self.gif_duration = gif_duration
7883
if title:
7984
self.title = title
8085
if caption:

telegram/inlinequeryresultmpeg4gif.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
3232
thumb_url (str): URL of the static thumbnail (jpeg or gif) for the result.
3333
mpeg4_width (Optional[int]): Video width.
3434
mpeg4_height (Optional[int]): Video height.
35+
mpeg4_duration (Optional[int]): Video duration
3536
title (Optional[str]): Title for the result.
3637
caption (Optional[str]): Caption of the MPEG-4 file to be sent, 0-200 characters.
3738
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]): Inline keyboard attached
@@ -44,6 +45,7 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
4445
thumb_url (str): URL of the static thumbnail (jpeg or gif) for the result.
4546
mpeg4_width (Optional[int]): Video width.
4647
mpeg4_height (Optional[int]): Video height.
48+
mpeg4_duration (Optional[int]): Video duration
4749
title (Optional[str]): Title for the result.
4850
caption (Optional[str]): Caption of the MPEG-4 file to be sent, 0-200 characters.
4951
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]): Inline keyboard attached
@@ -64,6 +66,7 @@ def __init__(self,
6466
caption=None,
6567
reply_markup=None,
6668
input_message_content=None,
69+
mpeg4_duration=None,
6770
**kwargs):
6871

6972
# Required
@@ -76,6 +79,8 @@ def __init__(self,
7679
self.mpeg4_width = mpeg4_width
7780
if mpeg4_height:
7881
self.mpeg4_height = mpeg4_height
82+
if mpeg4_duration:
83+
self.mpeg4_duration = mpeg4_duration
7984
if title:
8085
self.title = title
8186
if caption:

telegram/message.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

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

2930

@@ -130,6 +131,7 @@ def __init__(self,
130131
location=None,
131132
venue=None,
132133
new_chat_member=None,
134+
new_chat_members=None,
133135
left_chat_member=None,
134136
new_chat_title=None,
135137
new_chat_photo=None,
@@ -167,7 +169,8 @@ def __init__(self,
167169
self.contact = contact
168170
self.location = location
169171
self.venue = venue
170-
self.new_chat_member = new_chat_member
172+
self._new_chat_member = new_chat_member
173+
self.new_chat_members = new_chat_members
171174
self.left_chat_member = left_chat_member
172175
self.new_chat_title = new_chat_title
173176
self.new_chat_photo = new_chat_photo
@@ -224,6 +227,7 @@ def de_json(data, bot):
224227
data['location'] = Location.de_json(data.get('location'), bot)
225228
data['venue'] = Venue.de_json(data.get('venue'), bot)
226229
data['new_chat_member'] = User.de_json(data.get('new_chat_member'), bot)
230+
data['new_chat_members'] = User.de_list(data.get('new_chat_members'), bot)
227231
data['left_chat_member'] = User.de_json(data.get('left_chat_member'), bot)
228232
data['new_chat_photo'] = PhotoSize.de_list(data.get('new_chat_photo'), bot)
229233
data['pinned_message'] = Message.de_json(data.get('pinned_message'), bot)
@@ -257,6 +261,9 @@ def to_dict(self):
257261
data['entities'] = [e.to_dict() for e in self.entities]
258262
if self.new_chat_photo:
259263
data['new_chat_photo'] = [p.to_dict() for p in self.new_chat_photo]
264+
data['new_chat_member'] = data.pop('_new_chat_member', None)
265+
if self.new_chat_members:
266+
data['new_chat_members'] = [u.to_dict() for u in self.new_chat_members]
260267

261268
return data
262269

@@ -712,3 +719,8 @@ def text_markdown(self):
712719
else:
713720
markdown_text += escape_markdown(message_text[last_offset * 2:].decode('utf-16-le'))
714721
return markdown_text
722+
723+
@property
724+
def new_chat_member(self):
725+
warn_deprecate_obj('new_chat_member', 'new_chat_members')
726+
return self._new_chat_member

telegram/user.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,22 @@ def get_profile_photos(self, *args, **kwargs):
9999
Shortcut for ``bot.getUserProfilePhotos(update.message.from_user.id, *args, **kwargs)``
100100
"""
101101
return self.bot.getUserProfilePhotos(self.id, *args, **kwargs)
102+
103+
@staticmethod
104+
def de_list(data, bot):
105+
"""
106+
Args:
107+
data (list):
108+
bot (telegram.Bot):
109+
110+
Returns:
111+
List<telegram.User>:
112+
"""
113+
if not data:
114+
return []
115+
116+
users = list()
117+
for user in data:
118+
users.append(User.de_json(user, bot))
119+
120+
return users

telegram/utils/deprecate.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,18 @@
2121
import warnings
2222

2323

24-
def warn_deprecate_obj(old, new):
25-
warnings.warn('{0} is being deprecated, please use {1} from now on'.format(old, new))
24+
# We use our own DeprecationWarning since they are muted by default and "UserWarning" makes it
25+
# seem like it's the user that issued the warning
26+
# We name it something else so that you don't get confused when you attempt to suppress it
27+
class TelegramDeprecationWarning(Warning):
28+
pass
29+
30+
31+
def warn_deprecate_obj(old, new, stacklevel=3):
32+
warnings.warn(
33+
'{0} is being deprecated, please use {1} from now on.'.format(old, new),
34+
category=TelegramDeprecationWarning,
35+
stacklevel=stacklevel)
2636

2737

2838
def deprecate(func, old, new):

tests/test_filters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ def test_filters_game(self):
121121
def test_filters_status_update(self):
122122
self.assertFalse(Filters.status_update(self.message))
123123

124-
self.message.new_chat_member = 'test'
124+
self.message.new_chat_members = ['test']
125125
self.assertTrue(Filters.status_update(self.message))
126-
self.message.new_chat_member = None
126+
self.message.new_chat_members = None
127127

128128
self.message.left_chat_member = 'test'
129129
self.assertTrue(Filters.status_update(self.message))

tests/test_inlinequeryresultgif.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def setUp(self):
3737
self.gif_url = 'gif url'
3838
self.gif_width = 10
3939
self.gif_height = 15
40+
self.gif_duration = 1
4041
self.thumb_url = 'thumb url'
4142
self.title = 'title'
4243
self.caption = 'caption'
@@ -50,6 +51,7 @@ def setUp(self):
5051
'gif_url': self.gif_url,
5152
'gif_width': self.gif_width,
5253
'gif_height': self.gif_height,
54+
'gif_duration': self.gif_duration,
5355
'thumb_url': self.thumb_url,
5456
'title': self.title,
5557
'caption': self.caption,
@@ -65,6 +67,7 @@ def test_gif_de_json(self):
6567
self.assertEqual(gif.gif_url, self.gif_url)
6668
self.assertEqual(gif.gif_width, self.gif_width)
6769
self.assertEqual(gif.gif_height, self.gif_height)
70+
self.assertEqual(gif.gif_duration, self.gif_duration)
6871
self.assertEqual(gif.thumb_url, self.thumb_url)
6972
self.assertEqual(gif.title, self.title)
7073
self.assertEqual(gif.caption, self.caption)

tests/test_inlinequeryresultmpeg4gif.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def setUp(self):
3737
self.mpeg4_url = 'mpeg4 url'
3838
self.mpeg4_width = 10
3939
self.mpeg4_height = 15
40+
self.mpeg4_duration = 1
4041
self.thumb_url = 'thumb url'
4142
self.title = 'title'
4243
self.caption = 'caption'
@@ -50,6 +51,7 @@ def setUp(self):
5051
'mpeg4_url': self.mpeg4_url,
5152
'mpeg4_width': self.mpeg4_width,
5253
'mpeg4_height': self.mpeg4_height,
54+
'mpeg4_duration': self.mpeg4_duration,
5355
'thumb_url': self.thumb_url,
5456
'title': self.title,
5557
'caption': self.caption,
@@ -65,6 +67,7 @@ def test_mpeg4_de_json(self):
6567
self.assertEqual(mpeg4.mpeg4_url, self.mpeg4_url)
6668
self.assertEqual(mpeg4.mpeg4_width, self.mpeg4_width)
6769
self.assertEqual(mpeg4.mpeg4_height, self.mpeg4_height)
70+
self.assertEqual(mpeg4.mpeg4_duration, self.mpeg4_duration)
6871
self.assertEqual(mpeg4.thumb_url, self.thumb_url)
6972
self.assertEqual(mpeg4.title, self.title)
7073
self.assertEqual(mpeg4.caption, self.caption)

0 commit comments

Comments
 (0)