summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <cbeok@protonmail.com>2020-04-13 05:54:53 -0500
committerColin Okay <cbeok@protonmail.com>2020-04-13 05:54:53 -0500
commit01d7494630925aacb81afdbff764a68c429ee5cb (patch)
treed224849b1b08b652afafab233e7885e3e9e4de70
parent76436d85124b0d433794af8f65ade436641cf534 (diff)
minimal error handling to bot
-rw-r--r--posterbot.lisp21
1 files changed, 12 insertions, 9 deletions
diff --git a/posterbot.lisp b/posterbot.lisp
index f274225..7e66561 100644
--- a/posterbot.lisp
+++ b/posterbot.lisp
@@ -19,11 +19,13 @@
(defun download-link (link)
"Downloads the file at LINK to a temporary file. Returns the path to
the downloaded file."
- (cl-fad:with-output-to-temporary-file (out :element-type '(unsigned-byte 8))
- (let ((buffer (make-array 4096 :element-type '(unsigned-byte 8)))
- (file-stream (drakma:http-request link :want-stream t)))
- (loop :for bytes = (read-sequence buffer file-stream)
- :while (plusp bytes) :do (write-sequence buffer out)))))
+ (handler-case
+ (cl-fad:with-output-to-temporary-file (out :element-type '(unsigned-byte 8))
+ (let ((buffer (make-array 4096 :element-type '(unsigned-byte 8)))
+ (file-stream (drakma:http-request link :want-stream t)))
+ (loop :for bytes = (read-sequence buffer file-stream)
+ :while (plusp bytes) :do (write-sequence buffer out))))
+ (error () nil)))
(defun filename-from-link (link)
@@ -48,10 +50,11 @@ is, downloads the image and posts it to the current room."
(let* ((file-path (download-link link))
(file-name (filename-from-link link))
(mxc-uri
- (upload *posterbot*
- file-name
- (alexandria:read-file-into-byte-vector file-path)
- :content-type (make-mime-type word))))
+ (and file-path
+ (upload *posterbot*
+ file-name
+ (alexandria:read-file-into-byte-vector file-path)
+ :content-type (make-mime-type word)))))
(if mxc-uri
(send-image-message *posterbot* *room-id* file-name mxc-uri
:info (list :|mimetype| (make-mime-type word)))