Browse files

handle errors a little more robustly. Sending a notice to a dead conn…

…ection now logs the error, puts the notice back in the queue and sleeps for 60 seconds. A disconnect from the server hopefully is observed and a reconnect attempted within 10 seconds.
  • Loading branch information...
1 parent cda209d commit 76ae24e96d3cec4ecabdcc5d2ffffc581f8a0fcb @erikg committed Apr 4, 2013
Showing with 15 additions and 4 deletions.
  1. +15 −4 irc.lisp
19 irc.lisp
@@ -81,10 +81,13 @@
(bordeaux-threads:with-lock-held (*notice-lock*)
(when (notices *state*)
(let ((n (pop (notices *state*))))
-; (handler-case
+ (handler-case
(cl-irc:privmsg (find-connection-by-name (car n)) (cadr n) (caddr n))
-; (t '()))
+ (push n (notices *state*))
+ (format t "notice-wrangler error: ~s~%" e)
+ (sleep 60))))))))
(defun start-notice-wrangler ()
(bordeaux-threads:with-lock-held (*notice-lock*)
@@ -160,7 +163,7 @@
(respond msg (get-excuse))))
-(defun bot (&key (nick +bot-nick+) (ident +bot-ident+) (server +bot-server+) (channels +bot-channels+) (realname +bot-realname+) (nickserv-passwd +bot-nickserv-passwd+))
+(defun bot-make-connection (nick ident server channels realname nickserv-passwd)
(setf *connection* (cl-irc:connect :username ident :realname realname :server server :nickname nick))
(cl-irc:add-hook (find-connection-by-name "freenode") 'irc::irc-privmsg-message 'msg-hook)
(cl-irc:add-hook (find-connection-by-name "freenode") 'irc::irc-notice-message 'notice-hook)
@@ -171,6 +174,14 @@
(cl-irc:join (find-connection-by-name "freenode") c))
(setf *bot-thread* (bordeaux-threads:make-thread (lambda () (cl-irc:read-message-loop (find-connection-by-name "freenode"))) :name "cl-cia ircbot")))
+(defun bot (&key (nick +bot-nick+) (ident +bot-ident+) (server +bot-server+) (channels +bot-channels+) (realname +bot-realname+) (nickserv-passwd +bot-nickserv-passwd+))
+ (bordeaux-threads:make-thread (lambda ()
+ (loop
+ (unless (and *bot-thread* (sb-thread:thread-alive-p *bot-thread*))
+ (bot-make-connection nick ident server channels realname nickserv-passwd))
+ (sleep 10)))
+ :name "cl-cia ircbot-connect-overmind"))
(defun stop-bot ()
(cl-irc:quit (find-connection-by-name "freenode") "EVACUATE! EVACUATE!")
; (bordeaux-threads:join-thread *bot-thread*)

0 comments on commit 76ae24e

Please sign in to comment.