diff --git a/README.md b/README.md index 48a0ad8361..6c9c2fe55a 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ TrustyJAID's Cogs for [Red-DiscordBot](https://github.com/Cog-Creators/Red-Disc | NotSoBot | 2.5.5 |
Some working commands from NotSoBotMagick, trigger and manipulate images with many commands from NotSoSuper's NotSoBot. This cog has a lot of requirements, view the [cog README.md](https://github.com/TrustyJAID/Trusty-cogs/blob/master/notsobot/README.md) for details.
| NotSoSuper and TrustyJAID | | Reddit | 1.2.0 |
A cog to post updates from reddit.Reddit commands for getting updates on specified subreddits.
| TrustyJAID | | Rekt | 1.0.0 |
Get REKTAre you REKT?
| TrustyJAID | -| ReTrigger | 2.27.0 |
Trigger events via Regular Expressions!Trigger events based on regex! Check out and for help setting up the cog. Note: This cog can become quite resource heavy. Optional features are available if the requirements are present such as pillow for image resizing and pytesseract to scan images for text (OCR).
| TrustyJAID | +| ReTrigger | 2.27.1 |
Trigger events via Regular Expressions!Trigger events based on regex! Check out and for help setting up the cog. Note: This cog can become quite resource heavy. Optional features are available if the requirements are present such as pillow for image resizing and pytesseract to scan images for text (OCR).
| TrustyJAID | | RoleTools | 1.5.11 |
Various role related tools.Various role utility commands. Including Reaction roles, Sticky roles, and Auto role.
| TrustyJAID | | runescape | 1.5.1 |
Show your Runescape stats in discord!A cog to grab Runescape and OSRS stats and profile information.
| TrustyJAID | | ServerStats | 1.8.0 |
A plethora of potentially useful commands for any bot owner.A plethora of potentially useful commands for any bot owner. Includes a way to track the bot joining new servers, find cheaters on global economies, get user avatars and even larger emojis.
| TrustyJAID and Preda | diff --git a/retrigger/abc.py b/retrigger/abc.py index df2dc99ed5..22d35c4072 100644 --- a/retrigger/abc.py +++ b/retrigger/abc.py @@ -51,6 +51,12 @@ async def is_mod_or_admin(self, member: discord.Member) -> bool: async def make_guild_folder(self, directory) -> None: raise NotImplementedError() + @abstractmethod + async def save_attachment_location( + self, attachment: discord.Attachment, guild: discord.Guild + ) -> Optional[str]: + raise NotImplementedError() + @abstractmethod async def save_image_location(self, image_url: str, guild: discord.Guild) -> Optional[str]: raise NotImplementedError() diff --git a/retrigger/retrigger.py b/retrigger/retrigger.py index 9e4b6d80d9..987809f968 100644 --- a/retrigger/retrigger.py +++ b/retrigger/retrigger.py @@ -94,7 +94,7 @@ class ReTrigger( """ __author__ = ["TrustyJAID"] - __version__ = "2.27.0" + __version__ = "2.27.1" def __init__(self, bot): super().__init__() @@ -1810,8 +1810,7 @@ async def image( msg = await self.wait_for_image(ctx) if not msg or not msg.attachments: return - image_url = msg.attachments[0].url - filename = await self.save_image_location(image_url, guild) + filename = await self.save_attachment_location(msg.attachments[0], guild) if not filename: await ctx.send(_("That is not a valid file link.")) return diff --git a/retrigger/triggerhandler.py b/retrigger/triggerhandler.py index 69dcb56a8d..bf0f8dc691 100644 --- a/retrigger/triggerhandler.py +++ b/retrigger/triggerhandler.py @@ -49,7 +49,7 @@ RE_CTX: re.Pattern = re.compile(r"{([^}]+)\}") RE_POS: re.Pattern = re.compile(r"{((\d+)[^.}]*(\.[^:}]+)?[^}]*)\}") LINK_REGEX: re.Pattern = re.compile( - r"(http[s]?:\/\/[^\"\']*\.(?:png|jpg|jpeg|gif|mp3|mp4|webp))", flags=re.I + r"(http[s]?:\/\/[^\"\']*\.(?:png|jpg|jpeg|gif|mp3|mp4|webp)).*", flags=re.I ) IMAGE_REGEX: re.Pattern = re.compile( r"(?:(?:https?):\/\/)?[\w\/\-?=%.]+\.(?:png|jpg|jpeg|webp)+", flags=re.I @@ -108,6 +108,17 @@ async def make_guild_folder(self, directory) -> None: log.info("Creating guild folder") directory.mkdir(exist_ok=True, parents=True) + async def save_attachment_location( + self, attachment: discord.Attachment, guild: discord.Guild + ) -> Optional[str]: + seed = "".join(random.sample(string.ascii_uppercase + string.digits, k=5)) + filename = "{}-{}".format(seed, attachment.filename) + directory = cog_data_path(self).joinpath(str(guild.id)) + file_path = cog_data_path(self).joinpath(str(guild.id), str(filename)) + await self.make_guild_folder(directory) + await attachment.save(file_path) + return filename + async def save_image_location(self, image_url: str, guild: discord.Guild) -> Optional[str]: good_image_url = LINK_REGEX.search(image_url) if not good_image_url: @@ -115,11 +126,11 @@ async def save_image_location(self, image_url: str, guild: discord.Guild) -> Opt seed = "".join(random.sample(string.ascii_uppercase + string.digits, k=5)) filename = good_image_url.group(1).split("/")[-1] filename = "{}-{}".format(seed, filename) - directory = cog_data_path(self) / str(guild.id) - file_path = str(cog_data_path(self)) + f"/{guild.id}/{filename}" + directory = cog_data_path(self).joinpath(str(guild.id)) + file_path = cog_data_path(self).joinpath(str(guild.id), str(filename)) await self.make_guild_folder(directory) async with aiohttp.ClientSession() as session: - async with session.get(good_image_url.group(1)) as resp: + async with session.get(good_image_url.group(0)) as resp: test = await resp.read() with open(file_path, "wb") as f: f.write(test)