Skip to content

Instantly share code, notes, and snippets.

@funrep
Created September 20, 2013 12:35
Show Gist options
  • Save funrep/6636805 to your computer and use it in GitHub Desktop.
Save funrep/6636805 to your computer and use it in GitHub Desktop.
#lang racket
(define connect (lambda () (
(let-values ([(in out) (tcp-connect "irc.codetalk.io" 6667)])
(begin
(displayln "NICK tob" out)
(displayln "USER tob 8 * : tob the bot" out)
(listen in out))))))
(define (listen in out) (begin
(define ss (get-line in))
(if (ping? ss)
(begin (pong ss out) (displayln "ponging"))
'())
(displayln ss)
(listen in out)))
(define (get-line in)
(let ([s (read-line in)])
(if (eof-object? s)
(error "connection failed")
(string-split s))))
(define (ping? ss) (eq? (car ss) "PING"))
(define (pong ss out)
(displayln (string-append "PONG " (car (cdr ss))) out))
@funrep
Copy link
Author

funrep commented Sep 20, 2013

> (enter! "tob.rkt")
  [re-loading /home/klrr/Sandbox/lisp/tob.rkt]
"tob.rkt"> (connect)
(:irc.codetalk.io NOTICE AUTH :*** Looking up your hostname...)
(:irc.codetalk.io NOTICE AUTH :*** Couldn't resolve your hostname; using your IP address instead)
(ERROR :Closing Link: [88.129.150.242] (Ping timeout: 36 seconds))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment