Compare commits

...

2 commits

Author SHA1 Message Date
3463907670
Add response option to ntfy 2024-10-27 18:55:08 +01:00
fb1e41ddc4
Fix some issues 2024-10-01 00:20:08 +02:00
4 changed files with 34 additions and 24 deletions

View file

@ -16,17 +16,9 @@ jobs:
source "$HOME/.cargo/env"
cargo build --release
shell: bash
- uses: https://code.forgejo.org/actions/upload-artifact@v3
with:
name: teamspeak-query-lib
path: ${{ github.workspace }}/target/release/teamspeak-query-lib
- uses: https://code.forgejo.org/actions/download-artifact@v3
with:
name: teamspeak-query-lib
path: /tmp/artifacts
shell: bash
- id: copy-ts-control-artificat
run: |
cp ${{ github.workspace }}/target/release/teamspeak-query-lib /tmp/artifacts
cp ${{ github.workspace }}/ts-control /tmp/artifacts
shell: bash
- uses: https://code.forgejo.org/actions/forgejo-release@v1

2
Cargo.lock generated
View file

@ -182,7 +182,7 @@ dependencies = [
[[package]]
name = "teamspeak-query-lib"
version = "0.1.5"
version = "0.1.6"
dependencies = [
"clap",
"serde",

View file

@ -1,6 +1,6 @@
[package]
name = "teamspeak-query-lib"
version = "0.1.5"
version = "0.1.6"
edition = "2021"
[dependencies]

View file

@ -46,12 +46,16 @@ _ts_control_fetch() {
}
_ts_control_single_or_dmenu() {
options=$(echo "$1" | grep "$2")
filter="$2"
if [ "$filter" == "^$" ]; then
filter=""
fi
options=$(echo "$1" | grep "$filter")
count=$(echo "$options" | wc -l)
if [ "$count" -eq 1 ]; then
echo "$options"
else
echo "$options" | $DMENU
echo "$1" | $DMENU
fi
}
@ -60,6 +64,7 @@ handle_ntfy_events() {
msg=$(echo "$data" | jq -r --unbuffered '.message')
type=$(echo "$data" | jq -r --unbuffered '.type')
mode=$(echo "$data" | jq -r --unbuffered '.params.targetmode')
client_nickname=$(echo "$data" | jq -r --unbuffered '.client.client_nickname')
echo "$data"
@ -67,31 +72,44 @@ handle_ntfy_events() {
continue # Skip all messages that are not direct messages
fi
friendly_type="Event"
title="TS3 Event"
case $type in
"NotifyClientPoke")
friendly_type="Poke"
title="TS3 Poke"
;;
"NotifyTextMessage")
friendly_type="Message"
title="TS3 Message"
;;
esac
echo "($friendly_type) $target: $msg"
echo "($title) $target: $msg"
payload=$(jq -n \
--arg topic "$TS3_NTFY_TOPIC" \
--arg webhook "$TS3_NTFY_WEBHOOK&client=$client_nickname" \
--arg msg "$msg" \
--arg type "$title" \
'{
topic: $topic,
message: $msg,
title: $type,
actions: [{
action: "http",
label: "TS response",
method: "POST",
url: $webhook,
clear: true
}]
}')
curl -sSL \
-H "Authorization: Bearer $TS3_NTFY_TOKEN" \
-d "{
\"topic\": \"$TS3_NTFY_TOPIC\",
\"message\": \"$msg\",
\"title\": \"TS3 $friendly_type\"
}" \
-d "$payload" \
"$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$")
action=$(_ts_control_single_or_dmenu "$actions" "^$1$")
case $action in
"quick")