] unit-test
] with-irc
+[ { H{ { "factorbot" +operator+ } { "ircuser" +normal+ } } } [
+ "#factortest" <irc-channel-chat>
+ H{ { "ircuser" +normal+ } } clone >>participants
+ [ %add-named-chat ] keep
+ ":ircserver.net 353 factorbot @ #factortest :@factorbot " %push-line
+ ":ircserver.net 353 factorbot @ #factortest :ircuser2 " %push-line
+ ":ircserver.net 366 factorbot #factortest :End of /NAMES list." %push-line
+ ":ircserver.net 353 factorbot @ #factortest :@factorbot " %push-line
+ ":ircserver.net 353 factorbot @ #factortest :ircuser " %push-line
+ ":ircserver.net 366 factorbot #factortest :End of /NAMES list." %push-line
+ participants>>
+ ] unit-test
+] with-irc
+
! Namelist change notification
[ { T{ participant-changed f f f f } } [
"#factortest" <irc-channel-chat> [ %add-named-chat ] keep
TUPLE: irc-chat in-messages client ;
TUPLE: irc-server-chat < irc-chat ;
-TUPLE: irc-channel-chat < irc-chat name password timeout participants ;
+TUPLE: irc-channel-chat < irc-chat name password timeout participants clean-participants ;
TUPLE: irc-nick-chat < irc-chat name ;
SYMBOL: +server-chat+
<mailbox> f irc-server-chat boa ;
: <irc-channel-chat> ( name -- irc-channel-chat )
- [ <mailbox> f ] dip f 60 seconds H{ } clone
+ [ <mailbox> f ] dip f 60 seconds H{ } clone t
irc-channel-chat boa ;
: <irc-nick-chat> ( name -- irc-nick-chat )
trailing>> [ blank? ] trim " " split
[ >nick/mode 2array ] map >hashtable ;
+: maybe-clean-participants ( channel-chat -- )
+ dup clean-participants>> [
+ H{ } clone >>participants f >>clean-participants
+ ] when drop ;
+
M: names-reply process-message
[ names-reply>participants ] [ channel>> chat> ] bi [
- [ (>>participants) ]
- [ [ f f f <participant-changed> ] dip name>> to-chat ] bi
+ [ maybe-clean-participants ]
+ [ participants>> 2array assoc-combine ]
+ [ (>>participants) ] tri
] [ drop ] if* ;
+M: end-of-names process-message
+ channel>> chat> [
+ t >>clean-participants
+ [ f f f <participant-changed> ] dip name>> to-chat
+ ] when* ;
+
! ======================================
! Client message handling
! ======================================
TUPLE: notice < irc-message type ;
TUPLE: mode < irc-message name mode parameter ;
TUPLE: names-reply < irc-message who channel ;
+TUPLE: end-of-names < irc-message who channel ;
TUPLE: unhandled < irc-message ;
: <irc-client-message> ( command parameters trailing -- irc-message )
M: names-reply >>command-parameters ( names-reply params -- names-reply )
first3 nip [ >>who ] [ >>channel ] bi* ;
+M: end-of-names >>command-parameters ( names-reply params -- names-reply )
+ first2 [ >>who ] [ >>channel ] bi* ;
+
M: mode >>command-parameters ( mode params -- mode )
dup length 3 = [
first3 [ >>name ] [ >>mode ] [ >>parameter ] tri*
{ "001" [ logged-in ] }
{ "433" [ nick-in-use ] }
{ "353" [ names-reply ] }
+ { "366" [ end-of-names ] }
{ "JOIN" [ join ] }
{ "PART" [ part ] }
{ "NICK" [ nick ] }