-
Notifications
You must be signed in to change notification settings - Fork 1
/
reply.sh
executable file
·48 lines (40 loc) · 1.41 KB
/
reply.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
set -euo pipefail
PATH="/opt/homebrew/opt/grep/libexec/gnubin:$PATH"
MESSAGE="\
Hello, fellow traveler! Don't get lost in this derelict place... \
Join us over at https://mithril.zulipchat.com where life abounds \
and conversations flow.\n\nYes! ... and spread the word around so that others don't get astray."
GANDALF_ID='57a33f9b40f3a6eec05deab8'
function getLastMessageUserIdForRoom() {
ROOM_ID=$1
curl \
-H "Accept: application/json" \
-H "Authorization: Bearer $GANDALF_GITTER_TOKEN" \
"https://api.gitter.im/v1/rooms/$ROOM_ID/chatMessages?limit=1" \
| ./json/JSON.sh \
| grep -Po '"fromUser","id"\]\s*"[^"]*' \
| grep -Po '[^"]+$'
}
function postMessage() {
ROOM_ID=$1
curl -X POST -i \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer $GANDALF_GITTER_TOKEN" \
"https://api.gitter.im/v1/rooms/$ROOM_ID/chatMessages" \
-d "{\"text\":\"$MESSAGE\"}"
}
function postIfNeeded () {
ROOM_ID=$1
ROOM_NAME=$2
ID=$(getLastMessageUserIdForRoom $ROOM_ID)
if [[ "$GANDALF_ID" = "$ID" ]]; then
echo "Nothing to do in $ROOM_NAME"
else
echo "Repling to message in $ROOM_NAME"
postMessage $ROOM_ID
fi
}
echo $(postIfNeeded 5501985215522ed4b3dd2ac3 MithrilJS/mithril.js)
echo $(postIfNeeded 5441311bdb8155e6700cc6f7 MithrilJS/mithril-node-render)