WIP: Add UpdateChecker cog #14

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

View file

@ -37,7 +37,7 @@ import aiohttp
import discord
from redbot.cogs.downloader.repo_manager import Repo
from redbot.core import Config, commands
from redbot.core.utils.chat_formatting import humanize_list, inline
from redbot.core.utils.chat_formatting import box, humanize_list, inline
import feedparser
@ -113,6 +113,7 @@ class UpdateChecker(commands.Cog):
repo = cog._repo_manager.get_repo(repo_name)
if not repo:
continue
if repo.url.startswith("https://github.com"):
url = repo.url + r"/commits/" + repo.branch + ".atom"
response = await self.fetch_feed(url)
try:
@ -122,6 +123,16 @@ class UpdateChecker(commands.Cog):
image = response.entries[0]["media_thumbnail"][0]["url"].split("?")[0]
except AttributeError:
continue
else:
url = repo.url + "rss/branch/" + repo.branch
response = await self.fetch_feed(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
except AttributeError:
continue
saving_dict[repo_name] = commit
if whitelist:
if repo_name not in whitelist:
@ -147,18 +158,17 @@ class UpdateChecker(commands.Cog):
e.add_field(name="Branch", value=repo.branch)
e.add_field(name="Commit", value=cn)
e.add_field(name="Hash", value=hash)
if image is not None:
e.set_thumbnail(url=image)
else:
e = (
"```css\n"
e = box(
"[Update Checker]"
"``````css\n"
f" Repo: {repo.name}\n"
f" URL: {repo.url}\n"
f" Commit: {cn}\n"
f" Hash: {commit}\n"
f" Time: {datetime.utcnow()}"
"```"
f" Time: {datetime.utcnow()}",
'css'
)
try:
if use_embed: