From 695e903640d6c394dd4f23aa12fef4c7336dc74e Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sat, 16 Apr 2022 16:46:05 +0100 Subject: Output max 10 bumped threads on list --- bot/exts/utils/thread_bumper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/utils/thread_bumper.py b/bot/exts/utils/thread_bumper.py index ee0636b37..6d1c64956 100644 --- a/bot/exts/utils/thread_bumper.py +++ b/bot/exts/utils/thread_bumper.py @@ -111,7 +111,7 @@ class ThreadBumper(commands.Cog): title="Threads in the bump list", colour=constants.Colours.blue ) - await LinePaginator.paginate(lines, ctx, embed) + await LinePaginator.paginate(lines, ctx, embed, max_lines=10) @commands.Cog.listener() async def on_thread_update(self, _: discord.Thread, after: discord.Thread) -> None: -- cgit v1.2.3 From 90d4f908400a09cee127406805d0a7556c26315c Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sat, 16 Apr 2022 17:11:51 +0100 Subject: Use site api over redis for thread bumps --- bot/exts/utils/thread_bumper.py | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/bot/exts/utils/thread_bumper.py b/bot/exts/utils/thread_bumper.py index 6d1c64956..6bd9efc08 100644 --- a/bot/exts/utils/thread_bumper.py +++ b/bot/exts/utils/thread_bumper.py @@ -2,6 +2,7 @@ import typing as t import discord from async_rediscache import RedisCache +from botcore.site_api import ResponseCodeError from discord.ext import commands from bot import constants @@ -11,6 +12,7 @@ from bot.pagination import LinePaginator from bot.utils import channel log = get_logger(__name__) +THREAD_BUMP_ENDPOINT = "bot/bumped-threads" class ThreadBumper(commands.Cog): @@ -45,7 +47,7 @@ class ThreadBumper(commands.Cog): thread.name, thread.id ) - await self.threads_to_bump.delete(thread.id) + await self.bot.api_client.delete(f"{THREAD_BUMP_ENDPOINT}/{thread.id}") else: await thread.edit(archived=False) @@ -54,12 +56,16 @@ class ThreadBumper(commands.Cog): await self.bot.wait_until_guild_available() threads_to_maybe_bump = [] - for thread_id, _ in await self.threads_to_bump.items(): + for thread_id in await self.bot.api_client.get(THREAD_BUMP_ENDPOINT): try: thread = await channel.get_or_fetch_channel(thread_id) except discord.NotFound: log.info("Thread %d has been deleted, removing from bumped threads.", thread_id) - await self.threads_to_bump.delete(thread_id) + await self.bot.api_client.delete(f"{THREAD_BUMP_ENDPOINT}/{thread_id}") + continue + + if not isinstance(thread, discord.Thread): + await self.bot.api_client.delete(f"{THREAD_BUMP_ENDPOINT}/{thread_id}") continue if thread.archived: @@ -82,10 +88,14 @@ class ThreadBumper(commands.Cog): else: raise commands.BadArgument("You must provide a thread, or run this command within a thread.") - if await self.threads_to_bump.contains(thread.id): + try: + await self.bot.api_client.get(f"{THREAD_BUMP_ENDPOINT}/{thread.id}") + except ResponseCodeError: + pass + else: raise commands.BadArgument("This thread is already in the bump list.") - await self.threads_to_bump.set(thread.id, "sentinel") + await self.bot.api_client.post(THREAD_BUMP_ENDPOINT, data={"thread_id": thread.id}) await ctx.send(f":ok_hand:{thread.mention} has been added to the bump list.") @thread_bump_group.command(name="remove", aliases=("r", "rem", "d", "del", "delete")) @@ -97,16 +107,18 @@ class ThreadBumper(commands.Cog): else: raise commands.BadArgument("You must provide a thread, or run this command within a thread.") - if not await self.threads_to_bump.contains(thread.id): + try: + await self.bot.api_client.get(f"{THREAD_BUMP_ENDPOINT}/{thread.id}") + except ResponseCodeError: raise commands.BadArgument("This thread is not in the bump list.") - await self.threads_to_bump.delete(thread.id) + await self.bot.api_client.delete(f"{THREAD_BUMP_ENDPOINT}/{thread.id}") await ctx.send(f":ok_hand: {thread.mention} has been removed from the bump list.") @thread_bump_group.command(name="list", aliases=("get",)) async def list_all_threads_in_bump_list(self, ctx: commands.Context) -> None: """List all the threads in the bump list.""" - lines = [f"<#{k}>" for k, _ in await self.threads_to_bump.items()] + lines = [f"<#{thread_id}>" for thread_id in await self.bot.api_client.get(THREAD_BUMP_ENDPOINT)] embed = discord.Embed( title="Threads in the bump list", colour=constants.Colours.blue @@ -123,7 +135,11 @@ class ThreadBumper(commands.Cog): if not after.archived: return - if await self.threads_to_bump.contains(after.id): + try: + await self.bot.api_client.get(f"{THREAD_BUMP_ENDPOINT}/{after.id}") + except ResponseCodeError: + pass + else: await self.unarchive_threads_not_manually_archived([after]) async def cog_check(self, ctx: commands.Context) -> bool: -- cgit v1.2.3 From a196ec9d49c8da3bcca0f6a84b06b383797e6af7 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sat, 16 Apr 2022 17:14:31 +0100 Subject: Only call unarchive threads if there are threads to send --- bot/exts/utils/thread_bumper.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bot/exts/utils/thread_bumper.py b/bot/exts/utils/thread_bumper.py index 6bd9efc08..8d0ebdf1c 100644 --- a/bot/exts/utils/thread_bumper.py +++ b/bot/exts/utils/thread_bumper.py @@ -71,7 +71,8 @@ class ThreadBumper(commands.Cog): if thread.archived: threads_to_maybe_bump.append(thread) - await self.unarchive_threads_not_manually_archived(threads_to_maybe_bump) + if threads_to_maybe_bump: + await self.unarchive_threads_not_manually_archived(threads_to_maybe_bump) @commands.group(name="bump") async def thread_bump_group(self, ctx: commands.Context) -> None: -- cgit v1.2.3 From 930bf0f9203cf38b8b88a59d44e277ccc6201811 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sat, 16 Apr 2022 17:25:13 +0100 Subject: Only suppress 404s from site when checking for bumped threads --- bot/exts/utils/thread_bumper.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bot/exts/utils/thread_bumper.py b/bot/exts/utils/thread_bumper.py index 8d0ebdf1c..743919d4e 100644 --- a/bot/exts/utils/thread_bumper.py +++ b/bot/exts/utils/thread_bumper.py @@ -91,8 +91,9 @@ class ThreadBumper(commands.Cog): try: await self.bot.api_client.get(f"{THREAD_BUMP_ENDPOINT}/{thread.id}") - except ResponseCodeError: - pass + except ResponseCodeError as e: + if e.status != 404: + raise else: raise commands.BadArgument("This thread is already in the bump list.") @@ -138,8 +139,9 @@ class ThreadBumper(commands.Cog): try: await self.bot.api_client.get(f"{THREAD_BUMP_ENDPOINT}/{after.id}") - except ResponseCodeError: - pass + except ResponseCodeError as e: + if e.status != 404: + raise else: await self.unarchive_threads_not_manually_archived([after]) -- cgit v1.2.3 From 12b1f82c1a2757466469ffe236209d18feb4bc5e Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Thu, 28 Apr 2022 08:11:49 +0100 Subject: Use async with Messageable.typing() everywhere Closes BOT-33Z Closes #2154 With the latest version of discord.py support for the with Messageable.typingn() was droped, in favour of only using async with. --- bot/exts/info/doc/_cog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/info/doc/_cog.py b/bot/exts/info/doc/_cog.py index 079bfc942..dece44063 100644 --- a/bot/exts/info/doc/_cog.py +++ b/bot/exts/info/doc/_cog.py @@ -431,7 +431,7 @@ class DocCog(commands.Cog): async def refresh_command(self, ctx: commands.Context) -> None: """Refresh inventories and show the difference.""" old_inventories = set(self.base_urls) - with ctx.typing(): + async with ctx.typing(): await self.refresh_inventories() new_inventories = set(self.base_urls) -- cgit v1.2.3 From f57b48d4ac1418fa2e885255c6b302687e0a51b2 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Fri, 29 Apr 2022 19:27:27 -0400 Subject: Update wording for or-gotcha tag --- bot/resources/tags/or-gotcha.md | 1 + 1 file changed, 1 insertion(+) diff --git a/bot/resources/tags/or-gotcha.md b/bot/resources/tags/or-gotcha.md index d75a73d78..25ade8620 100644 --- a/bot/resources/tags/or-gotcha.md +++ b/bot/resources/tags/or-gotcha.md @@ -1,5 +1,6 @@ When checking if something is equal to one thing or another, you might think that this is possible: ```py +# Incorrect... if favorite_fruit == 'grapefruit' or 'lemon': print("That's a weird favorite fruit to have.") ``` -- cgit v1.2.3