.
This commit is contained in:
1 parent
1fd37f992b
commit
4475a2d86b
7 files changed
+262
-34
No files matched your search
@@ -48,6 +48,25 @@ describe('parseCommand', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('parses account register command', () => {
|
||||
expect(parseCommand('!내전 계정등록 hello world#KR1')).toEqual({
|
||||
kind: 'account-register',
|
||||
gameName: 'hello world',
|
||||
tagLine: 'KR1',
|
||||
});
|
||||
});
|
||||
|
||||
it('normalizes account register riot id', () => {
|
||||
const decomposedGameName = '프리리'.normalize('NFD');
|
||||
expect(
|
||||
parseCommand(`!내전 계정등록 ${decomposedGameName}\u200B#KR1\uFEFF`),
|
||||
).toEqual({
|
||||
kind: 'account-register',
|
||||
gameName: '프리리',
|
||||
tagLine: 'KR1',
|
||||
});
|
||||
});
|
||||
|
||||
it('throws not_a_command for non-prefix messages', () => {
|
||||
expect(() => parseCommand('안녕하세요')).toThrow(/not_a_command/);
|
||||
});
|
||||
|
||||
@@ -3,6 +3,11 @@ import { normalizeRiotIdPart } from '../riot-id.util';
|
||||
|
||||
export type DakaoCommand =
|
||||
| { kind: 'match-list' }
|
||||
| {
|
||||
kind: 'account-register';
|
||||
gameName: string;
|
||||
tagLine: string;
|
||||
}
|
||||
| {
|
||||
kind: 'match-join';
|
||||
matchId: string;
|
||||
@@ -49,11 +54,36 @@ export function parseCommand(rawMessage: string): DakaoCommand {
|
||||
return { kind: 'match-list' };
|
||||
case '신청':
|
||||
return parseJoinArgs(args);
|
||||
case '계정등록':
|
||||
return parseAccountRegisterArgs(args);
|
||||
default:
|
||||
throw new CommandParseError('unknown_command', subCommand);
|
||||
}
|
||||
}
|
||||
|
||||
function parseAccountRegisterArgs(args: string): DakaoCommand {
|
||||
if (args.length === 0) {
|
||||
throw new CommandParseError('usage');
|
||||
}
|
||||
|
||||
const hashIndex = args.lastIndexOf('#');
|
||||
if (hashIndex <= 0 || hashIndex === args.length - 1) {
|
||||
throw new CommandParseError('invalid_riot_id', args);
|
||||
}
|
||||
|
||||
const gameName = normalizeRiotIdPart(args.slice(0, hashIndex));
|
||||
const tagLine = normalizeRiotIdPart(args.slice(hashIndex + 1));
|
||||
if (gameName.length === 0 || tagLine.length === 0) {
|
||||
throw new CommandParseError('invalid_riot_id', args);
|
||||
}
|
||||
|
||||
return {
|
||||
kind: 'account-register',
|
||||
gameName,
|
||||
tagLine,
|
||||
};
|
||||
}
|
||||
|
||||
function parseJoinArgs(args: string): DakaoCommand {
|
||||
if (args.length === 0) {
|
||||
throw new CommandParseError('usage');
|
||||
|
||||
Reference in new issue
Block a user