This commit is contained in:
		
							parent
							
								
									915c2ccbbf
								
							
						
					
					
						commit
						b827471e6d
					
				
					 2 changed files with 43 additions and 1 deletions
				
			
		
							
								
								
									
										43
									
								
								ts-control
									
										
									
									
									
								
							
							
						
						
									
										43
									
								
								ts-control
									
										
									
									
									
								
							|  | @ -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 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue