better null handling
This commit is contained in:
		
							
								
								
									
										36
									
								
								bot.sh
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								bot.sh
									
									
									
									
									
								
							@@ -63,11 +63,11 @@ ookla_bytes_received=$(jq '.bytes_received' "$speedtest_ookla")
 | 
				
			|||||||
ookla_bytes_sent=$(jq '.bytes_sent' "$speedtest_ookla")
 | 
					ookla_bytes_sent=$(jq '.bytes_sent' "$speedtest_ookla")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# replacing null values
 | 
					# replacing null values
 | 
				
			||||||
[ "$ookla_ping" = "" ] && ookla_ping="-" || ookla_ping=$ookla_ping
 | 
					[ -z "$ookla_ping" ] && ookla_ping="-"
 | 
				
			||||||
[ "$ookla_download" = "" ] && ookla_download=0 || ookla_download=$ookla_download
 | 
					[ -z "$ookla_download" ] && ookla_download=0
 | 
				
			||||||
[ "$ookla_upload" = "" ] && ookla_upload=0 || ookla_upload=$ookla_upload
 | 
					[ -z "$ookla_upload" ] && ookla_upload=0
 | 
				
			||||||
[ "$ookla_bytes_received" = "" ] && ookla_bytes_received=0 || ookla_bytes_received=$ookla_bytes_received
 | 
					[ -z "$ookla_bytes_received" ] && ookla_bytes_received=0
 | 
				
			||||||
[ "$ookla_bytes_sent" = "" ] && ookla_bytes_sent=0 || ookla_bytes_sent=$ookla_bytes_sent
 | 
					[ -z "$ookla_bytes_sent" ] && ookla_bytes_sent=0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Converting to human readable units
 | 
					# Converting to human readable units
 | 
				
			||||||
ookla_download_mbps=$(echo "scale=2; $ookla_download / 1000000" | bc)
 | 
					ookla_download_mbps=$(echo "scale=2; $ookla_download / 1000000" | bc)
 | 
				
			||||||
@@ -89,11 +89,11 @@ libre_download=$(jq '.[0].download' "$speedtest_libre")
 | 
				
			|||||||
libre_server_name=$(jq -r '.[0].server.name' "$speedtest_libre")
 | 
					libre_server_name=$(jq -r '.[0].server.name' "$speedtest_libre")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# replacing null values
 | 
					# replacing null values
 | 
				
			||||||
[ "$libre_ping" = "null" ] && libre_ping="-" || libre_ping=$libre_ping
 | 
					[ "$libre_ping" = "null" ] || [ -z "$libre_ping" ] && libre_ping="-"
 | 
				
			||||||
[ "$libre_download" = "null" ] && libre_download=0 || libre_download=$libre_download
 | 
					[ "$libre_download" = "null" ] || [ -z "$libre_download" ] && libre_download=0
 | 
				
			||||||
[ "$libre_upload" = "null" ] && libre_upload=0 || libre_upload=$libre_upload
 | 
					[ "$libre_upload" = "null" ] || [ -z "$libre_upload" ] && libre_upload=0
 | 
				
			||||||
[ "$libre_bytes_received" = "null" ] && libre_bytes_received=0 || libre_bytes_received=$libre_bytes_received
 | 
					[ "$libre_bytes_received" = "null" ] || [ -z "$libre_bytes_received" ] && libre_bytes_received=0
 | 
				
			||||||
[ "$libre_bytes_sent" = "null" ] && libre_bytes_sent=0 || libre_bytes_sent=$libre_bytes_sent
 | 
					[ "$libre_bytes_sent" = "null" ] || [ -z "$libre_bytes_sent" ] && libre_bytes_sent=0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Converting to human readable units and replacing null values with 0
 | 
					# Converting to human readable units and replacing null values with 0
 | 
				
			||||||
libre_bytes_sent_mb=$(echo "scale=2; $libre_bytes_sent / 1048576" | bc)
 | 
					libre_bytes_sent_mb=$(echo "scale=2; $libre_bytes_sent / 1048576" | bc)
 | 
				
			||||||
@@ -109,11 +109,11 @@ fast_latency=$(jq '.latency' "$speedtest_fast")
 | 
				
			|||||||
fast_downloaded=$(jq '.downloaded' "$speedtest_fast")
 | 
					fast_downloaded=$(jq '.downloaded' "$speedtest_fast")
 | 
				
			||||||
fast_uploaded=$(jq '.uploaded' "$speedtest_fast")
 | 
					fast_uploaded=$(jq '.uploaded' "$speedtest_fast")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[ "$fast_latency" = "" ] && fast_latency="-" || fast_latency=$fast_latency
 | 
					[ -z "$fast_latency" ] && fast_latency="-"
 | 
				
			||||||
[ "$fast_download_speed" = "" ] && fast_download_speed=0 || fast_download_speed=$fast_download_speed
 | 
					[ -z "$fast_download_speed" ] && fast_download_speed=0
 | 
				
			||||||
[ "$fast_upload_speed" = "" ] && fast_upload_speed=0 || fast_upload_speed=$fast_upload_speed
 | 
					[ -z "$fast_upload_speed" ] && fast_upload_speed=0
 | 
				
			||||||
[ "$fast_downloaded" = "" ] && fast_downloaded=0 || fast_downloaded=$fast_downloaded
 | 
					[ -z "$fast_downloaded" ] && fast_downloaded=0
 | 
				
			||||||
[ "fast_uploaded" = "" ] && fast_uploaded=0 || fast_uploaded=$fast_uploaded
 | 
					[ -z "$fast_uploaded" ] && fast_uploaded=0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fast_total=$(echo $fast_downloaded+$fast_uploaded | bc)
 | 
					fast_total=$(echo $fast_downloaded+$fast_uploaded | bc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -128,9 +128,9 @@ echo Speedtests complete
 | 
				
			|||||||
valorant_ping=$(latency dynamodb.ap-southeast-1.amazonaws.com)
 | 
					valorant_ping=$(latency dynamodb.ap-southeast-1.amazonaws.com)
 | 
				
			||||||
cfdns_ping=$(latency 1.1.1.1)
 | 
					cfdns_ping=$(latency 1.1.1.1)
 | 
				
			||||||
googledns_ping=$(latency 8.8.8.8)
 | 
					googledns_ping=$(latency 8.8.8.8)
 | 
				
			||||||
[ "$valorant_ping" = "" ] && valorant_ping="-" || valorant_ping=$valorant_ping
 | 
					[ -z "$valorant_ping" ] && valorant_ping="-"
 | 
				
			||||||
[ "$cfdns_ping" = "" ] && cfdns_ping="-" || cfdns_ping=$cfdns_ping
 | 
					[ -z "$cfdns_ping" ] && cfdns_ping="-"
 | 
				
			||||||
[ "$googledns_ping" = "" ] && googledns_ping="-" || googledns_ping=$valorant_ping
 | 
					[ -z "$googledns_ping" ] && googledns_ping="-"
 | 
				
			||||||
#################################################################################
 | 
					#################################################################################
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#################################################################################
 | 
					#################################################################################
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user