forked from blizzthewolf/SeaCogs
feat(updatechecker): added support for thumbnails in gitea/forgejo
This commit is contained in:
parent
b4647a3c6b
commit
130fc6028a
1 changed files with 13 additions and 1 deletions
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue