forked from EliasKotlyar/Xiaomi-Dafang-Hacks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix
More file actions
executable file
·54 lines (43 loc) · 1.49 KB
/
Copy pathmatrix
File metadata and controls
executable file
·54 lines (43 loc) · 1.49 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
#!/bin/sh
CURL="/system/sdcard/bin/curl --silent"
JQ="/system/sdcard/bin/jq"
what="$1"
if [ "$what" = "m" ]; then
shift
sendtext="${@//\"/\\\"}"
else
filename="$2"
datafile="$3"
fi
. /system/sdcard/config/matrix.conf
uploadData() {
mimetype="$1"
msgtype="$2"
mxcuri="$($CURL -XPOST -H "Content-Type: $mimetype" --data-binary @"$datafile" "https://$host:$port/_matrix/media/r0/upload?filename=$filename&access_token=$access_token" | $JQ -cMr ".content_uri")"
if [ -n "$mxcuri" ] && [ "$mxcuri" != "null" ]; then
$CURL -XPOST -d '{"msgtype":"'"$msgtype"'", "body":"'"$filename"'", "url":"'"$mxcuri"'"}' "https://$host:$port/_matrix/client/r0/rooms/$room_id/send/m.room.message?access_token=$access_token"
fi
}
sendFile() {
echo "Sending file: $datafile"
uploadData "application/octet-stream" "m.file"
}
sendMessage() {
echo "Sending message: $sendtext"
$CURL -XPOST -d '{"msgtype":"m.notice", "body":"'"$sendtext"'"}' "https://$host:$port/_matrix/client/r0/rooms/$room_id/send/m.room.message?access_token=$access_token"
}
sendPicture() {
echo "Sending picture: $datafile"
filename="$filename.jpg"
uploadData "image/jpeg" "m.image"
}
sendVideo() {
echo "Sending video: $datafile"
filename="$filename.mp4"
uploadData "video/mp4" "m.video"
}
[ "$what" = "f" ] && sendFile
[ "$what" = "m" ] && sendMessage
[ "$what" = "p" ] && sendPicture
[ "$what" = "v" ] && sendVideo
[ -z "$what" ] && echo -e "$0 <m|f|p|v> <data|filename>\n m: message\n f: file\n p: picture\n v: video"