Skip to content

Commit c77bae0

Browse files
committed
feat: Add sample command
1 parent ee52ed5 commit c77bae0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/ps/commands/sample.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { parsePoint } from '@/utils/grid';
2+
import { sample } from '@/utils/random';
3+
4+
import type { PSCommand } from '@/types/chat';
5+
6+
export const command: PSCommand = {
7+
name: 'sample',
8+
help: 'Generates random numbers.',
9+
syntax: 'CMD [max=10] x [count=5]',
10+
aliases: ['random'],
11+
async run({ arg, broadcast, originalCommand }) {
12+
const [max, count] = parsePoint(arg) ?? [10, 5];
13+
const nums =
14+
originalCommand[0] === 'random'
15+
? Array.from({ length: count }, () => sample(max) + 1)
16+
: Array.from({ length: count }, (_, index) => index + 1).sample(count);
17+
broadcast(nums.join(', '));
18+
},
19+
};

0 commit comments

Comments
 (0)