WIP: Add UpdateChecker cog #14

Draft
cswimr wants to merge 37 commits from updatechecker into main
Showing only changes of commit 130fc6028a - Show all commits

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):