d.py 2.3 / pomelo changes (#6130)

Co-authored-by: Michael Oliveira <34169552+Flame442@users.noreply.github.com>
This commit is contained in:
Jakub Kuczys
2023-06-14 04:56:50 +02:00
committed by GitHub
parent 3abf4cac05
commit 10e09d6abc
20 changed files with 216 additions and 173 deletions

View File

@@ -183,13 +183,13 @@ def init_events(bot, cli_flags):
if guilds:
rich_console.print(
Columns(
[Panel(table_general_info, title=str(bot.user.name)), Panel(table_counts)],
[Panel(table_general_info, title=bot.user.display_name), Panel(table_counts)],
equal=True,
align="center",
)
)
else:
rich_console.print(Columns([Panel(table_general_info, title=str(bot.user.name))]))
rich_console.print(Columns([Panel(table_general_info, title=bot.user.display_name)]))
rich_console.print(
"Loaded {} cogs with {} commands".format(len(bot.cogs), len(bot.commands))

View File

@@ -1794,6 +1794,8 @@ class Red(
Checks if the user, message, context, or role should be considered immune from automated
moderation actions.
Bot users are considered immune.
This will return ``False`` in direct messages.
Parameters
@@ -1812,22 +1814,22 @@ class Red(
return False
if isinstance(to_check, discord.Role):
ids_to_check = [to_check.id]
ids_to_check = {to_check.id}
else:
author = getattr(to_check, "author", to_check)
if author.bot:
return True
ids_to_check = set()
try:
ids_to_check = [r.id for r in author.roles]
ids_to_check = {r.id for r in author.roles}
except AttributeError:
# webhook messages are a user not member,
# cheaper than isinstance
if author.bot and author.discriminator == "0000":
return True # webhooks require significant permissions to enable.
else:
ids_to_check.append(author.id)
# cheaper than isinstance(author, discord.User)
pass
ids_to_check.add(author.id)
immune_ids = await self._config.guild(guild).autoimmune_ids()
return any(i in immune_ids for i in ids_to_check)
return not ids_to_check.isdisjoint(immune_ids)
@staticmethod
async def send_filtered(

View File

@@ -2568,7 +2568,9 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
"This will delete all bank accounts for {scope}.\nIf you're sure, type "
"`{prefix}bankset reset yes`"
).format(
scope=self.bot.user.name if await bank.is_global() else _("this server"),
scope=self.bot.user.display_name
if await bank.is_global()
else _("this server"),
prefix=ctx.clean_prefix,
)
)
@@ -2576,7 +2578,9 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
await bank.wipe_bank(guild=ctx.guild)
await ctx.send(
_("All bank accounts for {scope} have been deleted.").format(
scope=self.bot.user.name if await bank.is_global() else _("this server")
scope=self.bot.user.display_name
if await bank.is_global()
else _("this server")
)
)
@@ -3855,7 +3859,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
"Global regional format: {regional_format}\n"
"Default embed colour: {colour}"
).format(
bot_name=ctx.bot.user.name,
bot_name=ctx.bot.user.display_name,
prefixes=prefix_string,
guild_settings=guild_settings,
locale=locale,

View File

@@ -306,8 +306,8 @@ class Case:
(note: it might not exist regardless of whether this attribute is `None`)
or if it has never been created.
last_known_username: Optional[str]
The last known username of the user.
`None` if the username of the user was never saved
The last known user handle (``username`` / ``username#1234``) of the user.
`None` if the handle of the user was never saved
or if their data had to be anonymized.
"""
@@ -393,9 +393,9 @@ class Case:
else:
setattr(self, item, value)
# update last known username
# update last known user handle
if not isinstance(self.user, int):
self.last_known_username = f"{self.user.name}#{self.user.discriminator}"
self.last_known_username = str(self.user)
if isinstance(self.channel, discord.Thread):
self.parent_channel_id = self.channel.parent_id
@@ -503,7 +503,15 @@ class Case:
# can't use _() inside f-string expressions, see bpo-36310 and red#3818
translated = _("Unknown or Deleted User")
user = f"[{translated}] ({self.user})"
# Handle pomelo usernames stored before we updated our implementation
elif self.last_known_username.endswith("#0"):
user = f"{self.last_known_username[:-2]} ({self.user})"
# New usernames can't contain `#` and old usernames couldn't either.
elif len(self.last_known_username) <= 5 or self.last_known_username[-5] != "#":
user = f"{self.last_known_username} ({self.user})"
# Last known user handle is a legacy username with a discriminator
else:
# isolate the name so that the direction of the discriminator and ID aren't changed
# See usage explanation here: https://www.unicode.org/reports/tr9/#Formatting
name = self.last_known_username[:-5]
discriminator = self.last_known_username[-4:]
@@ -511,8 +519,10 @@ class Case:
f"\N{FIRST STRONG ISOLATE}{name}"
f"\N{POP DIRECTIONAL ISOLATE}#{discriminator} ({self.user})"
)
elif self.user.discriminator == "0":
user = f"{self.user} ({self.user.id})"
else:
# isolate the name so that the direction of the discriminator and ID do not get changed
# isolate the name so that the direction of the discriminator and ID aren't changed
# See usage explanation here: https://www.unicode.org/reports/tr9/#Formatting
user = escape_spoilers(
filter_invites(
@@ -1019,7 +1029,7 @@ async def create_case(
channel: Optional[Union[discord.abc.GuildChannel, discord.Thread]]
The channel the action was taken in
last_known_username: Optional[str]
The last known username of the user
The last known user handle (``username`` / ``username#1234``) of the user
Note: This is ignored if a Member or User object is provided
in the user field

View File

@@ -162,7 +162,7 @@ class Tunnel(metaclass=TunnelMeta):
"""
files = []
max_size = 8 * 1000 * 1000
max_size = 26214400
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: