-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathannounce.sh
executable file
·66 lines (52 loc) · 1.65 KB
/
announce.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# announce.sh: Announce stream to a Discord channel.
#
# https://github.com/noodlebox/stream-announcer
#
# Requires 'curl' and 'jq'
#
# Add the following to your nginx-rtmp config:
# exec_kill_signal term;
# exec_push /path/to/announce.sh;
#
# Make sure announce.sh is marked executable for nginx's user.
#
# nginx-rtmp also supports passing along parameters with some information
# about the stream, so you could easily extend this script to handle those.
set -e
message_start="@here ~(' - ' ~) **STREAM IS LIVE** (~ ' - ')~"
message_stop="( ' - ') Stream's over, go home ( . - .)"
username='Stream Announcement'
stream_title='Stream Title'
stream_desc='A short message about the stream'
stream_url='https://example.com/stream_page'
# color = (r << 16) + (g << 8) + b
color='16764108'
id='WEBHOOK_ID'
token='WEBHOOK_TOKEN'
url="https://discordapp.com/api/webhooks/$id/$token"
webhook_post() {
curl --header 'Content-Type: application/json' --data-raw "$(</dev/fd/0)" "$1"
}
webhook_encode() {
jq -c -n --arg content "$1" --arg username "$2" --argjson embeds "$(</dev/fd/0)" \
'{$content, $username, $embeds}'
}
webhook_embed_encode() {
jq -c -n --arg title "$1" --arg description "$2" --arg url "$3" --argjson color "$4" \
'[{$title, $description, $url, $color}]'
}
announce_start() {
webhook_embed_encode "$stream_title" "$stream_desc" "$stream_url" "$color" \
| webhook_encode "$message_start" "$username" \
| webhook_post "$url"
}
announce_stop() {
webhook_encode "$message_stop" "$username" <<<'[]' \
| webhook_post "$url"
}
sleep 2 || exit
trap 'announce_stop; exit' INT TERM
announce_start
while sleep 10; do :; done
announce_stop