diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-08-05 20:51:46 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-08-05 20:51:46 -0400 |
commit | 0b955b561fe8073fb1f69f6b60e9f217fa51ff20 (patch) | |
tree | 3d459658811d54bfd99ae001987bcee1badb5bbe /src | |
parent | 3196d2517a0a36bf3049728690ca0f771a1c4777 (diff) | |
download | tanzanite-0b955b561fe8073fb1f69f6b60e9f217fa51ff20.tar.gz tanzanite-0b955b561fe8073fb1f69f6b60e9f217fa51ff20.tar.bz2 tanzanite-0b955b561fe8073fb1f69f6b60e9f217fa51ff20.zip |
maybe this fixes it?
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClientUtil.ts | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index 6ef34dd..3ee63a7 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -455,13 +455,16 @@ export class BushClientUtil extends ClientUtil { */ public async codeblock(code: string, length: number, language?: 'ts' | 'js' | 'sh' | 'json' | ''): Promise<string> { let hasteOut = ''; - const tildes = '```'; + const prefix = '```' + language + '\n'; + const suffix = '\n```'; language = language ?? ''; - const formattingLength = 2 * tildes.length + language?.length ?? 0 + 2 * '\n'.length; - if (code.length + formattingLength >= length) hasteOut = 'Too large to display. Hastebin: ' + (await this.haste(code)); + if (code.length + (prefix + suffix).length >= length) + hasteOut = 'Too large to display. Hastebin: ' + (await this.haste(code)); - const code2 = hasteOut ? code.substring(0, length - (hasteOut.length + '\n'.length + formattingLength)) : code; - const code3 = tildes + language + '\n' + code2 + '\n' + tildes + (hasteOut.length ? '\n' + hasteOut : ''); + const FormattedHaste = hasteOut.length ? '\n' + hasteOut : ''; + const shortenedCode = hasteOut ? code.substring(0, length - (prefix + code + FormattedHaste + suffix).length) : code; + + const code3 = prefix + shortenedCode + suffix; if (code3.length > length) { void client.console.warn(`codeblockError`, `Required Length: ${length}. Actual Length: ${code3.length}`, true); void client.console.warn(`codeblockError`, code3, true); |