Created
April 23, 2009 06:03
-
-
Save higepon/100350 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import (rnrs) | |
(mosh) | |
(mosh socket)) | |
(define (irc-bot server port nick channel) | |
(let ([socket (make-client-socket server port)]) | |
(define (send text) | |
(assert (<= (string-length text) 510)) | |
(socket-send socket (string->utf8 (string-append text "\r\n")))) | |
(define (recv) | |
(utf8->string (socket-recv socket 512))) | |
(define (say text) | |
(send (format "PRIVMSG ~a :~a" channel text))) | |
(send (format "NICK ~a" nick)) | |
(send (format "USER ~a 0 * :~a" nick nick)) | |
(send (format "JOIN ~a" channel)) | |
(let loop ([data (recv)]) | |
(cond | |
[(#/:([^!]+).*PRIVMSG[^:]+:(.*)/ data) => | |
(lambda (m) | |
(format #t "<~a> ~a\n" (m 1) (m 2)) | |
(say (format "~s ってなあに?" (m 2))))] | |
[(#/^PING/ data) | |
(send "PONG 0")] | |
[(#/:.*433.*Nickname is already in use.*/ data) | |
(error 'irc "Nickname is already in use")]) | |
; (display data) | |
(loop (recv))) | |
(socket-close socket))) | |
(irc-bot "irc.freenode.net" "6666" "kaela" "#higepon") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment