diff --git a/docs/cog_guides/core.rst b/docs/cog_guides/core.rst index d3a3ed849f9..69e1895494f 100644 --- a/docs/cog_guides/core.rst +++ b/docs/cog_guides/core.rst @@ -1683,8 +1683,11 @@ Set the tagline to be used. The maximum tagline length is 2048 characters. This setting only applies to embedded help. If no tagline is specified, the default will be used instead. +You can use ``[p]`` in your tagline, which will be replaced by the bot's prefix. + **Examples:** - ``[p]helpset tagline Thanks for using the bot!`` + - ``[p]helpset tagline Use [p]invite to add me to your server.`` - ``[p]helpset tagline`` - Resets the tagline to the default. **Arguments:** diff --git a/redbot/cogs/audio/core/commands/audioset.py b/redbot/cogs/audio/core/commands/audioset.py index 2ad0e0bbf61..57194fd649e 100644 --- a/redbot/cogs/audio/core/commands/audioset.py +++ b/redbot/cogs/audio/core/commands/audioset.py @@ -758,9 +758,17 @@ async def command_audioset_jukebox(self, ctx: commands.Context, price: int): """Set a price for queueing tracks for non-mods, 0 to disable.""" if price < 0: return await self.send_embed_msg( - ctx, title=_("Invalid Price"), description=_("Price can't be less than zero.") + ctx, + title=_("Invalid Price"), + description=_("Price can't be less than zero."), + ) + elif price > 2**63 - 1: + return await self.send_embed_msg( + ctx, + title=_("Invalid Price"), + description=_("Price can't be greater than 2^63 - 1."), ) - if price == 0: + elif price == 0: jukebox = False await self.send_embed_msg( ctx, title=_("Setting Changed"), description=_("Jukebox mode disabled.") diff --git a/redbot/cogs/audio/core/commands/playlists.py b/redbot/cogs/audio/core/commands/playlists.py index 746b4588193..b654828f8e3 100644 --- a/redbot/cogs/audio/core/commands/playlists.py +++ b/redbot/cogs/audio/core/commands/playlists.py @@ -7,6 +7,7 @@ from io import BytesIO from pathlib import Path +from urllib.parse import urlparse from typing import cast import discord @@ -1823,7 +1824,7 @@ async def command_playlist_upload( file_url = file_message.attachments[0].url except IndexError: return await self.send_embed_msg(ctx, title=_("Upload cancelled.")) - file_suffix = file_url.rsplit(".", 1)[1] + file_suffix = urlparse(file_url).path.rsplit(".", 1)[1] if file_suffix != "txt": return await self.send_embed_msg( ctx, title=_("Only Red playlist files can be uploaded.") @@ -1848,7 +1849,7 @@ async def command_playlist_upload( if len(track_list) > 10000: return await self.send_embed_msg(ctx, title=_("This playlist is too large.")) uploaded_playlist_name = uploaded_playlist.get( - "name", (file_url.split("/")[6]).split(".")[0] + "name", (urlparse(file_url).path.split("/")[-1]).rsplit(".", 1)[0] ) try: if self.api_interface is not None and ( diff --git a/redbot/cogs/cleanup/cleanup.py b/redbot/cogs/cleanup/cleanup.py index bd3095f2487..27bd4398fcd 100644 --- a/redbot/cogs/cleanup/cleanup.py +++ b/redbot/cogs/cleanup/cleanup.py @@ -54,6 +54,9 @@ async def check_100_plus(ctx: commands.Context, number: int) -> bool: if ctx.assume_yes: return True + if number > 2**63 - 1: + return await ctx.send(_("Try a smaller number instead.")) + prompt = await ctx.send( _("Are you sure you want to delete {number} messages?").format( number=humanize_number(number) diff --git a/redbot/cogs/general/general.py b/redbot/cogs/general/general.py index 1ffb1b97162..8e251fee594 100644 --- a/redbot/cogs/general/general.py +++ b/redbot/cogs/general/general.py @@ -40,7 +40,7 @@ def __init__(self, argument): self.choice = None -MAX_ROLL: Final[int] = 2**64 - 1 +MAX_ROLL: Final[int] = 2**63 - 1 @cog_i18n(_) diff --git a/redbot/cogs/trivia/converters.py b/redbot/cogs/trivia/converters.py index 211ed5d4bbe..a5b7a41eedc 100644 --- a/redbot/cogs/trivia/converters.py +++ b/redbot/cogs/trivia/converters.py @@ -8,6 +8,9 @@ _ = Translator("Trivia", __file__) +MAX_VALUE = 2**63 - 1 + + def finite_float(arg: str) -> float: try: ret = float(arg) diff --git a/redbot/cogs/trivia/session.py b/redbot/cogs/trivia/session.py index 824d75e5f00..abe31e0aa00 100644 --- a/redbot/cogs/trivia/session.py +++ b/redbot/cogs/trivia/session.py @@ -8,6 +8,7 @@ from redbot.core.i18n import Translator from redbot.core.utils.chat_formatting import box, bold, humanize_list, humanize_number from redbot.core.utils.common_filters import normalize_smartquotes +from .converters import MAX_VALUE from .log import LOG __all__ = ["TriviaSession"] @@ -320,6 +321,7 @@ async def pay_winners(self, multiplier: float): if not winners or num_humans < 3: return payout = int(top_score * multiplier / len(winners)) + payout = MAX_VALUE if payout > MAX_VALUE else payout if payout <= 0: return for winner in winners: diff --git a/redbot/core/commands/help.py b/redbot/core/commands/help.py index 75f05bc94bc..dcff3f0410e 100644 --- a/redbot/core/commands/help.py +++ b/redbot/core/commands/help.py @@ -308,6 +308,12 @@ def get_default_tagline(ctx: Context): command2=f"{ctx.clean_prefix}help ", ) + @staticmethod + def format_tagline(ctx: Context, tagline: str): + if not tagline: + return + return tagline.replace("[p]", ctx.clean_prefix) + @staticmethod def get_command_signature(ctx: Context, command: commands.Command) -> str: parent = command.parent @@ -345,7 +351,7 @@ async def format_command_help( description = command.description or "" - tagline = (help_settings.tagline) or self.get_default_tagline(ctx) + tagline = self.format_tagline(ctx, help_settings.tagline) or self.get_default_tagline(ctx) signature = _("Syntax: {command_signature}").format( command_signature=self.get_command_signature(ctx, command) ) @@ -569,7 +575,7 @@ async def format_cog_help(self, ctx: Context, obj: commands.Cog, help_settings: return description = obj.format_help_for_context(ctx) - tagline = (help_settings.tagline) or self.get_default_tagline(ctx) + tagline = self.format_tagline(ctx, help_settings.tagline) or self.get_default_tagline(ctx) if await self.embed_requested(ctx): emb = {"embed": {"title": "", "description": ""}, "footer": {"text": ""}, "fields": []} @@ -642,7 +648,7 @@ async def format_bot_help(self, ctx: Context, help_settings: HelpSettings): return description = ctx.bot.description or "" - tagline = (help_settings.tagline) or self.get_default_tagline(ctx) + tagline = self.format_tagline(ctx, help_settings.tagline) or self.get_default_tagline(ctx) if await self.embed_requested(ctx): emb = {"embed": {"title": "", "description": ""}, "footer": {"text": ""}, "fields": []} @@ -763,7 +769,9 @@ async def command_not_found(self, ctx, help_for, help_settings: HelpSettings): name=_("{ctx.me.display_name} Help Menu").format(ctx=ctx), icon_url=ctx.me.display_avatar, ) - tagline = help_settings.tagline or self.get_default_tagline(ctx) + tagline = self.format_tagline( + ctx, help_settings.tagline + ) or self.get_default_tagline(ctx) ret.set_footer(text=tagline) await ctx.send(embed=ret) else: @@ -776,7 +784,9 @@ async def command_not_found(self, ctx, help_for, help_settings: HelpSettings): name=_("{ctx.me.display_name} Help Menu").format(ctx=ctx), icon_url=ctx.me.display_avatar, ) - tagline = help_settings.tagline or self.get_default_tagline(ctx) + tagline = self.format_tagline( + ctx, help_settings.tagline + ) or self.get_default_tagline(ctx) ret.set_footer(text=tagline) await ctx.send(embed=ret) else: @@ -795,7 +805,9 @@ async def subcommand_not_found(self, ctx, command, not_found, help_settings: Hel name=_("{ctx.me.display_name} Help Menu").format(ctx=ctx), icon_url=ctx.me.display_avatar, ) - tagline = help_settings.tagline or self.get_default_tagline(ctx) + tagline = self.format_tagline(ctx, help_settings.tagline) or self.get_default_tagline( + ctx + ) ret.set_footer(text=tagline) await ctx.send(embed=ret) else: diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 6483de26adb..3930ac79408 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -4535,8 +4535,11 @@ async def helpset_tagline(self, ctx: commands.Context, *, tagline: str = None): The maximum tagline length is 2048 characters. This setting only applies to embedded help. If no tagline is specified, the default will be used instead. + You can use `[\u200bp]` in your tagline, which will be replaced by the bot's prefix. + **Examples:** - `[p]helpset tagline Thanks for using the bot!` + - `[p]helpset tagline Use [\u200bp]invite to add me to your server.` - `[p]helpset tagline` - Resets the tagline to the default. **Arguments:** diff --git a/redbot/core/utils/chat_formatting.py b/redbot/core/utils/chat_formatting.py index 8cf37e8a267..afcfc2d126d 100644 --- a/redbot/core/utils/chat_formatting.py +++ b/redbot/core/utils/chat_formatting.py @@ -576,7 +576,7 @@ def humanize_timedelta( def humanize_number(val: Union[int, float], override_locale=None) -> str: """ - Convert an int or float to a str with digit separators based on bot locale + Convert an int or float to a str with digit separators based on bot locale. Parameters ---------- @@ -585,10 +585,15 @@ def humanize_number(val: Union[int, float], override_locale=None) -> str: override_locale: Optional[str] A value to override bot's regional format. + Raises + ------ + decimals.InvalidOperation + If val is greater than 10 x 10^21 for some locales, 10 x 10^24 in others. + Returns ------- str - locale aware formatted number. + Locale-aware formatted number. """ return format_decimal(val, locale=get_babel_regional_format(override_locale))