fix: use clean prefix in code blocks (#3591)

This commit is contained in:
jack1142 2020-02-28 21:23:13 +01:00 committed by GitHub
parent 7b042be9db
commit eedec4ff02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 42 additions and 38 deletions

View File

@ -297,7 +297,7 @@ class Admin(commands.Cog):
await ctx.send(_("The announcement has begun.")) await ctx.send(_("The announcement has begun."))
else: else:
prefix = ctx.prefix prefix = ctx.clean_prefix
await ctx.send(_(RUNNING_ANNOUNCEMENT).format(prefix=prefix)) await ctx.send(_(RUNNING_ANNOUNCEMENT).format(prefix=prefix))
@announce.command(name="cancel") @announce.command(name="cancel")

View File

@ -111,7 +111,7 @@ class Bank(commands.Cog):
_( _(
"This will toggle the bank to be {banktype}, deleting all accounts " "This will toggle the bank to be {banktype}, deleting all accounts "
"in the process! If you're sure, type `{command}`" "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: else:
await bank.set_global(not cur_setting) await bank.set_global(not cur_setting)

View File

@ -236,7 +236,7 @@ class CustomCommands(commands.Cog):
except AlreadyExists: except AlreadyExists:
await ctx.send( await ctx.send(
_("This command already exists. Use `{command}` to edit it.").format( _("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: except AlreadyExists:
await ctx.send( await ctx.send(
_("This command already exists. Use `{command}` to edit it.").format( _("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: except ArgParseError as e:
@ -302,7 +302,7 @@ class CustomCommands(commands.Cog):
except NotFound: except NotFound:
await ctx.send( await ctx.send(
_("That command doesn't exist. Use `{command}` to add it.").format( _("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: except NotFound:
await ctx.send( await ctx.send(
_("That command doesn't exist. Use `{command}` to add it.").format( _("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: except ArgParseError as e:
@ -355,7 +355,7 @@ class CustomCommands(commands.Cog):
_( _(
"There are no custom commands in this server." "There are no custom commands in this server."
" Use `{command}` to start adding some." " Use `{command}` to start adding some."
).format(command="{}customcom create".format(ctx.prefix)) ).format(command=f"{ctx.clean_prefix}customcom create")
) )
return return

View File

@ -741,12 +741,12 @@ class Downloader(commands.Cog):
_( _(
"\nThese cogs are now pinned and won't get updated automatically." "\nThese cogs are now pinned and won't get updated automatically."
" To change this, use `{prefix}cog unpin <cog>`" " To change this, use `{prefix}cog unpin <cog>`"
).format(prefix=ctx.prefix) ).format(prefix=ctx.clean_prefix)
if rev is not None if rev is not None
else "" else ""
) )
+ _("\nYou can load them using `{prefix}load <cogs>`").format( + _("\nYou can load them using `{prefix}load <cogs>`").format(
prefix=ctx.prefix prefix=ctx.clean_prefix
) )
+ message + message
) )
@ -797,7 +797,7 @@ class Downloader(commands.Cog):
"\nThey were most likely removed without using `{prefix}cog uninstall`.\n" "\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." "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}`." " 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) await self.send_pagified(ctx, message)

View File

@ -247,7 +247,7 @@ class Economy(commands.Cog):
"`{prefix}bank reset yes`" "`{prefix}bank reset yes`"
).format( ).format(
scope=self.bot.user.name if await bank.is_global() else _("this server"), scope=self.bot.user.name if await bank.is_global() else _("this server"),
prefix=ctx.prefix, prefix=ctx.clean_prefix,
) )
) )
else: else:
@ -279,7 +279,7 @@ class Economy(commands.Cog):
"This will delete all bank accounts for users no longer in this server." "This will delete all bank accounts for users no longer in this server."
"\nIf you're sure, type " "\nIf you're sure, type "
"`{prefix}bank prune local yes`" "`{prefix}bank prune local yes`"
).format(prefix=ctx.prefix) ).format(prefix=ctx.clean_prefix)
) )
else: else:
await bank.bank_prune(self.bot, guild=ctx.guild) 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 " "This will delete all bank accounts for users "
"who no longer share a server with the bot." "who no longer share a server with the bot."
"\nIf you're sure, type `{prefix}bank prune global yes`" "\nIf you're sure, type `{prefix}bank prune global yes`"
).format(prefix=ctx.prefix) ).format(prefix=ctx.clean_prefix)
) )
else: else:
await bank.bank_prune(self.bot) await bank.bank_prune(self.bot)
@ -333,7 +333,7 @@ class Economy(commands.Cog):
"This will delete {name}'s bank account." "This will delete {name}'s bank account."
"\nIf you're sure, type " "\nIf you're sure, type "
"`{prefix}bank prune user {id} yes`" "`{prefix}bank prune user {id} yes`"
).format(prefix=ctx.prefix, id=uid, name=name) ).format(prefix=ctx.clean_prefix, id=uid, name=name)
) )
else: else:
await bank.bank_prune(self.bot, guild=ctx.guild, user_id=uid) await bank.bank_prune(self.bot, guild=ctx.guild, user_id=uid)

View File

@ -54,7 +54,7 @@ class Image(commands.Cog):
await ctx.send( await ctx.send(
_( _(
"A Client ID has not been set! Please set one with `{prefix}imgurcreds`." "A Client ID has not been set! Please set one with `{prefix}imgurcreds`."
).format(prefix=ctx.prefix) ).format(prefix=ctx.clean_prefix)
) )
return return
headers = {"Authorization": "Client-ID {}".format(imgur_client_id)} headers = {"Authorization": "Client-ID {}".format(imgur_client_id)}
@ -107,7 +107,7 @@ class Image(commands.Cog):
await ctx.send( await ctx.send(
_( _(
"A Client ID has not been set! Please set one with `{prefix}imgurcreds`." "A Client ID has not been set! Please set one with `{prefix}imgurcreds`."
).format(prefix=ctx.prefix) ).format(prefix=ctx.clean_prefix)
) )
return return
@ -151,7 +151,7 @@ class Image(commands.Cog):
"8. Check the captcha box and click next.\n" "8. Check the captcha box and click next.\n"
"9. Your Client ID will be on the next page.\n" "9. Your Client ID will be on the next page.\n"
"10. Run the command `{prefix}set api imgur client_id <your_client_id_here>`.\n" "10. Run the command `{prefix}set api imgur client_id <your_client_id_here>`.\n"
).format(prefix=ctx.prefix) ).format(prefix=ctx.clean_prefix)
await ctx.maybe_send_embed(message) await ctx.maybe_send_embed(message)
@ -169,7 +169,7 @@ class Image(commands.Cog):
if not giphy_api_key: if not giphy_api_key:
await ctx.send( await ctx.send(
_("An API key has not been set! Please set one with `{prefix}giphycreds`.").format( _("An API key has not been set! Please set one with `{prefix}giphycreds`.").format(
prefix=ctx.prefix prefix=ctx.clean_prefix
) )
) )
return return
@ -202,7 +202,7 @@ class Image(commands.Cog):
if not giphy_api_key: if not giphy_api_key:
await ctx.send( await ctx.send(
_("An API key has not been set! Please set one with `{prefix}giphycreds`.").format( _("An API key has not been set! Please set one with `{prefix}giphycreds`.").format(
prefix=ctx.prefix prefix=ctx.clean_prefix
) )
) )
return return
@ -235,6 +235,6 @@ class Image(commands.Cog):
"5. Write an app description, example: *Used for Red Bot*.\n" "5. Write an app description, example: *Used for Red Bot*.\n"
"6. Copy the API key shown.\n" "6. Copy the API key shown.\n"
"7. Run the command `{prefix}set api GIPHY api_key <your_api_key_here>`.\n" "7. Run the command `{prefix}set api GIPHY api_key <your_api_key_here>`.\n"
).format(prefix=ctx.prefix) ).format(prefix=ctx.clean_prefix)
await ctx.maybe_send_embed(message) await ctx.maybe_send_embed(message)

View File

@ -1,4 +1,5 @@
import asyncio import asyncio
import re
from abc import ABC from abc import ABC
from collections import defaultdict from collections import defaultdict
from typing import List, Tuple from typing import List, Tuple
@ -104,11 +105,12 @@ class Mod(
await self.settings.version.set("1.0.0") # set version of last update await self.settings.version.set("1.0.0") # set version of last update
if await self.settings.version() < "1.1.0": if await self.settings.version() < "1.1.0":
prefixes = await self.bot.get_valid_prefixes() prefixes = await self.bot.get_valid_prefixes()
prefix = re.sub(rf"<@!?{self.bot.user.id}>", f"@{self.bot.user.name}", prefixes[0])
msg = _( msg = _(
"Ignored guilds and channels have been moved. " "Ignored guilds and channels have been moved. "
"Please use `{prefix}moveignoredchannels` if " "Please use `{prefix}moveignoredchannels` if "
"you were previously using these functions." "you were previously using these functions."
).format(prefix=prefixes[0]) ).format(prefix=prefix)
self.bot.loop.create_task(self.bot.send_to_owners(msg)) self.bot.loop.create_task(self.bot.send_to_owners(msg))
await self.settings.version.set(__version__) await self.settings.version.set(__version__)

View File

@ -200,15 +200,15 @@ class ModSettings(MixinMeta):
if not cur_setting: if not cur_setting:
await self.settings.guild(guild).reinvite_on_unban.set(True) await self.settings.guild(guild).reinvite_on_unban.set(True)
await ctx.send( await ctx.send(
_("Users unbanned with {command} will be reinvited.").format( _("Users unbanned with `{command}` will be reinvited.").format(
command=f"{ctx.prefix}unban" command=f"{ctx.clean_prefix}unban"
) )
) )
else: else:
await self.settings.guild(guild).reinvite_on_unban.set(False) await self.settings.guild(guild).reinvite_on_unban.set(False)
await ctx.send( await ctx.send(
_("Users unbanned with {command} will not be reinvited.").format( _("Users unbanned with `{command}` will not be reinvited.").format(
command=f"{ctx.prefix}unban" command=f"{ctx.clean_prefix}unban"
) )
) )

View File

@ -111,7 +111,8 @@ class Streams(commands.Cog):
try: try:
tokens["client_secret"] tokens["client_secret"]
except KeyError: 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 = _( message = _(
"You need a client secret key to use correctly Twitch API on this cog.\n" "You need a client secret key to use correctly Twitch API on this cog.\n"
"Follow these steps:\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 " "The Twitch token is either invalid or has not been set. See "
"`{prefix}streamset twitchtoken`." "`{prefix}streamset twitchtoken`."
).format(prefix=ctx.prefix) ).format(prefix=ctx.clean_prefix)
) )
except InvalidYoutubeCredentials: except InvalidYoutubeCredentials:
await ctx.send( await ctx.send(
_( _(
"The YouTube API key is either invalid or has not been set. See " "The YouTube API key is either invalid or has not been set. See "
"`{prefix}streamset youtubekey`." "`{prefix}streamset youtubekey`."
).format(prefix=ctx.prefix) ).format(prefix=ctx.clean_prefix)
) )
except APIError: except APIError:
await ctx.send( await ctx.send(
@ -357,7 +358,7 @@ class Streams(commands.Cog):
_( _(
"The Twitch token is either invalid or has not been set. See " "The Twitch token is either invalid or has not been set. See "
"`{prefix}streamset twitchtoken`." "`{prefix}streamset twitchtoken`."
).format(prefix=ctx.prefix) ).format(prefix=ctx.clean_prefix)
) )
return return
except InvalidYoutubeCredentials: except InvalidYoutubeCredentials:
@ -365,7 +366,7 @@ class Streams(commands.Cog):
_( _(
"The YouTube API key is either invalid or has not been set. See " "The YouTube API key is either invalid or has not been set. See "
"`{prefix}streamset youtubekey`." "`{prefix}streamset youtubekey`."
).format(prefix=ctx.prefix) ).format(prefix=ctx.clean_prefix)
) )
return return
except APIError: except APIError:
@ -415,7 +416,7 @@ class Streams(commands.Cog):
"client_secret <your_client_secret_here>`\n\n" "client_secret <your_client_secret_here>`\n\n"
"Note: These tokens are sensitive and should only be used in a private channel\n" "Note: These tokens are sensitive and should only be used in a private channel\n"
"or in DM with the bot.\n" "or in DM with the bot.\n"
).format(prefix=ctx.prefix) ).format(prefix=ctx.clean_prefix)
await ctx.maybe_send_embed(message) await ctx.maybe_send_embed(message)
@ -436,7 +437,7 @@ class Streams(commands.Cog):
"`{prefix}set api youtube api_key <your_api_key_here>`\n\n" "`{prefix}set api youtube api_key <your_api_key_here>`\n\n"
"Note: These tokens are sensitive and should only be used in a private channel\n" "Note: These tokens are sensitive and should only be used in a private channel\n"
"or in DM with the bot.\n" "or in DM with the bot.\n"
).format(prefix=ctx.prefix) ).format(prefix=ctx.clean_prefix)
await ctx.maybe_send_embed(message) await ctx.maybe_send_embed(message)

View File

@ -198,7 +198,7 @@ class Trivia(commands.Cog):
_( _(
"Invalid category `{name}`. See `{prefix}trivia list` for a list of " "Invalid category `{name}`. See `{prefix}trivia list` for a list of "
"trivia categories." "trivia categories."
).format(name=category, prefix=ctx.prefix) ).format(name=category, prefix=ctx.clean_prefix)
) )
except InvalidListError: except InvalidListError:
await ctx.send( await ctx.send(
@ -302,7 +302,7 @@ class Trivia(commands.Cog):
_( _(
"Unknown field `{field_name}`, see `{prefix}help trivia leaderboard server` " "Unknown field `{field_name}`, see `{prefix}help trivia leaderboard server` "
"for valid fields to sort by." "for valid fields to sort by."
).format(field_name=sort_by, prefix=ctx.prefix) ).format(field_name=sort_by, prefix=ctx.clean_prefix)
) )
return return
guild = ctx.guild guild = ctx.guild
@ -331,7 +331,7 @@ class Trivia(commands.Cog):
_( _(
"Unknown field `{field_name}`, see `{prefix}help trivia leaderboard server` " "Unknown field `{field_name}`, see `{prefix}help trivia leaderboard server` "
"for valid fields to sort by." "for valid fields to sort by."
).format(field_name=sort_by, prefix=ctx.prefix) ).format(field_name=sort_by, prefix=ctx.clean_prefix)
) )
return return
data = await self.conf.all_members() data = await self.conf.all_members()

View File

@ -280,7 +280,7 @@ class Warnings(commands.Cog):
msg += " " + _( msg += " " + _(
"Do `{prefix}warningset allowcustomreasons true` to enable custom " "Do `{prefix}warningset allowcustomreasons true` to enable custom "
"reasons." "reasons."
).format(prefix=ctx.prefix) ).format(prefix=ctx.clean_prefix)
return await ctx.send(msg) return await ctx.send(msg)
else: else:
reason_type = registered_reasons[reason.lower()] reason_type = registered_reasons[reason.lower()]
@ -322,7 +322,7 @@ class Warnings(commands.Cog):
reason=_("{description}\nPoints: {points}").format( reason=_("{description}\nPoints: {points}").format(
description=reason_type["description"], points=reason_type["points"] description=reason_type["description"], points=reason_type["points"]
), ),
prefix=ctx.prefix, prefix=ctx.clean_prefix,
user=user.id, user=user.id,
message=ctx.message.id, message=ctx.message.id,
) )

View File

@ -3,6 +3,7 @@ import inspect
import logging import logging
import os import os
import platform import platform
import re
import shutil import shutil
import sys import sys
from collections import namedtuple from collections import namedtuple
@ -551,7 +552,7 @@ class RedBase(
destinations = await self.get_owner_notification_destinations() destinations = await self.get_owner_notification_destinations()
for destination in destinations: for destination in destinations:
prefixes = await self.get_valid_prefixes(getattr(destination, "guild", None)) 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: try:
await destination.send(content.format(prefix=prefix)) await destination.send(content.format(prefix=prefix))
except Exception as _exc: except Exception as _exc: