-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpm22
More file actions
executable file
·64 lines (50 loc) · 1.51 KB
/
pm22
File metadata and controls
executable file
·64 lines (50 loc) · 1.51 KB
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
#!/usr/bin/env bash
EDIT_ID=""
DELETE_ID=""
MESSAGE=""
while getopts "m:e:d:" opt; do
case $opt in
m) MESSAGE="$OPTARG" ;;
e) EDIT_ID="$OPTARG" ;;
d) DELETE_ID="$OPTARG" ;;
esac
done
SECRET_FILE="$HOME/.mysecrets/tg_bot_pm22.txt"
if [ ! -f "$SECRET_FILE" ]; then
echo "ok: false"
exit 1
fi
TG_TOKEN=$(tr -d '[:space:]' < "$SECRET_FILE")
if [ -z "$TG_TOKEN" ]; then
echo "ok: false"
exit 1
fi
CHAT_ID="-5088754677"
API_URL="https://api.telegram.org/bot$TG_TOKEN"
if [ -n "$DELETE_ID" ]; then
RESPONSE=$(curl -s -X POST "$API_URL/deleteMessage" \
-H "Content-Type: application/json" \
-d "{\"chat_id\": $CHAT_ID, \"message_id\": $DELETE_ID}")
OK_STATUS=$(echo "$RESPONSE" | jq -r '.ok')
[ "$OK_STATUS" = "true" ] && echo "ok: true" || echo "ok: false"
exit
fi
if [ -n "$EDIT_ID" ]; then
[ -z "$MESSAGE" ] && echo "Usage: pm22 -e <id> -m \"message\"" && exit 1
RESPONSE=$(curl -s -X POST "$API_URL/editMessageText" \
-H "Content-Type: application/json" \
-d "{\"chat_id\": $CHAT_ID, \"message_id\": $EDIT_ID, \"text\": \"$MESSAGE\"}")
else
[ -z "$MESSAGE" ] && echo "Usage: pm22 -m \"message\"" && exit 1
RESPONSE=$(curl -s -X POST "$API_URL/sendMessage" \
-H "Content-Type: application/json" \
-d "{\"chat_id\": $CHAT_ID, \"text\": \"$MESSAGE\"}")
fi
OK_STATUS=$(echo "$RESPONSE" | jq -r '.ok')
if [ "$OK_STATUS" = "true" ]; then
MESSAGE_ID=$(echo "$RESPONSE" | jq -r '.result.message_id')
echo "ok: true | message_id: $MESSAGE_ID"
else
echo "ok: false"
exit 1
fi