diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-11-28 09:27:41 -0500 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-11-28 09:27:41 -0500 |
commit | 453683b57b8ff013ff25e2aaa4aa1d2e047edcb7 (patch) | |
tree | 8b98d2f30dbb6a8448602446cfacf9091667cc33 /src/lib/common | |
parent | de4c3dcaf172804d34ae708be1ed3e75af42f4d5 (diff) | |
download | tanzanite-453683b57b8ff013ff25e2aaa4aa1d2e047edcb7.tar.gz tanzanite-453683b57b8ff013ff25e2aaa4aa1d2e047edcb7.tar.bz2 tanzanite-453683b57b8ff013ff25e2aaa4aa1d2e047edcb7.zip |
a few small changes
Diffstat (limited to 'src/lib/common')
-rw-r--r-- | src/lib/common/Format.ts | 52 | ||||
-rw-r--r-- | src/lib/common/util/Arg.ts | 6 |
2 files changed, 48 insertions, 10 deletions
diff --git a/src/lib/common/Format.ts b/src/lib/common/Format.ts index b47be38..6cb6edc 100644 --- a/src/lib/common/Format.ts +++ b/src/lib/common/Format.ts @@ -1,5 +1,5 @@ import { type CodeBlockLang } from '#lib'; -import { Formatters, Util } from 'discord.js'; +import { EscapeMarkdownOptions, Formatters, Util } from 'discord.js'; /** * Formats and escapes content for formatting @@ -19,8 +19,8 @@ export class Format { public static codeBlock(language: CodeBlockLang, content: string): string; public static codeBlock(languageOrContent: string, content?: string): string { return typeof content === 'undefined' - ? Formatters.codeBlock(Util.escapeCodeBlock(languageOrContent)) - : Formatters.codeBlock(languageOrContent, Util.escapeCodeBlock(languageOrContent)); + ? Formatters.codeBlock(Util.escapeCodeBlock(`${languageOrContent}`)) + : Formatters.codeBlock(`${languageOrContent}`, Util.escapeCodeBlock(`${content}`)); } /** @@ -28,7 +28,7 @@ export class Format { * @param content The content to wrap. */ public static inlineCode(content: string): string { - return Formatters.inlineCode(Util.escapeInlineCode(content)); + return Formatters.inlineCode(Util.escapeInlineCode(`${content}`)); } /** @@ -36,7 +36,7 @@ export class Format { * @param content The content to wrap. */ public static italic(content: string): string { - return Formatters.italic(Util.escapeItalic(content)); + return Formatters.italic(Util.escapeItalic(`${content}`)); } /** @@ -44,7 +44,7 @@ export class Format { * @param content The content to wrap. */ public static bold(content: string): string { - return Formatters.bold(Util.escapeBold(content)); + return Formatters.bold(Util.escapeBold(`${content}`)); } /** @@ -52,7 +52,7 @@ export class Format { * @param content The content to wrap. */ public static underscore(content: string): string { - return Formatters.underscore(Util.escapeUnderline(content)); + return Formatters.underscore(Util.escapeUnderline(`${content}`)); } /** @@ -60,7 +60,7 @@ export class Format { * @param content The content to wrap. */ public static strikethrough(content: string): string { - return Formatters.strikethrough(Util.escapeStrikethrough(content)); + return Formatters.strikethrough(Util.escapeStrikethrough(`${content}`)); } /** @@ -68,6 +68,40 @@ export class Format { * @param content The content to wrap. */ public static spoiler(content: string): string { - return Formatters.spoiler(Util.escapeSpoiler(content)); + return Formatters.spoiler(Util.escapeSpoiler(`${content}`)); + } + + /** + * Escapes any Discord-flavour markdown in a string. + * @param text Content to escape + * @param options Options for escaping the markdown + */ + public static escapeMarkdown(text: string, options?: EscapeMarkdownOptions): string { + return Util.escapeMarkdown(`${text}`, options); + } + + /** + * Formats input: makes it bold and escapes any other markdown + * @param text The input + */ + public static input(text: string): string { + return this.bold(this.escapeMarkdown(this.sanitizeWtlAndControl(`${text}`))); + } + + /** + * Formats input for logs: makes it highlighted + * @param text The input + */ + public static inputLog(text: string): string { + return `<<${this.sanitizeWtlAndControl(`${text}`)}>>`; + } + + /** + * Removes all characters in a string that are either control characters or change the direction of text etc. + * @param str The string you would like sanitized + */ + public static sanitizeWtlAndControl(str: string) { + // eslint-disable-next-line no-control-regex + return `${str}`.replace(/[\u0000-\u001F\u007F-\u009F\u200B]/g, ''); } } diff --git a/src/lib/common/util/Arg.ts b/src/lib/common/util/Arg.ts index ee9aee0..1982f4a 100644 --- a/src/lib/common/util/Arg.ts +++ b/src/lib/common/util/Arg.ts @@ -9,7 +9,11 @@ export class Arg { * @param message - Message that called the command. * @param phrase - Phrase to process. */ - public static cast(type: BushArgumentType, message: BushMessage | BushSlashMessage, phrase: string): Promise<any> { + public static cast( + type: BushArgumentType | ArgumentTypeCaster, + message: BushMessage | BushSlashMessage, + phrase: string + ): Promise<any> { return Argument.cast(type, client.commandHandler.resolver, message as Message, phrase); } |