Last active
December 24, 2015 09:49
-
-
Save funrep/6780313 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#lang racket | |
(define config | |
(hash "server" "irc.codetalk.io" | |
"port" 6667 | |
"chan" "#lobby" | |
"nick" "tob" | |
"name" "tob the bot")) | |
(define (connect) | |
(let-values ([(in out) (tcp-connect (hash-ref config "server") | |
(hash-ref config "port"))]) | |
(login out) | |
(listen in out))) | |
(define (listen in out) | |
(let ([msg (get-msg in)]) | |
(when (equal? "PING" (caddr msg)) (write-msg out "PONG" (string-append ":" (cadddr msg)))) | |
(when (equal? "266" (caddr msg)) (write-msg out "JOIN" (hash-ref config "chan"))) | |
(listen in out))) | |
(define (get-msg in) | |
(let ([s (read-line in)]) | |
(if (eof-object? s) | |
(error "connection failed") | |
(regexp-match #px"^(?:[:](\\S+) )?(\\S+)(?: (?!:)(.+?))?(?: [:](.+))?$" s)))) | |
(define (write-msg out cmd s) | |
(write (string-append cmd " " s "\r\n") out)) | |
(define (login out) | |
(write-msg out "NICK" (hash-ref config "nick")) | |
(write-msg out "USER" (string-append (hash-ref config "nick") " 0 * :" (hash-ref config "name")))) |
Author
funrep
commented
Oct 1, 2013
> NICK tob
> USER tob 0 * :tob the bot
)irc.codetalk.io NOTICE AUTH *** Looking up your hostname.....
)irc.codetalk.io NOTICE AUTH *** Couldn't resolve your hostname; using your IP address insteadad
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment