diff --git a/redbot/cogs/admin/admin.py b/redbot/cogs/admin/admin.py index 245cc242e..cfecd2d4f 100644 --- a/redbot/cogs/admin/admin.py +++ b/redbot/cogs/admin/admin.py @@ -297,7 +297,7 @@ class Admin(commands.Cog): await ctx.send(_("The announcement has begun.")) else: - prefix = ctx.prefix + prefix = ctx.clean_prefix await ctx.send(_(RUNNING_ANNOUNCEMENT).format(prefix=prefix)) @announce.command(name="cancel") diff --git a/redbot/cogs/bank/bank.py b/redbot/cogs/bank/bank.py index abee96905..48fb059e7 100644 --- a/redbot/cogs/bank/bank.py +++ b/redbot/cogs/bank/bank.py @@ -111,7 +111,7 @@ class Bank(commands.Cog): _( "This will toggle the bank to be {banktype}, deleting all accounts " "in the process! If you're sure, type `{command}`" - ).format(banktype=word, command="{}bankset toggleglobal yes".format(ctx.prefix)) + ).format(banktype=word, command=f"{ctx.clean_prefix}bankset toggleglobal yes") ) else: await bank.set_global(not cur_setting) diff --git a/redbot/cogs/customcom/customcom.py b/redbot/cogs/customcom/customcom.py index b9c674559..36e4b5284 100644 --- a/redbot/cogs/customcom/customcom.py +++ b/redbot/cogs/customcom/customcom.py @@ -236,7 +236,7 @@ class CustomCommands(commands.Cog): except AlreadyExists: await ctx.send( _("This command already exists. Use `{command}` to edit it.").format( - command="{}customcom edit".format(ctx.prefix) + command=f"{ctx.clean_prefix}customcom edit" ) ) @@ -257,7 +257,7 @@ class CustomCommands(commands.Cog): except AlreadyExists: await ctx.send( _("This command already exists. Use `{command}` to edit it.").format( - command="{}customcom edit".format(ctx.prefix) + command=f"{ctx.clean_prefix}customcom edit" ) ) except ArgParseError as e: @@ -302,7 +302,7 @@ class CustomCommands(commands.Cog): except NotFound: await ctx.send( _("That command doesn't exist. Use `{command}` to add it.").format( - command="{}customcom create".format(ctx.prefix) + command=f"{ctx.clean_prefix}customcom create" ) ) @@ -334,7 +334,7 @@ class CustomCommands(commands.Cog): except NotFound: await ctx.send( _("That command doesn't exist. Use `{command}` to add it.").format( - command="{}customcom create".format(ctx.prefix) + command=f"{ctx.clean_prefix}customcom create" ) ) except ArgParseError as e: @@ -355,7 +355,7 @@ class CustomCommands(commands.Cog): _( "There are no custom commands in this server." " Use `{command}` to start adding some." - ).format(command="{}customcom create".format(ctx.prefix)) + ).format(command=f"{ctx.clean_prefix}customcom create") ) return diff --git a/redbot/cogs/downloader/downloader.py b/redbot/cogs/downloader/downloader.py index 5cb091a1d..84afca173 100644 --- a/redbot/cogs/downloader/downloader.py +++ b/redbot/cogs/downloader/downloader.py @@ -741,12 +741,12 @@ class Downloader(commands.Cog): _( "\nThese cogs are now pinned and won't get updated automatically." " To change this, use `{prefix}cog unpin `" - ).format(prefix=ctx.prefix) + ).format(prefix=ctx.clean_prefix) if rev is not None else "" ) + _("\nYou can load them using `{prefix}load `").format( - prefix=ctx.prefix + prefix=ctx.clean_prefix ) + message ) @@ -797,7 +797,7 @@ class Downloader(commands.Cog): "\nThey were most likely removed without using `{prefix}cog uninstall`.\n" "You may need to remove those files manually if the cogs are still usable." " If so, ensure the cogs have been unloaded with `{prefix}unload {cogs}`." - ).format(prefix=ctx.prefix, cogs=" ".join(failed_cogs)) + ).format(prefix=ctx.clean_prefix, cogs=" ".join(failed_cogs)) ) await self.send_pagified(ctx, message) diff --git a/redbot/cogs/economy/economy.py b/redbot/cogs/economy/economy.py index 8fc12a8ae..4fc05cd0e 100644 --- a/redbot/cogs/economy/economy.py +++ b/redbot/cogs/economy/economy.py @@ -247,7 +247,7 @@ class Economy(commands.Cog): "`{prefix}bank reset yes`" ).format( scope=self.bot.user.name if await bank.is_global() else _("this server"), - prefix=ctx.prefix, + prefix=ctx.clean_prefix, ) ) else: @@ -279,7 +279,7 @@ class Economy(commands.Cog): "This will delete all bank accounts for users no longer in this server." "\nIf you're sure, type " "`{prefix}bank prune local yes`" - ).format(prefix=ctx.prefix) + ).format(prefix=ctx.clean_prefix) ) else: await bank.bank_prune(self.bot, guild=ctx.guild) @@ -301,7 +301,7 @@ class Economy(commands.Cog): "This will delete all bank accounts for users " "who no longer share a server with the bot." "\nIf you're sure, type `{prefix}bank prune global yes`" - ).format(prefix=ctx.prefix) + ).format(prefix=ctx.clean_prefix) ) else: await bank.bank_prune(self.bot) @@ -333,7 +333,7 @@ class Economy(commands.Cog): "This will delete {name}'s bank account." "\nIf you're sure, type " "`{prefix}bank prune user {id} yes`" - ).format(prefix=ctx.prefix, id=uid, name=name) + ).format(prefix=ctx.clean_prefix, id=uid, name=name) ) else: await bank.bank_prune(self.bot, guild=ctx.guild, user_id=uid) diff --git a/redbot/cogs/image/image.py b/redbot/cogs/image/image.py index 91d776ed5..dab583a91 100644 --- a/redbot/cogs/image/image.py +++ b/redbot/cogs/image/image.py @@ -54,7 +54,7 @@ class Image(commands.Cog): await ctx.send( _( "A Client ID has not been set! Please set one with `{prefix}imgurcreds`." - ).format(prefix=ctx.prefix) + ).format(prefix=ctx.clean_prefix) ) return headers = {"Authorization": "Client-ID {}".format(imgur_client_id)} @@ -107,7 +107,7 @@ class Image(commands.Cog): await ctx.send( _( "A Client ID has not been set! Please set one with `{prefix}imgurcreds`." - ).format(prefix=ctx.prefix) + ).format(prefix=ctx.clean_prefix) ) return @@ -151,7 +151,7 @@ class Image(commands.Cog): "8. Check the captcha box and click next.\n" "9. Your Client ID will be on the next page.\n" "10. Run the command `{prefix}set api imgur client_id `.\n" - ).format(prefix=ctx.prefix) + ).format(prefix=ctx.clean_prefix) await ctx.maybe_send_embed(message) @@ -169,7 +169,7 @@ class Image(commands.Cog): if not giphy_api_key: await ctx.send( _("An API key has not been set! Please set one with `{prefix}giphycreds`.").format( - prefix=ctx.prefix + prefix=ctx.clean_prefix ) ) return @@ -202,7 +202,7 @@ class Image(commands.Cog): if not giphy_api_key: await ctx.send( _("An API key has not been set! Please set one with `{prefix}giphycreds`.").format( - prefix=ctx.prefix + prefix=ctx.clean_prefix ) ) return @@ -235,6 +235,6 @@ class Image(commands.Cog): "5. Write an app description, example: *Used for Red Bot*.\n" "6. Copy the API key shown.\n" "7. Run the command `{prefix}set api GIPHY api_key `.\n" - ).format(prefix=ctx.prefix) + ).format(prefix=ctx.clean_prefix) await ctx.maybe_send_embed(message) diff --git a/redbot/cogs/mod/mod.py b/redbot/cogs/mod/mod.py index 65128f1bf..55a58e581 100644 --- a/redbot/cogs/mod/mod.py +++ b/redbot/cogs/mod/mod.py @@ -1,4 +1,5 @@ import asyncio +import re from abc import ABC from collections import defaultdict from typing import List, Tuple @@ -104,11 +105,12 @@ class Mod( await self.settings.version.set("1.0.0") # set version of last update if await self.settings.version() < "1.1.0": prefixes = await self.bot.get_valid_prefixes() + prefix = re.sub(rf"<@!?{self.bot.user.id}>", f"@{self.bot.user.name}", prefixes[0]) msg = _( "Ignored guilds and channels have been moved. " "Please use `{prefix}moveignoredchannels` if " "you were previously using these functions." - ).format(prefix=prefixes[0]) + ).format(prefix=prefix) self.bot.loop.create_task(self.bot.send_to_owners(msg)) await self.settings.version.set(__version__) diff --git a/redbot/cogs/mod/settings.py b/redbot/cogs/mod/settings.py index 24dfc7fc9..efa00c0e0 100644 --- a/redbot/cogs/mod/settings.py +++ b/redbot/cogs/mod/settings.py @@ -200,15 +200,15 @@ class ModSettings(MixinMeta): if not cur_setting: await self.settings.guild(guild).reinvite_on_unban.set(True) await ctx.send( - _("Users unbanned with {command} will be reinvited.").format( - command=f"{ctx.prefix}unban" + _("Users unbanned with `{command}` will be reinvited.").format( + command=f"{ctx.clean_prefix}unban" ) ) else: await self.settings.guild(guild).reinvite_on_unban.set(False) await ctx.send( - _("Users unbanned with {command} will not be reinvited.").format( - command=f"{ctx.prefix}unban" + _("Users unbanned with `{command}` will not be reinvited.").format( + command=f"{ctx.clean_prefix}unban" ) ) diff --git a/redbot/cogs/streams/streams.py b/redbot/cogs/streams/streams.py index a2d424755..197d624b6 100644 --- a/redbot/cogs/streams/streams.py +++ b/redbot/cogs/streams/streams.py @@ -111,7 +111,8 @@ class Streams(commands.Cog): try: tokens["client_secret"] except KeyError: - prefix = (await self.bot._config.prefix())[0] + prefixes = await self.bot.get_valid_prefixes() + prefix = re.sub(rf"<@!?{self.bot.user.id}>", f"@{self.bot.user.name}", prefixes[0]) message = _( "You need a client secret key to use correctly Twitch API on this cog.\n" "Follow these steps:\n" @@ -203,14 +204,14 @@ class Streams(commands.Cog): _( "The Twitch token is either invalid or has not been set. See " "`{prefix}streamset twitchtoken`." - ).format(prefix=ctx.prefix) + ).format(prefix=ctx.clean_prefix) ) except InvalidYoutubeCredentials: await ctx.send( _( "The YouTube API key is either invalid or has not been set. See " "`{prefix}streamset youtubekey`." - ).format(prefix=ctx.prefix) + ).format(prefix=ctx.clean_prefix) ) except APIError: await ctx.send( @@ -357,7 +358,7 @@ class Streams(commands.Cog): _( "The Twitch token is either invalid or has not been set. See " "`{prefix}streamset twitchtoken`." - ).format(prefix=ctx.prefix) + ).format(prefix=ctx.clean_prefix) ) return except InvalidYoutubeCredentials: @@ -365,7 +366,7 @@ class Streams(commands.Cog): _( "The YouTube API key is either invalid or has not been set. See " "`{prefix}streamset youtubekey`." - ).format(prefix=ctx.prefix) + ).format(prefix=ctx.clean_prefix) ) return except APIError: @@ -415,7 +416,7 @@ class Streams(commands.Cog): "client_secret `\n\n" "Note: These tokens are sensitive and should only be used in a private channel\n" "or in DM with the bot.\n" - ).format(prefix=ctx.prefix) + ).format(prefix=ctx.clean_prefix) await ctx.maybe_send_embed(message) @@ -436,7 +437,7 @@ class Streams(commands.Cog): "`{prefix}set api youtube api_key `\n\n" "Note: These tokens are sensitive and should only be used in a private channel\n" "or in DM with the bot.\n" - ).format(prefix=ctx.prefix) + ).format(prefix=ctx.clean_prefix) await ctx.maybe_send_embed(message) diff --git a/redbot/cogs/trivia/trivia.py b/redbot/cogs/trivia/trivia.py index ed19eff46..046aefbba 100644 --- a/redbot/cogs/trivia/trivia.py +++ b/redbot/cogs/trivia/trivia.py @@ -198,7 +198,7 @@ class Trivia(commands.Cog): _( "Invalid category `{name}`. See `{prefix}trivia list` for a list of " "trivia categories." - ).format(name=category, prefix=ctx.prefix) + ).format(name=category, prefix=ctx.clean_prefix) ) except InvalidListError: await ctx.send( @@ -302,7 +302,7 @@ class Trivia(commands.Cog): _( "Unknown field `{field_name}`, see `{prefix}help trivia leaderboard server` " "for valid fields to sort by." - ).format(field_name=sort_by, prefix=ctx.prefix) + ).format(field_name=sort_by, prefix=ctx.clean_prefix) ) return guild = ctx.guild @@ -331,7 +331,7 @@ class Trivia(commands.Cog): _( "Unknown field `{field_name}`, see `{prefix}help trivia leaderboard server` " "for valid fields to sort by." - ).format(field_name=sort_by, prefix=ctx.prefix) + ).format(field_name=sort_by, prefix=ctx.clean_prefix) ) return data = await self.conf.all_members() diff --git a/redbot/cogs/warnings/warnings.py b/redbot/cogs/warnings/warnings.py index 6ad3755b8..914745c96 100644 --- a/redbot/cogs/warnings/warnings.py +++ b/redbot/cogs/warnings/warnings.py @@ -280,7 +280,7 @@ class Warnings(commands.Cog): msg += " " + _( "Do `{prefix}warningset allowcustomreasons true` to enable custom " "reasons." - ).format(prefix=ctx.prefix) + ).format(prefix=ctx.clean_prefix) return await ctx.send(msg) else: reason_type = registered_reasons[reason.lower()] @@ -322,7 +322,7 @@ class Warnings(commands.Cog): reason=_("{description}\nPoints: {points}").format( description=reason_type["description"], points=reason_type["points"] ), - prefix=ctx.prefix, + prefix=ctx.clean_prefix, user=user.id, message=ctx.message.id, ) diff --git a/redbot/core/bot.py b/redbot/core/bot.py index a7e549577..0f53373dd 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -3,6 +3,7 @@ import inspect import logging import os import platform +import re import shutil import sys from collections import namedtuple @@ -551,7 +552,7 @@ class RedBase( destinations = await self.get_owner_notification_destinations() for destination in destinations: prefixes = await self.get_valid_prefixes(getattr(destination, "guild", None)) - prefix = prefixes[0] + prefix = re.sub(rf"<@!?{self.bot.user.id}>", f"@{self.bot.user.name}", prefixes[0]) try: await destination.send(content.format(prefix=prefix)) except Exception as _exc: