forked from topkecleon/telegram-bot-bash
-
Notifications
You must be signed in to change notification settings - Fork 2
/
sendNotify
executable file
·78 lines (74 loc) · 1.46 KB
/
sendNotify
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
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$DIR"
. global
l=0
markdown=0
disable_notification=0
noDesc=0
while getopts ":h :t: :f: :l: :n :m :s" opt; do
#echo "$opt"
case $opt in
h)
echo -e "Usage:\n -t Text of message\n -f path to file\n -l notify level"
echo -e " -n No description\n -m Text as markdown"
exit 0
;;
t)
text="$OPTARG";;
m)
markdown=1;;
n)
noDesc=1;;
s)
disable_notification=1;;
l)
l=$((10#$OPTARG));;
f)
file="$OPTARG"
if [ ! -f "$file" ]; then
echo "$file not found"
file=""
fi
;;
?)
echo "Unknown option $opt"
exit 1;;
:)
echo "Option -$OPTARG requires an argument."
exit 1
;;
esac
done
case "$l" in
1)
lDesc="Error";;
2)
lDesc="Warning";;
3)
lDesc="Success";;
*)
lDesc="";;
esac
if [ $noDesc -eq 0 ]; then
msg=`echo -e "$l $lDesc\n$text"`
else
msg=`echo -e "$text"`
fi
chats=`ls $nlDir"/"`
for chat in $chats; do
nl=`cat "$nlDir/$chat"` #as text
nl=$((10#$nl)) #as number
if [ $l -le $nl ]; then
echo -e "---\nchat:$chat file:$file\nText:$msg"
if [ $markdown -eq 0 ]; then
send_message "$chat" "$msg" "$disable_notification"
else
send_markdown_message "$chat" "$msg" "$disable_notification"
fi
if [ ! -z "$file" ]; then
#filename=`basename $file`
send_doc "$chat" "$file"
fi
fi
done