summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <cbeok@protonmail.com>2020-04-14 22:42:37 -0500
committerColin Okay <cbeok@protonmail.com>2020-04-14 22:42:37 -0500
commit8434c7d875e5bf2c737129184ac1741ff96ba410 (patch)
tree89ade1d44e25ef57db5ee90fdad305bf333dbfb6
parentdb7dbb33b0cc73aeea9e6212479ad32af89290d5 (diff)
tenor shortlinks
-rw-r--r--posterbot.lisp25
1 files changed, 13 insertions, 12 deletions
diff --git a/posterbot.lisp b/posterbot.lisp
index aee341c..c8d044d 100644
--- a/posterbot.lisp
+++ b/posterbot.lisp
@@ -73,7 +73,7 @@
:case-insensitive-mode t))
(defparameter +tenor-link-regex+
- (ppcre:create-scanner "https://tenor.com/view/.+"
+ (ppcre:create-scanner "(https://tenor.com/view/.+$)|(https://tenor.com/[a-zA-Z0-9]+.gif$)"
:case-insensitive-mode t))
(defun download-link (link)
@@ -119,20 +119,21 @@ the downloaded file. If there is an error thrown at any point, returns NIL."
e))))
(defun check-word-for-link (word)
- (cond ((ppcre:scan-to-strings +image-link-regex+ word)
- (ppcre:scan-to-strings +image-link-regex+ word))
+ (cond
+ ((ppcre:scan-to-strings +giphy-link-regex+ word)
+ (multiple-value-bind (string matches)
+ (ppcre:scan-to-strings +giphy-link-regex+ word)
+ (declare (ignore string))
+ (when (plusp (length matches))
+ (format nil "https://media.giphy.com/media/~a/giphy.gif" (elt matches 1)))))
- ((ppcre:scan-to-strings +giphy-link-regex+ word)
- (multiple-value-bind (string matches)
- (ppcre:scan-to-strings +giphy-link-regex+ word)
- (declare (ignore string))
- (when (plusp (length matches))
- (format nil "https://media.giphy.com/media/~a/giphy.gif" (elt matches 1)))))
+ ((ppcre:scan-to-strings +tenor-link-regex+ word)
+ (fetch-link-from-tenor-page word))
- ((ppcre:scan-to-strings +tenor-link-regex+ word)
- (fetch-link-from-tenor-page word))
+ ((ppcre:scan-to-strings +image-link-regex+ word)
+ (ppcre:scan-to-strings +image-link-regex+ word))
- (t nil)))
+ (t nil)))
(defun handle-link-candiate (word)
"Checks if WORD is an HTTP URI pointing to an image resource. If it