.
This commit is contained in:
1 parent
bd3cd4fa5f
commit
a5654c02a2
6 files changed
+327
-62
No files matched your search
@@ -15,9 +15,7 @@ describe('parseCommand', () => {
|
||||
);
|
||||
expect(result).toMatchObject({
|
||||
kind: 'match-join',
|
||||
matchId: '69b63bc96da18dfdb218ee8c',
|
||||
gameName: '프리리',
|
||||
tagLine: 'KR1',
|
||||
matchAndRiotId: '69b63bc96da18dfdb218ee8c 프리리#KR1',
|
||||
});
|
||||
if (result.kind === 'match-join') {
|
||||
expect(result.positions.positions).toEqual(['MID', 'TOP']);
|
||||
@@ -30,12 +28,11 @@ describe('parseCommand', () => {
|
||||
);
|
||||
expect(result).toMatchObject({
|
||||
kind: 'match-join',
|
||||
gameName: 'hello world',
|
||||
tagLine: 'KR1',
|
||||
matchAndRiotId: '69b63bc96da18dfdb218ee8c hello world#KR1',
|
||||
});
|
||||
});
|
||||
|
||||
it('normalizes hidden unicode differences in riot id', () => {
|
||||
it('parses hidden unicode differences in riot id input', () => {
|
||||
const decomposedGameName = '프리리'.normalize('NFD');
|
||||
const result = parseCommand(
|
||||
`!내전 신청 69b63bc96da18dfdb218ee8c ${decomposedGameName}\u200B#KR1\uFEFF 미드,탑`,
|
||||
@@ -43,8 +40,23 @@ describe('parseCommand', () => {
|
||||
|
||||
expect(result).toMatchObject({
|
||||
kind: 'match-join',
|
||||
gameName: '프리리',
|
||||
tagLine: 'KR1',
|
||||
matchAndRiotId: `69b63bc96da18dfdb218ee8c ${decomposedGameName}\u200B#KR1`,
|
||||
});
|
||||
});
|
||||
|
||||
it('parses match-join command without explicit match id', () => {
|
||||
const result = parseCommand('!내전 신청 프리리#KR1 미드,탑');
|
||||
expect(result).toMatchObject({
|
||||
kind: 'match-join',
|
||||
matchAndRiotId: '프리리#KR1',
|
||||
});
|
||||
});
|
||||
|
||||
it('parses match-join command with title prefix', () => {
|
||||
const result = parseCommand('!내전 신청 저녁 프리리#KR1 미드,탑');
|
||||
expect(result).toMatchObject({
|
||||
kind: 'match-join',
|
||||
matchAndRiotId: '저녁 프리리#KR1',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -89,10 +101,13 @@ describe('parseCommand', () => {
|
||||
expect(() => parseCommand('!내전 폭파')).toThrow(/unknown_command/);
|
||||
});
|
||||
|
||||
it('throws invalid_match_id for non-objectid match', () => {
|
||||
expect(() =>
|
||||
it('allows non-objectid join match reference for title matching', () => {
|
||||
expect(
|
||||
parseCommand('!내전 신청 not-an-id 프리리#KR1 미드,탑'),
|
||||
).toThrow(/invalid_match_id/);
|
||||
).toMatchObject({
|
||||
kind: 'match-join',
|
||||
matchAndRiotId: 'not-an-id 프리리#KR1',
|
||||
});
|
||||
});
|
||||
|
||||
it('throws invalid_match_id for non-objectid cancel match', () => {
|
||||
|
||||
@@ -10,9 +10,7 @@ export type DakaoCommand =
|
||||
}
|
||||
| {
|
||||
kind: 'match-join';
|
||||
matchId: string;
|
||||
gameName: string;
|
||||
tagLine: string;
|
||||
matchAndRiotId: string;
|
||||
positions: ParsedPositions;
|
||||
}
|
||||
| {
|
||||
@@ -111,38 +109,22 @@ function parseJoinArgs(args: string): DakaoCommand {
|
||||
throw new CommandParseError('usage');
|
||||
}
|
||||
|
||||
// 마지막 토큰이 포지션 리스트(쉼표 포함). 그 앞이 라이엇 ID(공백 포함 가능). 그 앞이 matchId.
|
||||
// 형식: <matchId> <gameName...>#<tagLine> <pos1>,<pos2>...
|
||||
// 마지막 토큰이 포지션 리스트(쉼표 포함). 그 앞은 내전 식별자(선택)와 라이엇 ID.
|
||||
// 형식: [<matchId|title...>] <gameName...>#<tagLine> <pos1>,<pos2>...
|
||||
// 끝에서부터 토큰을 분리해 안정적으로 파싱한다.
|
||||
const lastSpace = args.lastIndexOf(' ');
|
||||
if (lastSpace === -1) {
|
||||
throw new CommandParseError('usage');
|
||||
}
|
||||
const positionPart = args.slice(lastSpace + 1).trim();
|
||||
const head = args.slice(0, lastSpace).trim();
|
||||
if (positionPart.length === 0 || head.length === 0) {
|
||||
const matchAndRiotId = args.slice(0, lastSpace).trim();
|
||||
if (positionPart.length === 0 || matchAndRiotId.length === 0) {
|
||||
throw new CommandParseError('usage');
|
||||
}
|
||||
|
||||
const headSpace = head.indexOf(' ');
|
||||
if (headSpace === -1) {
|
||||
throw new CommandParseError('usage');
|
||||
}
|
||||
const matchId = head.slice(0, headSpace).trim();
|
||||
const riotId = head.slice(headSpace + 1).trim();
|
||||
|
||||
if (!isObjectIdHex(matchId)) {
|
||||
throw new CommandParseError('invalid_match_id', matchId);
|
||||
}
|
||||
|
||||
const hashIndex = riotId.lastIndexOf('#');
|
||||
if (hashIndex <= 0 || hashIndex === riotId.length - 1) {
|
||||
throw new CommandParseError('invalid_riot_id', riotId);
|
||||
}
|
||||
const gameName = normalizeRiotIdPart(riotId.slice(0, hashIndex));
|
||||
const tagLine = normalizeRiotIdPart(riotId.slice(hashIndex + 1));
|
||||
if (gameName.length === 0 || tagLine.length === 0) {
|
||||
throw new CommandParseError('invalid_riot_id', riotId);
|
||||
const hashIndex = matchAndRiotId.lastIndexOf('#');
|
||||
if (hashIndex <= 0 || hashIndex === matchAndRiotId.length - 1) {
|
||||
throw new CommandParseError('invalid_riot_id', matchAndRiotId);
|
||||
}
|
||||
|
||||
let positions: ParsedPositions;
|
||||
@@ -157,9 +139,7 @@ function parseJoinArgs(args: string): DakaoCommand {
|
||||
|
||||
return {
|
||||
kind: 'match-join',
|
||||
matchId,
|
||||
gameName,
|
||||
tagLine,
|
||||
matchAndRiotId,
|
||||
positions,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user