commit 3ef079dfd84c8c0919641a41ee406be851d7da14
parent 7e8ddeae69664a3d3aa553b22db27117b55e9ab4
Author: hhvn <dev@hhvn.uk>
Date: Thu, 10 Nov 2022 00:27:08 +0000
Commit messages amirite
Diffstat:
M | LICENSE | | | 2 | +- |
M | handler.rc | | | 32 | ++++++++++++++++++++++---------- |
M | main.sh | | | 43 | +++++++++++++++---------------------------- |
3 files changed, 38 insertions(+), 39 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2021 Hayden Hamilton <dev@hhvn.uk>
+Copyright (c) 2021-2022 hhvn <dev@hhvn.uk>
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
diff --git a/handler.rc b/handler.rc
@@ -8,6 +8,7 @@ mkdir -p data/locks
LINE = `$nl{echo $LINE | tr -d '\r'}
PARAMS = `' '$nl{echo $LINE | sed 's/ :.*//'}
PARAMS = ($PARAMS `$nl{echo $LINE | sed 's/.* ://'})
+PREV = `$nl{tail -n 10 < in.log}
fn match_raw {
echo $LINE | grep $* >/dev/null
@@ -68,8 +69,8 @@ fn unlock {
fn islocked {
for (f in data/locks/*) {
- d = `{cat $f}
- if (expr $d '<' `{date +%s}) {
+ d = `{cat $f >[2]/dev/null}
+ if (expr $d '<' `{date +%s} >/dev/null >[2=1]) {
rm $f
}
}
@@ -82,6 +83,7 @@ fn randomize {
}
fn title {
+ out = ()
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
@@ -102,12 +104,6 @@ fn title {
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 = `$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~'}
@@ -130,6 +126,12 @@ fn title {
out = $out ^ 'Content type: ' ^ $ctype ^ ' '
}
+ if (~ $server 'cloudflare') {
+ out = $out ^ 'Cloudflared '
+ } else {
+ out = $out ^ 'Server: ' ^ $server ^ ' '
+ }
+
send_notice $TARGET $out
}
}
@@ -140,6 +142,8 @@ if (~ $PARAMS(1) 'PING') {
# end of MOTD
send_join '#hlircnet'
send_join '#test'
+} else if (match_msg -i '^!help' || match_hilight -iE '^(help|source|src|usage|-h|--help)') {
+ send_msg $TARGET 'Source: git://hhvn.uk/ | Help: gopher://hhvn.uk/1/git/o/marvvin/file/data/help.txt.gph'
} else if (match_hilight -iE '^(calc|bc) ') {
exp = `$nl{echo $MSG | sed 's/[^ ]* *//'}
if (islocked bc) {
@@ -203,7 +207,7 @@ if (~ $PARAMS(1) 'PING') {
./bin/$CMD $ARGS | send_stdin $TARGET
} else if (match_hilight -E '^welcome back') {
send_msg $TARGET 'Thanks, ' ^ $NICK
-} else if (match_hilight -E '^wtf|^what') {
+} 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 ()) {
@@ -241,7 +245,7 @@ if (~ $PARAMS(1) 'PING') {
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 (!islocked insult && match_hilight -iE 'fuck you|go fuck yourself|stupid bot|idiot|retard|shut up') {
+} else if (!islocked insult && match_hilight -iE 'you suck|fuck you|go fuck yourself|stupid bot|idiot|retard|shut up') {
lock insult 150
send_msg $TARGET `$nl{randomize \
'If you hate me so much I can leave and never come back' \
@@ -253,6 +257,14 @@ if (~ $PARAMS(1) 'PING') {
'I have feelings too' \
'Bots have feelings too' \
'You''ll regret saying that one day'}
+} else if (match_hilight -iE '^(hi|hey|hej|hello|hallÄ)' || match_msg -iE '^(hi|hey|hej|hallo|hallÄ).*' ^ $nick ^ '[[:space:]]*$') {
+ if (!islocked personalgreet) {
+ SPLIT = `{echo $MSG}
+ send_msg $TARGET `$nl{printf \
+ 'Hey ' ^ $NICK ^ '\n' ^ 'Hey\n' ^ $NICK ^ ', hello\n' ^ 'Hello\n' ^ 'Hi ' ^ $NICK ^ '\n' ^ 'Hi\n' |
+ grep -ivF $SPLIT(1) | shuf -n 1}
+ lock personalgreet 60
+ }
} else if (match_hilight '.*') {
send_msg $TARGET `$nl{grep '^[^#]' < data/suggest/response | shuf -n 1}
} else {
diff --git a/main.sh b/main.sh
@@ -17,11 +17,6 @@ cd $(dirname $0)
export nick server port input inlog outlog comment tmpdir
-_mkfifo(){
- rm "$input"
- mkfifo "$input"
-}
-
# connect(host, port)
[ "$tls" = "y" ] && {
connect(){
@@ -33,27 +28,19 @@ _mkfifo(){
}
}
-while _mkfifo
+rm "$input"
+mkfifo "$input"
+(
+ printf '%s\r\n' "NICK $nick"
+ printf '%s\r\n' "USER $nick * * :${comment:-$nick}"
+) | cat - $input | \
+tee $outlog | \
+connect $server $port | \
+tee $inlog /dev/stderr | \
+while read -r line
do
- sleep 1
-
- (
- printf '%s\r\n' "NICK $nick"
- printf '%s\r\n' "USER $nick * * :${comment:-$nick}"
- ) | cat - $input | \
- tee $outlog | \
- connect $server $port | \
- tee $inlog /dev/stderr | \
- while read -r line
- do
- export LINE="$(printf '%s\n' "$line" | sed 's/:[^ ]* //')"
- export FROM="$(printf '%s\n' "$line" | grep -o '^:[^ ]*')"
- export NICK="$(printf '%s\n' "$FROM" | sed -E 's/[:!]*([^:!]*).*/\1/')"
- ./handler.rc
- done >/dev/null | tee $input
-
- [ -f stop ] && {
- rm stop
- kill -1 $$
- }
-done
+ export LINE="$(printf '%s\n' "$line" | sed 's/:[^ ]* //')"
+ export FROM="$(printf '%s\n' "$line" | grep -o '^:[^ ]*')"
+ export NICK="$(printf '%s\n' "$FROM" | sed -E 's/[:!]*([^:!]*).*/\1/')"
+ timeout 20 ./handler.rc
+done >/dev/null | tee $input