mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
Humanize number fix (#6283)
Co-authored-by: Jakub Kuczys <me@jacken.men>
This commit is contained in:
parent
47a267b38b
commit
531b4fe357
@ -758,9 +758,17 @@ class AudioSetCommands(MixinMeta, metaclass=CompositeMetaClass):
|
|||||||
"""Set a price for queueing tracks for non-mods, 0 to disable."""
|
"""Set a price for queueing tracks for non-mods, 0 to disable."""
|
||||||
if price < 0:
|
if price < 0:
|
||||||
return await self.send_embed_msg(
|
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."),
|
||||||
)
|
)
|
||||||
if price == 0:
|
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."),
|
||||||
|
)
|
||||||
|
elif price == 0:
|
||||||
jukebox = False
|
jukebox = False
|
||||||
await self.send_embed_msg(
|
await self.send_embed_msg(
|
||||||
ctx, title=_("Setting Changed"), description=_("Jukebox mode disabled.")
|
ctx, title=_("Setting Changed"), description=_("Jukebox mode disabled.")
|
||||||
|
|||||||
@ -54,6 +54,9 @@ class Cleanup(commands.Cog):
|
|||||||
if ctx.assume_yes:
|
if ctx.assume_yes:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
if number > 2**63 - 1:
|
||||||
|
return await ctx.send(_("Try a smaller number instead."))
|
||||||
|
|
||||||
prompt = await ctx.send(
|
prompt = await ctx.send(
|
||||||
_("Are you sure you want to delete {number} messages?").format(
|
_("Are you sure you want to delete {number} messages?").format(
|
||||||
number=humanize_number(number)
|
number=humanize_number(number)
|
||||||
|
|||||||
@ -40,7 +40,7 @@ class RPSParser:
|
|||||||
self.choice = None
|
self.choice = None
|
||||||
|
|
||||||
|
|
||||||
MAX_ROLL: Final[int] = 2**64 - 1
|
MAX_ROLL: Final[int] = 2**63 - 1
|
||||||
|
|
||||||
|
|
||||||
@cog_i18n(_)
|
@cog_i18n(_)
|
||||||
|
|||||||
@ -8,6 +8,9 @@ __all__ = ("finite_float",)
|
|||||||
_ = Translator("Trivia", __file__)
|
_ = Translator("Trivia", __file__)
|
||||||
|
|
||||||
|
|
||||||
|
MAX_VALUE = 2**63 - 1
|
||||||
|
|
||||||
|
|
||||||
def finite_float(arg: str) -> float:
|
def finite_float(arg: str) -> float:
|
||||||
try:
|
try:
|
||||||
ret = float(arg)
|
ret = float(arg)
|
||||||
|
|||||||
@ -8,6 +8,7 @@ from redbot.core import bank, errors
|
|||||||
from redbot.core.i18n import Translator
|
from redbot.core.i18n import Translator
|
||||||
from redbot.core.utils.chat_formatting import box, bold, humanize_list, humanize_number
|
from redbot.core.utils.chat_formatting import box, bold, humanize_list, humanize_number
|
||||||
from redbot.core.utils.common_filters import normalize_smartquotes
|
from redbot.core.utils.common_filters import normalize_smartquotes
|
||||||
|
from .converters import MAX_VALUE
|
||||||
from .log import LOG
|
from .log import LOG
|
||||||
|
|
||||||
__all__ = ["TriviaSession"]
|
__all__ = ["TriviaSession"]
|
||||||
@ -320,6 +321,7 @@ class TriviaSession:
|
|||||||
if not winners or num_humans < 3:
|
if not winners or num_humans < 3:
|
||||||
return
|
return
|
||||||
payout = int(top_score * multiplier / len(winners))
|
payout = int(top_score * multiplier / len(winners))
|
||||||
|
payout = MAX_VALUE if payout > MAX_VALUE else payout
|
||||||
if payout <= 0:
|
if payout <= 0:
|
||||||
return
|
return
|
||||||
for winner in winners:
|
for winner in winners:
|
||||||
|
|||||||
@ -576,7 +576,7 @@ def humanize_timedelta(
|
|||||||
|
|
||||||
def humanize_number(val: Union[int, float], override_locale=None) -> str:
|
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
|
Parameters
|
||||||
----------
|
----------
|
||||||
@ -585,10 +585,15 @@ def humanize_number(val: Union[int, float], override_locale=None) -> str:
|
|||||||
override_locale: Optional[str]
|
override_locale: Optional[str]
|
||||||
A value to override bot's regional format.
|
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
|
Returns
|
||||||
-------
|
-------
|
||||||
str
|
str
|
||||||
locale aware formatted number.
|
Locale-aware formatted number.
|
||||||
"""
|
"""
|
||||||
return format_decimal(val, locale=get_babel_regional_format(override_locale))
|
return format_decimal(val, locale=get_babel_regional_format(override_locale))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user