From c5b4a94a2eee3efe5627d52cb656be9eb09b4ed6 Mon Sep 17 00:00:00 2001 From: Kronifer <44979306+Kronifer@users.noreply.github.com> Date: Tue, 1 Jun 2021 10:32:32 -0500 Subject: command finished --- bot/exts/evergreen/avatar_modification/avatar_modify.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index 442df2f0..c4f5915e 100644 --- a/bot/exts/evergreen/avatar_modification/avatar_modify.py +++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py @@ -121,12 +121,12 @@ class AvatarModify(commands.Cog): await ctx.send(embed=embed, file=file) - @avatar_modify.command(aliases=("flip", "mirror")) + @avatar_modify.command(name="reverse", root_aliases=("reverse",)) async def reverse(self, ctx: commands.Context, *, text: t.Optional[str]) -> None: """Either flips your profile picture or the submitted text.""" if not text: async with ctx.typing(): - user = self._fetch_user(ctx.author.id) + user = await self._fetch_user(ctx.author.id) image_bytes = await user.avatar_url_as(size=1024).read() file_name = file_safe_name("reverse_avatar", ctx.author.display_name) @@ -143,10 +143,11 @@ class AvatarModify(commands.Cog): ) embed.set_image(url=f"attachment://{file_name}") - embed.set_footer(f"Made by {ctx.author.display_name}.", icon_url=user.avatar_url) + embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=user.avatar_url) await ctx.send(embed=embed, file=file) - + else: + await ctx.send(f"> {text[::-1]}") @avatar_modify.command(aliases=("easterify",), root_aliases=("easterify", "avatareasterify")) async def avatareasterify(self, ctx: commands.Context, *colours: t.Union[discord.Colour, str]) -> None: -- cgit v1.2.3 From ef3198074d5e1bf76fa3295993e4f1031a651f0e Mon Sep 17 00:00:00 2001 From: Kronifer <44979306+Kronifer@users.noreply.github.com> Date: Tue, 1 Jun 2021 10:38:48 -0500 Subject: Blocked mentions. --- bot/exts/evergreen/avatar_modification/avatar_modify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index c4f5915e..6789f44a 100644 --- a/bot/exts/evergreen/avatar_modification/avatar_modify.py +++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py @@ -147,7 +147,7 @@ class AvatarModify(commands.Cog): await ctx.send(embed=embed, file=file) else: - await ctx.send(f"> {text[::-1]}") + await ctx.send(f"> {text[::-1]}", allowed_mentions=discord.AllowedMentions.none()) @avatar_modify.command(aliases=("easterify",), root_aliases=("easterify", "avatareasterify")) async def avatareasterify(self, ctx: commands.Context, *colours: t.Union[discord.Colour, str]) -> None: -- cgit v1.2.3 From a25b9a2fea3ba48dd1ad036018169f6261894d39 Mon Sep 17 00:00:00 2001 From: Kronifer <44979306+Kronifer@users.noreply.github.com> Date: Tue, 1 Jun 2021 11:02:34 -0500 Subject: changes asked for by chris --- bot/exts/evergreen/avatar_modification/_effects.py | 3 +-- bot/exts/evergreen/avatar_modification/avatar_modify.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/avatar_modification/_effects.py b/bot/exts/evergreen/avatar_modification/_effects.py index 7811d148..c5e5cb86 100644 --- a/bot/exts/evergreen/avatar_modification/_effects.py +++ b/bot/exts/evergreen/avatar_modification/_effects.py @@ -97,13 +97,12 @@ class PfpEffects: return image.quantize() @staticmethod - def reverse_effect(image: Image.Image) -> Image.Image: + def flip_effect(image: Image.Image) -> Image.Image: """ Flips the image horizontally. This is done by just using ImageOps.flip(). """ - image = image.resize((1024, 1024)) image = ImageOps.mirror(image) return image diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index 6789f44a..4ed7f79d 100644 --- a/bot/exts/evergreen/avatar_modification/avatar_modify.py +++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py @@ -124,7 +124,7 @@ class AvatarModify(commands.Cog): @avatar_modify.command(name="reverse", root_aliases=("reverse",)) async def reverse(self, ctx: commands.Context, *, text: t.Optional[str]) -> None: """Either flips your profile picture or the submitted text.""" - if not text: + if text is None: async with ctx.typing(): user = await self._fetch_user(ctx.author.id) image_bytes = await user.avatar_url_as(size=1024).read() @@ -133,7 +133,7 @@ class AvatarModify(commands.Cog): file = await in_executor( PfpEffects.apply_effect, image_bytes, - PfpEffects.reverse_effect, + PfpEffects.flip_effect, file_name ) -- cgit v1.2.3 From fe529ddb89f34f8274b7c979a9508966b14c8d7f Mon Sep 17 00:00:00 2001 From: Kronifer <44979306+Kronifer@users.noreply.github.com> Date: Tue, 1 Jun 2021 11:20:10 -0500 Subject: checked if user returns None --- bot/exts/evergreen/avatar_modification/avatar_modify.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'bot') diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index 4ed7f79d..98f5f132 100644 --- a/bot/exts/evergreen/avatar_modification/avatar_modify.py +++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py @@ -127,6 +127,9 @@ class AvatarModify(commands.Cog): if text is None: async with ctx.typing(): user = await self._fetch_user(ctx.author.id) + if not user: + await ctx.send(f"{Emojis.cross_mark} Could not get user info.") + return image_bytes = await user.avatar_url_as(size=1024).read() file_name = file_safe_name("reverse_avatar", ctx.author.display_name) -- cgit v1.2.3 From 2c63f7fd419c506568e705093e9478b9cf29f4a8 Mon Sep 17 00:00:00 2001 From: Kronifer <44979306+Kronifer@users.noreply.github.com> Date: Tue, 1 Jun 2021 11:30:09 -0500 Subject: Small docstring change. Co-authored-by: ChrisJL --- bot/exts/evergreen/avatar_modification/_effects.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/evergreen/avatar_modification/_effects.py b/bot/exts/evergreen/avatar_modification/_effects.py index c5e5cb86..46d1a2ab 100644 --- a/bot/exts/evergreen/avatar_modification/_effects.py +++ b/bot/exts/evergreen/avatar_modification/_effects.py @@ -101,7 +101,7 @@ class PfpEffects: """ Flips the image horizontally. - This is done by just using ImageOps.flip(). + This is done by just using ImageOps.mirror(). """ image = ImageOps.mirror(image) -- cgit v1.2.3 From fcd635fe6209ce8021e6129fb1df0dd610fb451e Mon Sep 17 00:00:00 2001 From: Kronifer <44979306+Kronifer@users.noreply.github.com> Date: Tue, 1 Jun 2021 14:09:16 -0500 Subject: started cmd group --- .../evergreen/avatar_modification/avatar_modify.py | 58 ++++++++++++---------- 1 file changed, 33 insertions(+), 25 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index 98f5f132..526ad3d0 100644 --- a/bot/exts/evergreen/avatar_modification/avatar_modify.py +++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py @@ -121,36 +121,44 @@ class AvatarModify(commands.Cog): await ctx.send(embed=embed, file=file) - @avatar_modify.command(name="reverse", root_aliases=("reverse",)) - async def reverse(self, ctx: commands.Context, *, text: t.Optional[str]) -> None: - """Either flips your profile picture or the submitted text.""" - if text is None: - async with ctx.typing(): - user = await self._fetch_user(ctx.author.id) - if not user: - await ctx.send(f"{Emojis.cross_mark} Could not get user info.") - return - image_bytes = await user.avatar_url_as(size=1024).read() - file_name = file_safe_name("reverse_avatar", ctx.author.display_name) + @avatar_modify.group(name="reverse") + async def reverse(self, ctx: commands.Context) -> None: + if not ctx.invoked_subcommand: + await invoke_help_command(ctx) - file = await in_executor( - PfpEffects.apply_effect, - image_bytes, - PfpEffects.flip_effect, - file_name - ) + @reverse.command(name="text") + async def text(self, ctx: commands.Context, *, text: str) -> None: + """Sends the given text backwards.""" + await ctx.send(f"> {text[::-1]}", allowed_mentions=discord.AllowedMentions.none()) - embed = discord.Embed( - title="Your reversed avatar", - description="Here is your avatar. I think it's a spitting image of you." - ) + @reverse.command(name="image") + async def image(self, ctx: commands.Context) -> None: + """Sends a reversed version of the users profile picture.""" + async with ctx.typing(): + user = self._fetch_user(ctx.author.id) + if not user: + await ctx.send(f"{Emojis.cross_mark} Could not get user info.") + return + + image_bytes = await user.avatar_url_as(size=1024).read() + filename = file_safe_name("reverse_avatar", ctx.author.display_name) - embed.set_image(url=f"attachment://{file_name}") - embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=user.avatar_url) + file = await in_executor( + PfpEffects.apply_effect, + image_bytes, + PfpEffects.flip_effect, + filename + ) + + embed = discord.Embed( + title="Your reversed avatar.", + description="Here is your reversed avatar. I think it is a spitting image of you." + ) + + embed.set_image(f"attachment://{filename}") + embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=user.avatar_url) await ctx.send(embed=embed, file=file) - else: - await ctx.send(f"> {text[::-1]}", allowed_mentions=discord.AllowedMentions.none()) @avatar_modify.command(aliases=("easterify",), root_aliases=("easterify", "avatareasterify")) async def avatareasterify(self, ctx: commands.Context, *colours: t.Union[discord.Colour, str]) -> None: -- cgit v1.2.3 From 5be1c59450c363b5f4483d3e46a82780ea229632 Mon Sep 17 00:00:00 2001 From: Kronifer <44979306+Kronifer@users.noreply.github.com> Date: Wed, 2 Jun 2021 09:51:00 -0500 Subject: Finished extra functionality --- .../evergreen/avatar_modification/avatar_modify.py | 50 +++++++++++++++++++--- 1 file changed, 43 insertions(+), 7 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index 526ad3d0..940ff69e 100644 --- a/bot/exts/evergreen/avatar_modification/avatar_modify.py +++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py @@ -9,6 +9,7 @@ from concurrent.futures import ThreadPoolExecutor from pathlib import Path import discord +from PIL import UnidentifiedImageError from aiohttp import client_exceptions from discord.ext import commands @@ -121,8 +122,9 @@ class AvatarModify(commands.Cog): await ctx.send(embed=embed, file=file) - @avatar_modify.group(name="reverse") + @avatar_modify.group(name="reverse", root_aliases=['reverse']) async def reverse(self, ctx: commands.Context) -> None: + """Group for the reverse commands.""" if not ctx.invoked_subcommand: await invoke_help_command(ctx) @@ -132,14 +134,48 @@ class AvatarModify(commands.Cog): await ctx.send(f"> {text[::-1]}", allowed_mentions=discord.AllowedMentions.none()) @reverse.command(name="image") - async def image(self, ctx: commands.Context) -> None: - """Sends a reversed version of the users profile picture.""" + async def photo(self, ctx: commands.Context) -> None: + """ + Sends a reversed version of the users profile picture. + + If an image is attached, the given image will be flipped. + """ async with ctx.typing(): - user = self._fetch_user(ctx.author.id) + user = await self._fetch_user(ctx.author.id) if not user: await ctx.send(f"{Emojis.cross_mark} Could not get user info.") return - + if ctx.message.attachments: + url = str(ctx.message.attachments[0]) + async with self.bot.http_session.get(url) as r: + image_bytes = await r.read() + filename = file_safe_name("reverse_image", ctx.author.display_name) + + try: + file = await in_executor( + PfpEffects.apply_effect, + image_bytes, + PfpEffects.flip_effect, + filename + ) + except UnidentifiedImageError: + raise commands.BadArgument( + "The attachment given is not an image. Please ensure you send an image." + ) + return + + embed = discord.Embed( + title="Your reversed image.", + description="Here is your reversed image. I think it looks somewhat flipped." + ) + + embed.set_image(url=f"attachment://{filename}") + embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=user.avatar_url) + + await ctx.send(embed=embed, file=file) + + return + image_bytes = await user.avatar_url_as(size=1024).read() filename = file_safe_name("reverse_avatar", ctx.author.display_name) @@ -151,11 +187,11 @@ class AvatarModify(commands.Cog): ) embed = discord.Embed( - title="Your reversed avatar.", + title="Your reversed avatar.", description="Here is your reversed avatar. I think it is a spitting image of you." ) - embed.set_image(f"attachment://{filename}") + embed.set_image(url=f"attachment://{filename}") embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=user.avatar_url) await ctx.send(embed=embed, file=file) -- cgit v1.2.3 From 132af40b9a4d17252dfb77f38e41eee0d0e90980 Mon Sep 17 00:00:00 2001 From: Kronifer <44979306+Kronifer@users.noreply.github.com> Date: Fri, 4 Jun 2021 14:18:57 -0500 Subject: Small renaming Co-authored-by: ChrisJL --- bot/exts/evergreen/avatar_modification/avatar_modify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index 940ff69e..952f2350 100644 --- a/bot/exts/evergreen/avatar_modification/avatar_modify.py +++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py @@ -129,7 +129,7 @@ class AvatarModify(commands.Cog): await invoke_help_command(ctx) @reverse.command(name="text") - async def text(self, ctx: commands.Context, *, text: str) -> None: + async def reverse_text(self, ctx: commands.Context, *, text: str) -> None: """Sends the given text backwards.""" await ctx.send(f"> {text[::-1]}", allowed_mentions=discord.AllowedMentions.none()) -- cgit v1.2.3 From c866096a06ac35c751c1b1ec66de5e525f1ec5e4 Mon Sep 17 00:00:00 2001 From: Kronifer <44979306+Kronifer@users.noreply.github.com> Date: Fri, 4 Jun 2021 14:19:17 -0500 Subject: Another rename Co-authored-by: ChrisJL --- bot/exts/evergreen/avatar_modification/avatar_modify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index 952f2350..154fe5de 100644 --- a/bot/exts/evergreen/avatar_modification/avatar_modify.py +++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py @@ -134,7 +134,7 @@ class AvatarModify(commands.Cog): await ctx.send(f"> {text[::-1]}", allowed_mentions=discord.AllowedMentions.none()) @reverse.command(name="image") - async def photo(self, ctx: commands.Context) -> None: + async def reverse_photo(self, ctx: commands.Context) -> None: """ Sends a reversed version of the users profile picture. -- cgit v1.2.3 From 9ecaf7cbad9e34da467fa2612b81ff407ec227df Mon Sep 17 00:00:00 2001 From: Kronifer <44979306+Kronifer@users.noreply.github.com> Date: Fri, 4 Jun 2021 14:19:44 -0500 Subject: Removed the file upload Co-authored-by: ChrisJL --- .../evergreen/avatar_modification/avatar_modify.py | 30 ---------------------- 1 file changed, 30 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index 154fe5de..9356a9e7 100644 --- a/bot/exts/evergreen/avatar_modification/avatar_modify.py +++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py @@ -145,36 +145,6 @@ class AvatarModify(commands.Cog): if not user: await ctx.send(f"{Emojis.cross_mark} Could not get user info.") return - if ctx.message.attachments: - url = str(ctx.message.attachments[0]) - async with self.bot.http_session.get(url) as r: - image_bytes = await r.read() - filename = file_safe_name("reverse_image", ctx.author.display_name) - - try: - file = await in_executor( - PfpEffects.apply_effect, - image_bytes, - PfpEffects.flip_effect, - filename - ) - except UnidentifiedImageError: - raise commands.BadArgument( - "The attachment given is not an image. Please ensure you send an image." - ) - return - - embed = discord.Embed( - title="Your reversed image.", - description="Here is your reversed image. I think it looks somewhat flipped." - ) - - embed.set_image(url=f"attachment://{filename}") - embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=user.avatar_url) - - await ctx.send(embed=embed, file=file) - - return image_bytes = await user.avatar_url_as(size=1024).read() filename = file_safe_name("reverse_avatar", ctx.author.display_name) -- cgit v1.2.3 From 19b647f1f2613fe5f1cce006d9bf2f20ec8765c1 Mon Sep 17 00:00:00 2001 From: Kronifer <44979306+Kronifer@users.noreply.github.com> Date: Mon, 7 Jun 2021 09:19:05 -0500 Subject: Removed import --- bot/exts/evergreen/avatar_modification/avatar_modify.py | 1 - 1 file changed, 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index 9356a9e7..b482f42e 100644 --- a/bot/exts/evergreen/avatar_modification/avatar_modify.py +++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py @@ -9,7 +9,6 @@ from concurrent.futures import ThreadPoolExecutor from pathlib import Path import discord -from PIL import UnidentifiedImageError from aiohttp import client_exceptions from discord.ext import commands -- cgit v1.2.3 From 8e653f4f6fc64ad78809e5ec1943ee38865bf221 Mon Sep 17 00:00:00 2001 From: wookie184 Date: Fri, 6 Aug 2021 16:34:19 +0100 Subject: Replace fuzzywuzzy with rapidfuzz --- bot/exts/evergreen/help.py | 4 +- bot/exts/evergreen/snakes/_converter.py | 2 +- bot/exts/evergreen/trivia_quiz.py | 2 +- bot/exts/pride/pride_leader.py | 2 +- poetry.lock | 88 +++++++++++++++++++++++++++------ pyproject.toml | 2 +- 6 files changed, 78 insertions(+), 22 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/help.py b/bot/exts/evergreen/help.py index 3c9ba4d2..bfb5db17 100644 --- a/bot/exts/evergreen/help.py +++ b/bot/exts/evergreen/help.py @@ -8,7 +8,7 @@ from typing import List, NamedTuple, Union from discord import Colour, Embed, HTTPException, Message, Reaction, User from discord.ext import commands from discord.ext.commands import CheckFailure, Cog as DiscordCog, Command, Context -from fuzzywuzzy import fuzz, process +from rapidfuzz import process from bot import constants from bot.bot import Bot @@ -159,7 +159,7 @@ class HelpSession: # Combine command and cog names choices = list(self._bot.all_commands) + list(self._bot.cogs) - result = process.extractBests(query, choices, scorer=fuzz.ratio, score_cutoff=90) + result = process.extract(query, choices, score_cutoff=90) raise HelpQueryNotFound(f'Query "{query}" not found.', dict(result)) diff --git a/bot/exts/evergreen/snakes/_converter.py b/bot/exts/evergreen/snakes/_converter.py index 26bde611..c8d1909b 100644 --- a/bot/exts/evergreen/snakes/_converter.py +++ b/bot/exts/evergreen/snakes/_converter.py @@ -5,7 +5,7 @@ from typing import Iterable, List import discord from discord.ext.commands import Context, Converter -from fuzzywuzzy import fuzz +from rapidfuzz import fuzz from bot.exts.evergreen.snakes._utils import SNAKE_RESOURCES from bot.utils import disambiguate diff --git a/bot/exts/evergreen/trivia_quiz.py b/bot/exts/evergreen/trivia_quiz.py index 28924aed..bc25cbf7 100644 --- a/bot/exts/evergreen/trivia_quiz.py +++ b/bot/exts/evergreen/trivia_quiz.py @@ -9,7 +9,7 @@ from typing import Callable, List, Optional import discord from discord.ext import commands -from fuzzywuzzy import fuzz +from rapidfuzz import fuzz from bot.bot import Bot from bot.constants import Colours, NEGATIVE_REPLIES, Roles diff --git a/bot/exts/pride/pride_leader.py b/bot/exts/pride/pride_leader.py index c3426ad1..8e88183b 100644 --- a/bot/exts/pride/pride_leader.py +++ b/bot/exts/pride/pride_leader.py @@ -6,7 +6,7 @@ from typing import Optional import discord from discord.ext import commands -from fuzzywuzzy import fuzz +from rapidfuzz import fuzz from bot import bot from bot import constants diff --git a/poetry.lock b/poetry.lock index 861dca0b..64709d7a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -316,17 +316,6 @@ python-versions = "*" [package.dependencies] pycodestyle = ">=2.0.0,<3.0.0" -[[package]] -name = "fuzzywuzzy" -version = "0.18.0" -description = "Fuzzy string matching in python" -category = "main" -optional = false -python-versions = "*" - -[package.extras] -speedup = ["python-levenshtein (>=0.12)"] - [[package]] name = "hiredis" version = "2.0.0" @@ -567,6 +556,14 @@ category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" +[[package]] +name = "rapidfuzz" +version = "1.4.1" +description = "rapid fuzzy string matching" +category = "main" +optional = false +python-versions = ">=3.5" + [[package]] name = "redis" version = "3.5.3" @@ -707,7 +704,7 @@ multidict = ">=4.0" [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "a73732d7a2ea8348dd9e38b87677eeab0ece557ba5f56a24a0bed88c07f4d78d" +content-hash = "a62da963535ba0b679739b026c6d86f6b2c1993b50e81c06d7d89f63507b9aa1" [metadata.files] aiodns = [ @@ -899,10 +896,6 @@ flake8-tidy-imports = [ flake8-todo = [ {file = "flake8-todo-0.7.tar.gz", hash = "sha256:6e4c5491ff838c06fe5a771b0e95ee15fc005ca57196011011280fc834a85915"}, ] -fuzzywuzzy = [ - {file = "fuzzywuzzy-0.18.0-py2.py3-none-any.whl", hash = "sha256:928244b28db720d1e0ee7587acf660ea49d7e4c632569cad4f1cd7e68a5f0993"}, - {file = "fuzzywuzzy-0.18.0.tar.gz", hash = "sha256:45016e92264780e58972dca1b3d939ac864b78437422beecebb3095f8efd00e8"}, -] hiredis = [ {file = "hiredis-2.0.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:b4c8b0bc5841e578d5fb32a16e0c305359b987b850a06964bd5a62739d688048"}, {file = "hiredis-2.0.0-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:0adea425b764a08270820531ec2218d0508f8ae15a448568109ffcae050fee26"}, @@ -1267,6 +1260,69 @@ pyyaml = [ {file = "PyYAML-5.4.1-cp39-cp39-win_amd64.whl", hash = "sha256:c20cfa2d49991c8b4147af39859b167664f2ad4561704ee74c1de03318e898db"}, {file = "PyYAML-5.4.1.tar.gz", hash = "sha256:607774cbba28732bfa802b54baa7484215f530991055bb562efbed5b2f20a45e"}, ] +rapidfuzz = [ + {file = "rapidfuzz-1.4.1-cp35-cp35m-macosx_10_9_x86_64.whl", hash = "sha256:72878878d6744883605b5453c382361716887e9e552f677922f76d93d622d8cb"}, + {file = "rapidfuzz-1.4.1-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:56a67a5b3f783e9af73940f6945366408b3a2060fc6ab18466e5a2894fd85617"}, + {file = "rapidfuzz-1.4.1-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:f5d396b64f8ae3a793633911a1fb5d634ac25bf8f13d440139fa729131be42d8"}, + {file = "rapidfuzz-1.4.1-cp35-cp35m-manylinux2010_i686.whl", hash = "sha256:4990698233e7eda7face7c09f5874a09760c7524686045cbb10317e3a7f3225f"}, + {file = "rapidfuzz-1.4.1-cp35-cp35m-manylinux2010_x86_64.whl", hash = "sha256:a87e212855b18a951e79ec71d71dbd856d98cd2019d0c2bd46ec30688a8aa68a"}, + {file = "rapidfuzz-1.4.1-cp35-cp35m-manylinux2014_aarch64.whl", hash = "sha256:1897d2ef03f5b51bc19bdb2d0398ae968766750fa319843733f0a8f12ddde986"}, + {file = "rapidfuzz-1.4.1-cp35-cp35m-manylinux2014_ppc64le.whl", hash = "sha256:e1fc4fd219057f5f1fa40bb9bc5e880f8ef45bf19350d4f5f15ca2ce7f61c99b"}, + {file = "rapidfuzz-1.4.1-cp35-cp35m-manylinux2014_s390x.whl", hash = "sha256:21300c4d048798985c271a8bf1ed1611902ebd4479fcacda1a3eaaebbad2f744"}, + {file = "rapidfuzz-1.4.1-cp35-cp35m-win32.whl", hash = "sha256:d2659967c6ac74211a87a1109e79253e4bc179641057c64800ef4e2dc0534fdb"}, + {file = "rapidfuzz-1.4.1-cp35-cp35m-win_amd64.whl", hash = "sha256:26ac4bfe564c516e053fc055f1543d2b2433338806738c7582e1f75ed0485f7e"}, + {file = "rapidfuzz-1.4.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:3b485c98ad1ce3c04556f65aaab5d6d6d72121cde656d43505169c71ae956476"}, + {file = "rapidfuzz-1.4.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:59db06356eaf22c83f44b0dded964736cbb137291cdf2cf7b4974c0983b94932"}, + {file = "rapidfuzz-1.4.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:fef95249af9a535854b617a68788c38cd96308d97ee14d44bc598cc73e986167"}, + {file = "rapidfuzz-1.4.1-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:7d8c186e8270e103d339b26ef498581cf3178470ccf238dfd5fd0e47d80e4c7d"}, + {file = "rapidfuzz-1.4.1-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:9246b9c5c8992a83a08ac7813c8bbff2e674ad0b681f9b3fb1ec7641eff6c21f"}, + {file = "rapidfuzz-1.4.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:f58c17f7a82b1bcc2ce304942cae14287223e6b6eead7071241273da7d9b9770"}, + {file = "rapidfuzz-1.4.1-cp36-cp36m-manylinux2014_ppc64le.whl", hash = "sha256:ed708620b23a09ac52eaaec0761943c1bbc9a62d19ecd2feb4da8c3f79ef9d37"}, + {file = "rapidfuzz-1.4.1-cp36-cp36m-manylinux2014_s390x.whl", hash = "sha256:bdec9ae5fd8a8d4d8813b4aac3505c027b922b4033a32a7aab66a9b2f03a7b47"}, + {file = "rapidfuzz-1.4.1-cp36-cp36m-win32.whl", hash = "sha256:fc668fd706ad1162ce14f26ca2957b4690d47770d23609756536c918a855ced0"}, + {file = "rapidfuzz-1.4.1-cp36-cp36m-win_amd64.whl", hash = "sha256:f9f35df5dd9b02669ff6b1d4a386607ff56982c86a7e57d95eb08c6afbab4ddd"}, + {file = "rapidfuzz-1.4.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8427310ea29ce2968e1c6f6779ae5a458b3a4984f9150fc4d16f92b96456f848"}, + {file = "rapidfuzz-1.4.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:1430dc745476e3798742ad835f61f6e6bf5d3e9a22cf9cd0288b28b7440a9872"}, + {file = "rapidfuzz-1.4.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:1d20311da611c8f4638a09e2bc5e04b327bae010cb265ef9628d9c13c6d5da7b"}, + {file = "rapidfuzz-1.4.1-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:d7881965e428cf6fe248d6e702e6d5857da02278ab9b21313bee717c080e443e"}, + {file = "rapidfuzz-1.4.1-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:f76c965f15861ec4d39e904bd65b84a39121334439ac17bfb8b900d1e6779a93"}, + {file = "rapidfuzz-1.4.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:61167f989415e701ac379de247e6b0a21ea62afc86c54d8a79f485b4f0173c02"}, + {file = "rapidfuzz-1.4.1-cp37-cp37m-manylinux2014_ppc64le.whl", hash = "sha256:645cfb9456229f0bd5752b3eda69f221d825fbb8cbb8855433516bc185111506"}, + {file = "rapidfuzz-1.4.1-cp37-cp37m-manylinux2014_s390x.whl", hash = "sha256:c28be57c9bc47b3d7f484340fab1bec8ed4393dee1090892c2774a4584435eb8"}, + {file = "rapidfuzz-1.4.1-cp37-cp37m-win32.whl", hash = "sha256:3c94b6d3513c693f253ff762112cc4580d3bd377e4abacb96af31a3d606fbe14"}, + {file = "rapidfuzz-1.4.1-cp37-cp37m-win_amd64.whl", hash = "sha256:506d50a066451502ee2f8bf016bc3ba3e3b04eede7a4059d7956248e2dd96179"}, + {file = "rapidfuzz-1.4.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:80b375098658bb3db14215a975d354f6573d3943ac2ae0c4627c7760d57ce075"}, + {file = "rapidfuzz-1.4.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:ba8f7cbd8fdbd3ae115f4484888f3cb94bc2ac7cbd4eb1ca95a3d4f874261ff8"}, + {file = "rapidfuzz-1.4.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:5fa8570720b0fdfc52f24f5663d66c52ea88ba19cb8b1ff6a39a8bc0b925b33b"}, + {file = "rapidfuzz-1.4.1-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:f35c8a4c690447fd335bfd77df4da42dfea37cfa06a8ecbf22543d86dc720e12"}, + {file = "rapidfuzz-1.4.1-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:27f9eef48e212d73e78f0f5ceedc62180b68f6a25fa0752d2ccfaedc3a840bec"}, + {file = "rapidfuzz-1.4.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:31e99216e2a04aec4f281d472b28a683921f1f669a429cf605d11526623eaeed"}, + {file = "rapidfuzz-1.4.1-cp38-cp38-manylinux2014_ppc64le.whl", hash = "sha256:f22bf7ba6eddd59764457f74c637ab5c3ed976c5fcfaf827e1d320cc0478e12b"}, + {file = "rapidfuzz-1.4.1-cp38-cp38-manylinux2014_s390x.whl", hash = "sha256:c43ddb354abd00e56f024ce80affb3023fa23206239bb81916d5877cba7f2d1e"}, + {file = "rapidfuzz-1.4.1-cp38-cp38-win32.whl", hash = "sha256:62c1f4ac20c8019ce8d481fb27235306ef3912a8d0b9a60b17905699f43ff072"}, + {file = "rapidfuzz-1.4.1-cp38-cp38-win_amd64.whl", hash = "sha256:2963f356c70b710dc6337b012ec976ce2fc2b81c2a9918a686838fead6eb4e1d"}, + {file = "rapidfuzz-1.4.1-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:c07f301fd549b266410654850c6918318d7dcde8201350e9ac0819f0542cf147"}, + {file = "rapidfuzz-1.4.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:fa4c8b6fc7e93e3a3fb9be9566f1fe7ef920735eadcee248a0d70f3ca8941341"}, + {file = "rapidfuzz-1.4.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:c200bd813bbd3b146ba0fd284a9ad314bbad9d95ed542813273bdb9d0ee4e796"}, + {file = "rapidfuzz-1.4.1-cp39-cp39-manylinux1_i686.whl", hash = "sha256:2cccc84e1f0c6217747c09cafe93164e57d3644e18a334845a2dfbdd2073cd2c"}, + {file = "rapidfuzz-1.4.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:f2033e3d61d1e498f618123b54dc7436d50510b0d18fd678d867720e8d7b2f23"}, + {file = "rapidfuzz-1.4.1-cp39-cp39-manylinux2010_i686.whl", hash = "sha256:26b7f48b3ddd9d97cf8482a88f0f6cba47ac13ff16e63386ea7ce06178174770"}, + {file = "rapidfuzz-1.4.1-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:bf18614f87fe3bfff783f0a3d0fad0eb59c92391e52555976e55570a651d2330"}, + {file = "rapidfuzz-1.4.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:8cb5c2502ff06028a1468bdf61323b53cc3a37f54b5d62d62c5371795b81086a"}, + {file = "rapidfuzz-1.4.1-cp39-cp39-manylinux2014_ppc64le.whl", hash = "sha256:f37f80c1541d6e0a30547261900086b8c0bac519ebc12c9cd6b61a9a43a7e195"}, + {file = "rapidfuzz-1.4.1-cp39-cp39-manylinux2014_s390x.whl", hash = "sha256:c13cd1e840aa93639ac1d131fbfa740a609fd20dfc2a462d5cd7bce747a2398d"}, + {file = "rapidfuzz-1.4.1-cp39-cp39-win32.whl", hash = "sha256:0ec346f271e96c485716c091c8b0b78ba52da33f7c6ebb52a349d64094566c2d"}, + {file = "rapidfuzz-1.4.1-cp39-cp39-win_amd64.whl", hash = "sha256:5208ce1b1989a10e6fc5b5ef5d0bb7d1ffe5408838f3106abde241aff4dab08c"}, + {file = "rapidfuzz-1.4.1-pp36-pypy36_pp73-macosx_10_9_x86_64.whl", hash = "sha256:4fa195ea9ca35bacfa2a4319c6d4ab03aa6a283ad2089b70d2dfa0f6a7d9c1bc"}, + {file = "rapidfuzz-1.4.1-pp36-pypy36_pp73-manylinux1_x86_64.whl", hash = "sha256:6e336cfd8103b0b38e107e01502e9d6bf7c7f04e49b970fb11a4bf6c7a932b94"}, + {file = "rapidfuzz-1.4.1-pp36-pypy36_pp73-manylinux2010_x86_64.whl", hash = "sha256:c798c5b87efe8a7e63f408e07ff3bc03ba8b94f4498a89b48eaab3a9f439d52c"}, + {file = "rapidfuzz-1.4.1-pp36-pypy36_pp73-win32.whl", hash = "sha256:bb16a10b40f5bd3c645f7748fbd36f49699a03f550c010a2c665905cc8937de8"}, + {file = "rapidfuzz-1.4.1-pp37-pypy37_pp73-macosx_10_9_x86_64.whl", hash = "sha256:2278001924031d9d75f821bff2c5fef565c8376f252562e04d8eec8857475c36"}, + {file = "rapidfuzz-1.4.1-pp37-pypy37_pp73-manylinux1_x86_64.whl", hash = "sha256:a89d11f3b5da35fdf3e839186203b9367d56e2be792e8dccb098f47634ec6eb9"}, + {file = "rapidfuzz-1.4.1-pp37-pypy37_pp73-manylinux2010_x86_64.whl", hash = "sha256:f8c79cd11b4778d387366a59aa747f5268433f9d68be37b00d16f4fb08fdf850"}, + {file = "rapidfuzz-1.4.1-pp37-pypy37_pp73-win32.whl", hash = "sha256:4364db793ed4b439f9dd28a335bee14e2a828283d3b93c2d2686cc645eeafdd5"}, + {file = "rapidfuzz-1.4.1.tar.gz", hash = "sha256:de20550178376d21bfe1b34a7dc42ab107bb282ef82069cf6dfe2805a0029e26"}, +] redis = [ {file = "redis-3.5.3-py2.py3-none-any.whl", hash = "sha256:432b788c4530cfe16d8d943a09d40ca6c16149727e4afe8c2c9d5580c59d9f24"}, {file = "redis-3.5.3.tar.gz", hash = "sha256:0e7e0cfca8660dea8b7d5cd8c4f6c5e29e11f31158c0b0ae91a397f00e5a05a2"}, diff --git a/pyproject.toml b/pyproject.toml index d244d2b0..293d4e12 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,8 +9,8 @@ license = "MIT" python = "^3.9" aiodns = "~=2.0" aioredis = "~1.3" +rapidfuzz = "~=1.4" arrow = "~=1.1.0" -fuzzywuzzy = "~=0.17" pillow = "~=8.1" sentry-sdk = "~=0.19" PyYAML = "~=5.4" -- cgit v1.2.3 From fac37b213aad8ce57ff1ccd407669c1ff22c36ba Mon Sep 17 00:00:00 2001 From: wookie184 Date: Fri, 6 Aug 2021 16:34:37 +0100 Subject: Modify code to comply with new linter error N818 --- bot/exts/christmas/advent_of_code/_helpers.py | 8 ++++---- bot/utils/pagination.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'bot') diff --git a/bot/exts/christmas/advent_of_code/_helpers.py b/bot/exts/christmas/advent_of_code/_helpers.py index 96de90c4..e26a17ca 100644 --- a/bot/exts/christmas/advent_of_code/_helpers.py +++ b/bot/exts/christmas/advent_of_code/_helpers.py @@ -67,7 +67,7 @@ class UnexpectedResponseStatus(aiohttp.ClientError): """Raised when an unexpected redirect was detected.""" -class FetchingLeaderboardFailed(Exception): +class FetchingLeaderboardFailedError(Exception): """Raised when one or more leaderboards could not be fetched at all.""" @@ -210,7 +210,7 @@ async def _fetch_leaderboard_data() -> typing.Dict[str, typing.Any]: except UnexpectedRedirect: if cookies["session"] == AdventOfCode.fallback_session: log.error("It seems like the fallback cookie has expired!") - raise FetchingLeaderboardFailed from None + raise FetchingLeaderboardFailedError from None # If we're here, it means that the original session did not # work. Let's fall back to the fallback session. @@ -218,7 +218,7 @@ async def _fetch_leaderboard_data() -> typing.Dict[str, typing.Any]: continue except aiohttp.ClientError: # Don't retry, something unexpected is wrong and it may not be the session. - raise FetchingLeaderboardFailed from None + raise FetchingLeaderboardFailedError from None else: # Get the participants and store their current count. board_participants = raw_data["members"] @@ -227,7 +227,7 @@ async def _fetch_leaderboard_data() -> typing.Dict[str, typing.Any]: break else: log.error(f"reached 'unreachable' state while fetching board `{leaderboard.id}`.") - raise FetchingLeaderboardFailed + raise FetchingLeaderboardFailedError log.info(f"Fetched leaderboard information for {len(participants)} participants") return participants diff --git a/bot/utils/pagination.py b/bot/utils/pagination.py index d9c0862a..b1062c09 100644 --- a/bot/utils/pagination.py +++ b/bot/utils/pagination.py @@ -20,7 +20,7 @@ PAGINATION_EMOJI = (FIRST_EMOJI, LEFT_EMOJI, RIGHT_EMOJI, LAST_EMOJI, DELETE_EMO log = logging.getLogger(__name__) -class EmptyPaginatorEmbed(Exception): +class EmptyPaginatorEmbedError(Exception): """Base Exception class for an empty paginator embed.""" @@ -141,7 +141,7 @@ class LinePaginator(Paginator): if not lines: if exception_on_empty_embed: log.exception("Pagination asked for empty lines iterable") - raise EmptyPaginatorEmbed("No lines to paginate") + raise EmptyPaginatorEmbedError("No lines to paginate") log.debug("No lines to add to paginator, adding '(nothing to display)' message") lines.append("(nothing to display)") @@ -349,7 +349,7 @@ class ImagePaginator(Paginator): if not pages: if exception_on_empty_embed: log.exception("Pagination asked for empty image list") - raise EmptyPaginatorEmbed("No images to paginate") + raise EmptyPaginatorEmbedError("No images to paginate") log.debug("No images to add to paginator, adding '(no images to display)' message") pages.append(("(no images to display)", "")) -- cgit v1.2.3 From dcd3bc3f70988e819de6b0e0f70a600029e1ebfb Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Tue, 10 Aug 2021 14:13:31 +0100 Subject: Add February in_month check to love calculator command This ensure the valentines themed command can only be ran during the valentines season. --- bot/exts/valentines/lovecalculator.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'bot') diff --git a/bot/exts/valentines/lovecalculator.py b/bot/exts/valentines/lovecalculator.py index b10b7bca..41ba25ae 100644 --- a/bot/exts/valentines/lovecalculator.py +++ b/bot/exts/valentines/lovecalculator.py @@ -12,6 +12,8 @@ from discord.ext import commands from discord.ext.commands import BadArgument, Cog, clean_content from bot.bot import Bot +from bot.constants import Month +from bot.utils.decorators import in_month log = logging.getLogger(__name__) @@ -22,6 +24,7 @@ LOVE_DATA = sorted((int(key), value) for key, value in LOVE_DATA.items()) class LoveCalculator(Cog): """A cog for calculating the love between two people.""" + @in_month(Month.FEBRUARY) @commands.command(aliases=("love_calculator", "love_calc")) @commands.cooldown(rate=1, per=5, type=commands.BucketType.user) async def love(self, ctx: commands.Context, who: Union[Member, str], whom: Union[Member, str] = None) -> None: -- cgit v1.2.3 From cd904229b7150d2db26fda9aba5a51abf3f95c58 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Tue, 10 Aug 2021 14:15:07 +0100 Subject: Require both members used in love calculator have opt-ed into lovefest This ensure that only uses that have opted into the love fest event can actually be used as part of this command. --- bot/exts/valentines/lovecalculator.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'bot') diff --git a/bot/exts/valentines/lovecalculator.py b/bot/exts/valentines/lovecalculator.py index 41ba25ae..ba5e0b92 100644 --- a/bot/exts/valentines/lovecalculator.py +++ b/bot/exts/valentines/lovecalculator.py @@ -4,7 +4,7 @@ import json import logging import random from pathlib import Path -from typing import Coroutine, Union +from typing import Coroutine, Optional, Union import discord from discord import Member @@ -12,7 +12,7 @@ from discord.ext import commands from discord.ext.commands import BadArgument, Cog, clean_content from bot.bot import Bot -from bot.constants import Month +from bot.constants import Lovefest, Month from bot.utils.decorators import in_month log = logging.getLogger(__name__) @@ -27,7 +27,7 @@ class LoveCalculator(Cog): @in_month(Month.FEBRUARY) @commands.command(aliases=("love_calculator", "love_calc")) @commands.cooldown(rate=1, per=5, type=commands.BucketType.user) - async def love(self, ctx: commands.Context, who: Union[Member, str], whom: Union[Member, str] = None) -> None: + async def love(self, ctx: commands.Context, who: Member, whom: Optional[Member] = None) -> None: """ Tells you how much the two love each other. @@ -49,6 +49,12 @@ class LoveCalculator(Cog): if whom is None: whom = ctx.author + if not all(( + Lovefest.role_id in [role.id for role in who.roles], + Lovefest.role_id in [role.id for role in whom.roles] + )): + raise BadArgument("Both members must have the love fest role!") + def normalize(arg: Union[Member, str]) -> Coroutine: if isinstance(arg, Member): # If we are given a member, return name#discrim without any extra changes -- cgit v1.2.3 From c334c20c03d4f3961c9b2628660efaae405e5d9c Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Tue, 10 Aug 2021 14:15:51 +0100 Subject: Sort the members before calculating a love score This ensures the same result for same input, regardless of order --- bot/exts/valentines/lovecalculator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/valentines/lovecalculator.py b/bot/exts/valentines/lovecalculator.py index ba5e0b92..d06d883d 100644 --- a/bot/exts/valentines/lovecalculator.py +++ b/bot/exts/valentines/lovecalculator.py @@ -65,7 +65,8 @@ class LoveCalculator(Cog): # This has to be done manually to be applied to usernames return clean_content(escape_markdown=True).convert(ctx, arg) - who, whom = [await normalize(arg) for arg in (who, whom)] + # Sort to ensure same result for same input, regardless of order + who, whom = sorted([await normalize(arg) for arg in (who, whom)]) # Make sure user didn't provide something silly such as 10 spaces if not (who and whom): -- cgit v1.2.3 From 66d531583beef60d27bcb3afdd4e127531b7cb75 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Tue, 10 Aug 2021 14:23:35 +0100 Subject: Update love calculator docstring to reflect new behaviour Since we update how the command behaves, by not allow arbitrary stings, and being symmetrical, we should reflect this in the docstring. --- bot/exts/valentines/lovecalculator.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'bot') diff --git a/bot/exts/valentines/lovecalculator.py b/bot/exts/valentines/lovecalculator.py index d06d883d..d80f2adf 100644 --- a/bot/exts/valentines/lovecalculator.py +++ b/bot/exts/valentines/lovecalculator.py @@ -31,20 +31,18 @@ class LoveCalculator(Cog): """ Tells you how much the two love each other. - This command accepts users or arbitrary strings as arguments. - Users are converted from: + This command requires at least one member as input, if two are given love will be calculated between + those two users, if only one is given, the second member is asusmed to be the invoker. + Members are converted from: - User ID - Mention - name#discrim - name - nickname - Any two arguments will always yield the same result, though the order of arguments matters: - Running .love joseph erlang will always yield the same result. - Running .love erlang joseph won't yield the same result as .love joseph erlang - - If you want to use multiple words for one argument, you must include quotes. - .love "Zes Vappa" "morning coffee" + Any two arguments will always yield the same result, regardless of the order of arguments: + Running .love @joe#6000 @chrisjl#2655 will always yield the same result. + Running .love @chrisjl#2655 @joe#6000 will yield the same result as before. """ if whom is None: whom = ctx.author -- cgit v1.2.3 From 0a2e18423a8042f6ab7e96e3d0775402a5cddac8 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Tue, 10 Aug 2021 14:24:57 +0100 Subject: Remove unneeded checks in love calculator command Now that we don't allow arbitrary strings, we can simplify the input validation/modification we do. --- bot/exts/valentines/lovecalculator.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'bot') diff --git a/bot/exts/valentines/lovecalculator.py b/bot/exts/valentines/lovecalculator.py index d80f2adf..46bcc6fd 100644 --- a/bot/exts/valentines/lovecalculator.py +++ b/bot/exts/valentines/lovecalculator.py @@ -4,7 +4,7 @@ import json import logging import random from pathlib import Path -from typing import Coroutine, Optional, Union +from typing import Coroutine, Optional import discord from discord import Member @@ -53,23 +53,13 @@ class LoveCalculator(Cog): )): raise BadArgument("Both members must have the love fest role!") - def normalize(arg: Union[Member, str]) -> Coroutine: - if isinstance(arg, Member): - # If we are given a member, return name#discrim without any extra changes - arg = str(arg) - else: - # Otherwise normalise case and remove any leading/trailing whitespace - arg = arg.strip().title() + def normalize(arg: Member) -> Coroutine: # This has to be done manually to be applied to usernames - return clean_content(escape_markdown=True).convert(ctx, arg) + return clean_content(escape_markdown=True).convert(ctx, str(arg)) # Sort to ensure same result for same input, regardless of order who, whom = sorted([await normalize(arg) for arg in (who, whom)]) - # Make sure user didn't provide something silly such as 10 spaces - if not (who and whom): - raise BadArgument("Arguments must be non-empty strings.") - # Hash inputs to guarantee consistent results (hashing algorithm choice arbitrary) # # hashlib is used over the builtin hash() to guarantee same result over multiple runtimes -- cgit v1.2.3 From 298f8fc85bf65b9fd52f524b0d61eb99ef7e4687 Mon Sep 17 00:00:00 2001 From: ChrisJL Date: Tue, 10 Aug 2021 15:17:30 +0100 Subject: Update love calculator error output to be consistent with other role check fails Co-authored-by: Matteo Bertucci --- bot/exts/valentines/lovecalculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/valentines/lovecalculator.py b/bot/exts/valentines/lovecalculator.py index 46bcc6fd..d9b60cfa 100644 --- a/bot/exts/valentines/lovecalculator.py +++ b/bot/exts/valentines/lovecalculator.py @@ -51,7 +51,7 @@ class LoveCalculator(Cog): Lovefest.role_id in [role.id for role in who.roles], Lovefest.role_id in [role.id for role in whom.roles] )): - raise BadArgument("Both members must have the love fest role!") + raise BadArgument("Both members must have the lovefest role!") def normalize(arg: Member) -> Coroutine: # This has to be done manually to be applied to usernames -- cgit v1.2.3 From 871445727937791645e892e9fe33c6e7f47c2e04 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Thu, 12 Aug 2021 18:41:32 +0100 Subject: Give lovefest unsub info in lovecalc footer --- bot/exts/valentines/lovecalculator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/valentines/lovecalculator.py b/bot/exts/valentines/lovecalculator.py index d9b60cfa..b59e60ad 100644 --- a/bot/exts/valentines/lovecalculator.py +++ b/bot/exts/valentines/lovecalculator.py @@ -12,7 +12,7 @@ from discord.ext import commands from discord.ext.commands import BadArgument, Cog, clean_content from bot.bot import Bot -from bot.constants import Lovefest, Month +from bot.constants import Client, Lovefest, Month from bot.utils.decorators import in_month log = logging.getLogger(__name__) @@ -85,6 +85,7 @@ class LoveCalculator(Cog): name="A letter from Dr. Love:", value=data["text"] ) + embed.set_footer(text=f"You can unsubscribe from lovefest by using {Client.prefix}lovefest unsub") await ctx.send(embed=embed) -- cgit v1.2.3 From 446c86f54ae92ee0cde9a52f2e3bf09362e0add4 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Thu, 12 Aug 2021 18:44:25 +0100 Subject: Don't role check if running lovecalc on yourself This skips the role check if the author is running the love calc command on themselves. We still want to check the the user running against has the role, along with if the author is running it against 2 other people. i have also included info on how to get the lovefest role in the error embed. --- bot/exts/valentines/lovecalculator.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'bot') diff --git a/bot/exts/valentines/lovecalculator.py b/bot/exts/valentines/lovecalculator.py index b59e60ad..1cb10e64 100644 --- a/bot/exts/valentines/lovecalculator.py +++ b/bot/exts/valentines/lovecalculator.py @@ -12,7 +12,7 @@ from discord.ext import commands from discord.ext.commands import BadArgument, Cog, clean_content from bot.bot import Bot -from bot.constants import Client, Lovefest, Month +from bot.constants import Channels, Client, Lovefest, Month from bot.utils.decorators import in_month log = logging.getLogger(__name__) @@ -44,15 +44,19 @@ class LoveCalculator(Cog): Running .love @joe#6000 @chrisjl#2655 will always yield the same result. Running .love @chrisjl#2655 @joe#6000 will yield the same result as before. """ + if ( + Lovefest.role_id not in [role.id for role in who.roles] + or (whom is not None and Lovefest.role_id not in [role.id for role in whom.roles]) + ): + raise BadArgument( + "This command can only be ran against members with the lovefest role! " + "This role be can assigned by running " + f"`{Client.prefix}lovefest sub` in <#{Channels.community_bot_commands}>." + ) + if whom is None: whom = ctx.author - if not all(( - Lovefest.role_id in [role.id for role in who.roles], - Lovefest.role_id in [role.id for role in whom.roles] - )): - raise BadArgument("Both members must have the lovefest role!") - def normalize(arg: Member) -> Coroutine: # This has to be done manually to be applied to usernames return clean_content(escape_markdown=True).convert(ctx, str(arg)) -- cgit v1.2.3 From 5ea96aabd779f7445b6db5236018b2b28b11a5dc Mon Sep 17 00:00:00 2001 From: Kronifer <44979306+Kronifer@users.noreply.github.com> Date: Mon, 16 Aug 2021 10:39:29 -0500 Subject: Merged .reverse into one command and made reversing the users profile picture the default behavior --- .../evergreen/avatar_modification/avatar_modify.py | 66 +++++++++------------- 1 file changed, 28 insertions(+), 38 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index b482f42e..ccbefbd7 100644 --- a/bot/exts/evergreen/avatar_modification/avatar_modify.py +++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py @@ -121,49 +121,39 @@ class AvatarModify(commands.Cog): await ctx.send(embed=embed, file=file) - @avatar_modify.group(name="reverse", root_aliases=['reverse']) - async def reverse(self, ctx: commands.Context) -> None: - """Group for the reverse commands.""" - if not ctx.invoked_subcommand: - await invoke_help_command(ctx) - - @reverse.command(name="text") - async def reverse_text(self, ctx: commands.Context, *, text: str) -> None: - """Sends the given text backwards.""" - await ctx.send(f"> {text[::-1]}", allowed_mentions=discord.AllowedMentions.none()) - - @reverse.command(name="image") - async def reverse_photo(self, ctx: commands.Context) -> None: - """ - Sends a reversed version of the users profile picture. - - If an image is attached, the given image will be flipped. - """ - async with ctx.typing(): - user = await self._fetch_user(ctx.author.id) - if not user: - await ctx.send(f"{Emojis.cross_mark} Could not get user info.") - return + @avatar_modify.command(name="reverse", root_aliases=("reverse",)) + async def reverse(self, ctx: commands.Context, *, text: t.Optional[str]): + """Reverses the sent text. + + If no text is provided, the user's profile picture will be reversed.""" + if not text: + async with ctx.typing(): + user = await self._fetch_user(ctx.author.id) + if not user: + await ctx.send(f"{Emojis.cross_mark} Could not get user info.") + return - image_bytes = await user.avatar_url_as(size=1024).read() - filename = file_safe_name("reverse_avatar", ctx.author.display_name) + image_bytes = await user.avatar_url_as(size=1024).read() + filename = file_safe_name("reverse_avatar", ctx.author.display_name) - file = await in_executor( - PfpEffects.apply_effect, - image_bytes, - PfpEffects.flip_effect, - filename - ) + file = await in_executor( + PfpEffects.apply_effect, + image_bytes, + PfpEffects.flip_effect, + filename + ) - embed = discord.Embed( - title="Your reversed avatar.", - description="Here is your reversed avatar. I think it is a spitting image of you." - ) + embed = discord.Embed( + title="Your reversed avatar.", + description="Here is your reversed avatar. I think it is a spitting image of you." + ) - embed.set_image(url=f"attachment://{filename}") - embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=user.avatar_url) + embed.set_image(url=f"attachment://{filename}") + embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=user.avatar_url) - await ctx.send(embed=embed, file=file) + await ctx.send(embed=embed, file=file) + else: + await ctx.send(f"> {text[::-1]}", allowed_mentions=discord.AllowedMentions.none()) @avatar_modify.command(aliases=("easterify",), root_aliases=("easterify", "avatareasterify")) async def avatareasterify(self, ctx: commands.Context, *colours: t.Union[discord.Colour, str]) -> None: -- cgit v1.2.3 From 6190278321112cf131485a4791e4711f27bd7952 Mon Sep 17 00:00:00 2001 From: Kronifer <44979306+Kronifer@users.noreply.github.com> Date: Mon, 16 Aug 2021 10:41:48 -0500 Subject: lint fix because precommit didn't run --- bot/exts/evergreen/avatar_modification/avatar_modify.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index ccbefbd7..5decfce4 100644 --- a/bot/exts/evergreen/avatar_modification/avatar_modify.py +++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py @@ -122,10 +122,12 @@ class AvatarModify(commands.Cog): await ctx.send(embed=embed, file=file) @avatar_modify.command(name="reverse", root_aliases=("reverse",)) - async def reverse(self, ctx: commands.Context, *, text: t.Optional[str]): - """Reverses the sent text. - - If no text is provided, the user's profile picture will be reversed.""" + async def reverse(self, ctx: commands.Context, *, text: t.Optional[str]) -> None: + """ + Reverses the sent text. + + If no text is provided, the user's profile picture will be reversed. + """ if not text: async with ctx.typing(): user = await self._fetch_user(ctx.author.id) -- cgit v1.2.3 From c18676eb72530dd8747fdd8d6572d4c6c748b6b3 Mon Sep 17 00:00:00 2001 From: Axis <77634274+blankRiot96@users.noreply.github.com> Date: Fri, 4 Jun 2021 22:21:03 +0530 Subject: Added more topics to `py_topics.yaml`. --- bot/resources/evergreen/py_topics.yaml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/resources/evergreen/py_topics.yaml b/bot/resources/evergreen/py_topics.yaml index 6b7e0206..a3fb2ccc 100644 --- a/bot/resources/evergreen/py_topics.yaml +++ b/bot/resources/evergreen/py_topics.yaml @@ -23,6 +23,19 @@ - When you were first learning, what is a resource you wish you had? - What is something you know now, that you wish you knew when starting out? - What is something simple that you still error on today? + - What do you plan on eventually achieving with Python? + - Is Python your first programming language? If not, what is it? + - What's your favourite aspect of Python development? (Backend, frontend, game dev, machine learning, ai, etc.) + - In what ways has Python Discord helped you with Python? + - Are you currently using Python professionally, for education, or as a hobby? + - What is your process when you decide to start a project in Python? + - Have you ever been unable to finish a Python project? What is it and why? + - How often do you program in Python? + - How would you learn a new library if needed to do so? + - Have you ever worked with a microcontroller or anything physical with Python before? + - How good would you say you are at Python so far? Beginner, intermediate, or advanced? + - Have you ever tried making your own programming language? + - Has a recently discovered Python module changed your general use of Python? # algos-and-data-structs 650401909852864553: @@ -52,7 +65,7 @@ - What unique features does your bot contain, if any? - What commands/features are you proud of making? - What feature would you be the most interested in making? - - What feature would you like to see added to the library? what feature in the library do you think is redundant? + - What feature would you like to see added to the library? What feature in the library do you think is redundant? - Do you think there's a way in which Discord could handle bots better? - What's one feature you wish more developers had in their bots? -- cgit v1.2.3 From 12b562ef9a6fd2cf3015156eb738ee765f82d070 Mon Sep 17 00:00:00 2001 From: Kronifer <44979306+Kronifer@users.noreply.github.com> Date: Mon, 16 Aug 2021 16:39:52 -0500 Subject: Removed a massive it block --- .../evergreen/avatar_modification/avatar_modify.py | 47 +++++++++++----------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index 5decfce4..185cdb38 100644 --- a/bot/exts/evergreen/avatar_modification/avatar_modify.py +++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py @@ -128,34 +128,35 @@ class AvatarModify(commands.Cog): If no text is provided, the user's profile picture will be reversed. """ - if not text: - async with ctx.typing(): - user = await self._fetch_user(ctx.author.id) - if not user: - await ctx.send(f"{Emojis.cross_mark} Could not get user info.") - return + if text: + await ctx.send(f"> {text[::-1]}", allowed_mentions=discord.AllowedMentions.none()) + return + + async with ctx.typing(): + user = await self._fetch_user(ctx.author.id) + if not user: + await ctx.send(f"{Emojis.cross_mark} Could not get user info.") + return - image_bytes = await user.avatar_url_as(size=1024).read() - filename = file_safe_name("reverse_avatar", ctx.author.display_name) + image_bytes = await user.avatar_url_as(size=1024).read() + filename = file_safe_name("reverse_avatar", ctx.author.display_name) - file = await in_executor( - PfpEffects.apply_effect, - image_bytes, - PfpEffects.flip_effect, - filename - ) + file = await in_executor( + PfpEffects.apply_effect, + image_bytes, + PfpEffects.flip_effect, + filename + ) - embed = discord.Embed( - title="Your reversed avatar.", - description="Here is your reversed avatar. I think it is a spitting image of you." - ) + embed = discord.Embed( + title="Your reversed avatar.", + description="Here is your reversed avatar. I think it is a spitting image of you." + ) - embed.set_image(url=f"attachment://{filename}") - embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=user.avatar_url) + embed.set_image(url=f"attachment://{filename}") + embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=user.avatar_url) - await ctx.send(embed=embed, file=file) - else: - await ctx.send(f"> {text[::-1]}", allowed_mentions=discord.AllowedMentions.none()) + await ctx.send(embed=embed, file=file) @avatar_modify.command(aliases=("easterify",), root_aliases=("easterify", "avatareasterify")) async def avatareasterify(self, ctx: commands.Context, *colours: t.Union[discord.Colour, str]) -> None: -- cgit v1.2.3 From 83eb6a6ea0bb8429504a0deddf3f6f2a2202547e Mon Sep 17 00:00:00 2001 From: wookie184 Date: Sat, 21 Aug 2021 12:47:42 +0100 Subject: Resize avatar to 1024x1024 before applying effects --- bot/exts/evergreen/avatar_modification/_effects.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/evergreen/avatar_modification/_effects.py b/bot/exts/evergreen/avatar_modification/_effects.py index 46d1a2ab..55eed6ad 100644 --- a/bot/exts/evergreen/avatar_modification/_effects.py +++ b/bot/exts/evergreen/avatar_modification/_effects.py @@ -22,6 +22,7 @@ class PfpEffects: """Applies the given effect to the image passed to it.""" im = Image.open(BytesIO(image_bytes)) im = im.convert("RGBA") + im = im.resize((1024, 1024)) im = effect(im, *args) bufferedio = BytesIO() @@ -74,7 +75,6 @@ class PfpEffects: @staticmethod def pridify_effect(image: Image.Image, pixels: int, flag: str) -> Image.Image: """Applies the given pride effect to the given image.""" - image = image.resize((1024, 1024)) image = PfpEffects.crop_avatar_circle(image) ring = Image.open(Path(f"bot/resources/pride/flags/{flag}.png")).resize((1024, 1024)) -- cgit v1.2.3 From df3c882db4cd2f970682087093e81a770b4f484a Mon Sep 17 00:00:00 2001 From: wookie184 Date: Sat, 21 Aug 2021 15:42:40 +0100 Subject: Refactor mosaic command to use apply_effect --- bot/exts/evergreen/avatar_modification/_effects.py | 18 ++++++++---------- .../evergreen/avatar_modification/avatar_modify.py | 5 +++-- 2 files changed, 11 insertions(+), 12 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/avatar_modification/_effects.py b/bot/exts/evergreen/avatar_modification/_effects.py index 55eed6ad..92244207 100644 --- a/bot/exts/evergreen/avatar_modification/_effects.py +++ b/bot/exts/evergreen/avatar_modification/_effects.py @@ -283,16 +283,14 @@ class PfpEffects: return new_image @staticmethod - def mosaic_effect(img_bytes: bytes, squares: int, file_name: str) -> discord.File: - """Separate function run from an executor which turns an image into a mosaic.""" - avatar = Image.open(BytesIO(img_bytes)) - avatar = avatar.convert("RGBA").resize((1024, 1024)) + def mosaic_effect(image: Image.Image, squares: int) -> Image.Image: + """ + Applies a mosaic effect to the given image. - img_squares = PfpEffects.split_image(avatar, squares) + The "squares" argument specifies the number of squares to split + the image into. This should be a square number. + """ + img_squares = PfpEffects.split_image(image, squares) new_img = PfpEffects.join_images(img_squares) - bufferedio = BytesIO() - new_img.save(bufferedio, format="PNG") - bufferedio.seek(0) - - return discord.File(bufferedio, filename=file_name) + return new_img diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index 765c316e..7b4ae9c7 100644 --- a/bot/exts/evergreen/avatar_modification/avatar_modify.py +++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py @@ -338,10 +338,11 @@ class AvatarModify(commands.Cog): img_bytes = await user.avatar_url_as(size=1024).read() file = await in_executor( - PfpEffects.mosaic_effect, + PfpEffects.apply_effect, img_bytes, + PfpEffects.mosaic_effect, + file_name, squares, - file_name ) if squares == 1: -- cgit v1.2.3