Skip to content

Commit 01bb577

Browse files
committed
Add /gh actions artifact, update to d.py 2.6.2
1 parent f91b778 commit 01bb577

File tree

13 files changed

+572
-89
lines changed

13 files changed

+572
-89
lines changed

bot/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ name = "ghutils-bot"
88
requires-python = ">=3.12"
99
dependencies = [
1010
"ghutils-common",
11-
"discord-py>=2.5.0",
11+
"discord-py>=2.6.2",
1212
"pydantic>=2.7.4",
1313
"pydantic-settings>=2.3.4",
1414
"fastapi>=0.111.0",
@@ -20,6 +20,7 @@ dependencies = [
2020
"fluent-runtime>=0.4.0",
2121
"pyyaml>=6.0.2",
2222
"pylette>=4.0.0",
23+
"humanize>=4.13.0",
2324
]
2425

2526
[tool.rye]

bot/src/ghutils/cogs/app_commands/github.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
PRReference,
3737
)
3838
from ghutils.utils.discord.transformers import RepositoryOption, UserOption
39+
from ghutils.utils.discord.views.select_artifact import SelectArtifactView
3940
from ghutils.utils.discord.visibility import MessageVisibility, respond_with_visibility
4041
from ghutils.utils.github import gh_request
4142
from ghutils.utils.l10n import translate_text
@@ -329,6 +330,13 @@ async def status(
329330

330331
await respond_with_visibility(interaction, visibility, embed=embed)
331332

333+
class Actions(SubGroup):
334+
@app_commands.command()
335+
async def artifact(self, interaction: Interaction, repo: RepositoryOption):
336+
await interaction.response.defer(ephemeral=True)
337+
view = await SelectArtifactView.new(interaction, repo)
338+
await interaction.followup.send(view=view, ephemeral=True)
339+
332340
class Search(SubGroup):
333341
@app_commands.command()
334342
async def files(

bot/src/ghutils/cogs/events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
RefreshIssueButton,
1111
RefreshIssuesButton,
1212
)
13-
from ghutils.utils.discord.visibility import PermanentDeleteButton
13+
from ghutils.utils.discord.visibility import DeleteButton
1414

1515
logger = logging.getLogger(__name__)
1616

@@ -22,7 +22,7 @@ class EventsCog(GHUtilsCog):
2222
async def on_ready(self):
2323
logger.info(f"Logged in as {self.bot.user}")
2424
self.bot.add_dynamic_items(
25-
PermanentDeleteButton,
25+
DeleteButton,
2626
RefreshCommitButton,
2727
RefreshIssueButton,
2828
RefreshIssuesButton,

bot/src/ghutils/resources/l10n/en-US/main.ftl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ gh-status_text_installs_value =
116116
gh-status_text_commands =
117117
Commands
118118
119+
# /gh actions
120+
121+
gh-actions_description =
122+
Commands for GitHub Actions.
123+
124+
# /gh actions artifact
125+
126+
gh-actions-artifact_description =
127+
Get a link to download a workflow artifact.
128+
129+
gh-actions-artifact_parameter-description_repo =
130+
Repository to search in (`owner/repo`).
131+
119132
# /gh search
120133

121134
gh-search_description =

bot/src/ghutils/utils/discord/commands.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
Interaction,
66
InteractionType,
77
)
8-
from discord.app_commands import Command
8+
from discord.app_commands import Command, ContextMenu
99
from discord.ext.commands import Paginator
1010

1111
from ..strings import truncate_str
1212

1313
AnyCommand = Command[Any, ..., Any]
1414

15+
AnyInteractionCommand = AnyCommand | ContextMenu | None
16+
1517

1618
def get_command(interaction: Interaction) -> AnyCommand | None:
1719
match interaction.command:

bot/src/ghutils/utils/discord/components.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from dataclasses import dataclass
22
from datetime import UTC, datetime, timedelta
33
from re import Match
4-
from typing import Any, override
4+
from typing import Any, Literal, overload, override
55

6-
from discord import Color, Embed, Interaction, Message
7-
from discord.ui import Button, DynamicItem, Item
6+
from discord import Color, Embed, Interaction, Message, SelectOption
7+
from discord.ui import Button, DynamicItem, Item, Select
88
from githubkit import GitHub
99
from githubkit.rest import Commit, Issue
1010
from pydantic import TypeAdapter
@@ -15,6 +15,7 @@
1515

1616
from ..github import RepositoryName, gh_request
1717
from .embeds import create_commit_embed, create_issue_embed, create_issue_embeds
18+
from .mentions import relative_timestamp
1819
from .references import (
1920
CommitReference,
2021
IssueReference,
@@ -196,6 +197,40 @@ async def callback(self, interaction: Interaction):
196197
)
197198

198199

200+
def update_select_menu_defaults(select: Select[Any]) -> list[SelectOption]:
201+
selected = set(select.values)
202+
result = list[SelectOption]()
203+
for option in select.options:
204+
option.default = option.value in selected
205+
if option.default:
206+
result.append(option)
207+
return result
208+
209+
210+
@overload
211+
def update_select_menu_default(
212+
select: Select[Any],
213+
required: Literal[True],
214+
) -> SelectOption: ...
215+
216+
217+
@overload
218+
def update_select_menu_default(
219+
select: Select[Any],
220+
required: Literal[False] = False,
221+
) -> SelectOption | None: ...
222+
223+
224+
def update_select_menu_default(
225+
select: Select[Any],
226+
required: bool = False,
227+
) -> SelectOption | None:
228+
selected = update_select_menu_defaults(select)
229+
if not required and not selected:
230+
return None
231+
return selected[0]
232+
233+
199234
async def _check_ratelimit(interaction: Interaction, state: LoginState) -> bool:
200235
now = datetime.now(UTC)
201236
if (
@@ -209,7 +244,7 @@ async def _check_ratelimit(interaction: Interaction, state: LoginState) -> bool:
209244
embed=Embed(
210245
title="Slow down!",
211246
description="This button can only be used once per minute by unauthenticated users."
212-
+ f" Use `/gh login` to authenticate, or try again <t:{retry_time.timestamp():.0f}:R>.",
247+
+ f" Use `/gh login` to authenticate, or try again {relative_timestamp(retry_time)}.",
213248
color=Color.red(),
214249
),
215250
ephemeral=True,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from datetime import datetime
2+
3+
4+
def relative_timestamp(when: datetime):
5+
return f"<t:{when.timestamp():.0f}:R>"

bot/src/ghutils/utils/discord/views/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)