mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-16 20:29:55 +01:00
Add Additional Shortcut Methods to Chat
(#3115)
This commit is contained in:
parent
24b4de9f10
commit
755945172d
2 changed files with 301 additions and 0 deletions
|
@ -790,6 +790,144 @@ class Chat(TelegramObject):
|
|||
api_kwargs=api_kwargs,
|
||||
)
|
||||
|
||||
async def set_photo(
|
||||
self,
|
||||
photo: FileInput,
|
||||
*,
|
||||
read_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
write_timeout: ODVInput[float] = 20,
|
||||
connect_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
pool_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
api_kwargs: JSONDict = None,
|
||||
) -> bool:
|
||||
"""Shortcut for::
|
||||
|
||||
await bot.set_chat_photo(
|
||||
chat_id=update.effective_chat.id, *args, **kwargs
|
||||
)
|
||||
|
||||
For the documentation of the arguments, please see
|
||||
:meth:`telegram.Bot.set_chat_photo`.
|
||||
|
||||
.. versionadded:: 20.0
|
||||
|
||||
Returns:
|
||||
:obj:`bool`: On success, :obj:`True` is returned.
|
||||
|
||||
"""
|
||||
return await self.get_bot().set_chat_photo(
|
||||
chat_id=self.id,
|
||||
photo=photo,
|
||||
read_timeout=read_timeout,
|
||||
write_timeout=write_timeout,
|
||||
connect_timeout=connect_timeout,
|
||||
pool_timeout=pool_timeout,
|
||||
api_kwargs=api_kwargs,
|
||||
)
|
||||
|
||||
async def delete_photo(
|
||||
self,
|
||||
*,
|
||||
read_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
write_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
connect_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
pool_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
api_kwargs: JSONDict = None,
|
||||
) -> bool:
|
||||
"""Shortcut for::
|
||||
|
||||
await bot.delete_chat_photo(
|
||||
chat_id=update.effective_chat.id, *args, **kwargs
|
||||
)
|
||||
|
||||
For the documentation of the arguments, please see
|
||||
:meth:`telegram.Bot.delete_chat_photo`.
|
||||
|
||||
.. versionadded:: 20.0
|
||||
|
||||
Returns:
|
||||
:obj:`bool`: On success, :obj:`True` is returned.
|
||||
|
||||
"""
|
||||
return await self.get_bot().delete_chat_photo(
|
||||
chat_id=self.id,
|
||||
read_timeout=read_timeout,
|
||||
write_timeout=write_timeout,
|
||||
connect_timeout=connect_timeout,
|
||||
pool_timeout=pool_timeout,
|
||||
api_kwargs=api_kwargs,
|
||||
)
|
||||
|
||||
async def set_title(
|
||||
self,
|
||||
title: str,
|
||||
*,
|
||||
read_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
write_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
connect_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
pool_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
api_kwargs: JSONDict = None,
|
||||
) -> bool:
|
||||
"""Shortcut for::
|
||||
|
||||
await bot.set_chat_title(
|
||||
chat_id=update.effective_chat.id, *args, **kwargs
|
||||
)
|
||||
|
||||
For the documentation of the arguments, please see
|
||||
:meth:`telegram.Bot.set_chat_title`.
|
||||
|
||||
.. versionadded:: 20.0
|
||||
|
||||
Returns:
|
||||
:obj:`bool`: On success, :obj:`True` is returned.
|
||||
|
||||
"""
|
||||
return await self.get_bot().set_chat_title(
|
||||
chat_id=self.id,
|
||||
title=title,
|
||||
read_timeout=read_timeout,
|
||||
write_timeout=write_timeout,
|
||||
connect_timeout=connect_timeout,
|
||||
pool_timeout=pool_timeout,
|
||||
api_kwargs=api_kwargs,
|
||||
)
|
||||
|
||||
async def set_description(
|
||||
self,
|
||||
description: str = None,
|
||||
*,
|
||||
read_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
write_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
connect_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
pool_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
api_kwargs: JSONDict = None,
|
||||
) -> bool:
|
||||
"""Shortcut for::
|
||||
|
||||
await bot.set_chat_description(
|
||||
chat_id=update.effective_chat.id, *args, **kwargs
|
||||
)
|
||||
|
||||
For the documentation of the arguments, please see
|
||||
:meth:`telegram.Bot.set_chat_description`.
|
||||
|
||||
.. versionadded:: 20.0
|
||||
|
||||
Returns:
|
||||
:obj:`bool`: On success, :obj:`True` is returned.
|
||||
|
||||
"""
|
||||
return await self.get_bot().set_chat_description(
|
||||
chat_id=self.id,
|
||||
description=description,
|
||||
read_timeout=read_timeout,
|
||||
write_timeout=write_timeout,
|
||||
connect_timeout=connect_timeout,
|
||||
pool_timeout=pool_timeout,
|
||||
api_kwargs=api_kwargs,
|
||||
)
|
||||
|
||||
async def pin_message(
|
||||
self,
|
||||
message_id: int,
|
||||
|
@ -1894,6 +2032,86 @@ class Chat(TelegramObject):
|
|||
protect_content=protect_content,
|
||||
)
|
||||
|
||||
async def forward_from(
|
||||
self,
|
||||
from_chat_id: Union[str, int],
|
||||
message_id: int,
|
||||
disable_notification: DVInput[bool] = DEFAULT_NONE,
|
||||
protect_content: ODVInput[bool] = DEFAULT_NONE,
|
||||
*,
|
||||
read_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
write_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
connect_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
pool_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
api_kwargs: JSONDict = None,
|
||||
) -> "Message":
|
||||
"""Shortcut for::
|
||||
|
||||
await bot.forward_message(chat_id=update.effective_chat.id, *args, **kwargs)
|
||||
|
||||
For the documentation of the arguments, please see :meth:`telegram.Bot.forward_message`.
|
||||
|
||||
.. seealso:: :meth:`forward_to`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the message posted.
|
||||
|
||||
"""
|
||||
return await self.get_bot().forward_message(
|
||||
chat_id=self.id,
|
||||
from_chat_id=from_chat_id,
|
||||
message_id=message_id,
|
||||
disable_notification=disable_notification,
|
||||
read_timeout=read_timeout,
|
||||
write_timeout=write_timeout,
|
||||
connect_timeout=connect_timeout,
|
||||
pool_timeout=pool_timeout,
|
||||
api_kwargs=api_kwargs,
|
||||
protect_content=protect_content,
|
||||
)
|
||||
|
||||
async def forward_to(
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
message_id: int,
|
||||
disable_notification: DVInput[bool] = DEFAULT_NONE,
|
||||
protect_content: ODVInput[bool] = DEFAULT_NONE,
|
||||
*,
|
||||
read_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
write_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
connect_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
pool_timeout: ODVInput[float] = DEFAULT_NONE,
|
||||
api_kwargs: JSONDict = None,
|
||||
) -> "Message":
|
||||
"""Shortcut for::
|
||||
|
||||
await bot.forward_message(from_chat_id=update.effective_chat.id, *args, **kwargs)
|
||||
|
||||
For the documentation of the arguments, please see :meth:`telegram.Bot.forward_message`.
|
||||
|
||||
.. seealso:: :meth:`forward_from`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the message posted.
|
||||
|
||||
"""
|
||||
return await self.get_bot().forward_message(
|
||||
from_chat_id=self.id,
|
||||
chat_id=chat_id,
|
||||
message_id=message_id,
|
||||
disable_notification=disable_notification,
|
||||
read_timeout=read_timeout,
|
||||
write_timeout=write_timeout,
|
||||
connect_timeout=connect_timeout,
|
||||
pool_timeout=pool_timeout,
|
||||
api_kwargs=api_kwargs,
|
||||
protect_content=protect_content,
|
||||
)
|
||||
|
||||
async def export_invite_link(
|
||||
self,
|
||||
*,
|
||||
|
|
|
@ -373,6 +373,61 @@ class TestChat:
|
|||
monkeypatch.setattr("telegram.Bot.set_chat_administrator_custom_title", make_assertion)
|
||||
assert await chat.set_administrator_custom_title(user_id=42, custom_title="custom_title")
|
||||
|
||||
async def test_set_photo(self, monkeypatch, chat):
|
||||
async def make_assertion(*_, **kwargs):
|
||||
chat_id = kwargs["chat_id"] == chat.id
|
||||
photo = kwargs["photo"] == "test_photo"
|
||||
return chat_id, photo
|
||||
|
||||
assert check_shortcut_signature(Chat.set_photo, Bot.set_chat_photo, ["chat_id"], [])
|
||||
assert await check_shortcut_call(chat.set_photo, chat.get_bot(), "set_chat_photo")
|
||||
assert await check_defaults_handling(chat.set_photo, chat.get_bot())
|
||||
|
||||
monkeypatch.setattr(chat.get_bot(), "set_chat_photo", make_assertion)
|
||||
assert await chat.set_photo(photo="test_photo")
|
||||
|
||||
async def test_delete_photo(self, monkeypatch, chat):
|
||||
async def make_assertion(*_, **kwargs):
|
||||
chat_id = kwargs["chat_id"] == chat.id
|
||||
return chat_id
|
||||
|
||||
assert check_shortcut_signature(Chat.delete_photo, Bot.delete_chat_photo, ["chat_id"], [])
|
||||
assert await check_shortcut_call(chat.delete_photo, chat.get_bot(), "delete_chat_photo")
|
||||
assert await check_defaults_handling(chat.delete_photo, chat.get_bot())
|
||||
|
||||
monkeypatch.setattr(chat.get_bot(), "delete_chat_photo", make_assertion)
|
||||
assert await chat.delete_photo()
|
||||
|
||||
async def test_set_title(self, monkeypatch, chat):
|
||||
async def make_assertion(*_, **kwargs):
|
||||
chat_id = kwargs["chat_id"] == chat.id
|
||||
title = kwargs["title"] == "test_title"
|
||||
return chat_id, title
|
||||
|
||||
assert check_shortcut_signature(Chat.set_title, Bot.set_chat_title, ["chat_id"], [])
|
||||
assert await check_shortcut_call(chat.set_title, chat.get_bot(), "set_chat_title")
|
||||
assert await check_defaults_handling(chat.set_title, chat.get_bot())
|
||||
|
||||
monkeypatch.setattr(chat.get_bot(), "set_chat_title", make_assertion)
|
||||
assert await chat.set_title(title="test_title")
|
||||
|
||||
async def test_set_description(self, monkeypatch, chat):
|
||||
async def make_assertion(*_, **kwargs):
|
||||
chat_id = kwargs["chat_id"] == chat.id
|
||||
description = kwargs["description"] == "test_descripton"
|
||||
return chat_id, description
|
||||
|
||||
assert check_shortcut_signature(
|
||||
Chat.set_description, Bot.set_chat_description, ["chat_id"], []
|
||||
)
|
||||
assert await check_shortcut_call(
|
||||
chat.set_description, chat.get_bot(), "set_chat_description"
|
||||
)
|
||||
assert await check_defaults_handling(chat.set_description, chat.get_bot())
|
||||
|
||||
monkeypatch.setattr(chat.get_bot(), "set_chat_description", make_assertion)
|
||||
assert await chat.set_description(description="test_description")
|
||||
|
||||
async def test_pin_message(self, monkeypatch, chat):
|
||||
async def make_assertion(*_, **kwargs):
|
||||
return kwargs["chat_id"] == chat.id and kwargs["message_id"] == 42
|
||||
|
@ -643,6 +698,34 @@ class TestChat:
|
|||
monkeypatch.setattr(chat.get_bot(), "copy_message", make_assertion)
|
||||
assert await chat.copy_message(chat_id="test_copy", message_id=42)
|
||||
|
||||
async def test_instance_method_forward_from(self, monkeypatch, chat):
|
||||
async def make_assertion(*_, **kwargs):
|
||||
chat_id = kwargs["chat_id"] == chat.id
|
||||
message_id = kwargs["message_id"] == 42
|
||||
from_chat_id = kwargs["from_chat_id"] == "test_forward"
|
||||
return from_chat_id and message_id and chat_id
|
||||
|
||||
assert check_shortcut_signature(Chat.forward_from, Bot.forward_message, ["chat_id"], [])
|
||||
assert await check_shortcut_call(chat.forward_from, chat.get_bot(), "forward_message")
|
||||
assert await check_defaults_handling(chat.forward_from, chat.get_bot())
|
||||
|
||||
monkeypatch.setattr(chat.get_bot(), "forward_message", make_assertion)
|
||||
assert await chat.forward_from(from_chat_id="test_forward", message_id=42)
|
||||
|
||||
async def test_instance_method_forward_to(self, monkeypatch, chat):
|
||||
async def make_assertion(*_, **kwargs):
|
||||
from_chat_id = kwargs["from_chat_id"] == chat.id
|
||||
message_id = kwargs["message_id"] == 42
|
||||
chat_id = kwargs["chat_id"] == "test_forward"
|
||||
return from_chat_id and message_id and chat_id
|
||||
|
||||
assert check_shortcut_signature(Chat.forward_to, Bot.forward_message, ["from_chat_id"], [])
|
||||
assert await check_shortcut_call(chat.forward_to, chat.get_bot(), "forward_message")
|
||||
assert await check_defaults_handling(chat.forward_to, chat.get_bot())
|
||||
|
||||
monkeypatch.setattr(chat.get_bot(), "forward_message", make_assertion)
|
||||
assert await chat.forward_to(chat_id="test_forward", message_id=42)
|
||||
|
||||
async def test_export_invite_link(self, monkeypatch, chat):
|
||||
async def make_assertion(*_, **kwargs):
|
||||
return kwargs["chat_id"] == chat.id
|
||||
|
|
Loading…
Add table
Reference in a new issue