Add ntfy-events
All checks were successful
/ build-upload (push) Successful in 1m1s

This commit is contained in:
Tobias Reisinger 2024-09-27 16:16:21 +02:00
parent 915c2ccbbf
commit b827471e6d
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
2 changed files with 43 additions and 1 deletions

View file

@ -294,6 +294,7 @@ impl Serialize for Event {
x.serialize_field("type", &self.event_type)?;
x.serialize_field("channel", &self.channel)?;
x.serialize_field("client", &self.client)?;
x.serialize_field("params", &self.params)?;
x.serialize_field("message", &self.get_message())?;
x.end()
}

View file

@ -9,7 +9,8 @@ not away
back
message
message-user
events"
events
ntfy-events"
_ts_control_get_entity() {
entity=$(_ts_control_single_or_dmenu "$(teamspeak-query-lib "$1s")" "$2")
@ -54,6 +55,41 @@ _ts_control_single_or_dmenu() {
fi
}
handle_ntfy_events() {
while read -r data; do
msg=$(echo "$data" | jq -r --unbuffered '.message')
type=$(echo "$data" | jq -r --unbuffered '.type')
mode=$(echo "$data" | jq -r --unbuffered '.params.targetmode')
echo "$data"
if [ "$type" = "NotifyTextMessage" ] && [ "$mode" != "1" ]; then
continue # Skip all messages that are not direct messages
fi
friendly_type="Event"
case $type in
"NotifyClientPoke")
friendly_type="Poke"
;;
"NotifyTextMessage")
friendly_type="Message"
;;
esac
echo "($friendly_type) $target: $msg"
curl -sSL \
-H "Authorization: Bearer $TS3_NTFY_TOKEN" \
-d "{
\"topic\": \"$TS3_NTFY_TOPIC\",
\"message\": \"$msg\",
\"title\": \"TS3 $friendly_type\"
}" \
"$TS3_NTFY_HOST"
done
}
# Add '$' to $1 to add 'End of line' to the regex for grep
action=$(_ts_control_single_or_dmenu "$actions" "$1$")
@ -102,4 +138,9 @@ case $action in
teamspeak-query-lib events --filter=others NotifyClientMoved NotifyClientEnterView NotifyClientLeftView NotifyTextMessage NotifyClientPoke \
| jq -r --unbuffered '.message' \
| tee >(xargs -I{} notify-send "TS3 Event" "{}")
;;
"ntfy-events")
teamspeak-query-lib events --filter=others NotifyClientPoke NotifyTextMessage \
| handle_ntfy_events
;;
esac