-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.py
36 lines (27 loc) · 924 Bytes
/
utils.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
30
31
32
33
34
35
36
class DiscordEmbedTextPaginator:
DESC_MAX = 2048
FIELD_MAX = 1024
def __init__(self):
self.texts = []
self._last_text = ""
def add(self, text: str):
if len(self.texts) == 0:
_max = self.DESC_MAX
else:
_max = self.FIELD_MAX
if len(text) > _max:
raise ValueError("Text is too long to fit.")
if len(text) + len(self._last_text) > _max:
self.texts.append(self._last_text.strip())
self._last_text = text
else:
self._last_text += f"\n{text.strip()}"
def write_to(self, embed):
if self._last_text:
self.texts.append(self._last_text)
if not self.texts:
return embed
embed.description = self.texts[0]
for field in self.texts[1:]:
embed.add_field(name="** **", value=field, inline=False)
return embed