diff --git a/botcore.rkt b/botcore.rkt index 807b13a..a108696 100755 --- a/botcore.rkt +++ b/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) diff --git a/callbacks.rkt b/callbacks.rkt new file mode 100644 index 0000000..3b6dd87 --- /dev/null +++ b/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)) \ No newline at end of file diff --git a/irclib.rkt b/irclib.rkt index d999e72..1711381 100644 --- a/irclib.rkt +++ b/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)