]> gitweb.factorcode.org Git - factor.git/blob - extra/irc/client/chats/chats.factor
irc.client: Big refactor
[factor.git] / extra / irc / client / chats / chats.factor
1 ! Copyright (C) 2009 Bruno Deferrari
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors concurrency.mailboxes kernel calendar io.sockets io.encodings.8-bit
4 destructors arrays sequences ;
5 IN: irc.client.chats
6
7 CONSTANT: irc-port 6667 ! Default irc port
8
9 TUPLE: irc-chat in-messages client ;
10 TUPLE: irc-server-chat  < irc-chat ;
11 TUPLE: irc-channel-chat < irc-chat name password participants clear-participants ;
12 TUPLE: irc-nick-chat    < irc-chat name ;
13 SYMBOL: +server-chat+
14
15 : <irc-server-chat> ( -- irc-server-chat )
16      irc-server-chat new
17          <mailbox> >>in-messages ;
18
19 : <irc-channel-chat> ( name -- irc-channel-chat )
20      irc-channel-chat new
21          swap       >>name
22          <mailbox>  >>in-messages
23          f          >>password
24          H{ } clone >>participants
25          t          >>clear-participants ;
26
27 : <irc-nick-chat> ( name -- irc-nick-chat )
28      irc-nick-chat new
29          swap      >>name
30          <mailbox> >>in-messages ;
31
32 TUPLE: irc-profile server port nickname password ;
33 C: <irc-profile> irc-profile
34
35 TUPLE: irc-client profile stream in-messages out-messages
36        chats is-running nick connect reconnect-time is-ready
37        exceptions ;
38
39 : <irc-client> ( profile -- irc-client )
40     dup nickname>> irc-client new
41         swap       >>nick
42         swap       >>profile
43         <mailbox>  >>in-messages
44         <mailbox>  >>out-messages
45         H{ } clone >>chats
46         15 seconds >>reconnect-time
47         V{ } clone >>exceptions
48         [ <inet> latin1 <client> ] >>connect ;
49
50 SINGLETONS: irc-chat-end irc-end irc-disconnected irc-connected ;