From 9fff0ef6eea9e91f40e23330881e434df22c49a8 Mon Sep 17 00:00:00 2001 From: aikaterna <20862007+aikaterna@users.noreply.github.com> Date: Mon, 11 Jan 2021 11:26:13 -0800 Subject: [PATCH 1/8] Document limit, very small text cleanup --- redbot/core/utils/chat_formatting.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/redbot/core/utils/chat_formatting.py b/redbot/core/utils/chat_formatting.py index e265d348c95..d3435b467f1 100644 --- a/redbot/core/utils/chat_formatting.py +++ b/redbot/core/utils/chat_formatting.py @@ -519,7 +519,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 ---------- @@ -528,10 +528,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)) From 6fd8aaaa6850ece9b297594302b977fb7760f320 Mon Sep 17 00:00:00 2001 From: aikaterna <20862007+aikaterna@users.noreply.github.com> Date: Mon, 11 Jan 2021 11:28:19 -0800 Subject: [PATCH 2/8] Cap audioset jukebox price --- redbot/cogs/audio/core/commands/audioset.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/redbot/cogs/audio/core/commands/audioset.py b/redbot/cogs/audio/core/commands/audioset.py index 830f83b945e..b4c2f4870b9 100644 --- a/redbot/cogs/audio/core/commands/audioset.py +++ b/redbot/cogs/audio/core/commands/audioset.py @@ -754,9 +754,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.") From e7fbd79c539fcca4f938e3019fca6bfb6fc85c87 Mon Sep 17 00:00:00 2001 From: aikaterna <20862007+aikaterna@users.noreply.github.com> Date: Mon, 11 Jan 2021 11:29:45 -0800 Subject: [PATCH 3/8] Cap cleanup number value --- redbot/cogs/cleanup/cleanup.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/redbot/cogs/cleanup/cleanup.py b/redbot/cogs/cleanup/cleanup.py index 928f795872e..a4bb0125573 100644 --- a/redbot/cogs/cleanup/cleanup.py +++ b/redbot/cogs/cleanup/cleanup.py @@ -50,6 +50,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? (y/n)").format( number=humanize_number(number) From a9bc4fb2080dcad309ad33b9bcd22e1b3d2c6fbf Mon Sep 17 00:00:00 2001 From: aikaterna <20862007+aikaterna@users.noreply.github.com> Date: Mon, 11 Jan 2021 11:31:04 -0800 Subject: [PATCH 4/8] Update MAX_ROLL to be in line with value cap --- redbot/cogs/general/general.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redbot/cogs/general/general.py b/redbot/cogs/general/general.py index 8fd3fcf6290..1f026c920c1 100644 --- a/redbot/cogs/general/general.py +++ b/redbot/cogs/general/general.py @@ -39,7 +39,7 @@ def __init__(self, argument): self.choice = None -MAX_ROLL: Final[int] = 2 ** 64 - 1 +MAX_ROLL: Final[int] = 2 ** 63 - 1 @cog_i18n(_) From 34c170a86d0cf183cd8108bc6f14335b27c824cb Mon Sep 17 00:00:00 2001 From: aikaterna <20862007+aikaterna@users.noreply.github.com> Date: Mon, 11 Jan 2021 11:31:52 -0800 Subject: [PATCH 5/8] Add max value to trivia --- redbot/cogs/trivia/converters.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/redbot/cogs/trivia/converters.py b/redbot/cogs/trivia/converters.py index 211ed5d4bbe..fcc729347ec 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) From 591ab2faaca42e66f20da779f5b73820590a6623 Mon Sep 17 00:00:00 2001 From: aikaterna <20862007+aikaterna@users.noreply.github.com> Date: Mon, 11 Jan 2021 11:32:32 -0800 Subject: [PATCH 6/8] Implement max value payout in trivia --- redbot/cogs/trivia/session.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/redbot/cogs/trivia/session.py b/redbot/cogs/trivia/session.py index a748e613d18..eeb4c2a838f 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"] @@ -301,6 +302,7 @@ async def pay_winner(self, multiplier: float): contestants.remove(me_) if len(contestants) >= 3: amount = int(multiplier * score) + amount = MAX_VALUE if amount > MAX_VALUE else amount if amount > 0: LOG.debug("Paying trivia winner: %d credits --> %s", amount, str(winner)) try: From d322d91a18d162e53a4e92a78716dd2edace54bd Mon Sep 17 00:00:00 2001 From: Michael Oliveira <34169552+Flame442@users.noreply.github.com> Date: Fri, 29 Dec 2023 16:11:27 -0500 Subject: [PATCH 7/8] [Audio] Fix attachment suffix reading on playlist upload w/ urllib (#6280) --- redbot/cogs/audio/core/commands/playlists.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 ( From 47a267b38bc63c7f750e2e81d049b617eb25cd07 Mon Sep 17 00:00:00 2001 From: Kreusada Ramicario <67752638+Kreusada@users.noreply.github.com> Date: Tue, 2 Jan 2024 04:25:02 +0000 Subject: [PATCH 8/8] [Help] Allow prefix formatting in taglines (#4972) Co-authored-by: Michael Oliveira <34169552+Flame442@users.noreply.github.com> --- docs/cog_guides/core.rst | 3 +++ redbot/core/commands/help.py | 24 ++++++++++++++++++------ redbot/core/core_commands.py | 3 +++ 3 files changed, 24 insertions(+), 6 deletions(-) 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/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:**