-
Notifications
You must be signed in to change notification settings - Fork 7
/
irc-bot.rkt
51 lines (39 loc) · 1.38 KB
/
irc-bot.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#lang racket/base
(require irc racket/async-channel)
(provide pasterack-irc-connect irc-paste)
;; pasterack irc bot
(define MIRROR? #f)
(define FREENODE "chat.freenode.net")
(define PORT 6667)
(define NAME (if MIRROR? "pasteracktest" "pasterack"))
(define irc-channels (if MIRROR? '("#racktest") '("#racket")))
(define current-irc-connection #f)
(define current-irc-listener (thread void))
(define current-irc-monitor (thread void))
(define (irc-connect/internal)
(define-values (irc-connection ready)
(irc-connect FREENODE PORT NAME NAME NAME #:return-eof #t))
(define achan (irc-connection-incoming irc-connection))
(set! current-irc-connection irc-connection)
(set! current-irc-listener
(thread
(lambda ()
(let loop ()
(unless (eof-object? (async-channel-get achan))
(loop))))))
ready)
;; creates an irc monitor thread
(define (pasterack-irc-connect)
(set! current-irc-monitor
(thread
(lambda ()
(let loop ()
(when (thread-dead? current-irc-listener)
(sync (irc-connect/internal))
(join-channels))
(sleep 60)
(loop))))))
(define (join-channels)
(for ([c irc-channels]) (irc-join-channel current-irc-connection c)))
(define (irc-paste msg)
(for ([c irc-channels]) (irc-send-message current-irc-connection c msg)))