Browse Source

refactored callbacks into separate module

master
wes 12 years ago
parent
commit
862ffb683b
  1. 37
      botcore.rkt
  2. 39
      callbacks.rkt
  3. 3
      irclib.rkt

37
botcore.rkt

@ -4,46 +4,13 @@
(require "commands.rkt")
(require "database.rkt")
(require "config.rkt")
(require "callbacks.rkt")
;Here is how the connection flow has to go
;First send the NICK and USER commands to the server
;Wait a few seconds for a PING, if no PING increase
;the wait time by the last time * 1.5 to a maximum of n seconds
;; CALLBACK FUNCTIONS
(define (privmsg-handler send userinfo content join part)
(match (parse-at content)
['nil 'nil]
; joining a channel
[(list-rest "join" args)
(match (admin-info (first userinfo)) ; check to see if we have privileges, 0 = highest privs
[0 (join (car (first args)))]
[_ 'nil])]
[(list-rest "quit" (list message))
(match (admin-info (first userinfo))
[0 (match message
[(list-rest quit-msg _)
(quit quit-msg)]
[_ 'nil])]
[_ 'nil])]
[result
(let ([result (dispatch userinfo content)])
(display result)
(match result
['nil 'nil]
[(? hash?) (send "OK")]
[_ (send (format "~a" result))]))]))
;; Callback for join messages
(define (join-handler privmsg userinfo)
userinfo)
;; Callback for quit messages
(define (quit-handler userinfo)
userinfo)
;; Timeout combinator, tries to get output and times out if there is none
(define ((timeout-check max-wait) input?)
(letrec ([matcher
@ -123,5 +90,5 @@
(file-stream-buffer-mode output 'line)
(values input output)))
(call-with-values (λ () (connect "irc.freenode.org" 6667))
(call-with-values (λ () (connect "localhost" 6667))
ircloop)

39
callbacks.rkt

@ -0,0 +1,39 @@
#lang racket
(require "commands.rkt")
(require "config.rkt")
;; CALLBACK FUNCTIONS
(define (privmsg-handler send userinfo content join part quit)
(match (parse-at content)
['nil 'nil]
; joining a channel
[(list-rest "join" args)
(match (admin-info (first userinfo)) ; check to see if we have privileges, 0 = highest privs
[0 (join (car (first args)))]
[_ 'nil])]
[(list-rest "quit" (list message))
(match (admin-info (first userinfo))
[0 (match message
[(list-rest quit-msg _)
(quit quit-msg)]
[_ 'nil])]
[_ 'nil])]
[result
(let ([result (dispatch userinfo content)])
(display result)
(match result
['nil 'nil]
[(? hash?) (send "OK")]
[_ (send (format "~a" result))]))]))
;; Callback for join messages
(define (join-handler privmsg userinfo)
userinfo)
;; Callback for quit messages
(define (quit-handler userinfo)
userinfo)
(provide (all-defined-out))

3
irclib.rkt

@ -105,7 +105,8 @@
userinfo
content
join
((curry part) (first userinfo)))]
((curry part) (first userinfo))
quit)]
; JOIN handler (called when a user joins the channel)
[(list "JOIN" userinfo channel) (join-response
((curry privmsg)

Loading…
Cancel
Save