Skip to content

Commit b5609c1

Browse files
committed
Fixed titles in !daily and !keen
!daily used to say "Leaderboard for None:" on the top row. Now it has a title with the year and day shown. Altered the parameter name to be more in line with what it does, and commands pass in the full title now. (year -> title) Fixed !keen having different title parity by moving the title inside the code block. Fixed referencing undeclared variable "year". "year" exists in [this PR](#12) This will need to be changed if/when both are merged to [the parent](CSSUoB/advent-of-code-bot) Included !keen title in the code block This fixes parity with the other commands, which have the leaderboard title at the top of their code blocks.
1 parent 5c03ce9 commit b5609c1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def get_players(year: int = CURRENT_YEAR):
8080
return players_cache[year][1]
8181

8282

83-
async def output_leaderboard(context, leaderboard_lst, year=None):
84-
output_str = f'Leaderboard for {year}:\n'
83+
async def output_leaderboard(context, leaderboard_lst, title = None):
84+
output_str = "" if title is None else title
8585

8686
for i, player in enumerate(leaderboard_lst):
8787
if len(output_str) + len(player) > MAX_MESSAGE_LEN:
@@ -138,7 +138,7 @@ async def leaderboard(context, num_players: int = 20, year: int = CURRENT_YEAR):
138138
await context.send(f'```No one has completed any stars yet for {year}```')
139139
return
140140

141-
await output_leaderboard(context, ranking, year)
141+
await output_leaderboard(context, ranking, f'Leaderboard for {year}:\n')
142142

143143

144144
@bot.command(name='rank', help='Responds with the current ranking of the supplied player')
@@ -183,7 +183,7 @@ async def keen(context):
183183
# Find the first person who got the max stars
184184
i, player = min(players, key=lambda t: t[1][3])
185185

186-
result = 'Today\'s keenest bean is:\n```'
186+
result = '```Today\'s keenest bean is:\n'
187187
result += PLAYER_STR_FORMAT.format(rank=i+1,
188188
name=player[0], name_pad=len(player[0]),
189189
points=player[1], points_pad=len(str(player[1])),
@@ -259,7 +259,7 @@ async def daily(context, day: str = None):
259259
stars=player[2], stars_pad=max_stars_len,
260260
star_time=time.strftime('%H:%M %d/%m', time.localtime(player[3]))))
261261

262-
await output_leaderboard(context, ranking)
262+
await output_leaderboard(context, ranking, f'Leaderboard for {CURRENT_YEAR}, day {day}:\n')
263263

264264

265265
bot.run(TOKEN)

0 commit comments

Comments
 (0)