-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsumer.sh
executable file
·32 lines (26 loc) · 963 Bytes
/
consumer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from_user=$1;
room=$2;
echo "Hi $from_user, joining to $room! MOOOOOOOOOOOOOOOOOO";
room_join="$from_user has joined $room"
curl -s -X POST -d "{ \"from\": \"COWCHAT\", \"contents\": \"$room_join\" }" \
"https://cowchat-bd025.firebaseio.com/rooms/$room/messages.json" > /dev/null
while read meth
do
if [[ $meth =~ "put" ]]; then
read next
data=$(echo $next | cut -c 6- | jq ".data");
from=$(echo $data | jq -r ".from");
contents=$(echo $data | jq -r ".contents");
if [[ $contents != "null" && $from != $from_user ]]; then
say "moooooooooooooooooooooo"
echo "$from:
$contents" | cowsay -n
fi
elif [[ $meth =~ "@" ]]; then
msg=$(echo $meth | cut -d "@" -f 2)
echo "$from_user:
$msg" | cowsay -n -f ./reverse.cow
curl -s -X POST -d "{ \"from\": \"$from_user\", \"contents\": \"$msg\" }" \
"https://cowchat-bd025.firebaseio.com/rooms/$room/messages.json" > /dev/null
fi
done < /dev/stdin