-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathaction-utils.ts
More file actions
34 lines (32 loc) · 1.01 KB
/
action-utils.ts
File metadata and controls
34 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import type { SessionAction } from './types.ts';
export function inferFillText(action: SessionAction): string {
const resultText = action.result?.text;
if (typeof resultText === 'string' && resultText.trim().length > 0) {
return resultText;
}
const positionals = action.positionals ?? [];
if (positionals.length === 0) return '';
const first = positionals[0];
if (first?.startsWith('@')) {
if (positionals.length >= 3) return positionals.slice(2).join(' ').trim();
return positionals.slice(1).join(' ').trim();
}
if (
positionals.length >= 3 &&
!Number.isNaN(Number(positionals[0])) &&
!Number.isNaN(Number(positionals[1]))
) {
return positionals.slice(2).join(' ').trim();
}
return positionals.slice(1).join(' ').trim();
}
export function uniqueStrings(values: string[]): string[] {
const seen = new Set<string>();
const output: string[] = [];
for (const value of values) {
if (seen.has(value)) continue;
seen.add(value);
output.push(value);
}
return output;
}