marvvin

IRC bot
Log | Files | Refs | README | LICENSE

commit 67f0823fed70d95f1f206351754e2fabaa1a90bb
parent 7f04dc4e2f2cddb207ea9a914bcdfdbff3dcafe4
Author: hhvn <dev@hhvn.uk>
Date:   Mon, 28 Feb 2022 20:36:10 +0000

URL titles.

Diffstat:
Mhandler.rc | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+), 0 deletions(-)

diff --git a/handler.rc b/handler.rc @@ -48,6 +48,10 @@ fn send_msg { send_raw 'PRIVMSG %s :%s\r\n' $1 $2 } +fn send_notice { + send_raw 'NOTICE %s :%s\r\n' $1 $2 +} + fn lock { echo `{date +%s} ^ ' + ' ^ $2 | bc > data/locks/$1 } @@ -71,6 +75,59 @@ fn randomize { echo $*($n) } +fn title { + url = `$nl{echo $1 | sed 's/invidio.us/www.youtube.com/g;s/m.imdb.com/www.imdb.com/g' | tr -d '\r' | sed 's~embed/~watch?v=~g' | grep -o '[a-z]*://[^ ]*' | sed 's/[\.?>,]$//'} + curl -qsLD - $url | tr -d '\r' | sed '/^[^[:print:]]*$/q' | tr '[:upper:]' '[:lower:]' > data/headers + curl -qsL $url | tr -d '\r' > data/content + if (echo $url | grep 'http[s]*://[w.]*youtu[.]*be' >/dev/null) { + title = `{< data/content \ + grep '\[{\"videoPrimaryInfoRenderer\":{\"title\":{\"runs\"\:\[{\"text\":' | + sed 's/.*\[{\"videoPrimaryInfoRenderer\":{\"title\":{\"runs\"\:\[{\"text\":// ; s/}\]}.*// ; s/\\//g ; s/^\"// ; s/.$//'} + author = `{< data/content \ + grep -o 'author":[^}]*}' | + sed -E 's/.*:"([^"]*).*/\1/g'} + date = `{< data/content \ + grep -o 'uploadDate":[^}]*}' | + sed -E 's/.*:"([^"]*).*/\1/g;s/([0-9]*)-([0-9]*)-([0-9]*)/\3-\2-\1/'} + + send_notice $TARGET '05You05,16Tube ::: Title: ' ^ $title ^ ' ::: Author: ' ^ $author ^ ' ::: Uploaded: ' ^ $date + } else { + code = `{head -n 1 < data/headers} + ctype = `{awk -F: '$1 == "content-type" {print $2}' < data/headers} + server = `{awk -F: '$1 == "server" {print $2}' < data/headers} + + if (~ $server 'Cloudflare') { + out = $out ^ 'Cloudflared ' + } else { + out = $out ^ 'Server: ' ^ $server ^ ' ' + } + + if (~ $ctype 'text/html'*) { + title = `{< data/content grep -o '<title[^>]*>[^<]*</title>' | sed 's~.*<title[^>]*>~~g;s~</title>.*~~g' | head -n 1} + published = `{< data/content grep -o '<meta[^>]*"published_time[^>]*>' | sed -E 's/.*content="([^"]*)".*/\1/;s/T.*//;s~([0-9]*)-([0-9]*)-([0-9]*)~\3/\2/\1~'} + modified = `{< data/content grep -o '<meta[^>]*"modified_time[^>]*>' | sed -E 's/.*content="([^"]*)".*/\1/;s/T.*//;s~([0-9]*)-([0-9]*)-([0-9]*)~\3/\2/\1~'} + author = `{< data/content grep -o '<meta[^>]*"author[^>]*>' | sed -E 's/.*content="([^"]*)".*/\1/'} + generator = `{< data/content grep -io '<meta[^>]*"generator[^>]*>' | sed -E 's/.*content="([^"]*)".*/\1/'} + + if (echo $title | grep '.' >/dev/null) + out = $out ^ 'Title: ' ^ $title ^ ' ' + if (echo $published | grep '.' >/dev/null) + out = $out ^ 'Published: ' ^ $published ^ ' ' + if (echo $modified | grep '.' >/dev/null) + out = $out ^ 'Modified: ' ^ $modified ^ ' ' + if (echo $author | grep '.' >/dev/null) + out = $out ^ 'Author: ' ^ $author ^ ' ' + if (echo $generator | grep '.' >/dev/null) + out = $out ^ 'Generator: ' ^ $generator ^ ' ' + } else { + if (echo $ctype | grep '.' >/dev/null) + out = $out ^ 'Content type: ' ^ $ctype ^ ' ' + } + + send_notice $TARGET $out + } +} + if (~ $PARAMS(1) 'PING') { send_raw 'PONG :%s\r\n' $PARAMS(2) } else if (~ $PARAMS(1) '376') { @@ -120,4 +177,10 @@ if (~ $PARAMS(1) 'PING') { 'Try something else..' \ 'I''m a fucking bot man, cut me some slack' \ '*yawn* RTFM'} +} else { + urls = `$nl{echo $MSG | grep -Eo 'https?://[^ ]*'} + for (url in $urls) { + title $url + echo $url >/dev/stderr + } }