summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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))))))