From 3f99fe15eb87c43de9c7df6514413d67099658f0 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Mon, 13 Apr 2020 17:16:46 -0500 Subject: better giphy link matching --- README.org | 4 +++- posterbot.lisp | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.org b/README.org index e6437a2..fdac04e 100644 --- a/README.org +++ b/README.org @@ -39,7 +39,9 @@ git clone https://github.com/cbeo/granolin granolin - Invite the bot to a room, it should automatically accept your invitation. -- Post a link to an image. The link should end in one of =.gif=, =.jpg=, =.bmp=, =.jpeg=, or =.png=. +- Post a link to an image. The link should end in one of =.gif=, + =.jpg=, =.bmp=, =.jpeg=, or =.png=. Likes to giphy also result in a + posted gif, so long as the links look like =https://giphy.com/gifs/somethingsomething= diff --git a/posterbot.lisp b/posterbot.lisp index c354154..0af7d07 100644 --- a/posterbot.lisp +++ b/posterbot.lisp @@ -69,7 +69,7 @@ :case-insensitive-mode t)) (defparameter +giphy-link-regex+ - (ppcre:create-scanner "https://giphy.com/gifs/.+-([a-zA-Z0-9]+)" + (ppcre:create-scanner "https://giphy.com/gifs/([a-z0-9]+-)*([a-zA-Z0-9]+)" :case-insensitive-mode t)) (defun download-link (link) @@ -108,7 +108,7 @@ the downloaded file. If there is an error thrown at any point, returns NIL." (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 0))))) + (format nil "https://media.giphy.com/media/~a/giphy.gif" (elt matches 1))))) (t nil))) (defun handle-link-candiate (word) -- cgit v1.2.3