diff options
-rwxr-xr-x | idc_irc_proxy.py | 8 | ||||
-rw-r--r-- | miniirc_idc.py | 22 |
2 files changed, 17 insertions, 13 deletions
diff --git a/idc_irc_proxy.py b/idc_irc_proxy.py index 1faa5f2..de5c7ba 100755 --- a/idc_irc_proxy.py +++ b/idc_irc_proxy.py @@ -218,14 +218,16 @@ class Server: def main(): import argparse parser = argparse.ArgumentParser() - parser.add_argument('local_port', type=int) + parser.add_argument('bind_port', type=int) parser.add_argument('username') parser.add_argument('password') parser.add_argument('--debug', '-v', action='store_true') + parser.add_argument('--idc-ip', default='andrewyu.org') + parser.add_argument('--idc-port', type=int, default=6835) args = parser.parse_args() - Server('andrewyu.org', 6835, '', ssl=True, persist=False, - local_addr=('127.0.0.1', args.local_port), debug=args.debug, + Server(args.idc_ip, args.idc_port, '', ssl=True, persist=False, + local_addr=('127.0.0.1', args.bind_port), debug=args.debug, ns_identity=(args.username, args.password)).main() if __name__ == '__main__': diff --git a/miniirc_idc.py b/miniirc_idc.py index d8a3d46..c264d73 100644 --- a/miniirc_idc.py +++ b/miniirc_idc.py @@ -31,7 +31,6 @@ import datetime, miniirc, re, traceback # type: ignore assert miniirc.ver >= (1,8,1) -_LEADING_COLON = '' if miniirc.ver[0] > 2 else ':' _esc_re = re.compile(r'\\(.)') # Backslash must be first @@ -53,9 +52,8 @@ def _parse_join(irc: IDC, hostmask: tuple[str, str, str], tags: Mapping[str, str], args: list[str]) -> None: users = tags.get('=idc-join-users') if isinstance(users, str): - irc._dispatch('353', '', [irc.current_nick, '=', args[0], users]) - irc._dispatch('366', '', [irc.current_nick, args[0], - 'End of /NAMES list']) + irc._numeric('353', '=', args[0], users) + irc._numeric('366', args[0], 'End of /NAMES list') class IDC(miniirc.IRC): @@ -70,7 +68,7 @@ class IDC(miniirc.IRC): else: def _dispatch(self, command: str, user: str, args: list[str]) -> None: if args: - args[-1] = _LEADING_COLON + args[-1] + args[-1] = ':' + args[-1] self._handle( command, (user, '~u', f'idc/{user}') if user else ('', '', ''), @@ -78,6 +76,9 @@ class IDC(miniirc.IRC): args, ) + def _numeric(self, numeric: str, *args: str) -> None: + self._dispatch(numeric, '', [self.current_nick, *args]) + def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) self.Handler('JOIN', colon=False, ircv3=True)(_parse_join) @@ -115,6 +116,7 @@ class IDC(miniirc.IRC): command = 'PRIVMSG' args = ['#' + idc_args['TARGET'], idc_args['MESSAGE']] elif idc_cmd == 'LOGIN_GOOD': + self._sasl = True command = '001' args = [self.current_nick, f'Welcome to IDC {self.current_nick}'] elif idc_cmd == 'PONG': @@ -165,7 +167,7 @@ class IDC(miniirc.IRC): return miniirc.IRCMessage(command, hostmask, tags, args) else: if args: - args[-1] = _LEADING_COLON + args[-1] + args[-1] = ':' + args[-1] return command, hostmask, tags, args # Send raw messages @@ -195,10 +197,7 @@ class IDC(miniirc.IRC): label = tags.get('label') if tags else None if cmd in ('PRIVMSG', 'NOTICE'): target = args[0] - # TODO: Make miniirc think that SASL worked PMs to NickServ don't - # have to be blocked. - if target == 'NickServ': - return + assert target != 'NickServ' msg = args[1] msg_type: Optional[str] @@ -226,7 +225,10 @@ class IDC(miniirc.IRC): label=label) self.active_caps = self.ircv3_caps & { 'account-tag', 'echo-message', 'labeled-response', + 'message-tags' } + elif self.connected: + self._numeric('421', cmd, 'Unknown command') # Override the message parser to change the default parser. def change_parser(self, parser=None): |