|
|
@ -3,13 +3,6 @@ from typing import List, Optional |
|
|
|
|
|
|
|
MAX_MESSAGE_SIZE = 512 |
|
|
|
|
|
|
|
EXPECTED_ARG_COUNT = { |
|
|
|
"NICK": 1, |
|
|
|
"USER": 4, |
|
|
|
"JOIN": 1, |
|
|
|
"PRIVMSG": 2, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class ParsingError(Exception): |
|
|
|
message: Optional[str] |
|
|
@ -56,10 +49,5 @@ def parse_message(raw: bytes) -> Message: |
|
|
|
raise ParsingError("Message has no command") |
|
|
|
|
|
|
|
cmd = tokens[0].upper() |
|
|
|
if cmd in EXPECTED_ARG_COUNT and EXPECTED_ARG_COUNT[cmd] != len(tokens) - 1: |
|
|
|
raise ParsingError( |
|
|
|
f"{cmd} had {len(tokens)-1} arguments, expected {EXPECTED_ARG_COUNT[cmd]}" |
|
|
|
) |
|
|
|
|
|
|
|
tokens[-1] = tokens[-1].strip() |
|
|
|
return Message(cmd=tokens[0], args=tokens[1:]) |
|
|
|
return Message(cmd=cmd, args=tokens[1:]) |