Skip to content

Commit

Permalink
try that
Browse files Browse the repository at this point in the history
  • Loading branch information
ackle-dev committed Dec 18, 2024
1 parent 83d4033 commit 5f7cb0b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/commands/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export async function execute(interaction: ChatInputCommandInteraction) {
const response = results.length
? results
.map(
({ word, meaning, extra, type }) =>
`${word} (${type}): ${meaning} ${extra?.join(' ') ?? ''}`
({ word, meaning, impl, type }) =>
`${word} (${type}): ${meaning}${impl ? ` – ${impl}` : ''}`
)
.join('\n')
: 'No results found.';
Expand Down
10 changes: 7 additions & 3 deletions src/lib/kumilinwa/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ export async function searchLangSpec(
matching?: MatchType
): Promise<FullEntry[]> {
const matchWord = matching === 'word' || !matching,
matchMeaning = matching === 'meaning' || !matching;
matchMeaning = matching === 'meaning' || !matching,
matchImpl = matching === 'impl' || !matching,
matchObscurism = matching === 'obscurism' || !matching;
const results: FullEntry[] = [];
for (const entry of await CompleteLangSpec())
if (
(matchWord && entry.word.includes(query)) ||
(matchMeaning && entry.meaning.includes(query))
(matchMeaning && (entry.meaning ?? entry.impl!).includes(query)) ||
(matchImpl && entry.impl?.includes(query)) ||
(matchObscurism && entry.obscurism?.includes(query))
)
results.push(entry);
return results;
}

export type MatchType = 'word' | 'meaning';
export type MatchType = 'word' | 'meaning' | 'impl' | 'obscurism' | 'all';
18 changes: 10 additions & 8 deletions src/lib/kumilinwa/types.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/**
* The type of the entry in each separated file (i.e. verbs.json)
*/
export interface Section {
title?: string;
type: WordType;
title: string | null;
headers: string[];
type: WordType;
entries: Entry[];
}

/**
* The type of the entry in each separated file (i.e. verbs.json)
*/
export interface Entry {
word: string;
meaning: string;
extra?: string[];
meaning: string | null;
impl: string | null;
obscurism: string | null;
}

/**
Expand All @@ -36,4 +37,5 @@ export type WordType =
| 'preposition'
| 'pronoun'
| 'suffix'
| 'verb';
| 'verb'
| 'article';

0 comments on commit 5f7cb0b

Please sign in to comment.