mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Economy] Add embed to leaderboard (#4184)
This commit is contained in:
parent
94784f366f
commit
3e6a73ae8c
@ -3,6 +3,7 @@ import logging
|
|||||||
import random
|
import random
|
||||||
from collections import defaultdict, deque, namedtuple
|
from collections import defaultdict, deque, namedtuple
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
from math import ceil
|
||||||
from typing import cast, Iterable, Union, Literal
|
from typing import cast, Iterable, Union, Literal
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
@ -13,7 +14,7 @@ from redbot.core import Config, bank, commands, errors, checks
|
|||||||
from redbot.core.i18n import Translator, cog_i18n
|
from redbot.core.i18n import Translator, cog_i18n
|
||||||
from redbot.core.utils import AsyncIter
|
from redbot.core.utils import AsyncIter
|
||||||
from redbot.core.utils.chat_formatting import box, humanize_number
|
from redbot.core.utils.chat_formatting import box, humanize_number
|
||||||
from redbot.core.utils.menus import menu, DEFAULT_CONTROLS
|
from redbot.core.utils.menus import close_menu, menu, DEFAULT_CONTROLS
|
||||||
|
|
||||||
from redbot.core.bot import Red
|
from redbot.core.bot import Red
|
||||||
|
|
||||||
@ -482,14 +483,22 @@ class Economy(commands.Cog):
|
|||||||
"""
|
"""
|
||||||
guild = ctx.guild
|
guild = ctx.guild
|
||||||
author = ctx.author
|
author = ctx.author
|
||||||
|
embed_requested = await ctx.embed_requested()
|
||||||
|
footer_message = _("Page {page_num}/{page_len}.")
|
||||||
max_bal = await bank.get_max_balance(ctx.guild)
|
max_bal = await bank.get_max_balance(ctx.guild)
|
||||||
|
|
||||||
if top < 1:
|
if top < 1:
|
||||||
top = 10
|
top = 10
|
||||||
|
|
||||||
|
base_embed = discord.Embed(title=_("Economy Leaderboard"))
|
||||||
if await bank.is_global() and show_global:
|
if await bank.is_global() and show_global:
|
||||||
# show_global is only applicable if bank is global
|
# show_global is only applicable if bank is global
|
||||||
bank_sorted = await bank.get_leaderboard(positions=top, guild=None)
|
bank_sorted = await bank.get_leaderboard(positions=top, guild=None)
|
||||||
|
base_embed.set_author(name=ctx.bot.user.name, icon_url=ctx.bot.user.avatar_url)
|
||||||
else:
|
else:
|
||||||
bank_sorted = await bank.get_leaderboard(positions=top, guild=guild)
|
bank_sorted = await bank.get_leaderboard(positions=top, guild=guild)
|
||||||
|
base_embed.set_author(name=guild.name, icon_url=guild.icon_url)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bal_len = len(humanize_number(bank_sorted[0][1]["balance"]))
|
bal_len = len(humanize_number(bank_sorted[0][1]["balance"]))
|
||||||
bal_len_max = len(humanize_number(max_bal))
|
bal_len_max = len(humanize_number(max_bal))
|
||||||
@ -536,15 +545,41 @@ class Economy(commands.Cog):
|
|||||||
f"<<{author.display_name}>>\n"
|
f"<<{author.display_name}>>\n"
|
||||||
)
|
)
|
||||||
if pos % 10 == 0:
|
if pos % 10 == 0:
|
||||||
|
if embed_requested:
|
||||||
|
embed = base_embed.copy()
|
||||||
|
embed.description = box(temp_msg, lang="md")
|
||||||
|
embed.set_footer(
|
||||||
|
text=footer_message.format(
|
||||||
|
page_num=len(highscores) + 1, page_len=ceil(len(bank_sorted) / 10),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
highscores.append(embed)
|
||||||
|
else:
|
||||||
highscores.append(box(temp_msg, lang="md"))
|
highscores.append(box(temp_msg, lang="md"))
|
||||||
temp_msg = header
|
temp_msg = header
|
||||||
pos += 1
|
pos += 1
|
||||||
|
|
||||||
if temp_msg != header:
|
if temp_msg != header:
|
||||||
|
if embed_requested:
|
||||||
|
embed = base_embed.copy()
|
||||||
|
embed.description = box(temp_msg, lang="md")
|
||||||
|
embed.set_footer(
|
||||||
|
text=footer_message.format(
|
||||||
|
page_num=len(highscores) + 1, page_len=ceil(len(bank_sorted) / 10),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
highscores.append(embed)
|
||||||
|
else:
|
||||||
highscores.append(box(temp_msg, lang="md"))
|
highscores.append(box(temp_msg, lang="md"))
|
||||||
|
|
||||||
if highscores:
|
if highscores:
|
||||||
await menu(ctx, highscores, DEFAULT_CONTROLS)
|
await menu(
|
||||||
|
ctx,
|
||||||
|
highscores,
|
||||||
|
DEFAULT_CONTROLS if len(highscores) > 1 else {"\N{CROSS MARK}": close_menu},
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
await ctx.send(_("No balances found."))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@guild_only_check()
|
@guild_only_check()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user