Skip to content

Commit

Permalink
Humanize number fix (#6283)
Browse files Browse the repository at this point in the history
Co-authored-by: Jakub Kuczys <[email protected]>
  • Loading branch information
aikaterna and Jackenmen authored Jan 4, 2024
1 parent 47a267b commit 531b4fe
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
12 changes: 10 additions & 2 deletions redbot/cogs/audio/core/commands/audioset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
3 changes: 3 additions & 0 deletions redbot/cogs/cleanup/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion redbot/cogs/general/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)
Expand Down
3 changes: 3 additions & 0 deletions redbot/cogs/trivia/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
_ = Translator("Trivia", __file__)


MAX_VALUE = 2**63 - 1


def finite_float(arg: str) -> float:
try:
ret = float(arg)
Expand Down
2 changes: 2 additions & 0 deletions redbot/cogs/trivia/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions redbot/core/utils/chat_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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))

Expand Down

0 comments on commit 531b4fe

Please sign in to comment.