home · contact · privacy
Move IrcConnSetup attributes defaulting into Client.__init__, refactor cmd_connect.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 26 Sep 2025 03:03:55 +0000 (05:03 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 26 Sep 2025 03:03:55 +0000 (05:03 +0200)
src/ircplom/client.py
src/ircplom/client_tui.py
src/test.txt

index b6d0c24f11477c9c01b1c6e7af1ddc4bead96c0e..63c6ed4bc7d6f29382592d2970110655fbcca847 100644 (file)
@@ -825,8 +825,9 @@ class Client(ABC, ClientQueueMixin):
             setattr(self.db, k, getattr(conn_setup, k))
         if self.db.port <= 0:
             self.db.port = PORT_SSL
-        if not self.db.user_wanted:
-            self.db.user_wanted = getuser()
+        for attr_name in {'nick_wanted', 'user_wanted', 'realname'}:
+            if not getattr(self.db, attr_name):
+                setattr(self.db, attr_name, getuser())
 
     def connect(self) -> None:
         'Attempt to open connection, on success perform session init steps.'
index 190d0dcbe9ab84c4824758e81d6155aa37ad276b..046bc7ec4b3b03a6f4c4eb8243f6ecf92ac31231 100644 (file)
@@ -483,31 +483,23 @@ class ClientTui(BaseTui):
     def cmd__connect(self,
                      host_port: str,
                      nickname_pw: str = '',
-                     username_realname: str = ''
+                     realname_username: str = ''
                      ) -> Optional[str]:
         'Create Client and pass it via NewClientEvent.'
-        split = host_port.split(':', maxsplit=1)
-        hostname = split[0]
+        def from_split(input_: str) -> tuple[str, ...]:
+            return tuple(input_.split(':', maxsplit=1) if ':' in input_
+                         else (input_, ''))
+        hostname, port_str = from_split(host_port)
         if hostname in self._client_mngrs:
             return f'already set up connection to {hostname}'
         port = -1
-        if len(split) > 1:
-            to_int = split[1]
-            if to_int.isdigit():
-                port = int(split[1])
+        if port_str:
+            if port_str.isdigit():
+                port = int(port_str)
             else:
-                return f'invalid port number: {to_int}'
-        split = nickname_pw.split(':', maxsplit=1)
-        nickname = split[0] if nickname_pw else getuser()
-        password = split[1] if len(split) > 1 else ''
-        if not username_realname:
-            username = ''
-            realname = nickname
-        elif ':' in username_realname:
-            username, realname = username_realname.split(':', maxsplit=1)
-        else:
-            username = ''
-            realname = username_realname
+                return f'invalid port number: {port_str}'
+        nickname, password = from_split(nickname_pw)
+        realname, username = from_split(realname_username)
         setup = IrcConnSetup(
                 hostname, port, nickname, username, realname, password)
         self._put(NewClientEvent(self._new_client(setup, set())))
index c69157239e4cb9631530ee48accda05fa7d1633a..5371e01487400a41bf8959de5a229fe58ff3274d 100644 (file)
@@ -16,7 +16,7 @@
 # some simple expected command successes
 > /help
 0 # commands available in this window:
-0 #   /connect HOST_PORT [NICKNAME_PW] [USERNAME_REALNAME]
+0 #   /connect HOST_PORT [NICKNAME_PW] [REALNAME_USERNAME]
 0 #   /help
 0 #   /list
 0 #   /prompt_enter
@@ -43,7 +43,7 @@
 # CONNECTED INTERACTIONS
 
 # on /connect init databases, log in new windows
-> /connect foo.bar.baz foo:bar foobarbazquux:baz
+> /connect foo.bar.baz foo:bar baz:foobarbazquux
 , $ DISCONNECTED
 1 $ isupport cleared
 1 $ isupport:CHANTYPES set to: [#&]
 > /window 1
 > /help
 1 # commands available in this window:
-1 #   /connect HOST_PORT [NICKNAME_PW] [USERNAME_REALNAME]
+1 #   /connect HOST_PORT [NICKNAME_PW] [REALNAME_USERNAME]
 1 #   /disconnect [QUIT_MSG]
 1 #   /help
 1 #   /join CHANNEL