Skip to content

Commit

Permalink
Truncate player list if too long
Browse files Browse the repository at this point in the history
  • Loading branch information
Kexanone committed Jan 12, 2023
1 parent e256e7e commit 88b4f80
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion apyllo/embed_status_getters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import discord


MAX_EMBED_VALUE_SIZE = 1024


def basic_embed_status_getter(server):
if server.is_online:
color = 0x43B581
Expand All @@ -18,10 +21,17 @@ def basic_embed_status_getter(server):
def add_player_fields(embed, server, player_status_getter):
player_counts = f'{server.player_count}/{server.max_player_count}'
embed.add_field(name='Player count', value=player_counts, inline=False)
player_info_size = 44
player_info_lines = ['```']
if server.player_list:
for player in server.player_list:
player_info_lines.append(f'• {player_status_getter(player)}')
line = f'• {player_status_getter(player)}'
player_info_size += 1 + len(line)
if player_info_size > MAX_EMBED_VALUE_SIZE:
# Truncate player list
player_info_lines.append('...')
break
player_info_lines.append(line)
else:
player_info_lines.append(' ')
player_info_lines.append('```')
Expand Down

0 comments on commit 88b4f80

Please sign in to comment.