package function import ( "encoding/json" "fmt" "io" "net/http" "net/url" "os" "strings" "time" "github.com/JamZYM/golagrange/api" "github.com/shirou/gopsutil/v4/cpu" "github.com/shirou/gopsutil/v4/disk" "github.com/shirou/gopsutil/v4/mem" ) func Func_bvdl(msg_text string, connBot api.WsBot, user_id int) { bv := strings.Replace(msg_text, "/bvdl ", "", 1) info, err := http.Post("http://"+os.Getenv("HOST")+":"+os.Getenv("BVDLPORT")+"/api/info?bv="+bv, "application/json", nil) if err != nil { connBot.Send_private_msg(user_id, "请求失败") fmt.Println(err) } else { defer info.Body.Close() var jsondata map[string]interface{} data, _ := io.ReadAll(info.Body) json.Unmarshal(data, &jsondata) title := jsondata["videos"].(map[string]interface{})["1"].(map[string]interface{})["title"].(string) fmt.Println("http://" + os.Getenv("HOST") + ":" + os.Getenv("BVDLPORT") + "/api/download?bv=" + bv + "&title=" + title) qbv := url.QueryEscape(bv) qtitle := url.QueryEscape(title) geturl := "http://" + os.Getenv("HOST") + ":" + os.Getenv("BVDLPORT") + "/api/download?bv=" + qbv + "&title=" + qtitle result, err := http.Get(geturl) if err != nil { connBot.Send_private_msg(user_id, "下载失败") fmt.Println(err) } else { fmt.Print(result.Body) connBot.Send_private_msg(user_id, title) } } } func Func_serverStatus(connBot api.WsBot, user_id int) { _mem, err := mem.VirtualMemory() _cpu, _ := cpu.Percent(time.Second, false) _disk, _ := disk.Usage("/") // _net, _ := net.IOCounters(true) // response_text := fmt.Sprintf("内存: %v%%,\nCPU:%v%%,\n磁盘:%v%%", fmt.Sprintf("%.1f", _mem.UsedPercent), fmt.Sprintf("%.1f", _cpu[0]), fmt.Sprintf("%.1f", _disk.UsedPercent)) response_text := fmt.Sprintf("内存: %v%%,CPU:%v%%,磁盘:%v%%", fmt.Sprintf("%.1f", _mem.UsedPercent), fmt.Sprintf("%.1f", _cpu[0]), fmt.Sprintf("%.1f", _disk.UsedPercent)) println(response_text) if err != nil { connBot.Send_private_msg(user_id, "服务器异常") } else { connBot.Send_private_msg(user_id, "服务器状态:") connBot.Send_private_msg(user_id, response_text) } }