Fix uses of re.sub() (#3826)

* Fix uses of `re.sub()` (pt. 1)

* Fix uses of `re.sub()` (pt. 2)

* Fix uses of `re.sub()` (pt. 3)

* Fix uses of `re.sub()` (pt. 4)

* Revert commands.py
This commit is contained in:
jack1142 2020-05-28 23:51:53 +02:00 committed by GitHub
parent 45afaa8ec8
commit ed89f70f98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 4 deletions

View File

@ -262,7 +262,7 @@ class Context(DPYContext):
"""str: The command prefix, but a mention prefix is displayed nicer.""" """str: The command prefix, but a mention prefix is displayed nicer."""
me = self.me me = self.me
pattern = re.compile(rf"<@!?{me.id}>") pattern = re.compile(rf"<@!?{me.id}>")
return pattern.sub(f"@{me.display_name}", self.prefix) return pattern.sub(f"@{me.display_name}".replace("\\", r"\\"), self.prefix)
@property @property
def me(self) -> Union[discord.ClientUser, discord.Member]: def me(self) -> Union[discord.ClientUser, discord.Member]:

View File

@ -1585,7 +1585,7 @@ class Core(commands.Cog, CoreLogic):
footer += _(" | Server ID: {}").format(guild.id) footer += _(" | Server ID: {}").format(guild.id)
prefixes = await ctx.bot.get_valid_prefixes() prefixes = await ctx.bot.get_valid_prefixes()
prefix = re.sub(rf"<@!?{ctx.me.id}>", f"@{ctx.me.name}", prefixes[0]) prefix = re.sub(rf"<@!?{ctx.me.id}>", f"@{ctx.me.name}".replace("\\", r"\\"), prefixes[0])
content = _("Use `{}dm {} <text>` to reply to this user").format(prefix, author.id) content = _("Use `{}dm {} <text>` to reply to this user").format(prefix, author.id)
@ -1690,7 +1690,7 @@ class Core(commands.Cog, CoreLogic):
return return
prefixes = await ctx.bot.get_valid_prefixes() prefixes = await ctx.bot.get_valid_prefixes()
prefix = re.sub(rf"<@!?{ctx.me.id}>", f"@{ctx.me.name}", prefixes[0]) prefix = re.sub(rf"<@!?{ctx.me.id}>", f"@{ctx.me.name}".replace("\\", r"\\"), prefixes[0])
description = _("Owner of {}").format(ctx.bot.user) description = _("Owner of {}").format(ctx.bot.user)
content = _("You can reply to this message with {}contact").format(prefix) content = _("You can reply to this message with {}contact").format(prefix)
if await ctx.embed_requested(): if await ctx.embed_requested():

View File

@ -287,7 +287,9 @@ async def send_to_owners_with_prefix_replaced(bot: Red, content: str, **kwargs):
async def preprocessor(bot: Red, destination: discord.abc.Messageable, content: str) -> str: async def preprocessor(bot: Red, destination: discord.abc.Messageable, content: str) -> str:
prefixes = await bot.get_valid_prefixes(getattr(destination, "guild", None)) prefixes = await bot.get_valid_prefixes(getattr(destination, "guild", None))
prefix = re.sub(rf"<@!?{bot.user.id}>", f"@{bot.user.name}", prefixes[0]) prefix = re.sub(
rf"<@!?{bot.user.id}>", f"@{bot.user.name}".replace("\\", r"\\"), prefixes[0]
)
return content.replace("[p]", prefix) return content.replace("[p]", prefix)
await send_to_owners_with_preprocessor(bot, content, content_preprocessor=preprocessor) await send_to_owners_with_preprocessor(bot, content, content_preprocessor=preprocessor)