feat(updatechecker): added support for thumbnails in gitea/forgejo
Some checks failed
Build Documentation and Lint Code / build and lint (pull_request) Failing after 27s

This commit is contained in:
Seaswimmer 2024-01-07 13:41:53 +00:00
parent b4647a3c6b
commit 130fc6028a
Signed by: cswimr
GPG key ID: D74DDDDF420E13DF

View file

@ -32,6 +32,7 @@ SOFTWARE.
import asyncio
import traceback
from datetime import datetime
from urllib.parse import urlparse
import aiohttp
import discord
@ -126,11 +127,12 @@ class UpdateChecker(commands.Cog):
else:
url = repo.url + "rss/branch/" + repo.branch
response = await self.fetch_feed(url)
parsed_url = urlparse(repo.url)
try:
commit = response.entries[0]["id"][33:]
hash = "[" + commit + "](" + response.entries[0]["link"] + ")"
cn = response.entries[0]["title"] + " - " + response.entries[0]["author"]
image = None
image = await self.fetch_gitea_thumbnail(parsed_url.scheme + "://" + parsed_url.netloc + "/api/v1/repos" + parsed_url.path)
except AttributeError:
continue
saving_dict[repo_name] = commit
@ -260,6 +262,16 @@ class UpdateChecker(commands.Cog):
return None
return ret
async def fetch_gitea_thumbnail(self, url: str) -> str:
timeout = aiohttp.client.ClientTimeout(total=15)
try:
async with self.session.get(url, timeout=timeout) as response:
data = await response.read()
except (aiohttp.ClientError, asyncio.TimeoutError):
return None
return data['avatar_url']
@commands.is_owner()
@commands.group(name="cogupdater", aliases=["cu"])
async def update(self, ctx):