|
@@ -2,15 +2,12 @@ package main
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
- "fmt"
|
|
|
- "io"
|
|
|
"log"
|
|
|
- "net/http"
|
|
|
- "net/url"
|
|
|
"os"
|
|
|
"strings"
|
|
|
|
|
|
"github.com/JamZYM/golagrange/api"
|
|
|
+ "github.com/JamZYM/golagrange/function"
|
|
|
"github.com/joho/godotenv"
|
|
|
)
|
|
|
|
|
@@ -18,58 +15,11 @@ func msgProccess(msg map[string]interface{}, connBot api.WsBot) {
|
|
|
// fmt.Println(msg)
|
|
|
if msg["message_type"].(string) == "private" {
|
|
|
user_id := int(msg["user_id"].(float64))
|
|
|
- // println(user_id)
|
|
|
- // fmt.Println(msg["message"].([]interface{})[0].(map[string]interface{})["type"].(string))
|
|
|
- if msg["message"].([]interface{})[0].(map[string]interface{})["type"].(string) == "text" {
|
|
|
- if strings.HasPrefix(msg["message"].([]interface{})[0].(map[string]interface{})["data"].(map[string]interface{})["text"].(string), "/bvdl ") {
|
|
|
- bv := strings.Replace(msg["message"].([]interface{})[0].(map[string]interface{})["data"].(map[string]interface{})["text"].(string), "/bvdl ", "", 1)
|
|
|
- // println(bv)
|
|
|
- // println(os.Getenv("HOST") + ":" + os.Getenv("BVDLPORT") + "/api/info")
|
|
|
- // info, err := http.Post("http://"+os.Getenv("HOST")+":"+os.Getenv("BVDLPORT")+"/api/info", "application/json",
|
|
|
- // bytes.NewBuffer([]byte(fmt.Sprintf(`
|
|
|
- // {
|
|
|
- // "bv":%s
|
|
|
- // }
|
|
|
- // `, bv))))
|
|
|
- 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)
|
|
|
- // fmt.Println(string(data))
|
|
|
- title := jsondata["videos"].(map[string]interface{})["1"].(map[string]interface{})["title"].(string)
|
|
|
- // result, err := http.Post("http://"+os.Getenv("HOST")+":"+os.Getenv("BVDLPORT")+"/api/download", "application/json",
|
|
|
- // bytes.NewBuffer([]byte(fmt.Sprintf(`
|
|
|
- // {
|
|
|
- // "bv":%s;
|
|
|
- // "title":"%s"
|
|
|
- // }
|
|
|
- // `, bv, title))))
|
|
|
- fmt.Println("http://" + os.Getenv("HOST") + ":" + os.Getenv("BVDLPORT") + "/api/download?bv=" + bv + "&title=" + title)
|
|
|
- // result, err := http.PostForm("http://"+os.Getenv("HOST")+":"+os.Getenv("BVDLPORT")+"/api/download?bv="+bv+"&title="+title, nil)
|
|
|
-
|
|
|
- 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)
|
|
|
-
|
|
|
- // url := "http://" + os.Getenv("HOST") + ":" + os.Getenv("BVDLPORT") + "/api/download"
|
|
|
- // body := fmt.Sprintf(`{"bv":"%s","title":"%s"}`, bv, title)
|
|
|
- // result, err := http.Post(url, "application/json", strings.NewReader(body))
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- connBot.Send_private_msg(user_id, "下载失败")
|
|
|
- fmt.Println(err)
|
|
|
- } else {
|
|
|
- fmt.Print(result.Body)
|
|
|
- connBot.Send_private_msg(user_id, title)
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ msg_type := msg["message"].([]interface{})[0].(map[string]interface{})["type"].(string)
|
|
|
+ if msg_type == "text" {
|
|
|
+ msg_text := msg["message"].([]interface{})[0].(map[string]interface{})["data"].(map[string]interface{})["text"].(string)
|
|
|
+ if strings.HasPrefix(msg_text, "/bvdl ") {
|
|
|
+ function.Func_bvdl(msg_text, connBot, user_id)
|
|
|
}
|
|
|
}
|
|
|
}
|