 ! 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 -- )

! Listener join request handling
! ======================================

: make-registered-listener ( join -- listener )
    <irc-listener> swap trailing>>
    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 ]
    curry future ;

PRIVATE>


    ] with-variable ;

: listen-to ( irc-client name -- future )
    swap current-irc-client [
        dup f maybe-join make-listener-future
    ] with-variable ;

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