diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-07-26 15:33:09 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-07-26 15:33:09 -0400 |
commit | 37a121011bf147ea1e56b299b7e2b5dfe3574532 (patch) | |
tree | 40051dedaaae4ba6ab8647cefd3a7cda75e47843 /src/lib/extensions/discord-akairo/BushClientUtil.ts | |
parent | 88e68875030086f5acf2c4295280e1b370242ec7 (diff) | |
download | tanzanite-37a121011bf147ea1e56b299b7e2b5dfe3574532.tar.gz tanzanite-37a121011bf147ea1e56b299b7e2b5dfe3574532.tar.bz2 tanzanite-37a121011bf147ea1e56b299b7e2b5dfe3574532.zip |
fix: refactored eval, sanitize decode, refactor price and fix trying to use an emoji as a color
Diffstat (limited to 'src/lib/extensions/discord-akairo/BushClientUtil.ts')
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClientUtil.ts | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index 1ba94c2..e8fe7fa 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -38,7 +38,7 @@ import { } from 'discord.js'; import got from 'got'; import humanizeDuration from 'humanize-duration'; -import { promisify } from 'util'; +import { inspect, InspectOptions, promisify } from 'util'; import { ActivePunishment, ActivePunishmentType } from '../../models/ActivePunishment'; import { BushNewsChannel } from '../discord.js/BushNewsChannel'; import { BushTextChannel } from '../discord.js/BushTextChannel'; @@ -449,21 +449,56 @@ export class BushClientUtil extends ClientUtil { /** * Surrounds text in a code block with the specified language and puts it in a hastebin if its too long. * - * * Embed Description Limit = 2048 characters + * * Embed Description Limit = 4096 characters * * Embed Field Limit = 1024 characters */ - public async codeblock(code: string, length: number, language: 'ts' | 'js' | 'sh' | 'json' | '' = ''): Promise<string> { + public async codeblock(code: string, length: number, language?: 'ts' | 'js' | 'sh' | 'json'): Promise<string> { let hasteOut = ''; const tildes = '```'; - const formattingLength = 2 * tildes.length + language.length + 2 * '\n'.length; + 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)); const code2 = hasteOut ? code.substring(0, length - (hasteOut.length + '\n'.length + formattingLength)) : code; return ( - tildes + language + '\n' + Util.cleanCodeBlockContent(code2) + '\n' + tildes + (hasteOut.length ? '\n' + hasteOut : '') + tildes + language ?? + '' + '\n' + Util.cleanCodeBlockContent(code2) + '\n' + tildes + (hasteOut.length ? '\n' + hasteOut : '') ); } + private mapCredential(old: string) { + const mapping = { + ['token']: 'Main Token', + ['devToken']: 'Dev Token', + ['betaToken']: 'Beta Token', + ['hypixelApiKey']: 'Hypixel Api Key' + }; + return mapping[old] || old; + } + + /** + * Redacts credentials from a string + */ + public redact(text: string) { + for (const credentialName in client.config.credentials) { + const credential = client.config.credentials[credentialName]; + const replacement = this.mapCredential(credentialName); + const escapeRegex = /[.*+?^${}()|[\]\\]/g; + text = text.replace(new RegExp(credential.toString().replace(escapeRegex, '\\$&'), 'g'), `[${replacement} Omitted]`); + text = text.replace( + new RegExp([...credential.toString()].reverse().join('').replace(escapeRegex, '\\$&'), 'g'), + `[${replacement} Omitted]` + ); + } + return text; + } + + public async inspectCleanRedactCodeblock(input: any, language: 'ts' | 'js', inspectOptions?: InspectOptions) { + input = typeof input !== 'string' && inspectOptions !== undefined ? inspect(input, inspectOptions) : input; + input = Util.cleanCodeBlockContent(input); + input = this.redact(input); + return client.util.codeblock(input, 1024, language); + } + public async slashRespond( interaction: CommandInteraction, responseOptions: BushSlashSendMessageType | BushSlashEditMessageType @@ -754,4 +789,8 @@ export class BushClientUtil extends ClientUtil { const autoModPhases = await message.guild.getSetting('autoModPhases'); if (autoModPhases.includes(message.content.toString()) && message.deletable) message.delete(); } + + public capitalizeFirstLetter(string: string): string { + return string.charAt(0)?.toUpperCase() + string.slice(1); + } } |