From b9ef96665eb50c0284da5689b265e3337a907daf Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sat, 6 Jan 2024 18:49:19 +0000 Subject: [PATCH 01/21] feat(docs): added documentation for the updatechecker cog --- .docs/updatechecker.md | 22 ++++++++++++++++++++++ mkdocs.yml | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 .docs/updatechecker.md diff --git a/.docs/updatechecker.md b/.docs/updatechecker.md new file mode 100644 index 0000000..2926302 --- /dev/null +++ b/.docs/updatechecker.md @@ -0,0 +1,22 @@ +# UpdateChecker + +/// admonition | This project is not ready for production use + type: danger +The UpdateChecker cog is currently in an unfinished state, until it is completed please use [NeuroAssassin's UpdateChecker cog](https://github.com/NeuroAssassin/Toxic-Cogs) instead. +/// + +UpdateChecker will tell when there is an update available for a repository you have added for your bot, and, depending on settings, will auto update or will just notify you. + +This is a fork of [NeuroAssassin's UpdateChecker cog](https://github.com/NeuroAssassin/Toxic-Cogs). +Additional features include support for Gitea/Forgejo RSS feeds, instead of just GitHub. (1) +{ .annotate } + +1. ⚠️ Not yet implemented. + +## Installation + +```bash +[p]repo add seacogs https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs +[p]cog install seacogs updatechecker +[p]cog load updatechecker +``` diff --git a/mkdocs.yml b/mkdocs.yml index 470aa1b..b61c86c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,5 +1,5 @@ site_name: SeaCogs Documentation -site_url: https://seacogs.readthedocs.io +site_url: http://seacogs.pages.coastalcommits.com repo_name: CoastalCommits repo_url: https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs edit_uri: src/branch/main/.docs @@ -17,6 +17,7 @@ nav: - Case Commands: aurora/case-commands.md - Configuration: aurora/configuration.md - Nerdify: nerdify.md + - UpdateChecker: updatechecker.md plugins: - git-authors -- 2.45.3 From 7513258cf552db04d8c6e9711354a5930e018887 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sat, 6 Jan 2024 18:54:31 +0000 Subject: [PATCH 02/21] feat(updatechecker): added the cog --- .gitignore | 1 + poetry.lock | 28 +- pyproject.toml | 1 + updatechecker/__init__.py | 10 + updatechecker/info.json | 17 ++ updatechecker/updatechecker.py | 453 +++++++++++++++++++++++++++++++++ 6 files changed, 508 insertions(+), 2 deletions(-) create mode 100644 updatechecker/__init__.py create mode 100644 updatechecker/info.json create mode 100644 updatechecker/updatechecker.py diff --git a/.gitignore b/.gitignore index 16d3c4d..2b23df4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .cache +.vscode diff --git a/poetry.lock b/poetry.lock index f3c6846..1d06dd9 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. [[package]] name = "aiodns" @@ -685,6 +685,20 @@ files = [ {file = "distro-1.8.0.tar.gz", hash = "sha256:02e111d1dc6a50abb8eed6bf31c3e48ed8b0830d1ea2a1b78c61765c2513fdd8"}, ] +[[package]] +name = "feedparser" +version = "6.0.11" +description = "Universal feed parser, handles RSS 0.9x, RSS 1.0, RSS 2.0, CDF, Atom 0.3, and Atom 1.0 feeds" +optional = false +python-versions = ">=3.6" +files = [ + {file = "feedparser-6.0.11-py3-none-any.whl", hash = "sha256:0be7ee7b395572b19ebeb1d6aafb0028dee11169f1c934e0ed67d54992f4ad45"}, + {file = "feedparser-6.0.11.tar.gz", hash = "sha256:c9d0407b64c6f2a065d0ebb292c2b35c01050cc0dc33757461aaabdc4c4184d5"}, +] + +[package.dependencies] +sgmllib3k = "*" + [[package]] name = "frozenlist" version = "1.4.0" @@ -2191,6 +2205,16 @@ files = [ [package.dependencies] contextlib2 = ">=0.5.5" +[[package]] +name = "sgmllib3k" +version = "1.0.0" +description = "Py3k port of sgmllib." +optional = false +python-versions = "*" +files = [ + {file = "sgmllib3k-1.0.0.tar.gz", hash = "sha256:7868fb1c8bfa764c1ac563d3cf369c381d1325d36124933a726f29fcdaa812e9"}, +] + [[package]] name = "six" version = "1.16.0" @@ -2558,4 +2582,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.12" -content-hash = "b3a94060974d7ece0d58a3625794c721dd84d34c8215296deeb352b0eb49e29b" +content-hash = "6f70528246aa941fb37cc239583217faa49660ccaa6196fe13eb39a9c3605735" diff --git a/pyproject.toml b/pyproject.toml index 3ac495a..ccbf3de 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ python = ">=3.9,<3.12" Red-DiscordBot = "^3.5.5" pytimeparse2 = "^1.7.1" humanize = "^4.8.0" +feedparser = "^6.0.11" [tool.poetry.group.dev] optional = true diff --git a/updatechecker/__init__.py b/updatechecker/__init__.py new file mode 100644 index 0000000..97f19f9 --- /dev/null +++ b/updatechecker/__init__.py @@ -0,0 +1,10 @@ +from .updatechecker import UpdateChecker + +__red_end_user_data_statement__ = ( + "This cog does not persistently store data or metadata about users." +) + + +async def setup(bot): + cog = UpdateChecker(bot) + await bot.add_cog(cog) diff --git a/updatechecker/info.json b/updatechecker/info.json new file mode 100644 index 0000000..6054252 --- /dev/null +++ b/updatechecker/info.json @@ -0,0 +1,17 @@ +{ + "author": [ + "SeaswimmerTheFsh", "Neuro Assassin" + ], + "install_msg": "Thank you for downloading this cog.", + "name": "updatechecker", + "short": "Notifies you when an update for a repo is available.", + "description": "This cog will tell when there is an update available for a repository you have added for your bot, and, depending on settings, will auto update or will just notify you.", + "tags": [ + "tools" + ], + "requirements": [ + "feedparser" + ], + "hidden": false, + "disabled": false +} diff --git a/updatechecker/updatechecker.py b/updatechecker/updatechecker.py new file mode 100644 index 0000000..0ed5cc2 --- /dev/null +++ b/updatechecker/updatechecker.py @@ -0,0 +1,453 @@ +""" +MIT License + +Copyright (c) 2018-Present NeuroAssassin + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +""" + +# Huge thanks to Sinbad for allowing me to copy parts of his RSS cog +# (https://github.com/mikeshardmind/SinbadCogs/tree/v3/rss), which I +# used to grab the latest commits from repositories. + +# Also, the code I use for updating repos I took directly from Red, +# and just took out the message interactions + +import asyncio +import traceback +from datetime import datetime + +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 + +import feedparser + + +class UpdateChecker(commands.Cog): + """Get notices or auto-update cogs when an update is available for it's repo""" + + def __init__(self, bot): + self.bot = bot + self.session = aiohttp.ClientSession() + self.conf = Config.get_conf(self, identifier=473541068378341376) + default_global = { + "repos": {}, + "auto": False, + "gochannel": 0, + "embed": True, + "whitelist": [], + "blacklist": [], + } + self.conf.register_global(**default_global) + self.task = self.bot.loop.create_task(self.bg_task()) + + def cog_unload(self): + self.__unload() + + def __unload(self): + self.task.cancel() + self.session.detach() + + async def red_delete_data_for_user(self, **kwargs): + """This cog does not store user data""" + return + + async def bg_task(self): + await self.bot.wait_until_ready() + # Just in case + await asyncio.sleep(10) + while True: + cog = self.bot.get_cog("Downloader") + if cog is not None: + data = await self.conf.all() + repos = data["repos"] + auto = data["auto"] + channel = data["gochannel"] + use_embed = data["embed"] + whitelist = data["whitelist"] + blacklist = data["blacklist"] + if channel: + channel = self.bot.get_channel(channel) + if channel is None: + await self.bot.send_to_owners( + "[Update Checker] It appears that I am no longer allowed to send messages to the designated update channel. " + "From now on, it will DM you." + ) + await self.conf.gochannel.set(0) + send = self.bot.send_to_owners + else: + use_embed = ( + use_embed and channel.permissions_for(channel.guild.me).embed_links + ) + send = channel.send + else: + send = self.bot.send_to_owners + + all_repos = cog._repo_manager.get_all_repo_names() + for repo in all_repos: + if not (repo in list(repos.keys())): + repos[repo] = "--default--" + await self.conf.repos.set(repos) + + saving_dict = {k: v for k, v in repos.items() if k in all_repos} + for repo_name, commit_saved in saving_dict.items(): + repo = cog._repo_manager.get_repo(repo_name) + if not repo: + continue + url = repo.url + r"/commits/" + repo.branch + ".atom" + 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 = response.entries[0]["media_thumbnail"][0]["url"].split("?")[0] + except AttributeError: + continue + saving_dict[repo_name] = commit + if whitelist: + if repo_name not in whitelist: + continue + if repo_name in blacklist: + continue + # CN is used here for backwards compatability, don't want people to get an + # update for each and every one of their cogs when updating this cog + if ( + commit != commit_saved + and cn != commit_saved + and commit_saved != "--default--" + ): + if True: # KACHOW + if use_embed: + e = discord.Embed( + title="Update Checker", + description=f"Update available for repo: {repo.name}", + timestamp=datetime.utcnow(), + color=0x00FF00, + ) + e.add_field(name="URL", value=repo.url) + e.add_field(name="Branch", value=repo.branch) + e.add_field(name="Commit", value=cn) + e.add_field(name="Hash", value=hash) + e.set_thumbnail(url=image) + else: + e = ( + "```css\n" + "[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()}" + "```" + ) + try: + if use_embed: + await send(embed=e) + else: + await send(e) + except discord.Forbidden: + # send_to_owners suppresses Forbidden, logging it to console. + # As a result, this will only happen if a channel was set. + await self.bot.send_to_owners( + "[Update Checker] It appears that I am no longer allowed to send messages to the designated update channel. " + "From now on, it will DM you." + ) + if use_embed: + await self.bot.send_to_owners(embed=e) + else: + await self.bot.send_to_owners(e) + await self.conf.gochannel.set(0) + else: + try: + await channel.send( + f"[Update Checker] Update found for repo: {repo.name}. Updating repos..." + ) + except AttributeError: + owner = (await self.bot.application_info()).owner + await owner.send( + "[Update Checker] It appears that the channel for this cog has been deleted. From now on, it will DM you." + ) + channel = owner + await self.conf.gochannel.set(0) + except discord.errors.Forbidden: + owner = (await self.bot.application_info()).owner + await owner.send( + "[Update Checker] It appears that I am no longer allowed to send messages to the designated update channel. From now on, it will DM you." + ) + channel = owner + await self.conf.gochannel.set(0) + # Just a copy of `[p]cog update`, but without using ctx things + try: + installed_cogs = set(await cog.installed_cogs()) + updated = await cog._repo_manager.update_all_repos() + updated_cogs = set( + cog for repo in updated for cog in repo.available_cogs + ) + installed_and_updated = updated_cogs & installed_cogs + if installed_and_updated: + await cog._reinstall_requirements(installed_and_updated) + await cog._reinstall_cogs(installed_and_updated) + await cog._reinstall_libraries(installed_and_updated) + cognames = {c.name for c in installed_and_updated} + message = humanize_list(tuple(map(inline, cognames))) + except Exception as error: + exception_log = ( + "Exception while updating repos in Update Checker \n" + ) + exception_log += "".join( + traceback.format_exception( + type(error), error, error.__traceback__ + ) + ) + try: + await channel.send( + f"[Update Checker]: Error while updating repos.\n\n{exception_log}" + ) + except discord.errors.Forbidden: + pass + else: + try: + await channel.send( + f"[Update Checker]: Ran cog update. Updated cogs: {message}" + ) + except discord.errors.Forbidden: + pass + await asyncio.sleep(1) + await self.conf.repos.set(saving_dict) + await asyncio.sleep(60) + + async def fetch_feed(self, url: str): + # Thank's to Sinbad's rss cog after which I copied this + 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 + + ret = feedparser.parse(data) + if ret.bozo: + return None + return ret + + @commands.is_owner() + @commands.group(name="cogupdater", aliases=["cu"]) + async def update(self, ctx): + """Group command for controlling the update checker cog.""" + pass + + @commands.is_owner() + @update.command() + async def auto(self, ctx): + """Changes automatic cog updates to the opposite setting.""" + if False: # KACHOW + auto = await self.conf.auto() + await self.conf.auto.set(not auto) + status = "disabled" if auto else "enabled" + await ctx.send(f"Auto cog updates are now {status}") + else: + await ctx.send( + "This command is disabled for the time being. Cog updates will not run automatically, however notifications will still send." + ) + + @commands.is_owner() + @update.command() + async def channel(self, ctx, channel: discord.TextChannel = None): + """ + Sets a channel for update messages to go to. + + If argument is not supplied, it will be sent to the default notifications channel(s) specified in `[p]set ownernotifications`. + By default, this goes to owner DMs. + """ + if channel: + await self.conf.gochannel.set(channel.id) + await ctx.send(f"Update messages will now be sent to {channel.mention}") + else: + await self.conf.gochannel.set(0) + await ctx.send("Update messages will now be DMed to you.") + + @commands.is_owner() + @update.command() + async def settings(self, ctx): + """See settings for the Update Checker cog. + + Right now, this shows whether the bot updates cogs automatically and what channel logs are sent to. + """ + auto = await self.conf.auto() + channel = await self.conf.gochannel() + embed = await self.conf.embed() + if embed: + e = discord.Embed(title="Update Checker settings", color=0x00FF00) + e.add_field(name="Automatic Cog Updates", value=str(auto)) + if channel == 0: + channel = "Direct Messages" + else: + try: + channel = self.bot.get_channel(channel).name + except: + channel = "Unknown" + e.add_field(name="Update Channel", value=channel) + await ctx.send(embed=e) + else: + if channel == 0: + channel = "Direct Messages" + else: + try: + channel = self.bot.get_channel(channel).name + except: + channel = "Unknown" + message = ( + "```css\n" + "[Update Checker settings]" + "``````css\n" + f"[Automatic Cog Updates]: {str(auto)}\n" + f" [Update Channel]: {channel}" + "```" + ) + await ctx.send(message) + + @commands.is_owner() + @update.command() + async def embed(self, ctx): + """Toggles whether to use embeds or colorful codeblock messages when sending an update.""" + c = await self.conf.embed() + await self.conf.embed.set(not c) + word = "disabled" if c else "enabled" + await ctx.send(f"Embeds are now {word}") + + @commands.is_owner() + @update.group(name="list") + async def whiteblacklist(self, ctx): + """Whitelist/blacklist certain repositories from which to receive updates.""" + if ctx.invoked_subcommand is None: + data = await self.conf.all() + whitelist = data["whitelist"] + blacklist = data["blacklist"] + await ctx.send( + f"Whitelisted: {humanize_list(tuple(map(inline, whitelist or ['None'])))}\nBlacklisted: {humanize_list(tuple(map(inline, blacklist or ['None'])))}" + ) + + @whiteblacklist.group() + async def whitelist(self, ctx): + """Whitelist certain repos from which to receive updates.""" + pass + + @whitelist.command(name="add") + async def whitelistadd(self, ctx, *repos: Repo): + """Add repos to the whitelist""" + data = await self.conf.whitelist() + ds = set(data) + ns = set([r.name for r in repos]) + ss = ds | ns + await self.conf.whitelist.set(list(ss)) + await ctx.send(f"Whitelist update successful: {humanize_list(tuple(map(inline, ss)))}") + + @whitelist.command(name="remove") + async def whitelistremove(self, ctx, *repos: Repo): + """Remove repos from the whitelist""" + data = await self.conf.whitelist() + ds = set(data) + ns = set([r.name for r in repos]) + ss = ds - ns + await self.conf.whitelist.set(list(ss)) + await ctx.send( + f"Whitelist update successful: {humanize_list(tuple(map(inline, ss or ['None'])))}" + ) + + @whitelist.command(name="clear") + async def whitelistclear(self, ctx): + """Removes all repos from the whitelist""" + await self.conf.whitelist.set([]) + await ctx.send("Whitelist update successful") + + @whiteblacklist.group() + async def blacklist(self, ctx): + """Blacklist certain repos from which to receive updates.""" + pass + + @blacklist.command(name="add") + async def blacklistadd(self, ctx, *repos: Repo): + """Add repos to the blacklist""" + data = await self.conf.blacklist() + ds = set(data) + ns = set([r.name for r in repos]) + ss = ds | ns + await self.conf.blacklist.set(list(ss)) + await ctx.send(f"Backlist update successful: {humanize_list(tuple(map(inline, ss)))}") + + @blacklist.command(name="remove") + async def blacklistremove(self, ctx, *repos: Repo): + """Remove repos from the blacklist""" + data = await self.conf.blacklist() + ds = set(data) + ns = set([r.name for r in repos]) + ss = ds - ns + await self.conf.blacklist.set(list(ss)) + await ctx.send( + f"Blacklist update successful: {humanize_list(tuple(map(inline, ss or ['None'])))}" + ) + + @blacklist.command(name="clear") + async def blacklistclear(self, ctx): + """Removes all repos from the blacklist""" + await self.conf.blacklist.set([]) + await ctx.send("Blacklist update successful") + + @commands.is_owner() + @update.group(name="task") + async def _group_update_task(self, ctx): + """View the status of the task (the one checking for updates).""" + pass + + @_group_update_task.command() + async def status(self, ctx): + """Get the current status of the update task.""" + message = "Task is currently " + cancelled = self.task.cancelled() + if cancelled: + message += "canceled." + else: + done = self.task.done() + if done: + message += "done." + else: + message += "running." + try: + self.task.exception() + except asyncio.exceptions.InvalidStateError: + message += " No error has been encountered." + else: + message += " An error has been encountered. Please run `[p]cogupdater task error` and report it to Neuro Assassin on the help server." + await ctx.send(message) + + @_group_update_task.command() + async def error(self, ctx): + """Gets the latest error of the update task.""" + try: + e = self.task.exception() + except asyncio.exceptions.InvalidStateError: + message = "No error has been encountered." + else: + ex = traceback.format_exception(type(e), e, e.__traceback__) + message = "An error has been encountered: ```py\n" + "".join(ex) + "```" + await ctx.send(message) -- 2.45.3 From f3022a980ef96944378686020ba6c7bd5fbb4b46 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 13:13:16 +0000 Subject: [PATCH 03/21] fix(docs): fixed images breaking on branch docs --- .forgejo/workflows/workflow.yaml | 10 ++++++---- mkdocs.yml | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.forgejo/workflows/workflow.yaml b/.forgejo/workflows/workflow.yaml index b1a975c..67967e3 100644 --- a/.forgejo/workflows/workflow.yaml +++ b/.forgejo/workflows/workflow.yaml @@ -18,13 +18,15 @@ jobs: - name: Install dependencies run: poetry install --with docs --with dev --no-root - - name: Build the documentation - run: mkdocs build - continue-on-error: true - - name: Set Environment Variables uses: actions/env@v2 + - name: Build the documentation + run: | + export SITE_URL="https://$CI_ACTION_REF_NAME_SLUG.seacogs.coastalcommits.com" + mkdocs build -v + continue-on-error: true + - name: Deploy the documentation to Meli (CoastalCommits Pages) run: | GREEN='\033[0;32m' diff --git a/mkdocs.yml b/mkdocs.yml index 05c027b..63ec33c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,5 +1,5 @@ site_name: SeaCogs Documentation -site_url: https://seacogs.coastalcommits.com +site_url: !ENV [SITE_NAME, 'https://seacogs.coastalcommits.com'] repo_name: CoastalCommits repo_url: https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs edit_uri: src/branch/main/.docs -- 2.45.3 From c2b2dcb8a068bbc8a4646b673dc77015466598ab Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 13:14:36 +0000 Subject: [PATCH 04/21] fix(docs): fixed env variable name --- mkdocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkdocs.yml b/mkdocs.yml index 63ec33c..8446e34 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,5 +1,5 @@ site_name: SeaCogs Documentation -site_url: !ENV [SITE_NAME, 'https://seacogs.coastalcommits.com'] +site_url: !ENV [SITE_URL, 'https://seacogs.coastalcommits.com'] repo_name: CoastalCommits repo_url: https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs edit_uri: src/branch/main/.docs -- 2.45.3 From b4647a3c6b7718d7e8712631ab99628d7deaa04e Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 13:30:02 +0000 Subject: [PATCH 05/21] feat(updatechecker): added gitea/forgejo support --- updatechecker/updatechecker.py | 42 +++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/updatechecker/updatechecker.py b/updatechecker/updatechecker.py index 0ed5cc2..520d116 100644 --- a/updatechecker/updatechecker.py +++ b/updatechecker/updatechecker.py @@ -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,15 +113,26 @@ class UpdateChecker(commands.Cog): repo = cog._repo_manager.get_repo(repo_name) if not repo: continue - url = repo.url + r"/commits/" + repo.branch + ".atom" - 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 = response.entries[0]["media_thumbnail"][0]["url"].split("?")[0] - except AttributeError: - continue + if repo.url.startswith("https://github.com"): + url = repo.url + r"/commits/" + repo.branch + ".atom" + 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 = 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) - e.set_thumbnail(url=image) + 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: -- 2.45.3 From 130fc6028ad4749d4ada82ea7f63afd03284e4cd Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 13:41:53 +0000 Subject: [PATCH 06/21] feat(updatechecker): added support for thumbnails in gitea/forgejo --- updatechecker/updatechecker.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/updatechecker/updatechecker.py b/updatechecker/updatechecker.py index 520d116..c1e426c 100644 --- a/updatechecker/updatechecker.py +++ b/updatechecker/updatechecker.py @@ -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): -- 2.45.3 From 3bf508859b215460fdd7159f1b0e56748948ae7b Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 13:47:45 +0000 Subject: [PATCH 07/21] fix(updatechecker): hopefully fixed detecting rss changes --- updatechecker/updatechecker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/updatechecker/updatechecker.py b/updatechecker/updatechecker.py index c1e426c..975e2fd 100644 --- a/updatechecker/updatechecker.py +++ b/updatechecker/updatechecker.py @@ -125,7 +125,7 @@ class UpdateChecker(commands.Cog): except AttributeError: continue else: - url = repo.url + "rss/branch/" + repo.branch + url = repo.url + r"/rss/branch/" + repo.branch response = await self.fetch_feed(url) parsed_url = urlparse(repo.url) try: -- 2.45.3 From be687a58fa1859e0e152dd7b9e9fb789de59ce6c Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 13:48:35 +0000 Subject: [PATCH 08/21] misc(updatechecker): docstring change --- updatechecker/updatechecker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/updatechecker/updatechecker.py b/updatechecker/updatechecker.py index 975e2fd..3aea860 100644 --- a/updatechecker/updatechecker.py +++ b/updatechecker/updatechecker.py @@ -44,7 +44,7 @@ import feedparser class UpdateChecker(commands.Cog): - """Get notices or auto-update cogs when an update is available for it's repo""" + """Get notices or auto-update cogs when an update is available for its repo""" def __init__(self, bot): self.bot = bot -- 2.45.3 From 0695dc061e67ed4d3f5f7c7fdf35e4d1cd5dc6a3 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 13:59:20 +0000 Subject: [PATCH 09/21] misc(updatechecker): moved parsed_url --- updatechecker/updatechecker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/updatechecker/updatechecker.py b/updatechecker/updatechecker.py index 3aea860..dada2a8 100644 --- a/updatechecker/updatechecker.py +++ b/updatechecker/updatechecker.py @@ -114,7 +114,8 @@ class UpdateChecker(commands.Cog): repo = cog._repo_manager.get_repo(repo_name) if not repo: continue - if repo.url.startswith("https://github.com"): + parsed_url = urlparse(repo.url) + if parsed_url.netloc == "github.com": url = repo.url + r"/commits/" + repo.branch + ".atom" response = await self.fetch_feed(url) try: @@ -127,7 +128,6 @@ class UpdateChecker(commands.Cog): else: url = repo.url + r"/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"] + ")" -- 2.45.3 From 8664c883a51ef5565911d0a875549a913e63b695 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 14:01:27 +0000 Subject: [PATCH 10/21] fix(updatechecker): use discord.ext tasks --- updatechecker/updatechecker.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/updatechecker/updatechecker.py b/updatechecker/updatechecker.py index dada2a8..4a95fc0 100644 --- a/updatechecker/updatechecker.py +++ b/updatechecker/updatechecker.py @@ -36,6 +36,7 @@ from urllib.parse import urlparse import aiohttp import discord +from discord.ext import tasks from redbot.cogs.downloader.repo_manager import Repo from redbot.core import Config, commands from redbot.core.utils.chat_formatting import box, humanize_list, inline @@ -72,10 +73,8 @@ class UpdateChecker(commands.Cog): """This cog does not store user data""" return + @tasks.loop(minutes=1) async def bg_task(self): - await self.bot.wait_until_ready() - # Just in case - await asyncio.sleep(10) while True: cog = self.bot.get_cog("Downloader") if cog is not None: @@ -246,7 +245,6 @@ class UpdateChecker(commands.Cog): pass await asyncio.sleep(1) await self.conf.repos.set(saving_dict) - await asyncio.sleep(60) async def fetch_feed(self, url: str): # Thank's to Sinbad's rss cog after which I copied this -- 2.45.3 From e837fb1293609ed301daa0f5572170ffddf55073 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 14:11:59 +0000 Subject: [PATCH 11/21] feat(workflow): seperated workflow into two seperate jobs --- .forgejo/workflows/workflow.yaml | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/.forgejo/workflows/workflow.yaml b/.forgejo/workflows/workflow.yaml index 67967e3..b287100 100644 --- a/.forgejo/workflows/workflow.yaml +++ b/.forgejo/workflows/workflow.yaml @@ -6,7 +6,20 @@ on: pull_request: jobs: - build and lint: + Lint Code (Pylint): + runs-on: docker + container: coastalcommits.com/seaswimmerthefsh/actionscontainers-seacogs:latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install dependencies + run: poetry install --with dev --no-root + + - name: Analysing the code with Pylint + run: pylint --rcfile .forgejo/workflows/config/.pylintrc $(git ls-files '*.py') + + Build Documentation (MkDocs): runs-on: docker container: coastalcommits.com/seaswimmerthefsh/actionscontainers-seacogs:latest steps: @@ -16,18 +29,18 @@ jobs: fetch-depth: 0 - name: Install dependencies - run: poetry install --with docs --with dev --no-root + run: poetry install --with docs --no-root - name: Set Environment Variables uses: actions/env@v2 - - name: Build the documentation + - name: Build documentation run: | export SITE_URL="https://$CI_ACTION_REF_NAME_SLUG.seacogs.coastalcommits.com" mkdocs build -v continue-on-error: true - - name: Deploy the documentation to Meli (CoastalCommits Pages) + - name: Deploy documentation to Meli (CoastalCommits Pages) run: | GREEN='\033[0;32m' YELLOW='\033[0;33m' @@ -50,6 +63,3 @@ jobs: env: GITEA_TOKEN: ${{ secrets.COASTALCOMMITSTOKEN }} continue-on-error: true - - - name: Analysing the code with Pylint - run: pylint --rcfile .forgejo/workflows/config/.pylintrc $(git ls-files '*.py') -- 2.45.3 From ee22541b997cca44941853cf0d1615b1eec6733e Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 14:15:01 +0000 Subject: [PATCH 12/21] misc(workflow): changed workflow name to Actions --- .forgejo/workflows/workflow.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/workflow.yaml b/.forgejo/workflows/workflow.yaml index b287100..107810f 100644 --- a/.forgejo/workflows/workflow.yaml +++ b/.forgejo/workflows/workflow.yaml @@ -1,4 +1,4 @@ -name: Build Documentation and Lint Code +name: Actions on: push: branches: -- 2.45.3 From a477c8482b2117e32fc982c8d93622d37f03a5fb Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 14:23:36 +0000 Subject: [PATCH 13/21] misc(workflow): some random changes --- .forgejo/workflows/workflow.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.forgejo/workflows/workflow.yaml b/.forgejo/workflows/workflow.yaml index 107810f..5a4a907 100644 --- a/.forgejo/workflows/workflow.yaml +++ b/.forgejo/workflows/workflow.yaml @@ -16,7 +16,7 @@ jobs: - name: Install dependencies run: poetry install --with dev --no-root - - name: Analysing the code with Pylint + - name: Analysing code with Pylint run: pylint --rcfile .forgejo/workflows/config/.pylintrc $(git ls-files '*.py') Build Documentation (MkDocs): @@ -31,7 +31,7 @@ jobs: - name: Install dependencies run: poetry install --with docs --no-root - - name: Set Environment Variables + - name: Set environment variables uses: actions/env@v2 - name: Build documentation @@ -40,7 +40,7 @@ jobs: mkdocs build -v continue-on-error: true - - name: Deploy documentation to Meli (CoastalCommits Pages) + - name: Deploy documentation run: | GREEN='\033[0;32m' YELLOW='\033[0;33m' -- 2.45.3 From 174775daada357b8e10e4d501c2aca70a3fa9e9f Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 14:32:26 +0000 Subject: [PATCH 14/21] fix(docs): fixed incorrect installation directions --- .docs/updatechecker.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.docs/updatechecker.md b/.docs/updatechecker.md index 2926302..24c6c2a 100644 --- a/.docs/updatechecker.md +++ b/.docs/updatechecker.md @@ -16,7 +16,7 @@ Additional features include support for Gitea/Forgejo RSS feeds, instead of just ## Installation ```bash -[p]repo add seacogs https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs -[p]cog install seacogs updatechecker +[p]repo add seacogs-updatechecker https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs updatechecker +[p]cog install seacogs-updatechecker updatechecker [p]cog load updatechecker ``` -- 2.45.3 From c179dd06493300661f8c75ffeb1678fbc478674a Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 18:52:25 +0000 Subject: [PATCH 15/21] feat(docs): read through mkdocs material documentation and enabled a whole bunch of qol features --- .forgejo/workflows/workflow.yaml | 1 + mkdocs.yml | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.forgejo/workflows/workflow.yaml b/.forgejo/workflows/workflow.yaml index 5a4a907..62967b5 100644 --- a/.forgejo/workflows/workflow.yaml +++ b/.forgejo/workflows/workflow.yaml @@ -37,6 +37,7 @@ jobs: - name: Build documentation run: | export SITE_URL="https://$CI_ACTION_REF_NAME_SLUG.seacogs.coastalcommits.com" + export EDIT_URI="src/branch/$CI_ACTION_REF_NAME/.docs" mkdocs build -v continue-on-error: true diff --git a/mkdocs.yml b/mkdocs.yml index 8446e34..01b84ed 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -2,7 +2,7 @@ site_url: !ENV [SITE_URL, 'https://seacogs.coastalcommits.com'] repo_name: CoastalCommits repo_url: https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs -edit_uri: src/branch/main/.docs +edit_uri: !ENV [EDIT_URI, 'src/branch/main/.docs'] copyright: Copyright © 2024, SeaswimmerTheFsh docs_dir: .docs @@ -12,7 +12,7 @@ site_description: Documentation for my Red-DiscordBot Cogs. nav: - Home: index.md - Aurora: - - Home: aurora/index.md + - aurora/index.md - Moderation Commands: aurora/moderation-commands.md - Case Commands: aurora/case-commands.md - Configuration: aurora/configuration.md @@ -64,18 +64,41 @@ markdown_extensions: theme: name: material palette: - scheme: slate + - media: '(prefers-color-scheme: light)' + scheme: default + primary: orange + accent: amber + toggle: + icon: material/toggle-switch + name: Switch to dark mode + + - media: '(prefers-color-scheme: dark)' + scheme: slate + primary: orange + accent: amber + toggle: + icon: material/toggle-switch-off-outline + name: Switch to light mode features: - content.code.annotate - content.code.copy - navigation.instant + - navigation.instant.progress - navigation.tabs + - navigation.tracking + - navigation.top + - navigation.sections + - navigation.indexes - search.suggest - search.highlight - search.share + - toc.follow logo: img/logo.png favicon: img/logo.png + icon: + repo: simple/forgejo watch: - ./aurora - ./nerdify + - ./updatechecker -- 2.45.3 From 77a4001fed8fd9163734846dfb37a460d0da0e5e Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 19:11:40 +0000 Subject: [PATCH 16/21] misc(docs): changed colors --- .docs/.overrides/main.html.disabled | 5 +++++ mkdocs.yml | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .docs/.overrides/main.html.disabled diff --git a/.docs/.overrides/main.html.disabled b/.docs/.overrides/main.html.disabled new file mode 100644 index 0000000..bace02a --- /dev/null +++ b/.docs/.overrides/main.html.disabled @@ -0,0 +1,5 @@ +{% extends "base.html" %} + +{% block announce %} + Put an announcement here. +{% endblock %} diff --git a/mkdocs.yml b/mkdocs.yml index 01b84ed..2ab3bdb 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -63,23 +63,25 @@ markdown_extensions: theme: name: material + custom_dir: ./.docs/.overrides palette: - media: '(prefers-color-scheme: light)' scheme: default - primary: orange - accent: amber + primary: cyan + accent: light blue toggle: icon: material/toggle-switch name: Switch to dark mode - media: '(prefers-color-scheme: dark)' scheme: slate - primary: orange - accent: amber + primary: cyan + accent: light blue toggle: icon: material/toggle-switch-off-outline name: Switch to light mode features: + - announce.dismiss - content.code.annotate - content.code.copy - navigation.instant -- 2.45.3 From bc57fb8ecaeae3a78cb12e8d63bd78b6320bf455 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 19:20:21 +0000 Subject: [PATCH 17/21] fix(updatechecker): pylint fixes --- updatechecker/updatechecker.py | 225 ++++++++++++++++----------------- 1 file changed, 109 insertions(+), 116 deletions(-) diff --git a/updatechecker/updatechecker.py b/updatechecker/updatechecker.py index 4a95fc0..31027b6 100644 --- a/updatechecker/updatechecker.py +++ b/updatechecker/updatechecker.py @@ -62,14 +62,14 @@ class UpdateChecker(commands.Cog): self.conf.register_global(**default_global) self.task = self.bot.loop.create_task(self.bg_task()) - def cog_unload(self): + async def cog_unload(self): self.__unload() def __unload(self): self.task.cancel() self.session.detach() - async def red_delete_data_for_user(self, **kwargs): + async def red_delete_data_for_user(self, **kwargs): # pylint: disable=unused-argument """This cog does not store user data""" return @@ -102,7 +102,7 @@ class UpdateChecker(commands.Cog): else: send = self.bot.send_to_owners - all_repos = cog._repo_manager.get_all_repo_names() + all_repos = cog._repo_manager.get_all_repo_names() # pylint: disable=protected-access for repo in all_repos: if not (repo in list(repos.keys())): repos[repo] = "--default--" @@ -110,7 +110,7 @@ class UpdateChecker(commands.Cog): saving_dict = {k: v for k, v in repos.items() if k in all_repos} for repo_name, commit_saved in saving_dict.items(): - repo = cog._repo_manager.get_repo(repo_name) + repo = cog._repo_manager.get_repo(repo_name) # pylint: disable=protected-access if not repo: continue parsed_url = urlparse(repo.url) @@ -119,7 +119,7 @@ class UpdateChecker(commands.Cog): response = await self.fetch_feed(url) try: commit = response.entries[0]["id"][33:] - hash = "[" + commit + "](" + response.entries[0]["link"] + ")" + chash = "[" + commit + "](" + response.entries[0]["link"] + ")" cn = response.entries[0]["title"] + " - " + response.entries[0]["author"] image = response.entries[0]["media_thumbnail"][0]["url"].split("?")[0] except AttributeError: @@ -129,7 +129,7 @@ class UpdateChecker(commands.Cog): response = await self.fetch_feed(url) try: commit = response.entries[0]["id"][33:] - hash = "[" + commit + "](" + response.entries[0]["link"] + ")" + chash = "[" + commit + "](" + response.entries[0]["link"] + ")" cn = response.entries[0]["title"] + " - " + response.entries[0]["author"] image = await self.fetch_gitea_thumbnail(parsed_url.scheme + "://" + parsed_url.netloc + "/api/v1/repos" + parsed_url.path) except AttributeError: @@ -142,107 +142,102 @@ class UpdateChecker(commands.Cog): continue # CN is used here for backwards compatability, don't want people to get an # update for each and every one of their cogs when updating this cog - if ( - commit != commit_saved - and cn != commit_saved - and commit_saved != "--default--" - ): - if True: # KACHOW - if use_embed: - e = discord.Embed( - title="Update Checker", - description=f"Update available for repo: {repo.name}", - timestamp=datetime.utcnow(), - color=0x00FF00, - ) - e.add_field(name="URL", value=repo.url) - 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 = box( - "[Update Checker]" - f" Repo: {repo.name}\n" - f" URL: {repo.url}\n" - f" Commit: {cn}\n" - f" Hash: {commit}\n" - f" Time: {datetime.utcnow()}", - 'css' - ) - try: - if use_embed: - await send(embed=e) - else: - await send(e) - except discord.Forbidden: - # send_to_owners suppresses Forbidden, logging it to console. - # As a result, this will only happen if a channel was set. - await self.bot.send_to_owners( - "[Update Checker] It appears that I am no longer allowed to send messages to the designated update channel. " - "From now on, it will DM you." - ) - if use_embed: - await self.bot.send_to_owners(embed=e) - else: - await self.bot.send_to_owners(e) - await self.conf.gochannel.set(0) + if commit_saved not in (commit, cn, '--default--'): + if use_embed: + e = discord.Embed( + title="Update Checker", + description=f"Update available for repo: {repo.name}", + timestamp=datetime.utcnow(), + color=0x00FF00, + ) + e.add_field(name="URL", value=repo.url) + e.add_field(name="Branch", value=repo.branch) + e.add_field(name="Commit", value=cn) + e.add_field(name="Hash", value=chash) + if image is not None: + e.set_thumbnail(url=image) else: - try: - await channel.send( - f"[Update Checker] Update found for repo: {repo.name}. Updating repos..." - ) - except AttributeError: - owner = (await self.bot.application_info()).owner - await owner.send( - "[Update Checker] It appears that the channel for this cog has been deleted. From now on, it will DM you." - ) - channel = owner - await self.conf.gochannel.set(0) - except discord.errors.Forbidden: - owner = (await self.bot.application_info()).owner - await owner.send( - "[Update Checker] It appears that I am no longer allowed to send messages to the designated update channel. From now on, it will DM you." - ) - channel = owner - await self.conf.gochannel.set(0) - # Just a copy of `[p]cog update`, but without using ctx things - try: - installed_cogs = set(await cog.installed_cogs()) - updated = await cog._repo_manager.update_all_repos() - updated_cogs = set( - cog for repo in updated for cog in repo.available_cogs - ) - installed_and_updated = updated_cogs & installed_cogs - if installed_and_updated: - await cog._reinstall_requirements(installed_and_updated) - await cog._reinstall_cogs(installed_and_updated) - await cog._reinstall_libraries(installed_and_updated) - cognames = {c.name for c in installed_and_updated} - message = humanize_list(tuple(map(inline, cognames))) - except Exception as error: - exception_log = ( - "Exception while updating repos in Update Checker \n" - ) - exception_log += "".join( - traceback.format_exception( - type(error), error, error.__traceback__ - ) - ) - try: - await channel.send( - f"[Update Checker]: Error while updating repos.\n\n{exception_log}" - ) - except discord.errors.Forbidden: - pass + e = box( + "[Update Checker]" + f" Repo: {repo.name}\n" + f" URL: {repo.url}\n" + f" Commit: {cn}\n" + f" Hash: {commit}\n" + f" Time: {datetime.utcnow()}", + 'css' + ) + try: + if use_embed: + await send(embed=e) else: - try: - await channel.send( - f"[Update Checker]: Ran cog update. Updated cogs: {message}" - ) - except discord.errors.Forbidden: - pass + await send(e) + except discord.Forbidden: + # send_to_owners suppresses Forbidden, logging it to console. + # As a result, this will only happen if a channel was set. + await self.bot.send_to_owners( + "[Update Checker] It appears that I am no longer allowed to send messages to the designated update channel. " + "From now on, it will DM you." + ) + if use_embed: + await self.bot.send_to_owners(embed=e) + else: + await self.bot.send_to_owners(e) + await self.conf.gochannel.set(0) + # Was already inaccessible before I got here, so I'm just gonna leave it and look at it later -- Sea + # try: + # await channel.send( + # f"[Update Checker] Update found for repo: {repo.name}. Updating repos..." + # ) + # except AttributeError: + # owner = (await self.bot.application_info()).owner + # await owner.send( + # "[Update Checker] It appears that the channel for this cog has been deleted. From now on, it will DM you." + # ) + # channel = owner + # await self.conf.gochannel.set(0) + # except discord.errors.Forbidden: + # owner = (await self.bot.application_info()).owner + # await owner.send( + # "[Update Checker] It appears that I am no longer allowed to send messages to the designated update channel. From now on, it will DM you." + # ) + # channel = owner + # await self.conf.gochannel.set(0) + # # Just a copy of `[p]cog update`, but without using ctx things + # try: + # installed_cogs = set(await cog.installed_cogs()) + # updated = await cog._repo_manager.update_all_repos() + # updated_cogs = set( + # cog for repo in updated for cog in repo.available_cogs + # ) + # installed_and_updated = updated_cogs & installed_cogs + # if installed_and_updated: + # await cog._reinstall_requirements(installed_and_updated) + # await cog._reinstall_cogs(installed_and_updated) + # await cog._reinstall_libraries(installed_and_updated) + # cognames = {c.name for c in installed_and_updated} + # message = humanize_list(tuple(map(inline, cognames))) + # except Exception as error: + # exception_log = ( + # "Exception while updating repos in Update Checker \n" + # ) + # exception_log += "".join( + # traceback.format_exception( + # type(error), error, error.__traceback__ + # ) + # ) + # try: + # await channel.send( + # f"[Update Checker]: Error while updating repos.\n\n{exception_log}" + # ) + # except discord.errors.Forbidden: + # pass + # else: + # try: + # await channel.send( + # f"[Update Checker]: Ran cog update. Updated cogs: {message}" + # ) + # except discord.errors.Forbidden: + # pass await asyncio.sleep(1) await self.conf.repos.set(saving_dict) @@ -274,21 +269,19 @@ class UpdateChecker(commands.Cog): @commands.group(name="cogupdater", aliases=["cu"]) async def update(self, ctx): """Group command for controlling the update checker cog.""" - pass @commands.is_owner() @update.command() async def auto(self, ctx): """Changes automatic cog updates to the opposite setting.""" - if False: # KACHOW - auto = await self.conf.auto() - await self.conf.auto.set(not auto) - status = "disabled" if auto else "enabled" - await ctx.send(f"Auto cog updates are now {status}") - else: - await ctx.send( - "This command is disabled for the time being. Cog updates will not run automatically, however notifications will still send." - ) + # Was already inaccessible before I got here, so I'm just gonna leave it and look at it later -- Sea + # auto = await self.conf.auto() + # await self.conf.auto.set(not auto) + # status = "disabled" if auto else "enabled" + # await ctx.send(f"Auto cog updates are now {status}") + await ctx.send( + "This command is disabled for the time being. Cog updates will not run automatically, however notifications will still send." + ) @commands.is_owner() @update.command() @@ -457,7 +450,7 @@ class UpdateChecker(commands.Cog): except asyncio.exceptions.InvalidStateError: message += " No error has been encountered." else: - message += " An error has been encountered. Please run `[p]cogupdater task error` and report it to Neuro Assassin on the help server." + message += " An error has been encountered. Please run `[p]cogupdater task error` and report it to SeaswimmerTheFsh (.seasw) on the help server." await ctx.send(message) @_group_update_task.command() -- 2.45.3 From 45fcc00cdbce521de94f5383c40d280ae6200ae1 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 19:27:19 +0000 Subject: [PATCH 18/21] fix(updatechecker): more pylint fixes --- updatechecker/updatechecker.py | 331 ++++++++++++++++----------------- 1 file changed, 162 insertions(+), 169 deletions(-) diff --git a/updatechecker/updatechecker.py b/updatechecker/updatechecker.py index 31027b6..1182383 100644 --- a/updatechecker/updatechecker.py +++ b/updatechecker/updatechecker.py @@ -75,171 +75,169 @@ class UpdateChecker(commands.Cog): @tasks.loop(minutes=1) async def bg_task(self): - while True: - cog = self.bot.get_cog("Downloader") - if cog is not None: - data = await self.conf.all() - repos = data["repos"] - auto = data["auto"] - channel = data["gochannel"] - use_embed = data["embed"] - whitelist = data["whitelist"] - blacklist = data["blacklist"] - if channel: - channel = self.bot.get_channel(channel) - if channel is None: + cog = self.bot.get_cog("Downloader") + if cog is not None: + data = await self.conf.all() + repos = data["repos"] + channel = data["gochannel"] + use_embed = data["embed"] + whitelist = data["whitelist"] + blacklist = data["blacklist"] + if channel: + channel = self.bot.get_channel(channel) + if channel is None: + await self.bot.send_to_owners( + "[Update Checker] It appears that I am no longer allowed to send messages to the designated update channel. " + "From now on, it will DM you." + ) + await self.conf.gochannel.set(0) + send = self.bot.send_to_owners + else: + use_embed = ( + use_embed and channel.permissions_for(channel.guild.me).embed_links + ) + send = channel.send + else: + send = self.bot.send_to_owners + + all_repos = cog._repo_manager.get_all_repo_names() # pylint: disable=protected-access + for repo in all_repos: + if not (repo in list(repos.keys())): + repos[repo] = "--default--" + await self.conf.repos.set(repos) + + saving_dict = {k: v for k, v in repos.items() if k in all_repos} + for repo_name, commit_saved in saving_dict.items(): + repo = cog._repo_manager.get_repo(repo_name) # pylint: disable=protected-access + if not repo: + continue + parsed_url = urlparse(repo.url) + if parsed_url.netloc == "github.com": + url = repo.url + r"/commits/" + repo.branch + ".atom" + response = await self.fetch_feed(url) + try: + commit = response.entries[0]["id"][33:] + chash = "[" + commit + "](" + response.entries[0]["link"] + ")" + cn = response.entries[0]["title"] + " - " + response.entries[0]["author"] + image = response.entries[0]["media_thumbnail"][0]["url"].split("?")[0] + except AttributeError: + continue + else: + url = repo.url + r"/rss/branch/" + repo.branch + response = await self.fetch_feed(url) + try: + commit = response.entries[0]["id"][33:] + chash = "[" + commit + "](" + response.entries[0]["link"] + ")" + cn = response.entries[0]["title"] + " - " + response.entries[0]["author"] + 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 + if whitelist: + if repo_name not in whitelist: + continue + if repo_name in blacklist: + continue + # CN is used here for backwards compatability, don't want people to get an + # update for each and every one of their cogs when updating this cog + if commit_saved not in (commit, cn, '--default--'): + if use_embed: + e = discord.Embed( + title="Update Checker", + description=f"Update available for repo: {repo.name}", + timestamp=datetime.utcnow(), + color=0x00FF00, + ) + e.add_field(name="URL", value=repo.url) + e.add_field(name="Branch", value=repo.branch) + e.add_field(name="Commit", value=cn) + e.add_field(name="Hash", value=chash) + if image is not None: + e.set_thumbnail(url=image) + else: + e = box( + "[Update Checker]" + f" Repo: {repo.name}\n" + f" URL: {repo.url}\n" + f" Commit: {cn}\n" + f" Hash: {commit}\n" + f" Time: {datetime.utcnow()}", + 'css' + ) + try: + if use_embed: + await send(embed=e) + else: + await send(e) + except discord.Forbidden: + # send_to_owners suppresses Forbidden, logging it to console. + # As a result, this will only happen if a channel was set. await self.bot.send_to_owners( "[Update Checker] It appears that I am no longer allowed to send messages to the designated update channel. " "From now on, it will DM you." ) - await self.conf.gochannel.set(0) - send = self.bot.send_to_owners - else: - use_embed = ( - use_embed and channel.permissions_for(channel.guild.me).embed_links - ) - send = channel.send - else: - send = self.bot.send_to_owners - - all_repos = cog._repo_manager.get_all_repo_names() # pylint: disable=protected-access - for repo in all_repos: - if not (repo in list(repos.keys())): - repos[repo] = "--default--" - await self.conf.repos.set(repos) - - saving_dict = {k: v for k, v in repos.items() if k in all_repos} - for repo_name, commit_saved in saving_dict.items(): - repo = cog._repo_manager.get_repo(repo_name) # pylint: disable=protected-access - if not repo: - continue - parsed_url = urlparse(repo.url) - if parsed_url.netloc == "github.com": - url = repo.url + r"/commits/" + repo.branch + ".atom" - response = await self.fetch_feed(url) - try: - commit = response.entries[0]["id"][33:] - chash = "[" + commit + "](" + response.entries[0]["link"] + ")" - cn = response.entries[0]["title"] + " - " + response.entries[0]["author"] - image = response.entries[0]["media_thumbnail"][0]["url"].split("?")[0] - except AttributeError: - continue - else: - url = repo.url + r"/rss/branch/" + repo.branch - response = await self.fetch_feed(url) - try: - commit = response.entries[0]["id"][33:] - chash = "[" + commit + "](" + response.entries[0]["link"] + ")" - cn = response.entries[0]["title"] + " - " + response.entries[0]["author"] - 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 - if whitelist: - if repo_name not in whitelist: - continue - if repo_name in blacklist: - continue - # CN is used here for backwards compatability, don't want people to get an - # update for each and every one of their cogs when updating this cog - if commit_saved not in (commit, cn, '--default--'): if use_embed: - e = discord.Embed( - title="Update Checker", - description=f"Update available for repo: {repo.name}", - timestamp=datetime.utcnow(), - color=0x00FF00, - ) - e.add_field(name="URL", value=repo.url) - e.add_field(name="Branch", value=repo.branch) - e.add_field(name="Commit", value=cn) - e.add_field(name="Hash", value=chash) - if image is not None: - e.set_thumbnail(url=image) + await self.bot.send_to_owners(embed=e) else: - e = box( - "[Update Checker]" - f" Repo: {repo.name}\n" - f" URL: {repo.url}\n" - f" Commit: {cn}\n" - f" Hash: {commit}\n" - f" Time: {datetime.utcnow()}", - 'css' - ) - try: - if use_embed: - await send(embed=e) - else: - await send(e) - except discord.Forbidden: - # send_to_owners suppresses Forbidden, logging it to console. - # As a result, this will only happen if a channel was set. - await self.bot.send_to_owners( - "[Update Checker] It appears that I am no longer allowed to send messages to the designated update channel. " - "From now on, it will DM you." - ) - if use_embed: - await self.bot.send_to_owners(embed=e) - else: - await self.bot.send_to_owners(e) - await self.conf.gochannel.set(0) - # Was already inaccessible before I got here, so I'm just gonna leave it and look at it later -- Sea - # try: - # await channel.send( - # f"[Update Checker] Update found for repo: {repo.name}. Updating repos..." - # ) - # except AttributeError: - # owner = (await self.bot.application_info()).owner - # await owner.send( - # "[Update Checker] It appears that the channel for this cog has been deleted. From now on, it will DM you." - # ) - # channel = owner - # await self.conf.gochannel.set(0) - # except discord.errors.Forbidden: - # owner = (await self.bot.application_info()).owner - # await owner.send( - # "[Update Checker] It appears that I am no longer allowed to send messages to the designated update channel. From now on, it will DM you." - # ) - # channel = owner - # await self.conf.gochannel.set(0) - # # Just a copy of `[p]cog update`, but without using ctx things - # try: - # installed_cogs = set(await cog.installed_cogs()) - # updated = await cog._repo_manager.update_all_repos() - # updated_cogs = set( - # cog for repo in updated for cog in repo.available_cogs - # ) - # installed_and_updated = updated_cogs & installed_cogs - # if installed_and_updated: - # await cog._reinstall_requirements(installed_and_updated) - # await cog._reinstall_cogs(installed_and_updated) - # await cog._reinstall_libraries(installed_and_updated) - # cognames = {c.name for c in installed_and_updated} - # message = humanize_list(tuple(map(inline, cognames))) - # except Exception as error: - # exception_log = ( - # "Exception while updating repos in Update Checker \n" - # ) - # exception_log += "".join( - # traceback.format_exception( - # type(error), error, error.__traceback__ - # ) - # ) - # try: - # await channel.send( - # f"[Update Checker]: Error while updating repos.\n\n{exception_log}" - # ) - # except discord.errors.Forbidden: - # pass - # else: - # try: - # await channel.send( - # f"[Update Checker]: Ran cog update. Updated cogs: {message}" - # ) - # except discord.errors.Forbidden: - # pass - await asyncio.sleep(1) - await self.conf.repos.set(saving_dict) + await self.bot.send_to_owners(e) + await self.conf.gochannel.set(0) + # Was already inaccessible before I got here, so I'm just gonna leave it and look at it later -- Sea + # try: + # await channel.send( + # f"[Update Checker] Update found for repo: {repo.name}. Updating repos..." + # ) + # except AttributeError: + # owner = (await self.bot.application_info()).owner + # await owner.send( + # "[Update Checker] It appears that the channel for this cog has been deleted. From now on, it will DM you." + # ) + # channel = owner + # await self.conf.gochannel.set(0) + # except discord.errors.Forbidden: + # owner = (await self.bot.application_info()).owner + # await owner.send( + # "[Update Checker] It appears that I am no longer allowed to send messages to the designated update channel. From now on, it will DM you." + # ) + # channel = owner + # await self.conf.gochannel.set(0) + # # Just a copy of `[p]cog update`, but without using ctx things + # try: + # installed_cogs = set(await cog.installed_cogs()) + # updated = await cog._repo_manager.update_all_repos() + # updated_cogs = set( + # cog for repo in updated for cog in repo.available_cogs + # ) + # installed_and_updated = updated_cogs & installed_cogs + # if installed_and_updated: + # await cog._reinstall_requirements(installed_and_updated) + # await cog._reinstall_cogs(installed_and_updated) + # await cog._reinstall_libraries(installed_and_updated) + # cognames = {c.name for c in installed_and_updated} + # message = humanize_list(tuple(map(inline, cognames))) + # except Exception as error: + # exception_log = ( + # "Exception while updating repos in Update Checker \n" + # ) + # exception_log += "".join( + # traceback.format_exception( + # type(error), error, error.__traceback__ + # ) + # ) + # try: + # await channel.send( + # f"[Update Checker]: Error while updating repos.\n\n{exception_log}" + # ) + # except discord.errors.Forbidden: + # pass + # else: + # try: + # await channel.send( + # f"[Update Checker]: Ran cog update. Updated cogs: {message}" + # ) + # except discord.errors.Forbidden: + # pass + await asyncio.sleep(1) + await self.conf.repos.set(saving_dict) async def fetch_feed(self, url: str): # Thank's to Sinbad's rss cog after which I copied this @@ -315,9 +313,8 @@ class UpdateChecker(commands.Cog): if channel == 0: channel = "Direct Messages" else: - try: - channel = self.bot.get_channel(channel).name - except: + channel = self.bot.get_channel(channel).name + if channel is None: channel = "Unknown" e.add_field(name="Update Channel", value=channel) await ctx.send(embed=e) @@ -325,9 +322,8 @@ class UpdateChecker(commands.Cog): if channel == 0: channel = "Direct Messages" else: - try: - channel = self.bot.get_channel(channel).name - except: + channel = self.bot.get_channel(channel).name + if channel is None: channel = "Unknown" message = ( "```css\n" @@ -363,7 +359,6 @@ class UpdateChecker(commands.Cog): @whiteblacklist.group() async def whitelist(self, ctx): """Whitelist certain repos from which to receive updates.""" - pass @whitelist.command(name="add") async def whitelistadd(self, ctx, *repos: Repo): @@ -396,7 +391,6 @@ class UpdateChecker(commands.Cog): @whiteblacklist.group() async def blacklist(self, ctx): """Blacklist certain repos from which to receive updates.""" - pass @blacklist.command(name="add") async def blacklistadd(self, ctx, *repos: Repo): @@ -430,7 +424,6 @@ class UpdateChecker(commands.Cog): @update.group(name="task") async def _group_update_task(self, ctx): """View the status of the task (the one checking for updates).""" - pass @_group_update_task.command() async def status(self, ctx): @@ -462,5 +455,5 @@ class UpdateChecker(commands.Cog): message = "No error has been encountered." else: ex = traceback.format_exception(type(e), e, e.__traceback__) - message = "An error has been encountered: ```py\n" + "".join(ex) + "```" + message = "An error has been encountered:" + box("".join(ex), "py") await ctx.send(message) -- 2.45.3 From 88ee068cbd2cec08b1ab99b1dbafa22cb8f7eae8 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 19:29:01 +0000 Subject: [PATCH 19/21] fix(updatechecker): final pylint fixes (for now) --- updatechecker/updatechecker.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/updatechecker/updatechecker.py b/updatechecker/updatechecker.py index 1182383..b35a14a 100644 --- a/updatechecker/updatechecker.py +++ b/updatechecker/updatechecker.py @@ -365,7 +365,7 @@ class UpdateChecker(commands.Cog): """Add repos to the whitelist""" data = await self.conf.whitelist() ds = set(data) - ns = set([r.name for r in repos]) + ns = {r.name for r in repos} ss = ds | ns await self.conf.whitelist.set(list(ss)) await ctx.send(f"Whitelist update successful: {humanize_list(tuple(map(inline, ss)))}") @@ -375,7 +375,7 @@ class UpdateChecker(commands.Cog): """Remove repos from the whitelist""" data = await self.conf.whitelist() ds = set(data) - ns = set([r.name for r in repos]) + ns = {r.name for r in repos} ss = ds - ns await self.conf.whitelist.set(list(ss)) await ctx.send( @@ -397,7 +397,7 @@ class UpdateChecker(commands.Cog): """Add repos to the blacklist""" data = await self.conf.blacklist() ds = set(data) - ns = set([r.name for r in repos]) + ns = {r.name for r in repos} ss = ds | ns await self.conf.blacklist.set(list(ss)) await ctx.send(f"Backlist update successful: {humanize_list(tuple(map(inline, ss)))}") @@ -407,7 +407,7 @@ class UpdateChecker(commands.Cog): """Remove repos from the blacklist""" data = await self.conf.blacklist() ds = set(data) - ns = set([r.name for r in repos]) + ns = {r.name for r in repos} ss = ds - ns await self.conf.blacklist.set(list(ss)) await ctx.send( -- 2.45.3 From 50180c6301aeddaf472ddc041ab86c8b504af6ff Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 7 Jan 2024 19:51:18 +0000 Subject: [PATCH 20/21] fix(updatechecker): fixed error in the fetch_gitea_thumbnail method --- updatechecker/updatechecker.py | 38 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/updatechecker/updatechecker.py b/updatechecker/updatechecker.py index b35a14a..0d79d2e 100644 --- a/updatechecker/updatechecker.py +++ b/updatechecker/updatechecker.py @@ -257,7 +257,7 @@ class UpdateChecker(commands.Cog): timeout = aiohttp.client.ClientTimeout(total=15) try: async with self.session.get(url, timeout=timeout) as response: - data = await response.read() + data = await response.json() except (aiohttp.ClientError, asyncio.TimeoutError): return None @@ -265,12 +265,12 @@ class UpdateChecker(commands.Cog): @commands.is_owner() @commands.group(name="cogupdater", aliases=["cu"]) - async def update(self, ctx): + async def update(self, ctx: commands.Context): """Group command for controlling the update checker cog.""" @commands.is_owner() @update.command() - async def auto(self, ctx): + async def auto(self, ctx: commands.Context): """Changes automatic cog updates to the opposite setting.""" # Was already inaccessible before I got here, so I'm just gonna leave it and look at it later -- Sea # auto = await self.conf.auto() @@ -283,7 +283,7 @@ class UpdateChecker(commands.Cog): @commands.is_owner() @update.command() - async def channel(self, ctx, channel: discord.TextChannel = None): + async def channel(self, ctx: commands.Context, channel: discord.TextChannel = None): """ Sets a channel for update messages to go to. @@ -299,7 +299,7 @@ class UpdateChecker(commands.Cog): @commands.is_owner() @update.command() - async def settings(self, ctx): + async def settings(self, ctx: commands.Context): """See settings for the Update Checker cog. Right now, this shows whether the bot updates cogs automatically and what channel logs are sent to. @@ -337,7 +337,7 @@ class UpdateChecker(commands.Cog): @commands.is_owner() @update.command() - async def embed(self, ctx): + async def embed(self, ctx: commands.Context): """Toggles whether to use embeds or colorful codeblock messages when sending an update.""" c = await self.conf.embed() await self.conf.embed.set(not c) @@ -346,7 +346,7 @@ class UpdateChecker(commands.Cog): @commands.is_owner() @update.group(name="list") - async def whiteblacklist(self, ctx): + async def whiteblacklist(self, ctx: commands.Context): """Whitelist/blacklist certain repositories from which to receive updates.""" if ctx.invoked_subcommand is None: data = await self.conf.all() @@ -357,11 +357,11 @@ class UpdateChecker(commands.Cog): ) @whiteblacklist.group() - async def whitelist(self, ctx): + async def whitelist(self, ctx: commands.Context): """Whitelist certain repos from which to receive updates.""" @whitelist.command(name="add") - async def whitelistadd(self, ctx, *repos: Repo): + async def whitelistadd(self, ctx: commands.Context, *repos: Repo): """Add repos to the whitelist""" data = await self.conf.whitelist() ds = set(data) @@ -371,7 +371,7 @@ class UpdateChecker(commands.Cog): await ctx.send(f"Whitelist update successful: {humanize_list(tuple(map(inline, ss)))}") @whitelist.command(name="remove") - async def whitelistremove(self, ctx, *repos: Repo): + async def whitelistremove(self, ctx: commands.Context, *repos: Repo): """Remove repos from the whitelist""" data = await self.conf.whitelist() ds = set(data) @@ -383,17 +383,17 @@ class UpdateChecker(commands.Cog): ) @whitelist.command(name="clear") - async def whitelistclear(self, ctx): + async def whitelistclear(self, ctx: commands.Context): """Removes all repos from the whitelist""" await self.conf.whitelist.set([]) await ctx.send("Whitelist update successful") @whiteblacklist.group() - async def blacklist(self, ctx): + async def blacklist(self, ctx: commands.Context): """Blacklist certain repos from which to receive updates.""" @blacklist.command(name="add") - async def blacklistadd(self, ctx, *repos: Repo): + async def blacklistadd(self, ctx: commands.Context, *repos: Repo): """Add repos to the blacklist""" data = await self.conf.blacklist() ds = set(data) @@ -403,7 +403,7 @@ class UpdateChecker(commands.Cog): await ctx.send(f"Backlist update successful: {humanize_list(tuple(map(inline, ss)))}") @blacklist.command(name="remove") - async def blacklistremove(self, ctx, *repos: Repo): + async def blacklistremove(self, ctx: commands.Context, *repos: Repo): """Remove repos from the blacklist""" data = await self.conf.blacklist() ds = set(data) @@ -415,18 +415,18 @@ class UpdateChecker(commands.Cog): ) @blacklist.command(name="clear") - async def blacklistclear(self, ctx): + async def blacklistclear(self, ctx: commands.Context): """Removes all repos from the blacklist""" await self.conf.blacklist.set([]) await ctx.send("Blacklist update successful") @commands.is_owner() @update.group(name="task") - async def _group_update_task(self, ctx): + async def _group_update_task(self, ctx: commands.Context): """View the status of the task (the one checking for updates).""" @_group_update_task.command() - async def status(self, ctx): + async def status(self, ctx: commands.Context): """Get the current status of the update task.""" message = "Task is currently " cancelled = self.task.cancelled() @@ -443,11 +443,11 @@ class UpdateChecker(commands.Cog): except asyncio.exceptions.InvalidStateError: message += " No error has been encountered." else: - message += " An error has been encountered. Please run `[p]cogupdater task error` and report it to SeaswimmerTheFsh (.seasw) on the help server." + message += f" An error has been encountered. Please run `{ctx.prefix}cogupdater task error` and report it to SeaswimmerTheFsh (.seasw) on the help server." await ctx.send(message) @_group_update_task.command() - async def error(self, ctx): + async def error(self, ctx: commands.Context): """Gets the latest error of the update task.""" try: e = self.task.exception() -- 2.45.3 From 9a7b627854d9ed6826af5a8482f06add1e8f64dd Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 8 Jan 2024 06:06:30 +0000 Subject: [PATCH 21/21] fix(updatechecker): trying to figure out why I'm getting an error --- updatechecker/updatechecker.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/updatechecker/updatechecker.py b/updatechecker/updatechecker.py index 0d79d2e..b323c35 100644 --- a/updatechecker/updatechecker.py +++ b/updatechecker/updatechecker.py @@ -80,6 +80,7 @@ class UpdateChecker(commands.Cog): data = await self.conf.all() repos = data["repos"] channel = data["gochannel"] + auto = data["auto"] use_embed = data["embed"] whitelist = data["whitelist"] blacklist = data["blacklist"] @@ -308,7 +309,7 @@ class UpdateChecker(commands.Cog): channel = await self.conf.gochannel() embed = await self.conf.embed() if embed: - e = discord.Embed(title="Update Checker settings", color=0x00FF00) + e = discord.Embed(title="Update Checker Settings", color=0x00FF00) e.add_field(name="Automatic Cog Updates", value=str(auto)) if channel == 0: channel = "Direct Messages" @@ -443,7 +444,7 @@ class UpdateChecker(commands.Cog): except asyncio.exceptions.InvalidStateError: message += " No error has been encountered." else: - message += f" An error has been encountered. Please run `{ctx.prefix}cogupdater task error` and report it to SeaswimmerTheFsh (.seasw) on the help server." + message += f" An error has been encountered. Please run `{ctx.prefix}cogupdater task error` and report it to SeaswimmerTheFsh (seasw.) on the help server." await ctx.send(message) @_group_update_task.command() -- 2.45.3