MCPcopy Create free account
hub / github.com/Semporia/Scripts / getRandomCode

Function getRandomCode

jd_api_test.js:37–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35})()
36
37function getRandomCode() {
38 return new Promise(resolve => {
39 let cars = ['bean', 'farm', 'health', 'jxfactory', 'pet'];
40 let db = cars[Math.floor(Math.random() * 5)]
41 let num = Math.floor(Math.random() * 20 + 5)
42 console.log(`本次随机选择${db}获取${num}个随机助力码`)
43 $.get({url: `http://www.helpu.cf/jdcodes/getcode.php?type=${db}&num=${num}`, timeout: 3000}, (err, resp, data) => {
44 try {
45 if (data) {
46 data = JSON.parse(data)
47 console.log(JSON.stringify(data, null, ' '))
48 if (data.code === 200) {
49 if (data.data.length === num) {
50 console.log(`成功获取${num}个`)
51 }
52 }
53 } else {
54 // $.msg("JDHelloWorld", "获取助力池失败!", `请手动访问http://api.sharecode.ga/api/version`, {"open-url": "http://api.sharecode.ga/api/version"})
55 $.msg("JDHelloWorld", "获取助力池失败!", '请检查网络!')
56 if ($.isNode()) {
57 const notify = require('./sendNotify')
58 notify.sendNotify("JDHelloWorld", `获取助力池失败!请检查网络!`)
59 }
60 $.logErr("获取助力池失败!请检查网络!\n")
61 }
62 } catch (e) {
63 $.msg("JDHelloWorld", "获取助力池失败!", '请检查网络!')
64 if ($.isNode()) {
65 const notify = require('./sendNotify')
66 notify.sendNotify("JDHelloWorld", `获取助力池失败!请检查网络!`)
67 }
68 $.logErr("获取助力池失败!请检查网络!\n")
69 } finally {
70 resolve()
71 }
72 })
73 })
74}
75
76function version() {
77 return new Promise(resolve => {

Callers 1

jd_api_test.jsFile · 0.70

Calls 5

logMethod · 0.45
getMethod · 0.45
msgMethod · 0.45
isNodeMethod · 0.45
logErrMethod · 0.45

Tested by

no test coverage detected