Skip to content

Commit 5662fff

Browse files
committed
Add .send_*() methods to User and Chat
1 parent bc6e2d3 commit 5662fff

File tree

2 files changed

+209
-1
lines changed

2 files changed

+209
-1
lines changed

telegram/chat.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,107 @@ def unban_member(self, *args, **kwargs):
212212
213213
"""
214214
return self.bot.unban_chat_member(self.id, *args, **kwargs)
215+
216+
def send_message(self, *args, **kwargs):
217+
"""Shortcut for::
218+
219+
bot.send_message(Chat.chat_id, *args, **kwargs)
220+
221+
Where Chat is the current instance.
222+
223+
Returns:
224+
:class:`telegram.Message`: On success, instance representing the message posted.
225+
226+
"""
227+
return self.send_message(chat_id=self.id, *args, **kwargs)
228+
229+
def send_photo(self, *args, **kwargs):
230+
"""Shortcut for::
231+
232+
bot.send_photo(Chat.chat_id, *args, **kwargs)
233+
234+
Where Chat is the current instance.
235+
236+
Returns:
237+
:class:`telegram.Message`: On success, instance representing the message posted.
238+
239+
"""
240+
return self.send_photo(chat_id=self.id, *args, **kwargs)
241+
242+
def send_audio(self, *args, **kwargs):
243+
"""Shortcut for::
244+
245+
bot.send_audio(Chat.chat_id, *args, **kwargs)
246+
247+
Where Chat is the current instance.
248+
249+
Returns:
250+
:class:`telegram.Message`: On success, instance representing the message posted.
251+
252+
"""
253+
return self.send_audio(chat_id=self.id, *args, **kwargs)
254+
255+
def send_document(self, *args, **kwargs):
256+
"""Shortcut for::
257+
258+
bot.send_document(Chat.chat_id, *args, **kwargs)
259+
260+
Where Chat is the current instance.
261+
262+
Returns:
263+
:class:`telegram.Message`: On success, instance representing the message posted.
264+
265+
"""
266+
return self.send_document(chat_id=self.id, *args, **kwargs)
267+
268+
def send_sticker(self, *args, **kwargs):
269+
"""Shortcut for::
270+
271+
bot.send_sticker(Chat.chat_id, *args, **kwargs)
272+
273+
Where Chat is the current instance.
274+
275+
Returns:
276+
:class:`telegram.Message`: On success, instance representing the message posted.
277+
278+
"""
279+
return self.send_sticker(chat_id=self.id, *args, **kwargs)
280+
281+
def send_video(self, *args, **kwargs):
282+
"""Shortcut for::
283+
284+
bot.send_video(Chat.chat_id, *args, **kwargs)
285+
286+
Where Chat is the current instance.
287+
288+
Returns:
289+
:class:`telegram.Message`: On success, instance representing the message posted.
290+
291+
"""
292+
return self.send_video(chat_id=self.id, *args, **kwargs)
293+
294+
def send_video_note(self, *args, **kwargs):
295+
"""Shortcut for::
296+
297+
bot.send_video_note(Chat.chat_id, *args, **kwargs)
298+
299+
Where Chat is the current instance.
300+
301+
Returns:
302+
:class:`telegram.Message`: On success, instance representing the message posted.
303+
304+
"""
305+
return self.send_video_note(chat_id=self.id, *args, **kwargs)
306+
307+
def send_voice(self, *args, **kwargs):
308+
"""Shortcut for::
309+
310+
bot.send_voice(Chat.chat_id, *args, **kwargs)
311+
312+
Where Chat is the current instance.
313+
314+
Returns:
315+
:class:`telegram.Message`: On success, instance representing the message posted.
316+
317+
"""
318+
return self.send_voice(chat_id=self.id, *args, **kwargs)

telegram/user.py

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"""This module contains an object that represents a Telegram User."""
2121

2222
from telegram import TelegramObject
23-
from telegram.utils.helpers import mention_markdown as util_mention_markdown
2423
from telegram.utils.helpers import mention_html as util_mention_html
24+
from telegram.utils.helpers import mention_markdown as util_mention_markdown
2525

2626

2727
class User(TelegramObject):
@@ -146,3 +146,107 @@ def mention_html(self, name=None):
146146
return util_mention_html(self.id, self.name)
147147
else:
148148
return util_mention_html(self.id, name)
149+
150+
def send_message(self, *args, **kwargs):
151+
"""Shortcut for::
152+
153+
bot.send_message(User.chat_id, *args, **kwargs)
154+
155+
Where User is the current instance.
156+
157+
Returns:
158+
:class:`telegram.Message`: On success, instance representing the message posted.
159+
160+
"""
161+
return self.send_message(chat_id=self.id, *args, **kwargs)
162+
163+
def send_photo(self, *args, **kwargs):
164+
"""Shortcut for::
165+
166+
bot.send_photo(User.chat_id, *args, **kwargs)
167+
168+
Where User is the current instance.
169+
170+
Returns:
171+
:class:`telegram.Message`: On success, instance representing the message posted.
172+
173+
"""
174+
return self.send_photo(chat_id=self.id, *args, **kwargs)
175+
176+
def send_audio(self, *args, **kwargs):
177+
"""Shortcut for::
178+
179+
bot.send_audio(User.chat_id, *args, **kwargs)
180+
181+
Where User is the current instance.
182+
183+
Returns:
184+
:class:`telegram.Message`: On success, instance representing the message posted.
185+
186+
"""
187+
return self.send_audio(chat_id=self.id, *args, **kwargs)
188+
189+
def send_document(self, *args, **kwargs):
190+
"""Shortcut for::
191+
192+
bot.send_document(User.chat_id, *args, **kwargs)
193+
194+
Where User is the current instance.
195+
196+
Returns:
197+
:class:`telegram.Message`: On success, instance representing the message posted.
198+
199+
"""
200+
return self.send_document(chat_id=self.id, *args, **kwargs)
201+
202+
def send_sticker(self, *args, **kwargs):
203+
"""Shortcut for::
204+
205+
bot.send_sticker(User.chat_id, *args, **kwargs)
206+
207+
Where User is the current instance.
208+
209+
Returns:
210+
:class:`telegram.Message`: On success, instance representing the message posted.
211+
212+
"""
213+
return self.send_sticker(chat_id=self.id, *args, **kwargs)
214+
215+
def send_video(self, *args, **kwargs):
216+
"""Shortcut for::
217+
218+
bot.send_video(User.chat_id, *args, **kwargs)
219+
220+
Where User is the current instance.
221+
222+
Returns:
223+
:class:`telegram.Message`: On success, instance representing the message posted.
224+
225+
"""
226+
return self.send_video(chat_id=self.id, *args, **kwargs)
227+
228+
def send_video_note(self, *args, **kwargs):
229+
"""Shortcut for::
230+
231+
bot.send_video_note(User.chat_id, *args, **kwargs)
232+
233+
Where User is the current instance.
234+
235+
Returns:
236+
:class:`telegram.Message`: On success, instance representing the message posted.
237+
238+
"""
239+
return self.send_video_note(chat_id=self.id, *args, **kwargs)
240+
241+
def send_voice(self, *args, **kwargs):
242+
"""Shortcut for::
243+
244+
bot.send_voice(User.chat_id, *args, **kwargs)
245+
246+
Where User is the current instance.
247+
248+
Returns:
249+
:class:`telegram.Message`: On success, instance representing the message posted.
250+
251+
"""
252+
return self.send_voice(chat_id=self.id, *args, **kwargs)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy