From 296e8d34a223dc9d420385471ec428a7abb53cbd Mon Sep 17 00:00:00 2001 From: DiSharko Date: Tue, 23 Jul 2013 11:19:11 -0400 Subject: [PATCH 1/2] Updated azhu module with last response time --- modules/azhu.sh | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/modules/azhu.sh b/modules/azhu.sh index f6bea5d..dc3fa10 100755 --- a/modules/azhu.sh +++ b/modules/azhu.sh @@ -1,12 +1,38 @@ #!/bin/bash -day=$(date +%a) +. "../bot.properties" +log="../$log" + +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) 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 +if [ "$minutesBetween" -ge 0 ]; then + responsePercent=$(( -5000/($minutesBetween+40) - $minutesBetween/25 + 100 )) +fi + percent=0 -case $day in +case $dayOfWeek in "Mon" ) percent=$(($percent+25));; "Tue" ) @@ -25,9 +51,13 @@ esac hp=$((10#$hour*10#$hour*10#$hour/150)) -percent=$(($percent+$hp+$minute/20)) +percent=$((10#$percent+10#$hp+10#$minute/20)) +percent=$(($percent + $responsePercent)) -if [[ "$percent" -ge 100 ]]; then + +if [ "$percent" -le 0 ]; then + percent=0 +elif [ "$percent" -ge 100 ]; then percent=99 fi @@ -35,9 +65,9 @@ if [ $# -ge 1 ]; then if [ $1 == "azhu" ]; then percent=0; fi - echo "PRIVMSG $2 :$1: There is a $percent% chance azhu is sleeping right now." + echo "PRIVMSG $2 :$1: There is a $percent% chance $name is sleeping right now." else - echo "There is a $percent% chance azhu is sleeping right now." + echo "There is a $percent% chance $name is sleeping right now." fi From 424b3dd8c8d9e27630b9dcd6c4cfe54e7584ecec Mon Sep 17 00:00:00 2001 From: DiSharko Date: Tue, 23 Jul 2013 12:46:13 -0400 Subject: [PATCH 2/2] Fixed bugs --- modules/azhu/azhu.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/azhu/azhu.sh b/modules/azhu/azhu.sh index dc3fa10..11c582c 100755 --- a/modules/azhu/azhu.sh +++ b/modules/azhu/azhu.sh @@ -1,7 +1,7 @@ #!/bin/bash -. "../bot.properties" -log="../$log" +. "../../bot.properties" +log="../../$log" lines=$(grep "!azhu" $log) name=$(echo $lines | sed "s/.*\]:\(.*\)![^!]*/\1/g") @@ -26,7 +26,7 @@ fi responsePercent=0 -if [ "$minutesBetween" -ge 0 ]; then +if [ $minutesBetween -ge 0 ]; then responsePercent=$(( -5000/($minutesBetween+40) - $minutesBetween/25 + 100 )) fi