mirror of
https://github.com/Xevion/contest-assistant.git
synced 2026-01-31 04:23:51 -06:00
Improved 'leaderboard' command embed formatting
- Added proper vote count to leaderboard - Supported shared rankings in leaderboard - New generator in helpers 'ending_iterator'
This commit is contained in:
@@ -259,15 +259,20 @@ class ContestCommandsCog(commands.Cog, name='Contest'):
|
|||||||
.all()
|
.all()
|
||||||
|
|
||||||
description = ''
|
description = ''
|
||||||
for i, submission in enumerate(board, start=1):
|
position = 0 # It will be incremented on the first step, so we start at 0.
|
||||||
|
emotes = helpers.ending_iterator([':trophy:', ':second_place:', ':third_place:', ''])
|
||||||
|
emote, previous_count = None, None
|
||||||
|
|
||||||
|
for submission in board:
|
||||||
message = self.bot.get_message(guild.submission_channel, submission.id)
|
message = self.bot.get_message(guild.submission_channel, submission.id)
|
||||||
|
|
||||||
emote = ''
|
if submission.count != previous_count:
|
||||||
if i == 1: emote = ':trophy:'
|
emote = next(emotes)
|
||||||
elif i == 2: emote = ':second_place:'
|
previous_count = submission.count
|
||||||
elif i == 3: emote = ':third_place:'
|
position += 1
|
||||||
|
|
||||||
description += f'`{str(i).zfill(2)}` {emote + " " if emote else ""}<@{submission.user}> [Jump]({message.jump_url})\n'
|
description += f'`{str(position).zfill(2)}` {emote + " " if emote else ""}<@{submission.user}> with {submission.count} ' \
|
||||||
|
f'vote{"s" if submission.count != 1 else ""} [Jump]({message.jump_url})\n'
|
||||||
|
|
||||||
if not description:
|
if not description:
|
||||||
description = 'No one has submitted anything yet.'
|
description = 'No one has submitted anything yet.'
|
||||||
|
|||||||
+18
-3
@@ -1,5 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from typing import Union
|
from typing import Any, Generator, List, Union
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
@@ -14,9 +14,11 @@ def is_upvote(emoji: Union[discord.Emoji, discord.PartialEmoji, str]) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def general_embed(title: str = '', message: str = '', color: discord.Color = constants.GENERAL_COLOR, timestamp: bool = False) -> discord.Embed:
|
def general_embed(title: str = '', message: str = '', color: discord.Color = constants.GENERAL_COLOR,
|
||||||
|
timestamp: bool = False) -> discord.Embed:
|
||||||
"""A generic mostly unstyled embed with a blue color."""
|
"""A generic mostly unstyled embed with a blue color."""
|
||||||
return discord.Embed(title=title, description=message, timestamp=datetime.datetime.utcnow() if timestamp else discord.Embed.Empty, color=color)
|
return discord.Embed(title=title, description=message, timestamp=datetime.datetime.utcnow() if timestamp else discord.Embed.Empty,
|
||||||
|
color=color)
|
||||||
|
|
||||||
|
|
||||||
def error_embed(*args, **kwargs):
|
def error_embed(*args, **kwargs):
|
||||||
@@ -29,3 +31,16 @@ def success_embed(*args, **kwargs):
|
|||||||
"""A generic embed with a light green color."""
|
"""A generic embed with a light green color."""
|
||||||
kwargs['color'] = constants.SUCCESS_COLOR
|
kwargs['color'] = constants.SUCCESS_COLOR
|
||||||
return general_embed(*args, **kwargs)
|
return general_embed(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def ending_iterator(items: List[Any]) -> Generator[Any, None, None]:
|
||||||
|
"""A generator which iterates along the list until it reaches the end, where it continuously yields the final item forever."""
|
||||||
|
index = 0
|
||||||
|
length = len(items) - 1
|
||||||
|
last = items[-1]
|
||||||
|
while True:
|
||||||
|
if index == length:
|
||||||
|
yield last
|
||||||
|
else:
|
||||||
|
yield items[index]
|
||||||
|
index += 1
|
||||||
|
|||||||
Reference in New Issue
Block a user