(define bot-channel #f)
(define bot-proc-file #f)
(define usetls #t)
+(define allow-reload #f)
(define bot-proc #f)
+(define verbosity-level 0)
+
(define ping-period 60) ;seconds
(tcp-read-timeout #f) ;disable read timeout
(define (launch-bot)
;; (let-values (((in-port out-port) (tcp-connect host port)))
- (set! bot-proc (eval (with-input-from-file bot-proc-file read)))
+ (load-bot)
(let-values (((in-port out-port)
(if usetls
(ssl-connect* hostname: irc-host port: (or irc-port 6697))
(write-msg `(#f #f "PING" (,irc-host)) out-port) ; send ping
(loop)))))
+(define (load-bot)
+ (set! bot-proc (eval (with-input-from-file bot-proc-file read)))
+ (print "Loaded bot procedure file."))
+
(define (bot-loop in-port out-port)
(let ((privmsg (lambda (to . args)
- (write-msg (list #f #f "PRIVMSG" (cons to args)) out-port))))
+ (let ((msg (list #f #f "PRIVMSG" (cons to args))))
+ (write-msg msg out-port)
+ (when (>= verbosity-level 1)
+ (display "Responded with msg: ")
+ (write msg)
+ (newline))))))
(let loop ((msg (read-msg in-port)))
(match (cons (msg-source msg) (cons (msg-command msg) (msg-args msg)))
((_ "PING" token)
(write-msg `(#f #f "PONG" (,token)) out-port))
+ ((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.")))
((source "PRIVMSG" target args ...)
(when (string=? target bot-nick)
+ (when (>= verbosity-level 1)
+ (display "Received msg: ")
+ (write msg)
+ (newline))
(bot-proc source args privmsg)))
(_
;; Do nothing
(define (read-msg in-port)
(let ((msg (string->msg (read-line in-port))))
- (display "Received message: ")
- (write msg)
- (newline)
+ (when (>= verbosity-level 2)
+ (display "Received message: ")
+ (write msg)
+ (newline))
msg))
(define (write-msg msg out-port)
(with-output-to-port out-port
(lambda () (write-string (conc (msg->string msg) "\r\n"))))
- (print "Sent message: " msg))
+ (when (>= verbosity-level 2)
+ (print "Sent message: " msg)))
(define msg-regex
(irregex '(:
(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 " proc-file host nick")))
(define (main)
(equal? this-arg "--channel"))
(set! bot-channel (car rest-args))
(loop (cdr rest-args)))
+ ((or (equal? this-arg "-v")
+ (equal? this-arg "--verbose"))
+ (set! verbosity-level (+ 1 verbosity-level))
+ (loop rest-args))
+ ((or (equal? this-arg "-a")
+ (equal? this-arg "--allow-reload"))
+ (set! allow-reload #t)
+ (loop rest-args))
(else
(print "Unknown argument '" this-arg "'")
(print-usage progname)))