mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-06-04 21:01:17 +08:00
parent
a6410df3cf
commit
6b0971170e
@ -1,4 +1,5 @@
|
||||
const { log, hasEnv, shuffle, getRandomOne, delay, try_for_each } = require('../utils');
|
||||
const { send } = require('../net/http');
|
||||
const bili = require('../net/bili');
|
||||
const { sendNotify } = require('../helper/notify');
|
||||
const event_bus = require('../helper/event_bus');
|
||||
@ -24,6 +25,7 @@ class Monitor extends Searcher {
|
||||
['UIDs', this.getLotteryInfoByUID.bind(this)],
|
||||
['TAGs', this.getLotteryInfoByTag.bind(this)],
|
||||
['Articles', this.getLotteryInfoByArticle.bind(this)],
|
||||
['APIs', this.getLotteryInfoByAPI.bind(this)]
|
||||
]);
|
||||
}
|
||||
/**
|
||||
@ -172,7 +174,7 @@ class Monitor extends Searcher {
|
||||
async filterLotteryInfo() {
|
||||
const { lottery_param, LotteryInfoMap, attentionList } = this;
|
||||
/**
|
||||
* @type {import("./searcher").LotteryInfo}
|
||||
* @type {import("./searcher").LotteryInfo[]}
|
||||
*/
|
||||
let protoLotteryInfo = await LotteryInfoMap.get(lottery_param[0])(lottery_param[1]);
|
||||
|
||||
@ -186,7 +188,7 @@ class Monitor extends Searcher {
|
||||
/** 所有抽奖信息 */
|
||||
let alllotteryinfo = [];
|
||||
const
|
||||
{ key_words, model, chatmodel, max_create_time, is_imitator, only_followed, at_users, blockword, blacklist } = config,
|
||||
{ set_lottery_info_url, key_words, model, chatmodel, max_create_time, is_imitator, only_followed, at_users, blockword, blacklist } = config,
|
||||
now_ts = Date.now() / 1000;
|
||||
|
||||
/**
|
||||
@ -203,6 +205,28 @@ class Monitor extends Searcher {
|
||||
return true
|
||||
});
|
||||
|
||||
if (lottery_param[0] !== "APIs" && set_lottery_info_url) {
|
||||
log.info("上传抽奖信息", "开始")
|
||||
await new Promise((resolve) => {
|
||||
send({
|
||||
url: set_lottery_info_url,
|
||||
method: "POST",
|
||||
headers: {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
contents: protoLotteryInfo,
|
||||
success: ({ body }) => {
|
||||
log.info("发送获取到的动态数据", body)
|
||||
resolve()
|
||||
},
|
||||
failure: err => {
|
||||
log.error("发送获取到的动态数据", err)
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/* 检查动态是否满足要求 */
|
||||
await try_for_each(protoLotteryInfo, async function ({
|
||||
lottery_info_type, is_liked,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
const utils = require('../utils');
|
||||
const bili = require('../net/bili');
|
||||
const { send } = require("../net/http");
|
||||
const config = require("../data/config");
|
||||
|
||||
const { log } = utils
|
||||
@ -406,6 +407,41 @@ class Searcher {
|
||||
|
||||
return fomatdata
|
||||
}
|
||||
|
||||
/**
|
||||
* 从特定格式的api响应数据中获取抽奖信息
|
||||
* @param {string} api
|
||||
* @returns {Promise<LotteryInfo[] | null>}
|
||||
*/
|
||||
getLotteryInfoByAPI(api) {
|
||||
return new Promise((resolve) => {
|
||||
if (api) {
|
||||
log.info('获取动态', `开始获取链接(${api})中的抽奖信息`)
|
||||
send({
|
||||
url: api,
|
||||
config: {
|
||||
redirect: true
|
||||
},
|
||||
method: 'GET',
|
||||
success: ({ body }) => {
|
||||
if (body.err_msg) {
|
||||
log.error("从API响应数据中获取抽奖信息", body.err_msg)
|
||||
resolve(null)
|
||||
} else {
|
||||
resolve(JSON.parse(body).lottery_info)
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
log.error("从API响应数据中获取抽奖信息", err)
|
||||
resolve(null)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
log.warn('获取动态', `链接为空`)
|
||||
resolve(null)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -16,6 +16,34 @@ const config = {
|
||||
*/
|
||||
TAGs: [],
|
||||
|
||||
/**
|
||||
* 从API接口中获取抽奖信息
|
||||
* @typedef {object} LotteryInfo
|
||||
* @property {string} lottery_info_type
|
||||
* @property {number} create_time
|
||||
* @property {boolean} is_liked
|
||||
* @property {number[]} uids `[uid,ouid]`
|
||||
* @property {string} uname
|
||||
* @property {Array<{}>} ctrl
|
||||
* @property {string} dyid
|
||||
* @property {string} rid
|
||||
* @property {string} des
|
||||
* @property {number} type
|
||||
* @property {boolean} hasOfficialLottery 是否官方
|
||||
* @typedef RespondBody
|
||||
* @property {string} err_msg 错误信息
|
||||
* @property {LotteryInfo[]} lottery_info
|
||||
* API传回数据类型 {RespondBody}
|
||||
* 获取抽奖信息的链接字符串
|
||||
*/
|
||||
APIs: [],
|
||||
|
||||
/**
|
||||
* API发送数据类型 {LotteryInfo[]}
|
||||
* 上传抽奖信息的链接字符串
|
||||
*/
|
||||
set_lottery_info_url: "",
|
||||
|
||||
/**
|
||||
* 动态中的关键词(表示须同时满足以下条件)
|
||||
* 符合js正则表达式的字符串
|
||||
|
||||
@ -28,11 +28,12 @@ let global_var = {
|
||||
this.set(key_map.get(_item[0]), _item[1]);
|
||||
});
|
||||
|
||||
const { UIDs = [], TAGs = [], Articles = [] } = config;
|
||||
const { UIDs = [], TAGs = [], Articles = [], APIs = [] } = config;
|
||||
this.set('Lottery', [
|
||||
...UIDs.map(it => ['UIDs', it]),
|
||||
...TAGs.map(it => ['TAGs', it]),
|
||||
...Articles.map(it => ['Articles', it])
|
||||
...Articles.map(it => ['Articles', it]),
|
||||
...APIs.map(it => ['APIs', it])
|
||||
]);
|
||||
this.set('remoteconfig', await getRemoteConfig());
|
||||
}
|
||||
|
||||
@ -69,7 +69,8 @@ function send(detail) {
|
||||
let options = {
|
||||
timeout,
|
||||
method: method.toUpperCase(),
|
||||
host: thisURL.host,
|
||||
hostname: thisURL.hostname,
|
||||
port: thisURL.port,
|
||||
path: thisURL.pathname + thisURL.search + thisURL.hash,
|
||||
headers,
|
||||
};
|
||||
|
||||
@ -28,6 +28,34 @@ module.exports = Object.freeze({
|
||||
'抽奖',
|
||||
],
|
||||
|
||||
/**
|
||||
* 从API接口中获取抽奖信息
|
||||
* @typedef {object} LotteryInfo
|
||||
* @property {string} lottery_info_type
|
||||
* @property {number} create_time
|
||||
* @property {boolean} is_liked
|
||||
* @property {number[]} uids `[uid,ouid]`
|
||||
* @property {string} uname
|
||||
* @property {Array<{}>} ctrl
|
||||
* @property {string} dyid
|
||||
* @property {string} rid
|
||||
* @property {string} des
|
||||
* @property {number} type
|
||||
* @property {boolean} hasOfficialLottery 是否官方
|
||||
* @typedef RespondBody
|
||||
* @property {string} err_msg 错误信息
|
||||
* @property {LotteryInfo[]} lottery_info
|
||||
* API传回数据类型 {RespondBody}
|
||||
* 获取抽奖信息的链接字符串
|
||||
*/
|
||||
APIs: [],
|
||||
|
||||
/**
|
||||
* API发送数据类型 {LotteryInfo[]}
|
||||
* 上传抽奖信息的链接字符串
|
||||
*/
|
||||
set_lottery_info_url: "",
|
||||
|
||||
/**
|
||||
* 动态中的关键词(表示须同时满足以下条件)
|
||||
* 符合js正则表达式的字符串
|
||||
|
||||
Loading…
Reference in New Issue
Block a user