marvvin

IRC bot
Log | Files | Refs | README | LICENSE

commit ca5a89c9633e7e6319c0f805a68f715546e62392
parent c0e614ce8116d71f703df60f94deb6e78977a346
Author: hhvn <dev@hhvn.uk>
Date:   Wed, 23 Mar 2022 19:56:01 +0000

Update handler

Diffstat:
Mhandler.rc | 58++++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 40 insertions(+), 18 deletions(-)

diff --git a/handler.rc b/handler.rc @@ -81,8 +81,8 @@ fn title { curl -qsL $url | tr -d '\r' > data/content if (echo $url | grep 'http[s]*://[w.]*youtu[.]*be' >/dev/null) { title = `$nl{< data/content \ - grep '\[{\"videoPrimaryInfoRenderer\":{\"title\":{\"runs\"\:\[{\"text\":' | - sed 's/.*\[{\"videoPrimaryInfoRenderer\":{\"title\":{\"runs\"\:\[{\"text\":// ; s/}\]}.*// ; s/\\//g ; s/^\"// ; s/.$//'} + grep '<meta itemprop="name"' | + sed -E 's/.*<meta itemprop="name" content="([^"]*)">.*/\1/'} author = `$nl{< data/content \ grep -o 'author":[^}]*}' | sed -E 's/.*:"([^"]*).*/\1/g'} @@ -90,7 +90,7 @@ fn title { grep -o 'uploadDate":[^}]*}' | sed -E 's/.*:"([^"]*).*/\1/g;s/([0-9]*)-([0-9]*)-([0-9]*)/\3-\2-\1/'} - send_notice $TARGET `$nl{printf '40You91,16Tube ::: Title: %s ::: Author: %s ::: Uploaded: %s\n' $title $author $date} + send_notice $TARGET '40You91,16Tube ::: Title: ' ^ $^title ^ ' ::: Author: ' ^ $^author ^ ' ::: Uploaded: ' ^ $^date } else { code = `{head -n 1 < data/headers} ctype = `{awk -F: '$1 == "content-type" {print $2}' < data/headers} @@ -103,11 +103,11 @@ fn title { } 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/'} + title = `$nl{< data/content grep -o '<title[^>]*>[^<]*</title>' | sed 's~.*<title[^>]*>~~g;s~</title>.*~~g' | head -n 1} + published = `$nl{< 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 = `$nl{< 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 = `$nl{< data/content grep -o '<meta[^>]*"author[^>]*>' | sed -E 's/.*content="([^"]*)".*/\1/'} + generator = `$nl{< data/content grep -io '<meta[^>]*"generator[^>]*>' | sed -E 's/.*content="([^"]*)".*/\1/'} if (echo $title | grep '.' >/dev/null) out = $out ^ 'Title: ' ^ $title ^ ' ' @@ -159,24 +159,46 @@ if (~ $PARAMS(1) 'PING') { send_msg $TARGET `$nl{./bin/$CMD $ARGS} } else if (match_hilight -E '^welcome back') { send_msg $TARGET 'Thanks, ' ^ $NICK +} else if (match_hilight -E '^wtf|^what') { + acr = `$nl{echo $MSG | sed 's/[^ ]* *//;s/^is //' | tr '[:lower:]' '[:upper:]'} + out = `$nl{awk -F\t -vacr=$acr 'toupper($1) == acr {printf("%s, ", $2)}' < data/suggest/acronym | sed 's/, $//'} + if (~ $out ()) { + send_msg $TARGET 'No acronym ''' ^ $acr ^ ''' found. Use `marvvin: suggest acronym <acronym> <definition...>` to add one' + } else { + send_msg $TARGET $acr ^ ': ' ^ $out + } } else if (match_hilight '^suggest') { - categories = (response) - splitmsg = `{echo $MSG} + categories = (response acronym) + splitmsg = `{printf '%s' $MSG} if (~ $splitmsg(2) $categories) { + if (~ $splitmsg(2) 'acronym') { + MSG = `$nl{echo $MSG | sed -E 's/^([^ ]* *[^ ]* *[^ ]*) */\1\t/'} + if (!echo $MSG | grep `''{printf '\t'}) { + send_msg $TARGET $NICK ^ ': acronyms need a definition' + exit + } + } mkdir -p data/suggest/ - echo $MSG | sed 's/[^ ]* *[^ ]* *//' > data/suggest/$splitmsg(2) + echo '# [From: ' ^ $FROM ^ '] [Target: ' ^ $TARGET ^ '] ' ^ `$nl{date} >> data/suggest/$splitmsg(2) + echo $MSG | sed 's/[^ ]* *[^ ]* *//' >> data/suggest/$splitmsg(2) send_msg $TARGET $NICK ^ ': suggestion submitted to category ''' ^ $splitmsg(2) ^ '''' + } else if (~ $splitmsg(2) ()) { + send_msg $TARGET $NICK ^ ': categories: ' ^ $^categories } else { send_msg $TARGET $NICK ^ ': invalid category. Accepted categories are: ' ^ `$nl{echo $^categories | sed 's/ /, /g'} } +} else if (match_hilight '^ip ') { + arg = `{echo $MSG | sed 's/[^ ]* *//'} + ip4 = `{echo $arg | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'} + + if (~ $ip4 ()) { + ip4 = dig +short $arg A + } + + ipinfo = `{curl https://ipinfo.io/$ip4/json | jq .city,.region,.country | tr -d "} + send_msg $TARGET 'IPv4: ' ^ $ip4 ^ ' City: ' ^ $ipinfo(1) ^ ' Region: ' ^ $ipinfo(2) ^ ' Country: ' ^ $ipinfo(3) } else if (match_hilight '.*') { - send_msg $TARGET `$nl{randomize \ - $NICK ^ ', huh?' \ - 'I don''t get it' \ - 'That makes no sense' \ - 'Try something else..' \ - 'I''m a fucking bot man, cut me some slack' \ - '*yawn* RTFM'} + send_msg $TARGET `$nl{grep '^[^#]' < data/suggest/response | shuf -n 1} } else { urls = `$nl{echo $MSG | grep -Eo 'https?://[^ ]*'} for (url in $urls) {