[Utils] Add humanize_number() function to chat formatting (#2836)

This adds babel as a dependency, and also includes `redbot.core.i18n.get_babel_locale()`
This commit is contained in:
Draper
2019-08-27 23:44:52 +01:00
committed by Toby Harradine
parent 6c3a3fea66
commit 3c1b6ae4cf
15 changed files with 238 additions and 80 deletions

View File

@@ -19,7 +19,7 @@ import redbot.core
from redbot.core import Config, commands, checks, bank
from redbot.core.data_manager import cog_data_path
from redbot.core.i18n import Translator, cog_i18n
from redbot.core.utils.chat_formatting import bold, box, pagify
from redbot.core.utils.chat_formatting import bold, box, pagify, humanize_number
from redbot.core.utils.menus import (
menu,
DEFAULT_CONTROLS,
@@ -442,7 +442,7 @@ class Audio(commands.Cog):
await self._embed_msg(
ctx,
_("Track queueing command price set to {price} {currency}.").format(
price=price, currency=await bank.get_currency_name(ctx.guild)
price=humanize_number(price), currency=await bank.get_currency_name(ctx.guild)
),
)
@@ -613,7 +613,9 @@ class Audio(commands.Cog):
msg += _("DJ Role: [{role.name}]\n").format(role=dj_role_obj)
if jukebox:
msg += _("Jukebox: [{jukebox_name}]\n").format(jukebox_name=jukebox)
msg += _("Command price: [{jukebox_price}]\n").format(jukebox_price=jukebox_price)
msg += _("Command price: [{jukebox_price}]\n").format(
jukebox_price=humanize_number(jukebox_price)
)
if maxlength > 0:
msg += _("Max track length: [{tracklength}]\n").format(
tracklength=self._dynamic_time(maxlength)
@@ -762,11 +764,15 @@ class Audio(commands.Cog):
em = discord.Embed(
colour=await ctx.embed_colour(),
title=_("Playing in {num}/{total} servers:").format(
num=server_num, total=total_num
num=humanize_number(server_num), total=humanize_number(total_num)
),
description=page,
)
em.set_footer(text="Page {}/{}".format(pages, (math.ceil(len(msg) / 1500))))
em.set_footer(
text="Page {}/{}".format(
humanize_number(pages), humanize_number((math.ceil(len(msg) / 1500)))
)
)
pages += 1
servers_embed.append(em)
@@ -933,7 +939,9 @@ class Audio(commands.Cog):
embed = discord.Embed(
colour=await ctx.embed_colour(), description=(f"{header}\n{formatted_page}")
)
embed.set_footer(text=_("{num} preset(s)").format(num=len(list(eq_presets.keys()))))
embed.set_footer(
text=_("{num} preset(s)").format(num=humanize_number(len(list(eq_presets.keys()))))
)
page_list.append(embed)
if len(page_list) == 1:
return await ctx.send(embed=page_list[0])
@@ -1869,6 +1877,7 @@ class Audio(commands.Cog):
song_info = "{} {}".format(i["name"], i["artists"][0]["name"])
else:
song_info = "{} {}".format(i["track"]["name"], i["track"]["artists"][0]["name"])
try:
track_url = await self._youtube_api_search(yt_key, song_info)
except (RuntimeError, aiohttp.client_exceptions.ServerDisconnectedError):
@@ -1878,7 +1887,6 @@ class Audio(commands.Cog):
)
await playlist_msg.edit(embed=error_embed)
return None
pass
try:
yt_track = await player.get_tracks(track_url)
except (RuntimeError, aiohttp.client_exceptions.ServerDisconnectedError):
@@ -3416,8 +3424,8 @@ class Audio(commands.Cog):
" Votes: {num_votes}/{num_members}"
" ({cur_percent}% out of {required_percent}% needed)"
).format(
num_votes=num_votes,
num_members=num_members,
num_votes=humanize_number(num_votes),
num_members=humanize_number(num_members),
cur_percent=vote,
required_percent=percent,
)
@@ -3869,7 +3877,7 @@ class Audio(commands.Cog):
await self._embed_msg(
ctx,
_("Not enough {currency} ({required_credits} required).").format(
currency=credits_name, required_credits=jukebox_price
currency=credits_name, required_credits=humanize_number(jukebox_price)
),
)
return False