 ! Listener join request handling
 ! ======================================
 
-: make-registered-listener ( join -- listener )
-    <irc-listener> swap trailing>>
-    dup [ listener-loop ] curry "listener" spawn-irc-loop
+: make-registered-listener ( name -- listener )
+    <irc-listener> swap dup
+    [ listener-loop ] curry "listener" spawn-irc-loop
     [ irc-client> listeners>> set-at ] curry keep ;
 
 : make-join-future ( name -- future )
     [ [ swap trailing>> = ] curry ! compare name with channel name
       irc-client> join-messages>> 60 seconds rot mailbox-get-timeout?
-      make-registered-listener ]
+      trailing>> make-registered-listener ]
     curry future ;
+
+: make-user-future ( name -- future )
+    [ make-registered-listener ] curry future ;
+
+: maybe-join ( name password -- ? )
+    over "#" head? [ /JOIN t ] [ 2drop f ] if ;
+
+: make-listener-future ( name channel? -- future )
+    [ make-join-future ] [ make-user-future ] if ;
 
 PRIVATE>
 

    ] with-variable ;

: listen-to ( irc-client name -- future )
    swap current-irc-client [ [ f /JOIN ] keep make-join-future ] with-variable ;

! shorcut for privmsgs, etc
: sender>> ( obj -- string )

! Server message handling
! ======================================

: irc-message-origin ( irc-message -- name )
    dup name>> irc-client> nick>> name>> = [ sender>> ] [ name>> ] if ;

USE: prettyprint

GENERIC: handle-incoming-irc ( irc-message -- )
