HELP: irc-client "IRC Client object" ;
-HELP: irc-server-listener "Listener for server messages unmanaged by other listeners" ;
+HELP: irc-server-chat "Chat for server messages unmanaged by other chats" ;
-HELP: irc-channel-listener "Listener for irc channels" ;
+HELP: irc-channel-chat "Chat for irc channels" ;
-HELP: irc-nick-listener "Listener for irc users" ;
+HELP: irc-nick-chat "Chat for irc users" ;
HELP: irc-profile "IRC Client profile object" ;
{ $values { "irc-client" "an irc client object" } }
{ $description "Connects and logins " { $link irc-client } " using the settings specified on its " { $link irc-profile } "." } ;
-HELP: add-listener "Listening to irc channels/users/etc"
-{ $values { "irc-listener" "an irc listener object" } { "irc-client" "an irc client object" } }
-{ $description "Registers " { $snippet "irc-listener" } " with " { $snippet "irc-client" } " and starts listening." } ;
+HELP: attach-chat "Chatting with irc channels/users/etc"
+{ $values { "irc-chat" "an irc chat object" } { "irc-client" "an irc client object" } }
+{ $description "Registers " { $snippet "irc-chat" } " with " { $snippet "irc-client" } " and starts listening." } ;
-HELP: join-irc-channel "Joining channels"
-{ $values { "irc-client-listener" "an irc client listener object" } }
-{ $description "Joins to the channel being listened by " { $snippet "irc-listener" } "." } ;
-
-HELP: remove-listener "Stop an unregister listener"
-{ $values { "irc-listener" "an irc listener object" } { "irc-client" "an irc client object" } }
-{ $description "Unregisters " { $snippet "irc-listener" } " from " { $snippet "irc-client" } " and stops listening. This is how you part from a channel." } ;
+HELP: dettach-chat "Stop an unregister chat"
+{ $values { "irc-chat" "an irc chat object" } { "irc-client" "an irc client object" } }
+{ $description "Unregisters " { $snippet "irc-chat" } " from " { $snippet "irc-client" } " and stops listening. This is how you part from a channel." } ;
HELP: terminate-irc "Terminates an irc client"
{ $values { "irc-client" "an irc client object" } }
-{ $description "Terminates all activity by " { $link irc-client } " cleaning up resources and notifying listeners." } ;
+{ $description "Terminates all activity by " { $link irc-client } " cleaning up resources and notifying chats." } ;
-HELP: write-message "Sends a message through a listener"
-{ $values { "message" "a string or irc message object" } { "irc-listener" "an irc listener object" } }
-{ $description "Sends " { $snippet "message" } " through " { $snippet "irc-listener" } ". Strings are automatically promoted to privmsg objects." } ;
+HELP: speak "Sends a message through a chat"
+{ $values { "message" "a string or irc message object" } { "irc-chat" "an irc chat object" } }
+{ $description "Sends " { $snippet "message" } " through " { $snippet "irc-chat" } ". Strings are automatically promoted to privmsg objects." } ;
-HELP: read-message "Reads a message from a listener"
-{ $values { "irc-listener" "an irc listener object" } { "message" "an irc message object" } }
-{ $description "Reads " { $snippet "message" } " from " { $snippet "irc-listener" } "." } ;
+HELP: hear "Reads a message from a chat"
+{ $values { "irc-chat" "an irc chat object" } { "message" "an irc message object" } }
+{ $description "Reads " { $snippet "message" } " from " { $snippet "irc-chat" } "." } ;
ARTICLE: "irc.client" "IRC Client"
"An IRC Client library"
{ $heading "IRC objects:" }
{ $subsection irc-client }
-{ $heading "Listener objects:" }
-{ $subsection irc-server-listener }
-{ $subsection irc-channel-listener }
-{ $subsection irc-nick-listener }
+{ $heading "Chat objects:" }
+{ $subsection irc-server-chat }
+{ $subsection irc-channel-chat }
+{ $subsection irc-nick-chat }
{ $heading "Setup objects:" }
{ $subsection irc-profile }
{ $heading "Words:" }
{ $subsection connect-irc }
{ $subsection terminate-irc }
-{ $subsection add-listener }
-{ $subsection remove-listener }
-{ $subsection join-irc-channel }
-{ $subsection read-message }
-{ $subsection write-message }
+{ $subsection attach-chat }
+{ $subsection dettach-chat }
+{ $subsection hear }
+{ $subsection speak }
{ $heading "IRC messages" }
"Some of the RFC defined irc messages as objects:"
{ $table
{ $heading "Special messages" }
"Some special messages that are created by the library and not by the irc server."
{ $table
- { { $link irc-listener-end } "sent to a listener when it has been dettached from the client, the listener should stop after it receives this message. " }
- { { $link irc-end } " sent when the client isn't running anymore, listeners should stop after it receives this message." }
- { { $link irc-disconnected } " sent to notify listeners that connection was lost." }
- { { $link irc-connected } " sent to notify listeners that a connection with the irc server was established." } }
+ { { $link irc-chat-end } "sent to a chat when it has been dettached from the client, the chat should stop after it receives this message. " }
+ { { $link irc-end } " sent when the client isn't running anymore, chats should stop after it receives this message." }
+ { { $link irc-disconnected } " sent to notify chats that connection was lost." }
+ { { $link irc-connected } " sent to notify chats that a connection with the irc server was established." } }
{ $heading "Example:" }
{ $code
"\"irc.freenode.org\" irc-port \"mybot123\" f <irc-profile> <irc-client> bot set"
"! Connect to the server"
"bot get connect-irc"
- "! Create a channel listener"
- "\"#mychannel123\" <irc-channel-listener> mychannel set"
- "! Register and start listener (this joins the channel)"
- "mychannel get bot get add-listener"
- "! Join to the channel"
- "mychannel get join-irc-channel"
+ "! Create a channel chat"
+ "\"#mychannel123\" <irc-channel-chat> mychannel set"
+ "! Register and start chat (this joins the channel)"
+ "mychannel get bot get attach-chat"
"! Send a message to the channel"
- "\"what's up?\" mychannel get write-message"
+ "\"what's up?\" mychannel get speak"
"! Read a message from the channel"
- "mychannel get read-message"
+ "mychannel get hear"
}
;
USING: kernel tools.test accessors arrays sequences qualified
- io io.streams.duplex namespaces threads
+ io io.streams.duplex namespaces threads destructors
calendar irc.client.private irc.client irc.messages.private
concurrency.mailboxes classes assocs combinators ;
EXCLUDE: irc.messages => join ;
M: mb-writer stream-nl ( mb-writer -- )
[ [ last-line>> concat ] [ lines>> ] bi push ] keep
V{ } clone >>last-line drop ;
+M: mb-reader dispose drop ;
+M: mb-writer dispose drop ;
: spawn-client ( -- irc-client )
"someserver" irc-port "factorbot" f <irc-profile>
<irc-client>
+ t >>is-ready
t >>is-running
<test-stream> >>stream
dup [ spawn-irc yield ] with-irc-client ;
! to be used inside with-irc-client quotations
-: %add-named-listener ( listener -- ) irc> add-listener ;
+: %add-named-chat ( chat -- ) irc> attach-chat ;
: %push-line ( line -- ) irc> stream>> in>> push-line yield ;
-: %join ( channel -- )
- <irc-channel-listener>
- [ irc> add-listener ] [ join-irc-channel ] bi ;
+: %join ( channel -- ) <irc-channel-chat> irc> attach-chat ;
-: read-matching-message ( listener quot: ( msg -- ? ) -- irc-message )
+: read-matching-message ( chat quot: ( msg -- ? ) -- irc-message )
[ in-messages>> 0.1 seconds ] dip mailbox-get-timeout? ;
: with-irc ( quot: ( -- ) -- )
{ V{ "NICK factorbot" "USER factorbot hostname servername :irc.factor" } } [
"someserver" irc-port "factorbot" f <irc-profile> <irc-client>
[ 2drop <test-stream> t ] >>connect
- [ connect-irc ] keep stream>> out>> lines>>
+ [ connect-irc ] keep
+ stream>> [ in>> [ f ] dip push-line ] [ out>> lines>> ] bi
] unit-test
! Test join
] with-irc
[ { join_ "#factortest" } [
- "#factortest" <irc-channel-listener> [ %add-named-listener ] keep
+ "#factortest" <irc-channel-chat> [ %add-named-chat ] keep
{ ":factorbot!n=factorbo@some.where JOIN :#factortest"
":ircserver.net 353 factorbot @ #factortest :@factorbot "
":ircserver.net 366 factorbot #factortest :End of /NAMES list."
] with-irc
[ { T{ participant-changed f "somebody" +join+ } } [
- "#factortest" <irc-channel-listener> [ %add-named-listener ] keep
+ "#factortest" <irc-channel-chat> [ %add-named-chat ] keep
":somebody!n=somebody@some.where JOIN :#factortest" %push-line
[ participant-changed? ] read-matching-message
] unit-test
] with-irc
[ { privmsg "#factortest" "hello" } [
- "#factortest" <irc-channel-listener> [ %add-named-listener ] keep
+ "#factortest" <irc-channel-chat> [ %add-named-chat ] keep
":somebody!n=somebody@some.where PRIVMSG #factortest :hello" %push-line
[ privmsg? ] read-matching-message
[ class ] [ name>> ] [ trailing>> ] tri
] with-irc
[ { privmsg "factorbot" "hello" } [
- "ircuser" <irc-nick-listener> [ %add-named-listener ] keep
+ "ircuser" <irc-nick-chat> [ %add-named-chat ] keep
":ircuser!n=user@isp.net PRIVMSG factorbot :hello" %push-line
[ privmsg? ] read-matching-message
[ class ] [ name>> ] [ trailing>> ] tri
] with-irc
[ { mode } [
- "#factortest" <irc-channel-listener> [ %add-named-listener ] keep
+ "#factortest" <irc-channel-chat> [ %add-named-chat ] keep
":ircserver.net MODE #factortest +ns" %push-line
[ mode? ] read-matching-message class
] unit-test
! Participant lists tests
[ { H{ { "ircuser" +normal+ } } } [
- "#factortest" <irc-channel-listener> [ %add-named-listener ] keep
+ "#factortest" <irc-channel-chat> [ %add-named-chat ] keep
":ircuser!n=user@isp.net JOIN :#factortest" %push-line
participants>>
] unit-test
] with-irc
[ { H{ { "ircuser2" +normal+ } } } [
- "#factortest" <irc-channel-listener>
+ "#factortest" <irc-channel-chat>
H{ { "ircuser2" +normal+ }
{ "ircuser" +normal+ } } clone >>participants
- [ %add-named-listener ] keep
+ [ %add-named-chat ] keep
":ircuser!n=user@isp.net PART #factortest" %push-line
participants>>
] unit-test
] with-irc
[ { H{ { "ircuser2" +normal+ } } } [
- "#factortest" <irc-channel-listener>
+ "#factortest" <irc-channel-chat>
H{ { "ircuser2" +normal+ }
{ "ircuser" +normal+ } } clone >>participants
- [ %add-named-listener ] keep
+ [ %add-named-chat ] keep
":ircuser!n=user@isp.net QUIT" %push-line
participants>>
] unit-test
] with-irc
[ { H{ { "ircuser2" +normal+ } } } [
- "#factortest" <irc-channel-listener>
+ "#factortest" <irc-channel-chat>
H{ { "ircuser2" +normal+ }
{ "ircuser" +normal+ } } clone >>participants
- [ %add-named-listener ] keep
+ [ %add-named-chat ] keep
":ircuser2!n=user2@isp.net KICK #factortest ircuser" %push-line
participants>>
] unit-test
] with-irc
[ { H{ { "ircuser2" +normal+ } } } [
- "#factortest" <irc-channel-listener>
+ "#factortest" <irc-channel-chat>
H{ { "ircuser" +normal+ } } clone >>participants
- [ %add-named-listener ] keep
+ [ %add-named-chat ] keep
":ircuser!n=user2@isp.net NICK :ircuser2" %push-line
participants>>
] unit-test
! Namelist change notification
[ { T{ participant-changed f f f f } } [
- "#factortest" <irc-channel-listener> [ %add-named-listener ] keep
+ "#factortest" <irc-channel-chat> [ %add-named-chat ] keep
":ircserver.net 353 factorbot @ #factortest :@factorbot " %push-line
":ircserver.net 366 factorbot #factortest :End of /NAMES list." %push-line
[ participant-changed? ] read-matching-message
] with-irc
[ { T{ participant-changed f "ircuser" +part+ f } } [
- "#factortest" <irc-channel-listener>
+ "#factortest" <irc-channel-chat>
H{ { "ircuser" +normal+ } } clone >>participants
- [ %add-named-listener ] keep
+ [ %add-named-chat ] keep
":ircuser!n=user@isp.net QUIT" %push-line
[ participant-changed? ] read-matching-message
] unit-test
] with-irc
[ { T{ participant-changed f "ircuser" +nick+ "ircuser2" } } [
- "#factortest" <irc-channel-listener>
+ "#factortest" <irc-channel-chat>
H{ { "ircuser" +normal+ } } clone >>participants
- [ %add-named-listener ] keep
+ [ %add-named-chat ] keep
":ircuser!n=user2@isp.net NICK :ircuser2" %push-line
[ participant-changed? ] read-matching-message
] unit-test
C: <irc-profile> irc-profile
TUPLE: irc-client profile stream in-messages out-messages
- listeners is-running nick connect reconnect-time ;
+ chats is-running nick connect reconnect-time is-ready ;
: <irc-client> ( profile -- irc-client )
[ f <mailbox> <mailbox> H{ } clone f ] keep nickname>>
- [ <inet> latin1 <client> ] 15 seconds irc-client boa ;
+ [ <inet> latin1 <client> ] 15 seconds f irc-client boa ;
-TUPLE: irc-listener in-messages client ;
-TUPLE: irc-server-listener < irc-listener ;
-TUPLE: irc-channel-listener < irc-listener name password timeout participants ;
-TUPLE: irc-nick-listener < irc-listener name ;
-SYMBOL: +server-listener+
+TUPLE: irc-chat in-messages client ;
+TUPLE: irc-server-chat < irc-chat ;
+TUPLE: irc-channel-chat < irc-chat name password timeout participants ;
+TUPLE: irc-nick-chat < irc-chat name ;
+SYMBOL: +server-chat+
! participant modes
SYMBOL: +operator+
SYMBOL: +mode+
SYMBOL: +nick+
-! listener objects
-: <irc-listener> ( -- irc-listener ) <mailbox> <mailbox> irc-listener boa ;
+! chat objects
+: <irc-server-chat> ( -- irc-server-chat )
+ <mailbox> f irc-server-chat boa ;
-: <irc-server-listener> ( -- irc-server-listener )
- <mailbox> f irc-server-listener boa ;
-
-: <irc-channel-listener> ( name -- irc-channel-listener )
+: <irc-channel-chat> ( name -- irc-channel-chat )
[ <mailbox> f ] dip f 60 seconds H{ } clone
- irc-channel-listener boa ;
+ irc-channel-chat boa ;
-: <irc-nick-listener> ( name -- irc-nick-listener )
- [ <mailbox> f ] dip irc-nick-listener boa ;
+: <irc-nick-chat> ( name -- irc-nick-chat )
+ [ <mailbox> f ] dip irc-nick-chat boa ;
! ======================================
! Message objects
TUPLE: participant-changed nick action parameter ;
C: <participant-changed> participant-changed
-SINGLETON: irc-listener-end ! send to a listener to stop its execution
+SINGLETON: irc-chat-end ! sent to a chat to stop its execution
SINGLETON: irc-end ! sent when the client isn't running anymore
SINGLETON: irc-disconnected ! sent when connection is lost
SINGLETON: irc-connected ! sent when connection is established
-SINGLETON: irc-ready ! sent after the client is logged in
: terminate-irc ( irc-client -- )
[ is-running>> ] keep and [
f >>is-running
+ [ stream>> dispose ] keep
[ in-messages>> ] [ out-messages>> ] bi 2array
[ irc-end swap mailbox-put ] each
] when* ;
! ======================================
: irc> ( -- irc-client ) current-irc-client get ;
-: irc-stream> ( -- stream ) irc> stream>> ;
-: irc-write ( s -- ) irc-stream> stream-write ;
-: irc-print ( s -- ) irc-stream> [ stream-print ] keep stream-flush ;
+: irc-write ( s -- ) irc> stream>> stream-write ;
+: irc-print ( s -- ) irc> stream>> [ stream-print ] keep stream-flush ;
: irc-send ( irc-message -- ) irc> out-messages>> mailbox-put ;
-: listener> ( name -- listener/f ) irc> listeners>> at ;
+: chat> ( name -- chat/f ) irc> chats>> at ;
: channel-mode? ( mode -- ? ) name>> first "#&" member? ;
: me? ( string -- ? ) irc> nick>> = ;
-GENERIC: to-listener ( message obj -- )
+GENERIC: to-chat ( message obj -- )
-M: string to-listener
- listener> [ +server-listener+ listener> ] unless*
- [ to-listener ] [ drop ] if* ;
+M: string to-chat
+ chat> [ +server-chat+ chat> ] unless*
+ [ to-chat ] [ drop ] if* ;
-M: irc-listener to-listener in-messages>> mailbox-put ;
+M: irc-chat to-chat in-messages>> mailbox-put ;
-: unregister-listener ( name -- )
- irc> listeners>>
- [ at [ irc-listener-end ] dip to-listener ]
+: unregister-chat ( name -- )
+ irc> chats>>
+ [ at [ irc-chat-end ] dip to-chat ]
[ delete-at ]
2bi ;
-: (remove-participant) ( nick listener -- )
+: (remove-participant) ( nick chat -- )
[ participants>> delete-at ]
- [ [ +part+ f <participant-changed> ] dip to-listener ] 2bi ;
+ [ [ +part+ f <participant-changed> ] dip to-chat ] 2bi ;
: remove-participant ( nick channel -- )
- listener> [ (remove-participant) ] [ drop ] if* ;
+ chat> [ (remove-participant) ] [ drop ] if* ;
-: listeners-with-participant ( nick -- seq )
- irc> listeners>> values
- [ [ irc-channel-listener? ] keep and [ participants>> key? ] [ drop f ] if* ]
+: chats-with-participant ( nick -- seq )
+ irc> chats>> values
+ [ [ irc-channel-chat? ] keep and [ participants>> key? ] [ drop f ] if* ]
with filter ;
-: to-listeners-with-participant ( message nickname -- )
- listeners-with-participant [ to-listener ] with each ;
+: to-chats-with-participant ( message nickname -- )
+ chats-with-participant [ to-chat ] with each ;
: remove-participant-from-all ( nick -- )
- dup listeners-with-participant [ (remove-participant) ] with each ;
+ dup chats-with-participant [ (remove-participant) ] with each ;
-: notify-rename ( newnick oldnick listener -- )
+: notify-rename ( newnick oldnick chat -- )
[ participant-changed new +nick+ >>action
- [ (>>nick) ] [ (>>parameter) ] [ ] tri ] dip to-listener ;
+ [ (>>nick) ] [ (>>parameter) ] [ ] tri ] dip to-chat ;
-: rename-participant ( newnick oldnick listener -- )
- [ participants>> [ delete-at* drop ] [ [ swap ] dip set-at ] bi ]
+: rename-participant ( newnick oldnick chat -- )
+ [ participants>> [ delete-at* drop ] [ swapd set-at ] bi ]
[ notify-rename ] 3bi ;
: rename-participant-in-all ( oldnick newnick -- )
- swap dup listeners-with-participant [ rename-participant ] with with each ;
+ swap dup chats-with-participant [ rename-participant ] with with each ;
: add-participant ( mode nick channel -- )
- listener>
+ chat>
[ participants>> set-at ]
- [ [ +join+ f <participant-changed> ] dip to-listener ] 2bi ;
+ [ [ +join+ f <participant-changed> ] dip to-chat ] 2bi ;
: change-participant-mode ( channel mode nick -- )
- rot listener>
+ rot chat>
[ participants>> set-at ]
- [ [ [ +mode+ ] dip <participant-changed> ] dip to-listener ] 3bi ; ! FIXME
+ [ [ [ +mode+ ] dip <participant-changed> ] dip to-chat ] 3bi ; ! FIXME
DEFER: me?
! Server message handling
! ======================================
+GENERIC: initialize-chat ( chat -- )
+M: irc-chat initialize-chat drop ;
+M: irc-channel-chat initialize-chat [ name>> ] [ password>> ] bi /JOIN ;
+
GENERIC: forward-name ( irc-message -- name )
M: join forward-name trailing>> ;
M: part forward-name channel>> ;
GENERIC: forward-message ( irc-message -- )
M: irc-message forward-message
- +server-listener+ listener> [ to-listener ] [ drop ] if* ;
+ +server-chat+ chat> [ to-chat ] [ drop ] if* ;
-M: single-forward forward-message dup forward-name to-listener ;
+M: single-forward forward-message dup forward-name to-chat ;
M: multiple-forward forward-message
- dup irc-message-sender to-listeners-with-participant ;
+ dup irc-message-sender to-chats-with-participant ;
M: broadcast-forward forward-message
- irc> listeners>> values [ to-listener ] with each ;
+ irc> chats>> values [ to-chat ] with each ;
GENERIC: process-message ( irc-message -- )
M: object process-message drop ;
-M: logged-in process-message name>> irc> (>>nick) ;
+M: logged-in process-message
+ name>> f irc> [ (>>is-ready) ] [ (>>nick) ] [ chats>> ] tri
+ values [ initialize-chat ] each ;
M: ping process-message trailing>> /PONG ;
M: nick-in-use process-message name>> "_" append /NICK ;
M: join process-message
[ drop +normal+ ] [ irc-message-sender ] [ trailing>> ] tri
- dup listener> [ add-participant ] [ 3drop ] if ;
+ dup chat> [ add-participant ] [ 3drop ] if ;
M: part process-message
[ irc-message-sender ] [ channel>> ] bi remove-participant ;
M: kick process-message
[ [ who>> ] [ channel>> ] bi remove-participant ]
- [ dup who>> me? [ unregister-listener ] [ drop ] if ]
+ [ dup who>> me? [ unregister-chat ] [ drop ] if ]
bi ;
M: quit process-message
[ >nick/mode 2array ] map >hashtable ;
M: names-reply process-message
- [ names-reply>participants ] [ channel>> listener> ] bi [
+ [ names-reply>participants ] [ channel>> chat> ] bi [
[ (>>participants) ]
- [ [ f f f <participant-changed> ] dip name>> to-listener ] bi
+ [ [ f f f <participant-changed> ] dip name>> to-chat ] bi
] [ drop ] if* ;
! ======================================
tri ;
! FIXME: do something with the exception, store somewhere to help debugging
-: handle-disconnect ( error -- )
- drop irc> is-running>> [ (handle-disconnect) ] when ;
+: handle-disconnect ( error -- ? )
+ drop irc> is-running>> [ (handle-disconnect) t ] [ f ] if ;
: (reader-loop) ( -- ? )
irc> stream>> [
] with-destructors ;
: reader-loop ( -- ? )
- [ (reader-loop) ] [ handle-disconnect t ] recover ;
+ [ (reader-loop) ] [ handle-disconnect ] recover ;
: writer-loop ( -- ? )
irc> out-messages>> mailbox-get handle-outgoing-irc ;
[ nip ]
} cond ;
-GENERIC: annotate-message ( listener object -- object )
+GENERIC: annotate-message ( chat object -- object )
M: object annotate-message nip ;
M: part annotate-message swap name>> >>channel ;
M: privmsg annotate-message swap name>> >>name ;
[ in-multiplexer-loop ] "in-multiplexer-loop" spawn-server
3drop ;
-GENERIC: (add-listener) ( irc-listener -- )
-
-M: irc-listener (add-listener)
- [ irc> >>client ] [ name>> ] bi irc> listeners>> set-at ;
+GENERIC: (attach-chat) ( irc-chat -- )
+USE: prettyprint
+M: irc-chat (attach-chat)
+ [ [ irc> >>client ] [ name>> ] bi irc> chats>> set-at ]
+ [ [ irc> is-ready>> ] dip and [ initialize-chat ] when* ]
+ bi ;
-M: irc-server-listener (add-listener)
- irc> >>client +server-listener+ irc> listeners>> set-at ;
+M: irc-server-chat (attach-chat)
+ irc> >>client +server-chat+ irc> chats>> set-at ;
-GENERIC: (remove-listener) ( irc-listener -- )
+GENERIC: (remove-chat) ( irc-chat -- )
-M: irc-nick-listener (remove-listener)
- name>> unregister-listener ;
+M: irc-nick-chat (remove-chat)
+ name>> unregister-chat ;
-M: irc-channel-listener (remove-listener)
+M: irc-channel-chat (remove-chat)
[ part new annotate-message irc> out-messages>> mailbox-put ] keep
- name>> unregister-listener ;
+ name>> unregister-chat ;
-M: irc-server-listener (remove-listener)
- drop +server-listener+ unregister-listener ;
+M: irc-server-chat (remove-chat)
+ drop +server-chat+ unregister-chat ;
: (connect-irc) ( irc-client -- )
{
: connect-irc ( irc-client -- )
dup [ [ (connect-irc) ] [ nick>> /LOGIN ] bi spawn-irc ] with-irc-client ;
-: add-listener ( irc-listener irc-client -- )
- swap '[ _ (add-listener) ] with-irc-client ;
-
-: remove-listener ( irc-listener -- )
- [ client>> ] keep '[ _ (remove-listener) ] with-irc-client ;
+: attach-chat ( irc-chat irc-client -- ) [ (attach-chat) ] with-irc-client ;
-: join-irc-channel ( irc-channel-listener -- )
- dup client>> [ [ name>> ] [ password>> ] bi /JOIN ] with-irc-client ;
+: dettach-chat ( irc-chat -- )
+ [ client>> ] keep '[ _ (remove-chat) ] with-irc-client ;
-: write-message ( message irc-listener -- )
+: speak ( message irc-chat -- )
[ swap annotate-message ] [ client>> out-messages>> mailbox-put ] bi ;
-: read-message ( irc-listener -- message ) in-messages>> mailbox-get ;
+: hear ( irc-chat -- message ) in-messages>> mailbox-get ;