5 Commits

Author SHA1 Message Date
renovate[bot]
d4af241582 ⬆️ Upgrade actions/checkout action to v6 2025-11-20 17:40:59 +00:00
renovate[bot]
b0c8e0506f ⬆️ Upgrade astral-sh/setup-uv action to v6 (#23)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-04-25 00:59:24 +02:00
pre-commit-ci[bot]
b516973abf 👷 pre-commit autoupdate (#19)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Paillat <me@paillat.dev>
2025-04-15 22:07:42 +02:00
7be168f1b0 Add option to edit view response in send method 2025-03-29 17:10:05 +01:00
54002f1c17 🐛 Fix view context to support WebhookMessage 2025-03-29 17:05:20 +01:00
4 changed files with 28 additions and 15 deletions

View File

@@ -9,10 +9,10 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
environment: pypi environment: pypi
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v6
- name: "Install uv" - name: "Install uv"
uses: astral-sh/setup-uv@v5 uses: astral-sh/setup-uv@v6
with: with:
enable-cache: true enable-cache: true

View File

@@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v6
- name: Setup Copywrite - name: Setup Copywrite
uses: hashicorp/setup-copywrite@5e3e8a26d7b9f8a508848ad0a069dfd2f7aa5339 uses: hashicorp/setup-copywrite@5e3e8a26d7b9f8a508848ad0a069dfd2f7aa5339
- name: Check Header Compliance - name: Check Header Compliance
@@ -35,10 +35,10 @@ jobs:
name: ${{ matrix.name }} name: ${{ matrix.name }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v6
- name: "Install uv" - name: "Install uv"
uses: astral-sh/setup-uv@v5 uses: astral-sh/setup-uv@v6
with: with:
enable-cache: true enable-cache: true

View File

@@ -21,7 +21,7 @@ repos:
exclude: \.(po|pot|yml|yaml)$ exclude: \.(po|pot|yml|yaml)$
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version. # Ruff version.
rev: v0.9.10 rev: v0.11.5
hooks: hooks:
# Run the linter. # Run the linter.
- id: ruff - id: ruff

View File

@@ -1,7 +1,7 @@
# Copyright (c) Paillat-dev # Copyright (c) Paillat-dev
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
from typing import Self from typing import Any, Self
import discord import discord
from typing_extensions import override from typing_extensions import override
@@ -20,7 +20,13 @@ class ReactiveView(discord.ui.View):
) -> None: ) -> None:
super().__init__(timeout=timeout, disable_on_timeout=disable_on_timeout) # pyright: ignore[reportUnknownMemberType] super().__init__(timeout=timeout, disable_on_timeout=disable_on_timeout) # pyright: ignore[reportUnknownMemberType]
self._reactives: list[Reactive] = [] self._reactives: list[Reactive] = []
self.ctx: discord.ApplicationContext | discord.Interaction | None = None self.ctx: (
discord.InteractionMessage
| discord.ApplicationContext
| discord.Interaction
| discord.WebhookMessage
| None
) = None
@override @override
def add_item(self, item: discord.ui.Item[Self]) -> None: def add_item(self, item: discord.ui.Item[Self]) -> None:
@@ -52,15 +58,22 @@ class ReactiveView(discord.ui.View):
editable = self.ctx or self.message editable = self.ctx or self.message
if not editable: if not editable:
raise ValueError("View has no editable (not yet sent?), can't refresh") raise ValueError("View has no editable (not yet sent?), can't refresh")
kwargs: dict[str, Any] = {"view": self, "content": await self._get_content()} # pyright: ignore[reportExplicitAny]
if embeds := await self._get_embeds(): if embeds := await self._get_embeds():
await editable.edit(content=await self._get_content(), embeds=embeds, view=self) # pyright: ignore[reportUnknownMemberType] kwargs["embeds"] = embeds
else: await editable.edit(**kwargs) # pyright: ignore[reportUnknownMemberType]
await editable.edit(content=await self._get_content(), view=self) # pyright: ignore[reportUnknownMemberType]
async def send(self, ctx: discord.ApplicationContext | discord.Interaction, ephemeral: bool = False) -> None: async def send(
self, ctx: discord.ApplicationContext | discord.Interaction, ephemeral: bool = False, edit: bool = False
) -> None:
"""Send the view to a context.""" """Send the view to a context."""
self.ctx = ctx self.ctx = ctx
kwargs: dict[str, Any] = {"content": await self._get_content(), "ephemeral": ephemeral, "view": self} # pyright: ignore[reportExplicitAny]
if embeds := await self._get_embeds(): if embeds := await self._get_embeds():
await ctx.respond(content=await self._get_content(), embeds=embeds, view=self, ephemeral=ephemeral) # pyright: ignore [reportUnknownMemberType] kwargs["embeds"] = embeds
if edit:
r = await ctx.edit(**kwargs) # pyright: ignore[reportUnknownMemberType]
else: else:
await ctx.respond(content=await self._get_content(), view=self, ephemeral=ephemeral) # pyright: ignore [reportUnknownMemberType] r = await ctx.respond(**kwargs) # pyright: ignore[reportUnknownMemberType]
if isinstance(ctx, discord.Interaction):
self.ctx = r