diff --git a/wulkabot/bot.py b/wulkabot/bot.py index b6c2c7c..60c2f6b 100644 --- a/wulkabot/bot.py +++ b/wulkabot/bot.py @@ -48,7 +48,3 @@ class Wulkabot(commands.Bot): async def load_extensions(self, package: types.ModuleType) -> None: for extension in self.find_extensions(package): await self.load_extension(extension) - - async def reload_extensions(self) -> None: - for extension in set(self.extensions): - await self.reload_extension(extension) diff --git a/wulkabot/cogs/development.py b/wulkabot/cogs/development.py index da9d097..bbd47df 100644 --- a/wulkabot/cogs/development.py +++ b/wulkabot/cogs/development.py @@ -30,17 +30,6 @@ class Development(commands.Cog): f"Synced **{len(commands)} {destination}** commands\n{commands_str}" ) - @app_commands.command() - async def reload(self, interaction: discord.Interaction): - """Przeładowuje komendy bota""" - # temporary check, needs refactoring - if not await self.bot.is_owner(interaction.user): - await interaction.response.send_message("nie", ephemeral=True) - return - - await self.bot.reload_extensions() - await interaction.response.send_message("Reloaded successfuly") - async def setup(bot: bot.Wulkabot): await bot.add_cog(Development(bot)) diff --git a/wulkabot/cogs/github.py b/wulkabot/cogs/github.py index d0c56ad..8850d7e 100644 --- a/wulkabot/cogs/github.py +++ b/wulkabot/cogs/github.py @@ -7,12 +7,11 @@ from discord.ext import commands from .. import bot from ..utils import github +from ..utils.constants import REPO from ..utils.views import DeleteButton Repo = tuple[str, str] -DEFAULT_REPO: Repo = ("wulkanowy", "wulkanowy") - def parse_repo(text: str, *, default_owner: str | None = None) -> Repo | None: """ @@ -157,20 +156,20 @@ class GitHub(commands.Cog): try: topic = message.channel.topic # type: ignore except AttributeError: - channel_repo = DEFAULT_REPO + channel_repo = REPO else: if topic is not None: channel_repo = find_repo_in_channel_topic(topic) if channel_repo is None: - channel_repo = DEFAULT_REPO + channel_repo = REPO else: - channel_repo = DEFAULT_REPO + channel_repo = REPO for word in words: match = parse_issue(word, default_owner=channel_repo[0], default_repo=channel_repo[1]) if match is not None: repo, issue_number = match - repo = repo or DEFAULT_REPO + repo = repo or REPO try: issue = await self.github.fetch_issue(*repo, issue_number) except aiohttp.ClientResponseError: diff --git a/wulkabot/cogs/wulkanowy.py b/wulkabot/cogs/wulkanowy.py index 5766e74..d4d9267 100644 --- a/wulkabot/cogs/wulkanowy.py +++ b/wulkabot/cogs/wulkanowy.py @@ -6,8 +6,19 @@ from discord.ext import commands from .. import bot from ..utils import github, wulkanowy_manager +from ..utils.constants import ACCENT_COLOR, BUILDS_CHANNEL_ID, REPO from ..utils.wulkanowy_manager import WulkanowyBuild, WulkanowyManagerException +OTHER_DOWNLOADS = " | ".join( + ( + "[Google Play](https://play.google.com/store/apps/details?id=io.github.wulkanowy)", + "[GitHub](https://github.com/wulkanowy/wulkanowy/releases)", + "[F-Droid](https://f-droid.org/en/packages/io.github.wulkanowy)", + "[AppGallery](https://appgallery.huawei.com/app/C101440411)", + f"<#{BUILDS_CHANNEL_ID}>", + ) +) + class Wulkanowy(commands.Cog): def __init__(self, bot: bot.Wulkabot) -> None: @@ -22,20 +33,44 @@ class Wulkanowy(commands.Cog): @app_commands.command() async def pobierz(self, interaction: discord.Interaction): - branches = await self.github.fetch_branches("wulkanowy", "wulkanowy") + await interaction.response.defer(thinking=True) + + release = await self.github.fetch_latest_release(*REPO) + download_urls = [] + for asset in release["assets"]: + name = asset["name"] + url = asset["browser_download_url"] + download_urls.append(f"[{name}]({url})") + download_urls = "\n".join(download_urls) + + pulls = await self.github.fetch_open_pulls(*REPO) + branches = ["develop"] + branches.extend((pull["head"]["ref"] for pull in pulls)) 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 ) - 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) + lines = "\n".join( + ( + f"`{build.build_number}` – [{branch}]({build.download_url})" + for branch, build in zip(branches, builds, strict=True) + if isinstance(build, WulkanowyBuild) + ) ) - await interaction.response.send_message(embed=embed) + + text = "\n".join( + ( + f'**Najnowsza wersja {release["name"]}**', + download_urls, + "", + "**Wersje testowe**", + lines, + "", + "**Inne źródła**", + OTHER_DOWNLOADS, + ) + ) + embed = discord.Embed(title="Pobierz Wulkanowego!", description=text, color=ACCENT_COLOR) + await interaction.followup.send(embed=embed) async def setup(bot: bot.Wulkabot): diff --git a/wulkabot/utils/constants.py b/wulkabot/utils/constants.py new file mode 100644 index 0000000..c349a1f --- /dev/null +++ b/wulkabot/utils/constants.py @@ -0,0 +1,4 @@ +REPO = ("wulkanowy", "wulkanowy") +ACCENT_COLOR = 0xD32F2F +DEFAULT_BRANCH = "develop" +BUILDS_CHANNEL_ID = 983106478426693653 diff --git a/wulkabot/utils/github.py b/wulkabot/utils/github.py index 1e3bd12..c67c843 100644 --- a/wulkabot/utils/github.py +++ b/wulkabot/utils/github.py @@ -1,4 +1,4 @@ -from typing import Any +from typing import Any, Literal import aiohttp @@ -14,16 +14,23 @@ class GitHub: response.raise_for_status() return await response.json() - async def fetch_branches(self, owner: str, repo: str) -> list[str]: - response = await self._http.get(f"/repos/{owner}/{repo}/branches") + async def fetch_open_pulls(self, owner: str, repo: str): + response = await self._http.get( + f"/repos/{owner}/{repo}/pulls", + params={"state": "open", "sort": "updated", "direction": "desc", "per_page": 25}, + ) response.raise_for_status() - branches = await response.json() - return [branch["name"] for branch in branches] + return await response.json() async def fetch_issue(self, owner: str, repo: str, issue_number: int) -> dict[str, Any]: response = await self._http.get(f"/repos/{owner}/{repo}/issues/{issue_number}") response.raise_for_status() return await response.json() + async def fetch_latest_release(self, owner: str, repo: str): + response = await self._http.get(f"/repos/{owner}/{repo}/releases/latest") + response.raise_for_status() + return await response.json() + async def close(self): await self._http.close()