Improve pobierz command
This commit is contained in:
parent
325e56fab4
commit
007568d887
3 changed files with 13 additions and 7 deletions
|
@ -16,7 +16,7 @@ class Development(commands.Cog):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@app_commands.command()
|
@app_commands.command()
|
||||||
async def sync(self, interaction: discord.Interaction, current_guild: bool = True):
|
async def sync(self, interaction: discord.Interaction, current_guild: bool = False):
|
||||||
"""Synchronizuje komendy bota"""
|
"""Synchronizuje komendy bota"""
|
||||||
# temporary check, needs refactoring
|
# temporary check, needs refactoring
|
||||||
if not await self.bot.is_owner(interaction.user):
|
if not await self.bot.is_owner(interaction.user):
|
||||||
|
|
|
@ -12,6 +12,7 @@ from discord.ext import commands
|
||||||
|
|
||||||
from .. import bot
|
from .. import bot
|
||||||
from ..utils import github, wulkanowy_manager
|
from ..utils import github, wulkanowy_manager
|
||||||
|
from ..utils.wulkanowy_manager import WulkanowyBuild, WulkanowyManagerException
|
||||||
|
|
||||||
|
|
||||||
class Wulkanowy(commands.Cog):
|
class Wulkanowy(commands.Cog):
|
||||||
|
@ -28,10 +29,19 @@ class Wulkanowy(commands.Cog):
|
||||||
@app_commands.command()
|
@app_commands.command()
|
||||||
async def pobierz(self, interaction: discord.Interaction):
|
async def pobierz(self, interaction: discord.Interaction):
|
||||||
branches = await self.github.fetch_branches("wulkanowy", "wulkanowy")
|
branches = await self.github.fetch_branches("wulkanowy", "wulkanowy")
|
||||||
builds = await asyncio.gather(
|
builds: list[WulkanowyBuild | WulkanowyManagerException] = await asyncio.gather(
|
||||||
*(map(self.wulkanowy_manager.fetch_branch_build, branches)), return_exceptions=True
|
*(map(self.wulkanowy_manager.fetch_branch_build, branches)), return_exceptions=True
|
||||||
)
|
)
|
||||||
await interaction.response.send_message("\n".join(map(str, builds)), suppress_embeds=True)
|
text = []
|
||||||
|
for branch, build in zip(branches, builds, strict=True):
|
||||||
|
if isinstance(build, WulkanowyBuild):
|
||||||
|
text.append(f"{branch}: [pobierz]({build.download_url})")
|
||||||
|
else:
|
||||||
|
text.append(f"{branch}: brak")
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Pobierz najnowsze wersje testowe!", description="\n".join(text)
|
||||||
|
)
|
||||||
|
await interaction.response.send_message(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
async def setup(bot: bot.Wulkabot):
|
async def setup(bot: bot.Wulkabot):
|
||||||
|
|
|
@ -21,9 +21,6 @@ class WulkanowyBuild:
|
||||||
def download_url(self) -> str:
|
def download_url(self) -> str:
|
||||||
return f"{BASE_URL}/v1/download/app/{WULKANOWY_HASH}/build/{self.build_slug}/artifact/{self.artifact_slug}"
|
return f"{BASE_URL}/v1/download/app/{WULKANOWY_HASH}/build/{self.build_slug}/artifact/{self.artifact_slug}"
|
||||||
|
|
||||||
def __str__(self) -> str:
|
|
||||||
return self.download_url
|
|
||||||
|
|
||||||
|
|
||||||
class WulkanowyManagerException(Exception):
|
class WulkanowyManagerException(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -35,7 +32,6 @@ class WulkanowyManager:
|
||||||
|
|
||||||
async def fetch_branch_build(self, branch: str) -> WulkanowyBuild:
|
async def fetch_branch_build(self, branch: str) -> WulkanowyBuild:
|
||||||
response = await self._http.get(f"/v1/build/app/{WULKANOWY_HASH}/branch/{branch}")
|
response = await self._http.get(f"/v1/build/app/{WULKANOWY_HASH}/branch/{branch}")
|
||||||
response.raise_for_status()
|
|
||||||
json = await response.json()
|
json = await response.json()
|
||||||
if not json["success"]:
|
if not json["success"]:
|
||||||
raise WulkanowyManagerException(json["error"])
|
raise WulkanowyManagerException(json["error"])
|
||||||
|
|
Loading…
Reference in a new issue