diff --git a/modules/services/default.nix b/modules/services/default.nix index b19c6a3e..922dc520 100644 --- a/modules/services/default.nix +++ b/modules/services/default.nix @@ -586,9 +586,14 @@ inputs: message='xray:\n' for i in {0..${toString ((length userList) - 1)}} do - traffic_bytes=$(${xray} api stats --server=127.0.0.1:6149 \ + upload_bytes=$(${xray} api stats --server=127.0.0.1:6149 \ + -name "user>>>''${i}@xray.chn.moe>>>traffic>>>uplink" | , jq '.stat.value' | sed 's/"//g') + [ -z "$upload_bytes" ] && upload_bytes=0 + download_bytes=$(${xray} api stats --server=127.0.0.1:6149 \ -name "user>>>''${i}@xray.chn.moe>>>traffic>>>downlink" | , jq '.stat.value' | sed 's/"//g') - message=$message"$i"'\t'$(echo | ${awk} "{printf \"%.3f\",0''${traffic_bytes}/1073741824}")'G\n' + [ -z "$download_bytes" ] && download_bytes=0 + traffic_gb=$(echo | ${awk} "{printf \"%.3f\",(''${upload_bytes}+''${download_bytes})/1073741824}") + message="$message$i"'\t'"''${traffic_gb}"'G\n' done ${curl} -X POST -H 'Content-Type: application/json' \ -d "{\"chat_id\": \"$(cat ${chat})\", \"text\": \"$message\"}" \