From 0f4c7b0fe6ed1630a99f810c9c4b3acb3dc9f25e Mon Sep 17 00:00:00 2001 From: Jakub Kuczys Date: Tue, 4 Mar 2025 23:38:37 +0100 Subject: [PATCH] Bump deps (including d.py 2.5 bump) (#6529) Co-authored-by: Kowlin <10947836+Kowlin@users.noreply.github.com> --- .../workflows/scripts/merge_requirements.py | 14 ++++--- redbot/cogs/cleanup/cleanup.py | 8 ++++ redbot/cogs/filter/filter.py | 41 ++++++++++++++++++- redbot/core/commands/__init__.py | 4 ++ redbot/core/utils/tunnel.py | 3 +- requirements/base.in | 1 + requirements/base.txt | 10 +++-- 7 files changed, 69 insertions(+), 12 deletions(-) diff --git a/.github/workflows/scripts/merge_requirements.py b/.github/workflows/scripts/merge_requirements.py index 004047185..97b3b1ad3 100644 --- a/.github/workflows/scripts/merge_requirements.py +++ b/.github/workflows/scripts/merge_requirements.py @@ -137,25 +137,27 @@ for name in names: python_version_marker = ( # Requirement present on less Python versions than not. " or ".join( - f"python_version == '{python_version}'" for python_version in python_versions + f"python_version == '{python_version}'" + for python_version in sorted(python_versions) ) if len(python_versions) < len(all_python_versions - python_versions) # Requirement present on more Python versions than not # This may generate an empty string when Python version is irrelevant. else " and ".join( f"python_version != '{python_version}'" - for python_version in all_python_versions - python_versions + for python_version in sorted(all_python_versions - python_versions) ) ) platform_marker = ( # Requirement present on less platforms than not. - " or ".join(f"sys_platform == '{platform}'" for platform in platforms) + " or ".join(f"sys_platform == '{platform}'" for platform in sorted(platforms)) if len(platforms) < len(all_platforms - platforms) # Requirement present on more platforms than not # This may generate an empty string when platform is irrelevant. else " and ".join( - f"sys_platform != '{platform}'" for platform in all_platforms - platforms + f"sys_platform != '{platform}'" + for platform in sorted(all_platforms - platforms) ) ) @@ -169,12 +171,12 @@ for name in names: # Requirement present on less envs than not. " or ".join( f"(sys_platform == '{platform}' and python_version == '{python_version}')" - for platform, python_version in iter_envs(envs) + for platform, python_version in iter_envs(sorted(envs)) ) if len(envs) < len(all_envs - envs.keys()) else " and ".join( f"(sys_platform != '{platform}' and python_version != '{python_version}')" - for platform, python_version in iter_envs(all_envs - envs.keys()) + for platform, python_version in iter_envs(sorted(all_envs - envs.keys())) ) ) diff --git a/redbot/cogs/cleanup/cleanup.py b/redbot/cogs/cleanup/cleanup.py index 27bd4398f..79e36dede 100644 --- a/redbot/cogs/cleanup/cleanup.py +++ b/redbot/cogs/cleanup/cleanup.py @@ -708,11 +708,19 @@ class Cleanup(commands.Cog): def check(m): if m.attachments: return False + if m.components: + return False + if m.poll: + return False + if m.activity: + return False + ref = m.reference c = ( m.author.id, m.content, [embed.to_dict() for embed in m.embeds], [sticker.id for sticker in m.stickers], + ref and (ref.type, ref.message_id, ref.channel_id), ) if c in msgs: spam.append(m) diff --git a/redbot/cogs/filter/filter.py b/redbot/cogs/filter/filter.py index 84a311009..b0816bca5 100644 --- a/redbot/cogs/filter/filter.py +++ b/redbot/cogs/filter/filter.py @@ -2,7 +2,7 @@ import asyncio import discord import re from datetime import timezone -from typing import Union, Set, Literal, Optional +from typing import Union, Set, Literal, Optional, Iterable, Dict, Any from redbot.core import Config, modlog, commands from redbot.core.bot import Red @@ -515,6 +515,22 @@ class Filter(commands.Cog): texts.append(answer.text or "") for attachment in message.attachments: texts.append(attachment.description or "") + + if ( + message.reference is not None + and message.reference.type is discord.MessageReferenceType.forward + ): + # unlike user messages, forwards can include things that bots can send + # since you can forward a bot's message + for snapshot in message.message_snapshots: + texts.append(snapshot.content) + for attachment in snapshot.attachments: + texts.append(attachment.description or "") + for embed in snapshot.embeds: + texts.extend(_extract_string_values(embed.to_dict().values())) + for component in snapshot.components: + texts.extend(_extract_string_values_from_component(component)) + hits = await self.filter_hits(message.channel, *texts) if hits: @@ -624,3 +640,26 @@ class Filter(commands.Cog): except discord.HTTPException: pass return + + +def _extract_string_values_from_component( + component: Union[discord.ActionRow, discord.Button, discord.SelectMenu], +) -> Iterable[str]: + if isinstance(component, discord.ActionRow): + for child in component.children: + yield from _extract_string_values_from_component(child) + elif isinstance(component, discord.Button): + yield component.url + yield component.label + elif isinstance(component, discord.SelectMenu): + yield component.placeholder + + +def _extract_string_values(data: Iterable[Any]) -> Iterable[str]: + for value in data: + if isinstance(value, str): + yield value + elif isinstance(value, list): + yield from _extract_string_values(value) + elif isinstance(value, dict): + yield from _extract_string_values(value.values()) diff --git a/redbot/core/commands/__init__.py b/redbot/core/commands/__init__.py index 96bd69a64..6873bdf0a 100644 --- a/redbot/core/commands/__init__.py +++ b/redbot/core/commands/__init__.py @@ -206,6 +206,8 @@ from discord.ext.commands import ( RangeError as RangeError, parameter as parameter, HybridCommandError as HybridCommandError, + SoundboardSoundConverter as SoundboardSoundConverter, + SoundboardSoundNotFound as SoundboardSoundNotFound, ) __all__ = ( @@ -397,4 +399,6 @@ __all__ = ( "RangeError", "parameter", "HybridCommandError", + "SoundboardSoundConverter", + "SoundboardSoundNotFound", ) diff --git a/redbot/core/utils/tunnel.py b/redbot/core/utils/tunnel.py index 140b76e9c..15e41ade6 100644 --- a/redbot/core/utils/tunnel.py +++ b/redbot/core/utils/tunnel.py @@ -162,7 +162,8 @@ class Tunnel(metaclass=TunnelMeta): """ files = [] - max_size = 26214400 + # DEP-WARN + max_size = discord.utils.DEFAULT_FILE_SIZE_LIMIT_BYTES if m.attachments and sum(a.size for a in m.attachments) <= max_size: for a in m.attachments: if images_only and a.height is None: diff --git a/requirements/base.in b/requirements/base.in index f00e75df5..8a7cdb9dd 100644 --- a/requirements/base.in +++ b/requirements/base.in @@ -19,5 +19,6 @@ rich schema typing_extensions yarl +zstandard distro; sys_platform == "linux" uvloop; sys_platform != "win32" and platform_python_implementation == "CPython" diff --git a/requirements/base.txt b/requirements/base.txt index b94169da6..19bbe96aa 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -18,7 +18,7 @@ brotli==1.1.0 # via -r base.in click==8.1.8 # via -r base.in -discord-py==2.4.0 +discord-py==2.5.1 # via # -r base.in # red-lavalink @@ -46,7 +46,7 @@ platformdirs==4.3.6 # via -r base.in propcache==0.2.0 # via yarl -psutil==6.1.1 +psutil==7.0.0 # via -r base.in pygments==2.19.1 # via rich @@ -77,17 +77,19 @@ yarl==1.15.2 # via # -r base.in # aiohttp +zstandard==0.23.0 + # via -r base.in async-timeout==4.0.3; python_version != "3.11" # via aiohttp colorama==0.4.6; sys_platform == "win32" # via click distro==1.9.0; sys_platform == "linux" and sys_platform == "linux" # via -r base.in -importlib-metadata==8.5.0; python_version != "3.11" and python_version != "3.10" +importlib-metadata==8.5.0; python_version != "3.10" and python_version != "3.11" # via markdown pytz==2025.1; python_version == "3.8" # via babel uvloop==0.21.0; (sys_platform != "win32" and platform_python_implementation == "CPython") and sys_platform != "win32" # via -r base.in -zipp==3.20.2; python_version != "3.11" and python_version != "3.10" +zipp==3.20.2; python_version != "3.10" and python_version != "3.11" # via importlib-metadata