From b5d09f86800d17827b4f784c9c5049f0a9309c2b Mon Sep 17 00:00:00 2001 From: RejectModders <142326052+RejectModders@users.noreply.github.com> Date: Sun, 29 Nov 2026 20:49:28 -0600 Subject: [PATCH] fix(owner): keep the control panel working past 15 minutes The panel edited itself through the command's reply, which Discord allows for 15 minutes. It now uses the message a press carries. --- CHANGELOG.md | 2 ++ core/views/owner_views.py | 21 +++++++++++++++++++++ tests/test_owner_screens.py | 15 +++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80e392c..6855cc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/core/views/owner_views.py b/core/views/owner_views.py index eaf6f4c..1394241 100644 --- a/core/views/owner_views.py +++ b/core/views/owner_views.py @@ -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: diff --git a/tests/test_owner_screens.py b/tests/test_owner_screens.py index e10c5f5..8710616 100644 --- a/tests/test_owner_screens.py +++ b/tests/test_owner_screens.py @@ -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: