stormbot/modules/talk/talk.sh

38 lines
1.1 KiB
Bash
Raw Normal View History

2013-07-19 13:42:58 -04:00
#! /bin/sh
2013-07-22 10:34:08 -04:00
# Simple Question-Answering module
# author Vy Nguyen
#
2013-07-19 13:42:58 -04:00
2013-07-20 00:58:07 -04:00
arg1=$1 # sender (the person I am talking to)
arg2=$2 # unclear????
2013-07-19 13:42:58 -04:00
2013-07-22 10:06:32 -04:00
user_dir=modules/talk/logs/$1
2013-07-20 00:58:07 -04:00
if [ ! -d "$user_dir" ]; then
mkdir $user_dir
fi
2013-07-22 09:22:29 -04:00
# if the user said goodbye and changed her mind!
if [ -f "$user_dir/GOODBYE" ]; then
echo "PRIVMSG $arg2 :$arg1: I thought you just said goodbye!"
rm $user_dir/GOODBYE
fi
2013-07-22 12:16:31 -04:00
shift 2 # chop off the first two args
2013-07-20 00:58:07 -04:00
echo "$@" >> $user_dir/input
2013-07-22 10:06:32 -04:00
cat $user_dir/input | java -jar modules/talk/talk_bot.jar > $user_dir/output
2013-07-20 00:58:07 -04:00
# retcode of value 1 means the user said goodbye
retcode="${PIPESTATUS[1]}"
echo "PRIVMSG $arg2 :$arg1: `tail -n 1 $user_dir/output`"
2013-07-22 12:16:31 -04:00
if [ "$retcode" -eq "1" ]; then
2013-07-20 00:58:07 -04:00
echo "PRIVMSG $arg2 :$arg1: That was a joke! It's free to talk to me. But we do accept donations! ;D"
2013-07-22 09:22:29 -04:00
# clean up old conversations
stamp="`date +%s`"
mv $user_dir/input $user_dir/"input_$stamp"
mv $user_dir/output $user_dir/"output_$stamp"
# leave good-bye flag (indicating the user already said goodbye)
touch $user_dir/GOODBYE
2013-07-22 10:06:32 -04:00
fi