WIP: Add UpdateChecker cog #14

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

View file

@ -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()