Paste: first attempt at IRC message parsing

Author: Ycros
Mode: factor
Date: Wed, 12 Aug 2009 23:28:29
Plain Text |
USING: kernel io io.sockets io.encodings.ascii threads fry namespaces sequences splitting lists ;
IN: fircey

TUPLE: irc-message source command args longarg ;

: <irc-message> ( source command args longarg -- irc-message )
    irc-message boa ;

: split-up-irc-string ( string -- args longarg )
    ":" split1 [ nil ] unless*
    swap " " split "" swap remove
    swap ;

: parse-irc-message ( string -- irc-message )
    ":" ?head
    [
        split-up-irc-string
        swap
        unclip swap swapd
        unclip swap swapd
        swap
        <irc-message>
    ]
    [
        split-up-irc-string
        swap
        nil swap swapd
        unclip swap swapd
        swap
        <irc-message>
    ]
    if ;

: login ( -- )
    "NICK fircey" print
    "USER fircey fircey fircey fircey" print
    flush ;

: bot-handler ( stdout -- )
    [ dupd swap stream-print flush ] each-line drop ;

: bot-connection ( -- )
    "irc.freenode.net" 6667 <inet>
    ascii
    output-stream get '[ login _ bot-handler ]
    with-client ;

New Annotation

Summary:
Author:
Mode:
Body: