stormbot/modules/azhu/azhu.sh

86 lines
1.8 KiB
Bash
Raw Normal View History

2013-07-22 10:27:46 -04:00
#!/bin/bash
2013-07-23 13:01:18 -04:00
versionString="azhu® version 2.0.1 by Andrew DiMarco"
if [ $# == 3 ]; then
if [ $3 == "--version" ]; then
2013-07-23 13:27:38 -04:00
echo "PRIVMSG $2 :$1: "$versionString
2013-07-23 13:01:18 -04:00
exit
fi
elif [ $# == 1 ]; then
if [ $1 == "--version" ]; then
echo $versionString
exit
fi
fi
. "bot.properties"
lines=$(grep "!azhu" $log)
name=$(echo $lines | sed "s/.*\]:\(.*\)![^!]*/\1/g")
if [[ "$name" == "" ]]; then
name="azhu"
fi
line=$(echo $lines | sed "s/.*\[\(.*\)\].*/\1/g")
lastResponse_DayOfMonth=$(echo $line | sed "s/^.*:.*:\(.*\) .*:.*:.*$/\1/g")
dayOfWeek=$(date +%a)
dayOfMonth=$(date +%d)
2013-07-22 10:27:46 -04:00
hour=$(date +%T | sed "s/\([^:]*\):.*/\1/" )
minute=$(date +%M)
daysApart=$((10#$dayOfMonth - 10#$lastResponse_DayOfMonth))
if [ "$daysApart" -eq 0 ]; then
lastResponse_hour=$(echo $line | sed "s/^.*:.*:.* \(.*\):.*:.*$/\1/g")
lastResponse_minute=$(echo $line | sed "s/^.*:.*:.* .*:\(.*\):.*$/\1/g")
minutesBetween=$(((10#$hour - 10#$lastResponse_hour)*60 + 10#$minute - 10#$lastResponse_minute))
fi
responsePercent=0
2013-07-23 12:46:13 -04:00
if [ $minutesBetween -ge 0 ]; then
responsePercent=$(( -5000/($minutesBetween+40) - $minutesBetween/25 + 100 ))
fi
2013-07-22 10:27:46 -04:00
percent=0
case $dayOfWeek in
2013-07-22 10:27:46 -04:00
"Mon" )
percent=$(($percent+25));;
"Tue" )
percent=$(($percent+20));;
"Wed" )
percent=$(($percent+20));;
"Thu" )
percent=$(($percent+25));;
"Fri" )
percent=$(($percent+30));;
"Sat" )
percent=$(($percent+100));;
"Sun" )
percent=$(($percent+100));;
esac
hp=$((10#$hour*10#$hour*10#$hour/150))
percent=$((10#$percent+10#$hp+10#$minute/20))
percent=$(($percent + $responsePercent))
2013-07-22 10:27:46 -04:00
if [ "$percent" -le 0 ]; then
percent=0
elif [ "$percent" -ge 100 ]; then
2013-07-22 10:27:46 -04:00
percent=99
fi
if [ $# -ge 1 ]; then
if [ $1 == "azhu" ]; then
percent=0;
fi
echo "PRIVMSG $2 :$1: There is a $percent% chance $name is sleeping right now."
2013-07-22 10:27:46 -04:00
else
echo "There is a $percent% chance $name is sleeping right now."
2013-07-22 10:27:46 -04:00
fi