summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/1-ping.rkt5
-rw-r--r--modules/3-bots.rkt5
-rw-r--r--modules/3-youtube.rkt26
-rw-r--r--modules/9-listen.rkt6
4 files changed, 42 insertions, 0 deletions
diff --git a/modules/1-ping.rkt b/modules/1-ping.rkt
new file mode 100644
index 0000000..fc03c0e
--- /dev/null
+++ b/modules/1-ping.rkt
@@ -0,0 +1,5 @@
+#lang racket/base
+(require irc/core irc/bot)
+
+(on (command-is 'PING)
+ (send (msg 'PONG '() (suffix))))
diff --git a/modules/3-bots.rkt b/modules/3-bots.rkt
new file mode 100644
index 0000000..6ef9b77
--- /dev/null
+++ b/modules/3-bots.rkt
@@ -0,0 +1,5 @@
+#lang racket/base
+(require irc/bot)
+
+(on (suffix-is ".bots")
+ (reply "Reporting in! [Racket]"))
diff --git a/modules/3-youtube.rkt b/modules/3-youtube.rkt
new file mode 100644
index 0000000..835bee9
--- /dev/null
+++ b/modules/3-youtube.rkt
@@ -0,0 +1,26 @@
+#lang racket/base
+(require irc/bot racket/string net/url net/uri-codec json)
+(provide (all-defined-out))
+
+(define (youtube-query url)
+ (call/input-url
+ (string->url (format "https://noembed.com/embed?url=~a"
+ (uri-encode (url->string url))))
+ get-pure-port read-json))
+
+; catch youtube.com and youtu.be
+(define (extract-youtube-url s)
+ (define (is-yt-url u)
+ (and (url-host u)
+ (string-contains? (url-host u) "youtu")))
+
+ (let* ([urls (map string->url (string-split s))])
+ (findf is-yt-url urls)))
+
+(on (and (command-is 'PRIVMSG)
+ (context-is "#code"))
+ (let ([url (extract-youtube-url (suffix))])
+ (when url
+ (let* ([response (youtube-query url)]
+ [title (hash-ref response 'title)])
+ (reply (format "\"~a\"" title))))))
diff --git a/modules/9-listen.rkt b/modules/9-listen.rkt
new file mode 100644
index 0000000..4ff35e8
--- /dev/null
+++ b/modules/9-listen.rkt
@@ -0,0 +1,6 @@
+#lang racket/base
+(require irc/core)
+(listen)
+
+; okay, maybe this is overdoing the modularity bit,
+; but I don't know where else to put this