mirror of
https://github.com/Paillat-dev/pycord-reactive-views.git
synced 2026-01-02 17:14:56 +00:00
Compare commits
5 Commits
v1.0.3
...
pre-commit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed4a5b71bd | ||
|
|
b0c8e0506f | ||
|
|
b516973abf | ||
| 7be168f1b0 | |||
| 54002f1c17 |
2
.github/workflows/publish.yaml
vendored
2
.github/workflows/publish.yaml
vendored
@@ -12,7 +12,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: "Install uv"
|
||||
uses: astral-sh/setup-uv@v5
|
||||
uses: astral-sh/setup-uv@v6
|
||||
with:
|
||||
enable-cache: true
|
||||
|
||||
|
||||
2
.github/workflows/quality.yaml
vendored
2
.github/workflows/quality.yaml
vendored
@@ -38,7 +38,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: "Install uv"
|
||||
uses: astral-sh/setup-uv@v5
|
||||
uses: astral-sh/setup-uv@v6
|
||||
with:
|
||||
enable-cache: true
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ ci:
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v5.0.0
|
||||
rev: v6.0.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
exclude: \.(po|pot|yml|yaml)$
|
||||
@@ -21,7 +21,7 @@ repos:
|
||||
exclude: \.(po|pot|yml|yaml)$
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
# Ruff version.
|
||||
rev: v0.9.10
|
||||
rev: v0.14.10
|
||||
hooks:
|
||||
# Run the linter.
|
||||
- id: ruff
|
||||
@@ -29,6 +29,6 @@ repos:
|
||||
# Run the formatter.
|
||||
- id: ruff-format
|
||||
- repo: https://github.com/bhundven/copywrite # waiting for https://github.com/hashicorp/copywrite/pull/120 to be merged
|
||||
rev: 937f17f09c46992447dfa8977bb96eda512588c4
|
||||
rev: 9d021bf61a094a5eac6ae3084ceed2dda4700a73
|
||||
hooks:
|
||||
- id: add-headers
|
||||
- id: add-headers
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Copyright (c) Paillat-dev
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
from typing import Self
|
||||
from typing import Any, Self
|
||||
|
||||
import discord
|
||||
from typing_extensions import override
|
||||
@@ -20,7 +20,13 @@ class ReactiveView(discord.ui.View):
|
||||
) -> None:
|
||||
super().__init__(timeout=timeout, disable_on_timeout=disable_on_timeout) # pyright: ignore[reportUnknownMemberType]
|
||||
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
|
||||
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
|
||||
if not editable:
|
||||
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():
|
||||
await editable.edit(content=await self._get_content(), embeds=embeds, view=self) # pyright: ignore[reportUnknownMemberType]
|
||||
else:
|
||||
await editable.edit(content=await self._get_content(), view=self) # pyright: ignore[reportUnknownMemberType]
|
||||
kwargs["embeds"] = embeds
|
||||
await editable.edit(**kwargs) # 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."""
|
||||
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():
|
||||
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:
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user