Browse Source

:sparkles: 通知内容中增加流量统计, 默认不开启

Mizore 2 years ago
parent
commit
6f913a2d0f
1 changed files with 17 additions and 0 deletions
  1. 17 0
      script/util_notify.lua

+ 17 - 0
script/util_notify.lua

@@ -275,6 +275,23 @@ local function append()
         msg = msg .. "\n频段: B" .. band
     end
 
+    -- 流量统计
+    local uplinkGB, uplinkB, downlinkGB, downlinkB = mobile.dataTraffic()
+    uplinkB = uplinkGB * 1024 * 1024 * 1024 + uplinkB
+    downlinkB = downlinkGB * 1024 * 1024 * 1024 + downlinkB
+    local function formatBytes(bytes)
+        if bytes < 1024 then
+            return bytes .. "B"
+        elseif bytes < 1024 * 1024 then
+            return string.format("%.2fKB", bytes / 1024)
+        elseif bytes < 1024 * 1024 * 1024 then
+            return string.format("%.2fMB", bytes / 1024 / 1024)
+        else
+            return string.format("%.2fGB", bytes / 1024 / 1024 / 1024)
+        end
+    end
+    -- msg = msg .. "\n流量: ↑" .. formatBytes(uplinkB) .. " ↓" .. formatBytes(downlinkB)
+
     -- 位置
     local _, _, map_link = util_location.get()
     if map_link ~= "" then