aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions/discord-akairo
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-03-12 16:45:21 -0500
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-03-12 16:45:21 -0500
commit9e8e5aee80159730ec1d631acb5c3a1e581f1d69 (patch)
tree81776b91bd4bc66ea8c046fd871df03bae432497 /src/lib/extensions/discord-akairo
parentc4e6a313f8c34fdacc07232e12d9a44432aee472 (diff)
downloadtanzanite-9e8e5aee80159730ec1d631acb5c3a1e581f1d69.tar.gz
tanzanite-9e8e5aee80159730ec1d631acb5c3a1e581f1d69.tar.bz2
tanzanite-9e8e5aee80159730ec1d631acb5c3a1e581f1d69.zip
refactor: create and use util.overflowEmbed
Diffstat (limited to 'src/lib/extensions/discord-akairo')
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts
index 51daf70..04014ef 100644
--- a/src/lib/extensions/discord-akairo/BushClientUtil.ts
+++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts
@@ -22,9 +22,10 @@ import assert from 'assert';
import { exec } from 'child_process';
import deepLock from 'deep-lock';
import { ClientUtil, Util as AkairoUtil } from 'discord-akairo';
-import { APIMessage, OAuth2Scopes } from 'discord-api-types/v9';
+import { APIEmbed, APIMessage, OAuth2Scopes } from 'discord-api-types/v9';
import {
Constants as DiscordConstants,
+ Embed,
GuildMember,
Message,
PermissionFlagsBits,
@@ -962,6 +963,41 @@ export class BushClientUtil extends ClientUtil {
}
/**
+ * Overflows the description of an embed into multiple embeds.
+ * @param embed The options to be applied to the (first) embed.
+ * @param lines Each line of the description as an element in an array.
+ */
+ public overflowEmbed(embed: Omit<APIEmbed, 'description'>, lines: string[], maxLength = 4096): Embed[] {
+ const embeds: Embed[] = [];
+
+ const makeEmbed = () => {
+ embeds.push(new Embed().setColor(embed.color ?? null));
+ return embeds.at(-1)!;
+ };
+
+ for (const line of lines) {
+ let current = embeds.length ? embeds.at(-1)! : makeEmbed();
+ const joined = current.description ? `${current.description}\n${line}` : line;
+ if (joined.length >= maxLength) current = makeEmbed();
+
+ current.setDescription(joined);
+ }
+
+ if (!embeds.length) makeEmbed();
+
+ if (embed.author) embeds.at(0)?.setAuthor(embed.author);
+ if (embed.title) embeds.at(0)?.setTitle(embed.title);
+ if (embed.url) embeds.at(0)?.setURL(embed.url);
+ if (embed.fields) embeds.at(-1)?.setFields(...embed.fields);
+ if (embed.thumbnail) embeds.at(-1)?.setThumbnail(embed.thumbnail.url);
+ if (embed.footer) embeds.at(-1)?.setFooter(embed.footer);
+ if (embed.image) embeds.at(-1)?.setImage(embed.image.url);
+ if (embed.timestamp) embeds.at(-1)?.setTimestamp(new Date(embed.timestamp));
+
+ return embeds;
+ }
+
+ /**
* A wrapper for the Argument class that adds custom typings.
*/
public get arg() {