This repository has been archived by the owner on Jun 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot
executable file
·138 lines (114 loc) · 2.84 KB
/
bot
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
PROPERTIES=${slack_bot_home:-.}/application.properties
load_properties() {
file="${PROPERTIES}"
if [ -f "$file" ]
then
echo "$file found."
while IFS='=' read -r key value
do
key=$(echo ${key} | tr '.' '_')
eval "${key}='${value}'"
done < "$file"
else
echo "$file not found."
fi
}
send_slack_message() {
message="${1}"
curl --silent --request POST \
--url "${slack_hooks}" \
--data "{\"text\":\"${message}\"}"
}
create_post() {
title="${1}"
message="${2}"
image_url="${3}"
tags="${4}"
title="${title}" message="${message}" image_url="${image_url}" tags="${tags}" \
${slack_bot_home}/post > "${github_repo}/_posts/$(date "+%Y-%m-%d")-${1//[ #]/-}.md"
}
commit_post() {
message="${1}"
cd "${github_repo}"
git add .
git commit -m "${message} added"
}
build_post_message() {
title="${1}"
text="${2}"
room="${3}"
details_url="${4}"
next_date=`date "+%Y-%m-%d"`
message=`text="${text}" room="${room}" details_url="${details_url}" ${slack_bot_home}/post_message`
echo "${message}"
}
build_slack_message() {
title="${1}"
text="${2}"
room="${3}"
details_url="${4}"
next_date=`date "+%Y-%m-%d"`
message=`text="${text}" room="${room}" details_url="${details_url}" ${slack_bot_home}/slack_message`
echo "${message}"
}
create() {
title="${1}"
text="${2}"
room="${3}"
details_url="${4}"
image_url="${5}"
tags="${6}"
message=`build_post_message "${title}" "${text}" "${room}" "${details_url}"`
create_post "${title}" "${message}" "${image_url}" "${tags}"
commit_post "${title}"
}
wait_for_post() {
url=${githubio_path}/$(date "+%Y/%m/%d")/${1//[ #]/-}.html
echo "Waiting for post $url";
until $(curl --output /dev/null --silent --head --fail "$url"); do
printf '.'
sleep 5
done
}
update() {
echo "Not supported yet"
}
send() {
title="${1}"
text="${2}"
room="${3}"
details_url="${4}"
message=`build_slack_message "${title}" "${text}" "${room}" "${details_url}"`
send_slack_message "${message}\nSee updates at ${githubio_path}"
}
load_properties
program="${0}"
command="${1}"
title="${2}"
text="${3}"
room="${4}"
details_url="${5}"
image_url="${6}"
tags="${7}"
case "${command}" in
'create')
create "${title}" "${text}" "${room}" "${details_url}" "${image_url}" "${tags}"
;;
'update')
update
;;
'wait-for-post')
wait_for_post "${title}"
;;
'send')
send "${title}" "${text}" "${room}" "${details_url}"
;;
*)
echo
echo "Usage: ${program} { create | update | send } title message tags room"
echo
exit 1
;;
esac
exit 0