diff options
author | luk3yx <luk3yx@users.noreply.github.com> | 2022-04-21 13:42:27 +1200 |
---|---|---|
committer | luk3yx <luk3yx@users.noreply.github.com> | 2022-04-21 13:44:17 +1200 |
commit | f71a85aeb6366a264929d526b4ea708114a1884b (patch) | |
tree | 9fb7913368dd9e7e24b6777d8e48d5524ae68d83 /miniirc_idc.py | |
parent | 05a0b1f9bb03c9924ea01c26c91730b8e91f89c0 (diff) | |
download | miniirc_idc-f71a85aeb6366a264929d526b4ea708114a1884b.tar.gz miniirc_idc-f71a85aeb6366a264929d526b4ea708114a1884b.zip |
New message format
Diffstat (limited to 'miniirc_idc.py')
-rw-r--r-- | miniirc_idc.py | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/miniirc_idc.py b/miniirc_idc.py index 7353f60..77dca2c 100644 --- a/miniirc_idc.py +++ b/miniirc_idc.py @@ -12,31 +12,39 @@ _LEADING_COLON = '' if miniirc.ver[0] > 2 else ':' _esc_re = re.compile(r'\\(.)|\t') -idc_to_irc = { - #'MESSAGE': 'PRIVMSG', - 'RPL_LOGIN_GOOD': '001', -} +def _unix_str_to_iso(unix_str): + dt = datetime.datetime.utcfromtimestamp(float(unix_str)) + return dt.isoformat() + 'Z' class IDC(miniirc.IRC): def idc_message_parser(self, msg): - args = _esc_re.sub(lambda m: m.group(1) or '\udeff', msg).split('\udeff') + args = _esc_re.sub(lambda m: m.group(1) or '\udeff', msg + ).split('\udeff') - command = args.pop(0).upper() - hostmask = ('', '', '') tags = {} + if args[0].startswith(':'): + user = args.pop(0)[1:] + hostmask = (user, user, user) + tags['account'] = user + else: + hostmask = ('', '', '') + + command = args.pop(0).upper() if command == 'PRIVMSG': - dt = datetime.datetime.utcfromtimestamp(float(args[0])) - tags['time'] = dt.isoformat() + 'Z' - hostmask = (args[1], args[1], f'idc/{args[1]}') - args = [self.current_nick, args[2]] + tags['time'] = _unix_str_to_iso(args[0]) + args = [self.current_nick, args[1]] + elif command == 'CHANMSG': + command = 'PRIVMSG' + tags['time'] = _unix_str_to_iso(args[0]) + args = [args[1], args[2]] elif command == 'RPL_LOGIN_GOOD': command = '001' args = [self.current_nick, f'Welcome to IDC {self.current_nick}'] if args and _LEADING_COLON: args[-1] = _LEADING_COLON + args[-1] - return idc_to_irc.get(command, command), hostmask, tags, args + return command, hostmask, tags, args # Send raw messages def idc_send(self, *args): |