This commit is contained in:
dahyeon committed 2026-05-02 04:39:11 -07:00
1 parent 673ee3d80a
commit bd3cd4fa5f
9 files changed
+332 -3

No files matched your search

@@ -48,6 +48,20 @@ describe('parseCommand', () => {
});
});
it('parses match-cancel command (취소)', () => {
expect(parseCommand('!내전 취소 69b63bc96da18dfdb218ee8c')).toEqual({
kind: 'match-cancel',
matchId: '69b63bc96da18dfdb218ee8c',
});
});
it('parses match-cancel command (참가취소)', () => {
expect(parseCommand('!내전 참가취소 69b63bc96da18dfdb218ee8c')).toEqual({
kind: 'match-cancel',
matchId: '69b63bc96da18dfdb218ee8c',
});
});
it('parses account register command', () => {
expect(parseCommand('!내전 계정등록 hello world#KR1')).toEqual({
kind: 'account-register',
@@ -81,6 +95,12 @@ describe('parseCommand', () => {
).toThrow(/invalid_match_id/);
});
it('throws invalid_match_id for non-objectid cancel match', () => {
expect(() => parseCommand('!내전 취소 not-an-id')).toThrow(
/invalid_match_id/,
);
});
it('throws invalid_riot_id when # missing', () => {
expect(() =>
parseCommand('!내전 신청 69b63bc96da18dfdb218ee8c 프리리 미드,탑'),
@@ -14,6 +14,10 @@ export type DakaoCommand =
gameName: string;
tagLine: string;
positions: ParsedPositions;
}
| {
kind: 'match-cancel';
matchId: string;
};
export class CommandParseError extends Error {
@@ -54,6 +58,9 @@ export function parseCommand(rawMessage: string): DakaoCommand {
return { kind: 'match-list' };
case '신청':
return parseJoinArgs(args);
case '취소':
case '참가취소':
return parseCancelArgs(args);
case '계정등록':
return parseAccountRegisterArgs(args);
default:
@@ -84,6 +91,21 @@ function parseAccountRegisterArgs(args: string): DakaoCommand {
};
}
function parseCancelArgs(args: string): DakaoCommand {
const matchId = args.trim();
if (matchId.length === 0) {
throw new CommandParseError('usage');
}
if (!isObjectIdHex(matchId)) {
throw new CommandParseError('invalid_match_id', matchId);
}
return {
kind: 'match-cancel',
matchId,
};
}
function parseJoinArgs(args: string): DakaoCommand {
if (args.length === 0) {
throw new CommandParseError('usage');