Skip to content

Commit 2aa456d

Browse files
Eldinnietsnoam
authored andcommitted
remove Bot._message_wrapper (python-telegram-bot#822)
Moved tho code to the @message decorator instead fixes python-telegram-bot#752
1 parent 445bcde commit 2aa456d

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

telegram/bot.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,25 @@ def message(func):
6666
@functools.wraps(func)
6767
def decorator(self, *args, **kwargs):
6868
url, data = func(self, *args, **kwargs)
69-
return self._message_wrapper(url, data, *args, **kwargs)
69+
if kwargs.get('reply_to_message_id'):
70+
data['reply_to_message_id'] = kwargs.get('reply_to_message_id')
71+
72+
if kwargs.get('disable_notification'):
73+
data['disable_notification'] = kwargs.get('disable_notification')
74+
75+
if kwargs.get('reply_markup'):
76+
reply_markup = kwargs.get('reply_markup')
77+
if isinstance(reply_markup, ReplyMarkup):
78+
data['reply_markup'] = reply_markup.to_json()
79+
else:
80+
data['reply_markup'] = reply_markup
81+
82+
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
83+
84+
if result is True:
85+
return result
86+
87+
return Message.de_json(result, self)
7088

7189
return decorator
7290

@@ -148,27 +166,6 @@ def name(self):
148166

149167
return '@{0}'.format(self.username)
150168

151-
def _message_wrapper(self, url, data, *args, **kwargs):
152-
if kwargs.get('reply_to_message_id'):
153-
data['reply_to_message_id'] = kwargs.get('reply_to_message_id')
154-
155-
if kwargs.get('disable_notification'):
156-
data['disable_notification'] = kwargs.get('disable_notification')
157-
158-
if kwargs.get('reply_markup'):
159-
reply_markup = kwargs.get('reply_markup')
160-
if isinstance(reply_markup, ReplyMarkup):
161-
data['reply_markup'] = reply_markup.to_json()
162-
else:
163-
data['reply_markup'] = reply_markup
164-
165-
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
166-
167-
if result is True:
168-
return result
169-
170-
return Message.de_json(result, self)
171-
172169
@log
173170
def get_me(self, timeout=None, **kwargs):
174171
"""A simple method for testing your bot's auth token. Requires no parameters.

0 commit comments

Comments
 (0)