mirror of
https://github.com/Xevion/contest-assistant.git
synced 2025-12-12 20:11:17 -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:
@@ -1,5 +1,5 @@
|
||||
import datetime
|
||||
from typing import Union
|
||||
from typing import Any, Generator, List, Union
|
||||
|
||||
import discord
|
||||
|
||||
@@ -14,9 +14,11 @@ def is_upvote(emoji: Union[discord.Emoji, discord.PartialEmoji, str]) -> bool:
|
||||
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."""
|
||||
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):
|
||||
@@ -29,3 +31,16 @@ def success_embed(*args, **kwargs):
|
||||
"""A generic embed with a light green color."""
|
||||
kwargs['color'] = constants.SUCCESS_COLOR
|
||||
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