From 1ba3fc601d0b807816a775e47a3d15b5bbb8ed47 Mon Sep 17 00:00:00 2001 From: luk3yx Date: Mon, 9 Dec 2024 12:36:08 +1300 Subject: [PATCH] Add "server_password" argument Closes https://github.com/luk3yx/miniirc/issues/27 --- CHANGELOG.md | 15 +++++++++++++-- README.md | 5 +++-- miniirc.py | 13 ++++++++----- miniirc.pyi | 2 +- setup.py | 2 +- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b86a5aa..c6c8d90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,19 @@ Format partially copied from [Keep a Changelog](https://keepachangelog.com). Notes: - I strongly recommend you use the latest version of miniirc, there are major bugfixes that are not listed here. - - This changelog may contain typographical errors, it is still a - work-in-progress. + - This changelog may contain errors. + +## 1.10.0 - 2024-12-09 + +### Added + + - `server_password` command to send passwords on joining + +### Changed + + - Tags now get sent if you use an empty string as a value. + - Messages with multiple spaces separating arguments are now ignored instead + of being parsed incorrectly. ## 1.9.1 - 2022-12-14 diff --git a/README.md b/README.md index 3915905..0de2cd5 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ If you have previously used miniirc, you may want to read the ## Parameters ```py -irc = miniirc.IRC(ip, port, nick, channels=None, *, ssl=None, ident=None, realname=None, persist=True, debug=False, ns_identity=None, auto_connect=True, ircv3_caps=set(), quit_message='I grew sick and died.', ping_interval=60, ping_timeout=None, verify_ssl=True, executor=None) +irc = miniirc.IRC(ip, port, nick, channels=None, *, ssl=None, ident=None, realname=None, persist=True, debug=False, ns_identity=None, auto_connect=True, ircv3_caps=set(), quit_message='I grew sick and died.', ping_interval=60, ping_timeout=None, verify_ssl=True, server_password=None, executor=None) ``` *Note that everything before the \* is a positional argument.* @@ -63,7 +63,8 @@ irc.wait_until_disconnected() | `ping_interval` | If no packets are sent or received for this amount of seconds, miniirc will send a `PING`, and if no reply is sent, after the ping timeout, miniirc will attempt to reconnect. Set to `None` to disable. | | `ping_timeout` | The ping timeout used alongside the above `ping_interval` option, if unspecified will default to `ping_interval`. | | `verify_ssl` | Verifies TLS/SSL certificates. Disabling this is not recommended as it opens the IRC connection up to MiTM attacks. If you have trouble with certificate verification, try running `pip3 install certifi` first. | -| `executor` | An instance of `concurrent.futures.ThreadPoolExecutor` to use when running handlers. | +| `server_password` | Sends the password with `PASS` command immediately after connection. If you are looking to log into a NickServ account, you probably want to use `ns_identity` instead. | +| `executor` | An instance of `concurrent.futures.ThreadPoolExecutor` to use when running handlers. *New in v1.10.0.* | *The only mandatory parameters are `ip`, `port`, and `nick`.* diff --git a/miniirc.py b/miniirc.py index c87a159..d58ea4c 100755 --- a/miniirc.py +++ b/miniirc.py @@ -8,9 +8,9 @@ import atexit, threading, time, select, socket, ssl, sys, warnings # The version string and tuple -ver = __version_info__ = (1, 9, 1) -version = 'miniirc IRC framework v1.9.1' -__version__ = '1.9.1' +ver = __version_info__ = (1, 10, 0) +version = 'miniirc IRC framework v1.10.0' +__version__ = '1.10.0' # __all__ and _default_caps __all__ = ['CmdHandler', 'Handler', 'IRC'] @@ -228,7 +228,8 @@ def __init__(self, ip, port, nick, channels=None, *, ssl=None, ident=None, realname=None, persist=True, debug=False, ns_identity=None, auto_connect=True, ircv3_caps=None, connect_modes=None, quit_message='I grew sick and died.', ping_interval=60, - ping_timeout=None, verify_ssl=True, executor=None): + ping_timeout=None, verify_ssl=True, server_password=None, + executor=None): # Set basic variables self.ip = ip self.port = int(port) @@ -248,6 +249,7 @@ def __init__(self, ip, port, nick, channels=None, *, ssl=None, ident=None, self.ping_interval = ping_interval self.ping_timeout = ping_timeout self.verify_ssl = verify_ssl + self.server_password = server_password self._keepnick_active = False self._executor = executor @@ -414,9 +416,10 @@ def connect(self): ctx.verify_mode = ssl.CERT_NONE self.sock = ctx.wrap_socket(self.sock, server_hostname=self.ip) - # Begin IRCv3 CAP negotiation. self._current_nick = self._desired_nick self._unhandled_caps = None + if self.server_password is not None: + self.send('PASS', self.server_password, force=True) self.quote('CAP LS 302', force=True) self.quote('USER', self.ident, '0', '*', ':' + self.realname, force=True) diff --git a/miniirc.pyi b/miniirc.pyi index 8f02c70..767ce89 100644 --- a/miniirc.pyi +++ b/miniirc.pyi @@ -204,6 +204,6 @@ class IRC: auto_connect: bool = True, ircv3_caps: Optional[set[str]] = None, connect_modes: Optional[str] = None, quit_message: str = 'I grew sick and died.', ping_interval: int = 60, - verify_ssl: bool = True, + verify_ssl: bool = True, server_password: Optional[str] = None, executor: Optional[concurrent.futures.ThreadPoolExecutor] ) -> None: ... diff --git a/setup.py b/setup.py index 66ddb46..66b02d0 100755 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='miniirc', - version='1.9.1', + version='1.10.0', py_modules=['miniirc'], author='luk3yx', description='A lightweight IRC framework.',