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 asyncio
|
||||||
import traceback
|
import traceback
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import discord
|
import discord
|
||||||
|
@ -126,11 +127,12 @@ class UpdateChecker(commands.Cog):
|
||||||
else:
|
else:
|
||||||
url = repo.url + "rss/branch/" + repo.branch
|
url = repo.url + "rss/branch/" + repo.branch
|
||||||
response = await self.fetch_feed(url)
|
response = await self.fetch_feed(url)
|
||||||
|
parsed_url = urlparse(repo.url)
|
||||||
try:
|
try:
|
||||||
commit = response.entries[0]["id"][33:]
|
commit = response.entries[0]["id"][33:]
|
||||||
hash = "[" + commit + "](" + response.entries[0]["link"] + ")"
|
hash = "[" + commit + "](" + response.entries[0]["link"] + ")"
|
||||||
cn = response.entries[0]["title"] + " - " + response.entries[0]["author"]
|
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:
|
except AttributeError:
|
||||||
continue
|
continue
|
||||||
saving_dict[repo_name] = commit
|
saving_dict[repo_name] = commit
|
||||||
|
@ -260,6 +262,16 @@ class UpdateChecker(commands.Cog):
|
||||||
return None
|
return None
|
||||||
return ret
|
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.is_owner()
|
||||||
@commands.group(name="cogupdater", aliases=["cu"])
|
@commands.group(name="cogupdater", aliases=["cu"])
|
||||||
async def update(self, ctx):
|
async def update(self, ctx):
|
||||||
|
|
Loading…
Reference in a new issue