Skip to content

Instantly share code, notes, and snippets.

@funrep
Last active December 24, 2015 09:49
Show Gist options
  • Save funrep/6780313 to your computer and use it in GitHub Desktop.
Save funrep/6780313 to your computer and use it in GitHub Desktop.
#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"))))
@funrep
Copy link
Author

funrep commented Oct 1, 2013

)irc.codetalk.io NOTICE AUTH *** Looking up your hostname.....
)irc.codetalk.io NOTICE AUTH *** Couldn't resolve your hostname; using your IP address insteadad
)#f ERROR #f Closing Link: [88.129.148.60] (Ping timeout: 30 seconds)
; connection failed [,bt for context]

@funrep
Copy link
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