MCPcopy Create free account
hub / github.com/FloatTech/AnimeAPI / Shindanmaker

Function Shindanmaker

shindanmaker/shindanmaker.go:24–87  ·  view source on GitHub ↗

Shindanmaker 基于 https://shindanmaker.com 的 API id 是的不同页面的 url 里的数字, 例如 https://shindanmaker.com/a/162207 里的 162207 name 是要被测定的人的名字, 影响测定结果

(id int64, name string)

Source from the content-addressed store, hash-verified

22// id 是的不同页面的 url 里的数字, 例如 https://shindanmaker.com/a/162207 里的 162207
23// name 是要被测定的人的名字, 影响测定结果
24func Shindanmaker(id int64, name string) (string, error) {
25 url := fmt.Sprintf("https://shindanmaker.com/%d", id)
26 // seed 使每一天的结果都不同
27 now := time.Now()
28 seed := fmt.Sprintf("%d%d%d", now.Year(), now.Month(), now.Day())
29 name += seed
30
31 // 刷新 token 和 cookie or 获取shindan_token
32 shindantoken, err := refresh(url)
33 if err != nil {
34 return "", err
35 }
36
37 // 组装参数
38 client := &http.Client{}
39 payload := &bytes.Buffer{}
40 writer := multipart.NewWriter(payload)
41 _ = writer.WriteField("_token", token)
42 _ = writer.WriteField("shindanName", name)
43 _ = writer.WriteField("hiddenName", "名無しのR")
44 _ = writer.WriteField("type", "name")
45 _ = writer.WriteField("shindan_token", shindantoken)
46 _ = writer.Close()
47 // 发送请求
48 req, _ := http.NewRequest("POST", url, payload)
49 req.Header.Add("Cookie", cookie)
50 req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36")
51 req.Header.Set("Content-Type", writer.FormDataContentType())
52 resp, err := client.Do(req)
53 if err != nil {
54 return "", err
55 }
56 defer resp.Body.Close()
57 // 解析XPATH
58 doc, err := xpath.Parse(resp.Body)
59 if err != nil {
60 return "", err
61 }
62 // 取出每个返回的结果
63 list := xpath.Find(doc, `//*[@id="shindanResult"]`)
64 if len(list) == 0 {
65 token = ""
66 cookie = ""
67 return "", errors.New("无法查找到结果, 请稍后再试")
68 }
69 var output = []string{}
70 for child := list[0].FirstChild; child != nil; child = child.NextSibling {
71 text := xpath.InnerText(child)
72 switch {
73 case text != "":
74 output = append(output, text)
75 case child.Data == "img":
76 img := child.Attr[1].Val
77 if strings.Contains(img, "http") {
78 output = append(output, "[CQ:image,file="+img[strings.Index(img, ",")+1:]+"]")
79 } else {
80 output = append(output, "[CQ:image,file=base64://"+img[strings.Index(img, ",")+1:]+"]")
81 }

Callers

nothing calls this directly

Calls 2

refreshFunction · 0.85
SetMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…