Skip to content

Commit 4b298d2

Browse files
author
Pietro Albini
committed
Refactor Message.reply* methods
Now they accept a generic list of arguments, and they pass that to the equivalent Chat.send* method. This allows adding arguments to send* methods without worrying about forgetting to add them to the reply* methods.
1 parent 311210e commit 4b298d2

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

botogram/objects/mixins.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -149,46 +149,44 @@ def forward_to(self, to):
149149
})
150150

151151
@_require_api
152-
def reply(self, message, preview=True, syntax=None, extra=None):
152+
def reply(self, *args, **kwargs):
153153
"""Reply to the current message"""
154-
self.chat.send(message, preview, self.message_id, syntax, extra)
154+
self.chat.send(*args, reply_to=self, **kwargs)
155155

156156
@_require_api
157-
def reply_with_photo(self, path, caption=None, extra=None):
157+
def reply_with_photo(self, *args, **kwargs):
158158
"""Reply with a photo to the current message"""
159-
self.chat.send_photo(path, caption, self.message_id, extra)
159+
self.chat.send_photo(*args, reply_to=self, **kwargs)
160160

161161
@_require_api
162-
def reply_with_audio(self, path, duration=None, performer=None, title=None,
163-
extra=None):
162+
def reply_with_audio(self, *args, **kwargs):
164163
"""Reply with an audio track to the current message"""
165-
self.chat.send_audio(path, duration, performer, title, self.message_id,
166-
extra)
164+
self.chat.send_audio(*args, reply_to=self, **kwargs)
167165

168166
@_require_api
169-
def reply_with_voice(self, path, duration=None, extra=None):
167+
def reply_with_voice(self, *args, **kwargs):
170168
"""Reply with a voice message to the current message"""
171-
self.chat.send_voice(path, duration, self.message_id, extra)
169+
self.chat.send_voice(*args, reply_to=self, **kwargs)
172170

173171
@_require_api
174-
def reply_with_video(self, path, duration=None, caption=None, extra=None):
172+
def reply_with_video(self, *args, **kwargs):
175173
"""Reply with a video to the current message"""
176-
self.chat.send_video(path, duration, caption, self.message_id, extra)
174+
self.chat.send_video(*args, reply_to=self, **kwargs)
177175

178176
@_require_api
179-
def reply_with_file(self, path, extra=None):
177+
def reply_with_file(self, *args, **kwargs):
180178
"""Reply with a generic file to the current chat"""
181-
self.chat.send_file(path, self.message_id, extra)
179+
self.chat.send_file(*args, reply_to=self, **kwargs)
182180

183181
@_require_api
184-
def reply_with_location(self, latitude, longitude, extra=None):
182+
def reply_with_location(self, *args, **kwargs):
185183
"""Reply with a geographic location to the current chat"""
186-
self.chat.send_location(latitude, longitude, self.message_id, extra)
184+
self.chat.send_location(*args, reply_to=self, **kwargs)
187185

188186
@_require_api
189-
def reply_with_sticker(self, sticker, extra=None):
187+
def reply_with_sticker(self, *args, **kwargs):
190188
"""Reply with a sticker to the current message"""
191-
self.chat.send_sticker(sticker, self.message_id, extra)
189+
self.chat.send_sticker(*args, reply_to=self, **kwargs)
192190

193191

194192
class FileMixin:

0 commit comments

Comments
 (0)