Paste: logger bot

Author: tizoc
Mode: factor
Date: Tue, 14 Apr 2009 01:00:06
Plain Text |
USING: accessors fry io io.encodings.8-bit io.files irc.client
irc.client.chats irc.messages.base kernel threads ;
IN: irc.logbot

: bot-profile ( -- obj )
    "irc.freenode.org" 6667 "flogger" f <irc-profile> ;

: bot-channel ( -- seq ) "#concatenative" ;
: log-stream ( -- stream ) "/tmp/concatenative.log" latin1 <file-writer> ;

GENERIC: handle-message ( msg -- )

M: object      handle-message drop ;
M: irc-message handle-message line>> print flush ;

: (bot-loop) ( chat -- ) dup hear handle-message (bot-loop) ;
: bot-loop ( chat -- ) log-stream [ (bot-loop) ] with-output-stream ;

: start-bot ( -- )
    bot-profile <irc-client>
    [ connect-irc ]
    [
        [ bot-channel <irc-channel-chat> ] dip
        '[ _ [ _ attach-chat ] [ bot-loop ] bi ]
        "LogBot" spawn drop
    ] bi ;

: logbot ( -- ) start-bot ;

MAIN: logbot

New Annotation

Summary:
Author:
Mode:
Body: