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
...
renovate/a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6f842a8c3 | ||
|
|
b0c8e0506f | ||
|
|
b516973abf | ||
| 7be168f1b0 | |||
| 54002f1c17 |
4
.github/workflows/publish.yaml
vendored
4
.github/workflows/publish.yaml
vendored
@@ -12,12 +12,12 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- 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
|
||||||
|
|
||||||
- name: "Set up Python"
|
- name: "Set up Python"
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v6
|
||||||
with:
|
with:
|
||||||
python-version-file: "pyproject.toml"
|
python-version-file: "pyproject.toml"
|
||||||
|
|
||||||
|
|||||||
4
.github/workflows/quality.yaml
vendored
4
.github/workflows/quality.yaml
vendored
@@ -38,12 +38,12 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- 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
|
||||||
|
|
||||||
- name: "Set up Python"
|
- name: "Set up Python"
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v6
|
||||||
with:
|
with:
|
||||||
python-version-file: "pyproject.toml"
|
python-version-file: "pyproject.toml"
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -31,4 +31,4 @@ repos:
|
|||||||
- repo: https://github.com/bhundven/copywrite # waiting for https://github.com/hashicorp/copywrite/pull/120 to be merged
|
- repo: https://github.com/bhundven/copywrite # waiting for https://github.com/hashicorp/copywrite/pull/120 to be merged
|
||||||
rev: 937f17f09c46992447dfa8977bb96eda512588c4
|
rev: 937f17f09c46992447dfa8977bb96eda512588c4
|
||||||
hooks:
|
hooks:
|
||||||
- id: add-headers
|
- id: add-headers
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user