Refactor ts-control with bashly
This commit is contained in:
		
							parent
							
								
									93ebbbd5d2
								
							
						
					
					
						commit
						7694bf365c
					
				
					 21 changed files with 217 additions and 175 deletions
				
			
		
							
								
								
									
										52
									
								
								control_src/events_ntfy_command.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								control_src/events_ntfy_command.sh
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,52 @@ | |||
| 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') | ||||
|     client_nickname=$(echo "$data" | jq -r --unbuffered '.client.client_nickname') | ||||
|      | ||||
|     echo "$data" | ||||
| 
 | ||||
|     if [ "$type" = "NotifyTextMessage" ] && [ "$mode" != "1" ]; then | ||||
|       continue # Skip all messages that are not direct messages | ||||
|     fi | ||||
|      | ||||
|     title="TS3 Event" | ||||
|     case $type in | ||||
|       "NotifyClientPoke") | ||||
|         title="TS3 Poke" | ||||
|         ;; | ||||
|       "NotifyTextMessage") | ||||
|         title="TS3 Message" | ||||
|         ;; | ||||
|     esac | ||||
|      | ||||
|     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 "$payload" \ | ||||
|   		"$TS3_NTFY_HOST" | ||||
|   done | ||||
| } | ||||
| 
 | ||||
| teamspeak-query-lib events --filter=others NotifyClientPoke NotifyTextMessage \ | ||||
|   | handle_ntfy_events | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue