(chicken string)
(chicken pathname)
(chicken process-context)
+ (chicken condition)
(chicken irregex)
matchable srfi-13 srfi-1 srfi-18
tcp6 openssl)
(define (launch-bot)
;; (let-values (((in-port out-port) (tcp-connect host port)))
- (load-bot)
(let-values (((in-port out-port)
(if usetls
(ssl-connect* hostname: irc-host port: (or irc-port 6697))
(loop)))))
(define (load-bot)
- (set! bot-proc (eval (with-input-from-file bot-proc-file read)))
- (print "Loaded bot procedure file."))
+ (let ((new-bot-proc
+ (condition-case
+ (eval (with-input-from-file bot-proc-file read))
+ (o (exn)
+ (print-error-message o)
+ #f))))
+ (if new-bot-proc
+ (begin
+ (set! bot-proc new-bot-proc)
+ (print "Loaded bot procedure file."))
+ (print "Error loading procedure file."))
+ new-bot-proc))
(define (bot-loop in-port out-port)
(let ((privmsg (lambda (to . args)
((source "PRIVMSG" target "bbreload")
(when (and allow-reload (string=? target bot-nick))
(print "Reveived reload command from " source)
- (load-bot)
- (privmsg source "Reloaded bot script.")))
+ (if (load-bot)
+ (privmsg source "Reloaded bot script.")
+ (privmsg source "Error loading bot script."))))
((source "PRIVMSG" target args ...)
(when (string=? target bot-nick)
(when (>= verbosity-level 1)
(display "Received msg: ")
(write msg)
(newline))
- (bot-proc source args privmsg)))
+ (condition-case
+ (bot-proc source args privmsg)
+ (o (exn)
+ (print "Error executing bot script.")
+ (print-error-message o)))))
(_
;; Do nothing
))
(print "Usage:\n"
progname " [-h/--help]\n"
progname " [-p/--port PORT] [--notls] [-c/--channnel CHANNEL]\n"
- indent-str " [-v/--verbose] [-a/--allow-reload]"
+ indent-str " [-v/--verbose] [-a/--allow-reload]\n"
indent-str " proc-file host nick")))
(define (main)
(set! bot-proc-file procfile)
(set! irc-host host)
(set! bot-nick nick)
- (launch-bot))
+ (if (load-bot)
+ (launch-bot)
+ (error "Could not load bot procedure.")))
(else
(print "One or more invalid arguments.")
(print-usage progname)))))))))