- Notifications
You must be signed in to change notification settings - Fork5.7k
Bot API 7.11: AddCopyTextButton
and Integrate intoInlineKeyboardButton
#4547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionsdocs/source/telegram.at-tree.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletionsdocs/source/telegram.copytextbutton.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CopyTextButton | ||
============== | ||
.. autoclass:: telegram.CopyTextButton | ||
:members: | ||
:show-inheritance: |
2 changes: 2 additions & 0 deletionstelegram/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletionstelegram/_copytextbutton.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python | ||
# | ||
# A library that provides a Python interface to the Telegram Bot API | ||
# Copyright (C) 2015-2024 | ||
# Leandro Toledo de Souza <devs@python-telegram-bot.org> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Lesser Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser Public License | ||
# along with this program. If not, see [http://www.gnu.org/licenses/]. | ||
"""This module contains an object that represents a Telegram CopyTextButton.""" | ||
from typing import Optional | ||
from telegram._telegramobject import TelegramObject | ||
from telegram._utils.types import JSONDict | ||
class CopyTextButton(TelegramObject): | ||
""" | ||
This object represents an inline keyboard button that copies specified text to the clipboard. | ||
Objects of this class are comparable in terms of equality. Two objects of this class are | ||
considered equal, if their :attr:`text` is equal. | ||
.. versionadded:: NEXT.VERSION | ||
Args: | ||
text (:obj:`str`): The text to be copied to the clipboard; | ||
:tg-const:`telegram.constants.InlineKeyboardButtonLimit.MIN_COPY_TEXT`- | ||
:tg-const:`telegram.constants.InlineKeyboardButtonLimit.MAX_COPY_TEXT` characters | ||
Attributes: | ||
text (:obj:`str`): The text to be copied to the clipboard; | ||
:tg-const:`telegram.constants.InlineKeyboardButtonLimit.MIN_COPY_TEXT`- | ||
:tg-const:`telegram.constants.InlineKeyboardButtonLimit.MAX_COPY_TEXT` characters | ||
""" | ||
__slots__ = ("text",) | ||
def __init__(self, text: str, *, api_kwargs: Optional[JSONDict] = None): | ||
super().__init__(api_kwargs=api_kwargs) | ||
self.text: str = text | ||
self._id_attrs = (self.text,) | ||
self._freeze() |
13 changes: 13 additions & 0 deletionstelegram/_inline/inlinekeyboardbutton.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
12 changes: 10 additions & 2 deletionstelegram/constants.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletionstests/_inline/test_inlinekeyboardbutton.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletionstests/test_copytextbutton.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env python | ||
# | ||
# A library that provides a Python interface to the Telegram Bot API | ||
# Copyright (C) 2015-2024 | ||
# Leandro Toledo de Souza <devs@python-telegram-bot.org> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Lesser Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser Public License | ||
# along with this program. If not, see [http://www.gnu.org/licenses/]. | ||
import pytest | ||
from telegram import BotCommand, CopyTextButton | ||
from tests.auxil.slots import mro_slots | ||
@pytest.fixture(scope="module") | ||
def copy_text_button(): | ||
return CopyTextButton(text=CopyTextButtonTestBase.text) | ||
class CopyTextButtonTestBase: | ||
text = "This is some text" | ||
class TestCopyTextButtonWithoutRequest(CopyTextButtonTestBase): | ||
def test_slot_behaviour(self, copy_text_button): | ||
for attr in copy_text_button.__slots__: | ||
assert getattr(copy_text_button, attr, "err") != "err", f"got extra slot '{attr}'" | ||
assert len(mro_slots(copy_text_button)) == len( | ||
set(mro_slots(copy_text_button)) | ||
), "duplicate slot" | ||
def test_de_json(self, offline_bot): | ||
json_dict = {"text": self.text} | ||
copy_text_button = CopyTextButton.de_json(json_dict, offline_bot) | ||
assert copy_text_button.api_kwargs == {} | ||
assert copy_text_button.text == self.text | ||
assert CopyTextButton.de_json(None, offline_bot) is None | ||
def test_to_dict(self, copy_text_button): | ||
copy_text_button_dict = copy_text_button.to_dict() | ||
assert isinstance(copy_text_button_dict, dict) | ||
assert copy_text_button_dict["text"] == copy_text_button.text | ||
def test_equality(self): | ||
a = CopyTextButton(self.text) | ||
b = CopyTextButton(self.text) | ||
c = CopyTextButton("text") | ||
d = BotCommand("start", "description") | ||
assert a == b | ||
assert hash(a) == hash(b) | ||
assert a != c | ||
assert hash(a) != hash(c) | ||
assert a != d | ||
assert hash(a) != hash(d) |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.