summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authortilpner2018-08-12 21:14:28 +0200
committertilpner2018-08-12 21:14:28 +0200
commit068e52e766bf176adfe648dc9aa266f12c950471 (patch)
tree3cddaaea99bef28f160ec2faad77263de2206450 /modules
parent4c917d4ffc5d55110e96ca4ae6da55bbea275038 (diff)
downloadmeep-068e52e766bf176adfe648dc9aa266f12c950471.tar.gz
meep-068e52e766bf176adfe648dc9aa266f12c950471.tar.xz
meep-068e52e766bf176adfe648dc9aa266f12c950471.zip
Fix exception while encountering the supposed URL ':3', preventing the actual URL from bein processed
Diffstat (limited to 'modules')
-rw-r--r--modules/3-youtube.rkt17
1 files changed, 13 insertions, 4 deletions
diff --git a/modules/3-youtube.rkt b/modules/3-youtube.rkt
index 835bee9..0ddd1a1 100644
--- a/modules/3-youtube.rkt
+++ b/modules/3-youtube.rkt
@@ -1,5 +1,7 @@
#lang racket/base
-(require irc/bot racket/string net/url net/uri-codec json)
+(require irc/bot irc/clean
+ racket/string racket/format racket/function
+ net/url net/uri-codec json)
(provide (all-defined-out))
(define (youtube-query url)
@@ -8,13 +10,18 @@
(uri-encode (url->string url))))
get-pure-port read-json))
+(define (string->maybe-url s)
+ (with-handlers ([url-exception? (const #f)])
+ (string->url s)))
+
; catch youtube.com and youtu.be
(define (extract-youtube-url s)
(define (is-yt-url u)
- (and (url-host u)
+ (and u
+ (url-host u)
(string-contains? (url-host u) "youtu")))
- (let* ([urls (map string->url (string-split s))])
+ (let* ([urls (map (compose1 string->maybe-url clean-control) (string-split s))])
(findf is-yt-url urls)))
(on (and (command-is 'PRIVMSG)
@@ -23,4 +30,6 @@
(when url
(let* ([response (youtube-query url)]
[title (hash-ref response 'title)])
- (reply (format "\"~a\"" title))))))
+ (reply (~v title))))))
+
+;(format "\"~a\"" title))))))