From fe8563a00811115e95fb5aec5b8d762d68e97ed8 Mon Sep 17 00:00:00 2001 From: xHyroM Date: Thu, 14 Jul 2022 08:13:18 +0200 Subject: [PATCH] chore: updates fix(githubUtils): query, slice 0,93 feat(regexes): move regex --- src/utils/githubUtils.ts | 7 ++++--- src/utils/regexes.ts | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 src/utils/regexes.ts diff --git a/src/utils/githubUtils.ts b/src/utils/githubUtils.ts index 60d6161..52de7d7 100644 --- a/src/utils/githubUtils.ts +++ b/src/utils/githubUtils.ts @@ -6,6 +6,7 @@ import MiniSearch from 'minisearch'; import { Logger } from './Logger'; import { APIApplicationCommandOptionChoice } from 'discord-api-types/v10'; import { Database } from 'bun:sqlite'; +import { discordChoicesRegex } from './regexes'; interface Issue { id: number; @@ -185,7 +186,7 @@ export const search = async(query: string, repository: string): Promise new Object({ - name: `${issueOrPr.type} ${formatEmojiStatus(issueOrPr)} ${issueOrPr.title.slice(0, 95).replace(/[^a-z0-9 ]/gi, '')}`, + name: `${issueOrPr.type} ${formatEmojiStatus(issueOrPr)} ${issueOrPr.title.slice(0, 93).replace(discordChoicesRegex, '')}`, value: issueOrPr.number.toString() })) as APIApplicationCommandOptionChoice[] } @@ -204,7 +205,7 @@ export const search = async(query: string, repository: string): Promise new Object({ - name: `${issueOrPr.type} ${formatEmojiStatus(issueOrPr)} ${issueOrPr.title.slice(0, 95).replace(/[^a-z0-9 ]/gi, '')}`, + name: `${issueOrPr.type} ${formatEmojiStatus(issueOrPr)} ${issueOrPr.title.slice(0, 93).replace(discordChoicesRegex, '')}`, value: issueOrPr.number.toString() })) as APIApplicationCommandOptionChoice[] } catch(e) { @@ -247,7 +248,7 @@ export const formatEmojiStatus = (data: Issue | PullRequest) => { break; } - if (data.type === '(PR)' && !isNaN(new Date((data as PullRequest).merged_at).getTime())) emoji = '🟣'; + if (data.type === '(PR)' && (data as PullRequest).merged_at) emoji = '🟣'; return emoji; } \ No newline at end of file diff --git a/src/utils/regexes.ts b/src/utils/regexes.ts new file mode 100644 index 0000000..4f16572 --- /dev/null +++ b/src/utils/regexes.ts @@ -0,0 +1 @@ +export const discordChoicesRegex = /[^a-z0-9 (|)|-|*|/|+|,|<|>|&|!|?]/gi; \ No newline at end of file