Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The format follows [Keep a Changelog](https://keepachangelog.com/).

### Fixed

- The control panel can still update itself when it has been in use for more
than 15 minutes.
- A blacklisted user gets the notice at most once in two minutes, not for
every direct message.
- Staff are told when Discord refuses a reply. A new ticket whose first
Expand Down
21 changes: 21 additions & 0 deletions core/views/owner_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,27 @@ def __init__(self, bot: Bot, author: int, text: str) -> None:
]
self.add_item(box(self._text, *rows))

@override
async def interaction_check(self, interaction: Interaction) -> bool:
"""
Let only the owner who opened the panel press it.

Parameters
----------
interaction : Interaction
The press.

Returns
-------
bool
Whether the press counts.
"""
allowed = await super().interaction_check(interaction)
if allowed and interaction.message is not None:
# The command's own reply can be edited for 15 minutes only.
self.message: discord.Message | None = interaction.message
return allowed

async def refresh(self) -> None:
"""Show the cogs as they are now, if the panel's message is known."""
if self.message is not None:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_owner_screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,21 @@ async def test_the_control_panel_looks_as_before(
assert not await view.interaction_check(interaction(2))


async def test_the_panel_outlives_the_command_that_opened_it() -> None:
# The command's own reply can be edited for 15 minutes only. The message
# a press carries is edited with the bot's login, which does not expire.
panel = owner_views.ControlPanelView(MagicMock(), OWNER, "x")
panel.message = reply = MagicMock()
stranger = interaction(OWNER + 1)

assert not await panel.interaction_check(stranger)
assert panel.message is reply

press = interaction(OWNER)
assert await panel.interaction_check(press)
assert panel.message is press.message


async def test_a_refreshed_panel_keeps_its_buttons(
monkeypatch: pytest.MonkeyPatch,
) -> None:
Expand Down