initial commit
This commit is contained in:
commit
9b75138b47
253
start.sh
Executable file
253
start.sh
Executable file
@ -0,0 +1,253 @@
|
||||
#!/bin/sh
|
||||
|
||||
trap cleanup 1 2 3 6 9 11
|
||||
cleanup() { kill $PID; }
|
||||
|
||||
|
||||
BOTNICK="uugbot"
|
||||
SERVER="irc.uugrn.org"
|
||||
PORT="6660"
|
||||
CHANNEL="#uugrn"
|
||||
|
||||
BOTDIR="$PWD"
|
||||
|
||||
IRCIN="$BOTDIR/irc/$SERVER/$CHANNEL/in"
|
||||
IRCOUT="$BOTDIR/irc/$SERVER/$CHANNEL/out"
|
||||
|
||||
# $1 message
|
||||
say() {
|
||||
echo "out> $1"
|
||||
echo "$1" > $IRCIN
|
||||
sleep 1
|
||||
}
|
||||
# $1 message
|
||||
reply() {
|
||||
echo "out> $1: $2"
|
||||
echo "$NICK: $2" > $IRCIN
|
||||
}
|
||||
|
||||
settopic() {
|
||||
curl -s "https://vorstand.uugrn.org/Kalender/Termine.rem" \
|
||||
| remind -b1 -n - \
|
||||
| sort \
|
||||
| grep -vi vorstand \
|
||||
| head -1 \
|
||||
| while read -r line
|
||||
do
|
||||
date=$(echo "$line" \
|
||||
| cut -d" " -f 1 \
|
||||
| sed 's,\(....\)/\(..\)/\(..\),\3.\2.\1,g')
|
||||
|
||||
time=$(echo "$line" \
|
||||
| cut -d" " -f 2)
|
||||
|
||||
text=$(echo "$line" \
|
||||
| cut -d" " -f 3- \
|
||||
| cut -d"|" -f1 \
|
||||
| sed 's/ $//g')
|
||||
|
||||
say "/topic $CHANNEL :Willkommen bei der UUGRN | Nächstes event: $text am $date um $time Uhr."
|
||||
done
|
||||
}
|
||||
|
||||
kalender() {
|
||||
case "$1" in
|
||||
[12345]) NUM=$1; ;;
|
||||
*) say "Dieses Argument verstehe ich nicht (ignored)."; NUM=1; ;;
|
||||
esac
|
||||
curl -s "https://vorstand.uugrn.org/Kalender/Termine.rem" \
|
||||
| remind -b1 -n - \
|
||||
| sort \
|
||||
| head -$NUM \
|
||||
| while read -r line
|
||||
do
|
||||
date=$(echo "$line" \
|
||||
| cut -d" " -f 1 \
|
||||
| sed 's,\(....\)/\(..\)/\(..\),\3.\2.\1,g')
|
||||
|
||||
time=$(echo "$line" \
|
||||
| cut -d" " -f 2)
|
||||
|
||||
text=$(echo "$line" \
|
||||
| cut -d" " -f 3- \
|
||||
| cut -d"|" -f1 \
|
||||
| sed 's/ $//g')
|
||||
|
||||
loc=$(echo "$line" \
|
||||
| cut -d" " -f 3- \
|
||||
| cut -d"|" -f 2-)
|
||||
|
||||
if echo "$line" | fgrep ' |'
|
||||
then
|
||||
say "Am $date um $time Uhr findet \"$text\" im \"$loc\" statt."
|
||||
else
|
||||
say "Am $date um $time Uhr findet \"$text\" statt."
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# $1 nick
|
||||
# $2 -1 decrease, +1 increase
|
||||
savekarma() {
|
||||
mkdir -p $BOTDIR/karma
|
||||
[ ! -f "$BOTDIR/karma/$1" ] \
|
||||
&& echo 0 > "$BOTDIR/karma/$1"
|
||||
|
||||
old=$(cat "$BOTDIR/karma/$1")
|
||||
new=$(( old $2 ))
|
||||
echo $new > "$BOTDIR/karma/$1"
|
||||
say "$1 hat nun $new Gummipunkt(e)"
|
||||
}
|
||||
|
||||
# $1 nick
|
||||
reportkarma() {
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
n=$NICK
|
||||
else
|
||||
n=$1
|
||||
fi
|
||||
if [ ! -f "$BOTDIR/karma/$n" ]
|
||||
then
|
||||
if [ "$n" == "$NICK" ]
|
||||
then
|
||||
say "Du hast bisher leider noch keine Gummipunkte gesammelt, $n."
|
||||
else
|
||||
say "$n hat leider noch keine Gummipunkte gesammelt."
|
||||
fi
|
||||
else
|
||||
cur=$(cat "$BOTDIR/karma/$n")
|
||||
if [ "$n" == "$NICK" ]
|
||||
then
|
||||
say "Du hast momentan $cur Gummipunkt(e), $n."
|
||||
else
|
||||
say "$n hat momentan $cur Gummipunkt(e)."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
karma() {
|
||||
echo "karma: $1"
|
||||
n="$(echo "$1" | tr -d "+-")"
|
||||
[ -z "$n" ] && return
|
||||
|
||||
if [ "$n" == "$(echo "$NICK" | tr '[:upper:]' '[:lower:]' )" ]
|
||||
then
|
||||
say "So aber nicht mein lieber $NICK!"
|
||||
return
|
||||
fi
|
||||
|
||||
echo "$1" | fgrep "++" \
|
||||
&& savekarma $n "+1"
|
||||
echo "$1" | fgrep -- "--" \
|
||||
&& savekarma $n "-1"
|
||||
echo "$1" | fgrep "+-" \
|
||||
&& say "Echt jetzt, $NICK?"
|
||||
echo "$1" | fgrep -- "-+" \
|
||||
&& say "Echt jetzt, $NICK?"
|
||||
}
|
||||
transparenzbericht() {
|
||||
mkdir -p "$BOTDIR/karma"
|
||||
cd $BOTDIR/karma || return
|
||||
say "Gummipunkte Transparenzbericht:"
|
||||
for i in $(ls)
|
||||
do
|
||||
say "$i: $(cat "$i") Gummipunkte"
|
||||
done
|
||||
}
|
||||
|
||||
seen() {
|
||||
[ -z "$1" ] && return
|
||||
if [ -f "$BOTDIR/seen/$1" ]
|
||||
then
|
||||
say "$(cat "$BOTDIR/seen/$1")"
|
||||
else
|
||||
say "Hmm, ich habe keine Ahnung wann $1 zum letzten mal online war."
|
||||
fi
|
||||
}
|
||||
|
||||
usage() {
|
||||
say "!kalender <anzahl> - zeigt die nächsten Termine im UUGRN Kalender (max 5)"
|
||||
say "!wetter <ort> - zeigt das Wetter an <ort> oder Heidelberg"
|
||||
say "!punkte <nick> - zeigt den Gummipunktlevel von <nick> oder dir selbst an"
|
||||
say "!transparenzbericht - zeigt den Gummipunkte Transparenzbericht an"
|
||||
say "<nick>++ - vergibt einen Gummipunkt an <nick>"
|
||||
say "<nick>-- - nimmt <nick> einen Gummipunkt weg"
|
||||
say "!seen <nick> - zeigt die letzte Nachricht von <nick> an"
|
||||
say "!settopic - setzt das topic mit dem nächsten Event im Kalender"
|
||||
say "!hilfe - zeigt diesen hilfetext an"
|
||||
|
||||
}
|
||||
|
||||
# $1 loc
|
||||
weather() {
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
l=heidelberg
|
||||
else
|
||||
l=$1
|
||||
fi
|
||||
say "$(curl -s "https://wttr.in/$l?lang=de&format=%l:+%t+%C+%w+%h+Regen")"
|
||||
}
|
||||
|
||||
mkdir -p "$BOTDIR/irc"
|
||||
mkdir -p "$BOTDIR/seen"
|
||||
mkdir -p "$BOTDIR/karma"
|
||||
cd "$BOTDIR"
|
||||
|
||||
echo "connecting."
|
||||
ii -i $BOTDIR/irc -s $SERVER -p $PORT -n $BOTNICK &
|
||||
PID=$!
|
||||
sleep 1
|
||||
echo "/join $CHANNEL" > $BOTDIR/irc/$SERVER/in
|
||||
sleep 1
|
||||
|
||||
echo "ready."
|
||||
|
||||
tail -n 0 -f "$IRCOUT" \
|
||||
| while read -r line
|
||||
do
|
||||
NICK=$(echo "$line" \
|
||||
| sed -n 's/^....-..-.. ..:.. <\([^>]*\).*/\1/p')
|
||||
|
||||
if [ "$NICK" == "$BOTNICK" ]
|
||||
then
|
||||
# prevent loops
|
||||
continue
|
||||
fi
|
||||
|
||||
COMMAND=$(echo "$line" \
|
||||
| tr '[:upper:]' '[:lower:]' \
|
||||
| sed -n 's|.*\(![a-z]*\).*|\1|p')
|
||||
|
||||
ARG=$(echo "$line" \
|
||||
| tr '[:upper:]' '[:lower:]' \
|
||||
| sed -n 's|.*![a-z]* \([a-zA-Z0-9\-_+]*\).*|\1|p')
|
||||
|
||||
KARMA=$(echo "$line" \
|
||||
| tr '[:upper:]' '[:lower:]' \
|
||||
| sed -n 's|.* \([a-zA-Z0-9\-_]*[+-][+-]\).*|\1|p')
|
||||
|
||||
echo "in> $line"
|
||||
echo "in> NICK=$NICK, COMMAND=$COMMAND, ARG=$ARG, KARMA=$KARMA"
|
||||
|
||||
if [ ! -z "$NICK" ]
|
||||
then
|
||||
echo "$line" > "$BOTDIR/seen/$NICK"
|
||||
fi
|
||||
|
||||
case "$COMMAND" in
|
||||
"!kalender") kalender $ARG; ;;
|
||||
"!punkte") reportkarma $ARG; ;;
|
||||
"!transparenzbericht") transparenzbericht; ;;
|
||||
"!wetter") weather $ARG; ;;
|
||||
"!hilfe") usage; ;;
|
||||
"!settopic") settopic; ;;
|
||||
"!seen") seen $ARG; ;;
|
||||
esac
|
||||
case "$KARMA" in
|
||||
*[+-][+-]) karma $KARMA; ;;
|
||||
esac
|
||||
done
|
||||
|
||||
kill $PID
|
Loading…
Reference in New Issue
Block a user