-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathembedutils.py
29 lines (22 loc) · 902 Bytes
/
embedutils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from collections import namedtuple
from typing import List
EmbedField = namedtuple("EmbedField", "name value inline")
# Yoinked from the RedHelpFormatter https://github.com/Cog-Creators/Red-DiscordBot/blob/V3/develop/redbot/core/commands/help.py#L438-#L460
def group_embed_fields(fields: List[EmbedField], max_chars=1000):
curr_group = []
ret = []
current_count = 0
for i, f in enumerate(fields):
f_len = len(f.value) + len(f.name)
# Commands start at the 1st index of fields, i < 2 is a hacky workaround for now
if not current_count or f_len + current_count < max_chars or i < 2:
current_count += f_len
curr_group.append(f)
elif curr_group:
ret.append(curr_group)
current_count = f_len
curr_group = [f]
else:
if curr_group:
ret.append(curr_group)
return ret