mirror of
https://github.com/xHyroM/bun-discord-bot.git
synced 2024-12-23 04:31:06 +01:00
chore: updates
fix(githubUtils): query, slice 0,93 feat(regexes): move regex
This commit is contained in:
parent
21b74eb472
commit
fe8563a008
2 changed files with 5 additions and 3 deletions
|
@ -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<APIAppli
|
|||
if (!query) {
|
||||
const array = arrayFiltered.slice(0, 25);
|
||||
return array.map((issueOrPr: Issue | PullRequest) => 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<APIAppli
|
|||
const result = searcher.search(query);
|
||||
|
||||
return (result as unknown as Issue[] | PullRequest[]).slice(0, 25).map((issueOrPr: Issue | PullRequest) => 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;
|
||||
}
|
1
src/utils/regexes.ts
Normal file
1
src/utils/regexes.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export const discordChoicesRegex = /[^a-z0-9 (|)|-|*|/|+|,|<|>|&|!|?]/gi;
|
Loading…
Reference in a new issue