diff options
| author | 2018-11-04 15:35:52 +0000 | |
|---|---|---|
| committer | 2018-11-04 15:37:06 +0000 | |
| commit | 58363895f196ee4816d490c3ed094f3d2cf35a66 (patch) | |
| tree | 08627428b7dd36471eeb1725ef6404a4aa9720c8 /src/utils | |
| parent | Implement IRCv3's `draft/rename` (diff) | |
| signature | ||
Change line parsing to put arbitrary-length args on the end of
`args` so we can get rid of `last`/`arbitrary` and add IRCArgs (with .get())
to help only getting an arg index if it exists
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/irc.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/utils/irc.py b/src/utils/irc.py index 49e118f4..99a53d86 100644 --- a/src/utils/irc.py +++ b/src/utils/irc.py @@ -54,14 +54,21 @@ def seperate_hostmask(hostmask: str) -> IRCHostmask: class IRCLine(object): def __init__(self, tags: dict, prefix: typing.Optional[str], command: str, - args: typing.List[str], arbitrary: typing.Optional[str], - last: str): + args: IRCArgs, self.tags = tags self.prefix = prefix self.command = command self.args = args - self.arbitrary = arbitrary - self.last = last + +class IRCArgs(object): + def __init__(self, args: typing.List[str]): + self._args = args + def __getitem__(self, index) -> str: + return self_args[index] + def get(self, index: int) -> typing.Optional[str]: + if len(self._args) > index: + return self._args[index] + return None def parse_line(line: str) -> IRCLine: tags = {} @@ -83,9 +90,10 @@ def parse_line(line: str) -> IRCLine: command, _, line = line.partition(" ") args = line.split(" ") - last = arbitrary or args[-1] + if arbitrary: + args.append(arbitrary) - return IRCLine(tags, prefix, command, args, arbitrary, last) + return IRCLine(tags, prefix, command, IRCArgs(args)) COLOR_WHITE, COLOR_BLACK, COLOR_BLUE, COLOR_GREEN = 0, 1, 2, 3 COLOR_RED, COLOR_BROWN, COLOR_PURPLE, COLOR_ORANGE = 4, 5, 6, 7 |
