Fix string formatting for splitting categories into multiple rows.
This commit is contained in:
+10
-4
@@ -192,7 +192,7 @@ def format_highscore_message(group: CategoryGroup) -> str:
|
|||||||
# also grab the max category size
|
# also grab the max category size
|
||||||
categories = []
|
categories = []
|
||||||
category_ids = []
|
category_ids = []
|
||||||
max_cat_size = 0
|
max_cat_size: int = 0
|
||||||
pad_length = group.PadLength
|
pad_length = group.PadLength
|
||||||
for cat in session.scalars(stmt):
|
for cat in session.scalars(stmt):
|
||||||
if cat.Size > max_cat_size:
|
if cat.Size > max_cat_size:
|
||||||
@@ -257,19 +257,25 @@ def format_highscore_message(group: CategoryGroup) -> str:
|
|||||||
# need to use index to allow for modifying the list
|
# need to use index to allow for modifying the list
|
||||||
for ind, line in enumerate(str_list):
|
for ind, line in enumerate(str_list):
|
||||||
if len(line) > MAX_LINE_LENGTH:
|
if len(line) > MAX_LINE_LENGTH:
|
||||||
|
|
||||||
split_loc = int(MAX_LINE_LENGTH / pad_length) * pad_length
|
split_loc = int(MAX_LINE_LENGTH / pad_length) * pad_length
|
||||||
new_line = line[split_loc:]
|
new_line = line[split_loc:]
|
||||||
str_list[ind] = line[:split_loc]
|
str_list[ind] = line[:split_loc]
|
||||||
str_list.append(new_line)
|
str_list.append(new_line)
|
||||||
if ind + 1 / max_cat_size == 0:
|
|
||||||
str_list.append("\n")
|
|
||||||
|
|
||||||
# this list can now be placed into the format message function in the bot
|
# this list can now be placed into the format message function in the bot
|
||||||
for string in str_list:
|
for ind, string in enumerate(str_list):
|
||||||
# rstrip to clear unneeded spaces
|
# rstrip to clear unneeded spaces
|
||||||
# add newline here for each string
|
# add newline here for each string
|
||||||
ret_string += string.rstrip() + "\n"
|
ret_string += string.rstrip() + "\n"
|
||||||
|
|
||||||
|
# add extra newline at category split unless there is already a space.
|
||||||
|
if ((ind + 1) % (max_cat_size + 1)) == 0:
|
||||||
|
# checking inside the other if to ensure called as little as possible.
|
||||||
|
if not ret_string.endswith("\n\n"):
|
||||||
|
ret_string += "\n"
|
||||||
|
|
||||||
|
print(ret_string)
|
||||||
return ret_string + "```"
|
return ret_string + "```"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user