From f71a85aeb6366a264929d526b4ea708114a1884b Mon Sep 17 00:00:00 2001 From: luk3yx Date: Thu, 21 Apr 2022 13:42:27 +1200 Subject: New message format --- miniirc_idc.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'miniirc_idc.py') 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): -- cgit v1.2.3