mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-07-22 21:13:47 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fdee933ca4 | ||
|
|
53ae976caf | ||
|
|
de88467c03 | ||
|
|
6bbbfbb521 | ||
|
|
e7ab5790cd | ||
|
|
6c08cee944 | ||
|
|
236fcb6284 | ||
|
|
8bc053b352 | ||
|
|
f5a8ad75d2 | ||
|
|
cbce4b113d | ||
|
|
a63456bd29 |
@@ -76,12 +76,13 @@ Chrome浏览器:
|
||||
lottery.exe 可执行文件
|
||||
my_config.js 自定义设置文件
|
||||
```
|
||||
2. `env.js`中填入`COOKIE`和推送参数
|
||||
3. `my_config.js`中自定义设置
|
||||
4. 在当前目录下打开终端运行可执行文件`lottery`
|
||||
5. 输入`lottery start`启动抽奖|`lottery check`检测中奖|`lottery clear`清理动态
|
||||
2. 用记事本或其他编辑器修改`env.js`和`my_config.js`文件(右键选择用记事本打开)
|
||||
3. 在`env.js`中填入`COOKIE`和推送参数
|
||||
4. 在`my_config.js`中自定义设置
|
||||
5. 在当前目录下**打开终端**运行可执行文件`lottery`(勿直接点击`lottery`)
|
||||
6. 键入`lottery start`启动抽奖|`lottery check`检测中奖|`lottery clear`清理动态
|
||||
> 或者新建文本文档写入`lottery start`然后更改扩展名为.bat点击运行
|
||||
6. 运行截图
|
||||
7. 运行截图
|
||||

|
||||
|
||||
#### 以源码方式运行
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 210 KiB After Width: | Height: | Size: 123 KiB |
+10
-6
@@ -27,6 +27,16 @@ const account_parm = {
|
||||
|
||||
/**
|
||||
* 为防止环境变量过长, 请将多账号填在此处
|
||||
* @example
|
||||
* ```js
|
||||
* {
|
||||
* COOKIE: "",
|
||||
* NUMBER: 2,
|
||||
* CLEAR: true,
|
||||
* WAIT: 60 * 1000,
|
||||
* },
|
||||
* ```
|
||||
* 请按照以上格式将参数依次填写在下方
|
||||
*/
|
||||
const multiple_account_parm = [
|
||||
{
|
||||
@@ -35,12 +45,6 @@ const multiple_account_parm = [
|
||||
CLEAR: true,
|
||||
WAIT: 60 * 1000,
|
||||
},
|
||||
// {
|
||||
// COOKIE: "",
|
||||
// NUMBER: 2,
|
||||
// CLEAR: true,
|
||||
// WAIT: 60 * 1000,
|
||||
// },
|
||||
]
|
||||
|
||||
/**
|
||||
|
||||
+65
-8
@@ -74,7 +74,6 @@ const BiliAPI = {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: 'https://api.bilibili.com/x/msgfeed/unread',
|
||||
hasCookies: true,
|
||||
success: responseText => {
|
||||
let res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
@@ -148,7 +147,6 @@ const BiliAPI = {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: 'https://api.vc.bilibili.com/session_svr/v1/session_svr/single_unread',
|
||||
hasCookies: true,
|
||||
success: responseText => {
|
||||
let res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
@@ -213,6 +211,24 @@ const BiliAPI = {
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 获取一个动态的细节
|
||||
* @param {string} dyid
|
||||
* @return {Promise<string>}
|
||||
*/
|
||||
getOneDynamicByDyid(dyid) {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/get_dynamic_detail',
|
||||
queryStringsObj: {
|
||||
dynamic_id: dyid
|
||||
},
|
||||
success: responseText => {
|
||||
resolve(responseText)
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 获取一组动态的信息
|
||||
* @param {number} UID
|
||||
@@ -254,7 +270,6 @@ const BiliAPI = {
|
||||
queryStringsObj: {
|
||||
tag_name: tagename
|
||||
},
|
||||
hasCookies: false,
|
||||
success: responseText => {
|
||||
const res = strToJson(responseText);
|
||||
if (res.code !== 0) {
|
||||
@@ -306,6 +321,49 @@ const BiliAPI = {
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 搜索专栏
|
||||
* @param {string} keyword
|
||||
* @return {Promise<Array<number>>}
|
||||
*/
|
||||
searchArticlesByKeyword(keyword) {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: 'https://api.bilibili.com/x/web-interface/search/type',
|
||||
queryStringsObj: {
|
||||
keyword,
|
||||
page: 1,
|
||||
order: 'pubdate',
|
||||
search_type: 'article'
|
||||
},
|
||||
success: responseText => {
|
||||
const res = JSON.parse(responseText);
|
||||
if (res.code === 0) {
|
||||
log.info('搜索专栏', '成功 关键词: ' + keyword)
|
||||
resolve(res.data.result.map(it => it.id))
|
||||
} else {
|
||||
log.error('搜索专栏', '失败 原因:\n' + responseText)
|
||||
resolve([])
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 获取专栏内容
|
||||
* @param {number} cv
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
getOneArticleByCv(cv) {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: `https://www.bilibili.com/read/cv${cv}`,
|
||||
success: responseText => {
|
||||
resolve(responseText)
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 获取粉丝数
|
||||
* @param {number} uid
|
||||
@@ -365,7 +423,6 @@ const BiliAPI = {
|
||||
queryStringsObj: {
|
||||
dynamic_id: dyid
|
||||
},
|
||||
hasCookies: false,
|
||||
success: responseText => {
|
||||
const res = strToJson(responseText);
|
||||
/(?<=_prize_cmt":").*(?=")/.exec();
|
||||
@@ -525,10 +582,10 @@ const BiliAPI = {
|
||||
success: responseText => {
|
||||
const res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
log.info('自动取关', '取关成功');
|
||||
log.info('自动取关', `取关成功(${uid})`);
|
||||
resolve(true)
|
||||
} else {
|
||||
log.error('自动取关', `取关失败\n${responseText}`);
|
||||
log.error('自动取关', `取关失败(${uid})\n${responseText}`);
|
||||
resolve(false)
|
||||
}
|
||||
}
|
||||
@@ -665,10 +722,10 @@ const BiliAPI = {
|
||||
retry: false,
|
||||
success: responseText => {
|
||||
if (/^{"code":0/.test(responseText)) {
|
||||
log.info('删除动态', '成功删除一条动态');
|
||||
log.info('删除动态', `成功删除一条动态(${dyid})`);
|
||||
resolve(true);
|
||||
} else {
|
||||
log.error('删除动态', `删除动态失败\n${responseText}`);
|
||||
log.error('删除动态', `删除动态失败(${dyid})\n${responseText}`);
|
||||
resolve(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,157 +0,0 @@
|
||||
const { createReadStream, createWriteStream } = require('fs')
|
||||
const unzip = require('unzipper');
|
||||
const { strToJson, tooltip } = require("./Util")
|
||||
const { HttpRequest } = require("./HttpRequest")
|
||||
|
||||
const { GITHUB_REPOSITORY } = process.env;
|
||||
|
||||
|
||||
const GihubAPI = {
|
||||
/**
|
||||
* 列出第一个构件
|
||||
* @returns {Promise<{id: number, size_in_bytes: number}>}
|
||||
*/
|
||||
listArtifacts() {
|
||||
return new Promise((resolve) => {
|
||||
HttpRequest({
|
||||
method: 'GET',
|
||||
url: `https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/artifacts`,
|
||||
config: {
|
||||
retry: false
|
||||
},
|
||||
query: {
|
||||
page: 1,
|
||||
per_page: 5
|
||||
},
|
||||
headers: {
|
||||
Accept: 'application/json, text/plain, */*',
|
||||
},
|
||||
success: res => {
|
||||
const data = strToJson(res.body);
|
||||
if (data.total_count) {
|
||||
resolve(data.artifacts[0])
|
||||
} else {
|
||||
resolve({})
|
||||
tooltip.log('之前无构件');
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log(err);
|
||||
resolve({})
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 下载构件
|
||||
* @param {number} id
|
||||
* @returns {Promise<boolean>} success: true
|
||||
*/
|
||||
downloadArtifacts(id) {
|
||||
return new Promise((resolve) => {
|
||||
HttpRequest({
|
||||
method: 'GET',
|
||||
url: `https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/artifacts/${id}/zip`,
|
||||
headers: {
|
||||
accept: 'application/vnd.github.v3+json',
|
||||
authorization: `token ${process.env.PAT}`
|
||||
},
|
||||
config: {
|
||||
redirect: true,
|
||||
},
|
||||
stream: true,
|
||||
success: res => {
|
||||
let recv_length = 0;
|
||||
const wtbs = createWriteStream('dyid.zip');
|
||||
res.resStream.on('data', chuck => {
|
||||
recv_length += chuck.length
|
||||
tooltip.log(`已收到:${recv_length} Bytes`)
|
||||
})
|
||||
res.resStream.pipe(wtbs)
|
||||
wtbs.on('finish', () => {
|
||||
tooltip.log('下载完成开始解压')
|
||||
createReadStream('dyid.zip').pipe(unzip.Extract({
|
||||
path: 'lib',
|
||||
}).on('close', () => {
|
||||
tooltip.log('解压完成')
|
||||
resolve(true)
|
||||
}))
|
||||
}).on('error', () => {
|
||||
wtbs.destroy()
|
||||
resolve(false)
|
||||
})
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log(err);
|
||||
resolve(false)
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 检查是否正在抽奖或取关
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
hasLotteryRun() {
|
||||
return new Promise((resolve) => {
|
||||
HttpRequest({
|
||||
method: 'GET',
|
||||
url: `https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runs`,
|
||||
query: {
|
||||
status: "in_progress"
|
||||
},
|
||||
headers: {
|
||||
accept: 'application/vnd.github.v3+json',
|
||||
},
|
||||
success: res => {
|
||||
const { workflow_runs } = strToJson(res.body);
|
||||
if (workflow_runs instanceof Array) {
|
||||
workflow_runs.filter(wr => /sweepstakes|clear/.test(wr.name)).length > 1 ?
|
||||
resolve(true) : resolve(false)
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log(err);
|
||||
resolve(true)
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 触发一个workflow
|
||||
* @param {string} yaml_file
|
||||
*/
|
||||
trigger(yaml_file) {
|
||||
return new Promise((resolve) => {
|
||||
HttpRequest({
|
||||
method: 'POST',
|
||||
url: `https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows/${yaml_file}/dispatches`,
|
||||
contents: {
|
||||
ref: 'main'
|
||||
},
|
||||
headers: {
|
||||
accept: 'application/vnd.github.v3+json',
|
||||
'content-type': 'application/json',
|
||||
authorization: `token ${process.env.PAT}`
|
||||
},
|
||||
success: res => {
|
||||
if (res.body === '') {
|
||||
tooltip.log('成功触发'+yaml_file);
|
||||
} else {
|
||||
tooltip.log(`触发${yaml_file}失败 响应:\n${res.body}`);
|
||||
}
|
||||
resolve()
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log(err);
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = GihubAPI;
|
||||
+33
-24
@@ -14,13 +14,18 @@ const { log, hasEnv } = Util;
|
||||
class Monitor extends Public {
|
||||
/**
|
||||
* @constructor
|
||||
* @param {number | string} param
|
||||
* @param {[string, number | string]} lottery_param
|
||||
*/
|
||||
constructor(param) {
|
||||
constructor(lottery_param) {
|
||||
super();
|
||||
typeof param === 'number' ? this.UID = param : this.tag_name = param;
|
||||
this.lottery_param = lottery_param
|
||||
this.tagid = config.partition_id; /* tagid初始化 */
|
||||
this.attentionList = ''; /* 转为字符串的所有关注的up主uid */
|
||||
this.LotteryInfoMap = new Map([
|
||||
['UIDs', this.getLotteryInfoByUID.bind(this)],
|
||||
['TAGs', this.getLotteryInfoByTag.bind(this)],
|
||||
['Articles', this.getLotteryInfoByArticle.bind(this)],
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* 初始化
|
||||
@@ -37,7 +42,8 @@ class Monitor extends Public {
|
||||
return
|
||||
}
|
||||
}
|
||||
this.attentionList = await BiliAPI.getAttentionList(GlobalVar.get("myUID")); /* 获取关注列表 */
|
||||
/** 关注列表初始化 */
|
||||
this.attentionList = await BiliAPI.getAttentionList(GlobalVar.get("myUID"));
|
||||
switch (await this.startLottery()) {
|
||||
case 0:
|
||||
eventBus.emit('Turn_on_the_Monitor')
|
||||
@@ -83,7 +89,7 @@ class Monitor extends Public {
|
||||
log.info('筛选动态', `筛选完毕(${len})`);
|
||||
|
||||
if (len) {
|
||||
for (const Lottery of allLottery) {
|
||||
for (const Lottery of Util.shuffle(allLottery)) {
|
||||
let status = 0;
|
||||
if (Lottery.isOfficialLottery) {
|
||||
let { ts } = await BiliAPI.getLotteryNotice(Lottery.dyid);
|
||||
@@ -133,19 +139,17 @@ class Monitor extends Public {
|
||||
* @property {number[]} uid 用户标识
|
||||
* @property {string} dyid 动态标识
|
||||
* @property {boolean} isOfficialLottery 是否官方抽奖
|
||||
* @property {number} type 动态类型
|
||||
* @property {string} relay_chat 动态类型
|
||||
* @property {string} relay_chat 转发词
|
||||
* @property {string} ctrl 定位@
|
||||
* @property {string} rid 评论类型
|
||||
* @property {string} rid 评论标识
|
||||
* @property {number} chat_type 评论类型
|
||||
*/
|
||||
/**
|
||||
* @returns {Promise<LotteryOptions[]>}
|
||||
*/
|
||||
async filterLotteryInfo() {
|
||||
let self = this,
|
||||
protoLotteryInfo = typeof self.UID === 'number'
|
||||
? await self.getLotteryInfoByUID(self.UID)
|
||||
: await self.getLotteryInfoByTag(self.tag_name);
|
||||
const { lottery_param, LotteryInfoMap, attentionList } = this;
|
||||
let protoLotteryInfo = await LotteryInfoMap.get(lottery_param[0])(lottery_param[1]);
|
||||
|
||||
if (protoLotteryInfo === null)
|
||||
return [];
|
||||
@@ -188,9 +192,10 @@ class Monitor extends Public {
|
||||
/* 遇到转发过就退出 */
|
||||
if (dyids_map.get(dyid)) return false;
|
||||
|
||||
/**判断是转发源动态还是现动态 */
|
||||
const uid = lottery_info_type === 'tag' ? uids[0] : uids[1]
|
||||
, isFollowed = (new RegExp(uid)).test(self.attentionList)
|
||||
const
|
||||
/**判断是转发源动态还是现动态 */
|
||||
uid = lottery_info_type === 'uid' ? uids[1] : uids[0]
|
||||
, isFollowed = (new RegExp(uid)).test(attentionList)
|
||||
, description = typeof des === 'string' ? des : ''
|
||||
, needAt = /(?:@|艾特)[^@|(艾特)]*?好友/.test(description)
|
||||
, needTopic = (/(?<=[带加上](?:话题|tag))#.*#/i.exec(description) || [])[0]
|
||||
@@ -199,7 +204,7 @@ class Monitor extends Public {
|
||||
, has_key_words = key_words.every(it => new RegExp(it).test(description))
|
||||
, isBlock = new RegExp(blockword.join('|')).test(description)
|
||||
, isLottery =
|
||||
(lottery_info_type === 'uid' && is_imitator && model !== '00')
|
||||
(is_imitator && lottery_info_type === 'uid' && model !== '00')
|
||||
|| (hasOfficialLottery && model[0] === '1')
|
||||
|| (!hasOfficialLottery && model[1] === '1' && !isTwoLevelDynamic && has_key_words)
|
||||
, isSendChat =
|
||||
@@ -274,7 +279,7 @@ class Monitor extends Public {
|
||||
item.location += addlength;
|
||||
return item;
|
||||
}).forEach(it => new_ctrl.push(it))
|
||||
if (!(new RegExp(uids[1])).test(self.attentionList))
|
||||
if (!(new RegExp(uids[1])).test(attentionList))
|
||||
onelotteryinfo.uid.push(uids[1]);
|
||||
} else {
|
||||
onelotteryinfo.relay_chat = RandomStr;
|
||||
@@ -283,10 +288,14 @@ class Monitor extends Public {
|
||||
onelotteryinfo.ctrl = JSON.stringify(new_ctrl);
|
||||
|
||||
/* 根据动态的类型决定评论的类型 */
|
||||
onelotteryinfo.type = type === 2 ?
|
||||
11 : type === 4 || type === 1 ?
|
||||
17 : type === 8 ?
|
||||
1 : 0;
|
||||
onelotteryinfo.chat_type =
|
||||
type === 2
|
||||
? 11
|
||||
: type === 4 || type === 1
|
||||
? 17
|
||||
: type === 8
|
||||
? 1
|
||||
: 0;
|
||||
|
||||
/* 是否评论 */
|
||||
if (isSendChat) onelotteryinfo.rid = rid;
|
||||
@@ -314,13 +323,13 @@ class Monitor extends Public {
|
||||
log.info('NOT_GO_LOTTERY', 'ON');
|
||||
return 0
|
||||
}
|
||||
const { uid, dyid, type, rid, relay_chat, ctrl } = option;
|
||||
const { uid, dyid, chat_type, rid, relay_chat, ctrl } = option;
|
||||
/* 评论 */
|
||||
if (rid && type) {
|
||||
if (rid && chat_type) {
|
||||
let status = 0;
|
||||
const max_retry_times = 5;
|
||||
for (let times = 0; times < max_retry_times; times++) {
|
||||
status = await BiliAPI.sendChat(rid, Util.getRandomOne(config.chat), type)
|
||||
status = await BiliAPI.sendChat(rid, Util.getRandomOne(config.chat), chat_type)
|
||||
if (!status) {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -32,6 +32,9 @@ const MyStorage = {
|
||||
*/
|
||||
updateDyid: (dyid) => {
|
||||
log.info('更新dyid', `写入${dyid}`);
|
||||
if (dyid.length !== Util.dyid_length) {
|
||||
log.error('更新dyid', `dyid(${dyid})长度不为18 若出现此问题请即时通知开发者`)
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
const ws = Util.writeDyidFile(Number(process.env.NUMBER));
|
||||
ws.write(dyid + ',', () => {
|
||||
|
||||
+300
-188
@@ -1,173 +1,135 @@
|
||||
const Util = require('./Util');
|
||||
const BiliAPI = require('./BiliAPI');
|
||||
const config = require("./config");
|
||||
const MyStorage = require('./MyStorage');
|
||||
|
||||
const { log } = Util
|
||||
|
||||
/**
|
||||
* 解析dynamic_detail_card
|
||||
* 提取出的有用动态信息
|
||||
* @typedef {object} UsefulDynamicInfo
|
||||
* @property {number} uid
|
||||
* @property {string} uname
|
||||
* @property {number} createtime 10
|
||||
* @property {string} rid_str
|
||||
* @property {string} dynamic_id
|
||||
* @property {number} type
|
||||
* @property {string} description
|
||||
* @property {boolean} hasOfficialLottery
|
||||
* @property {Array<Object.<string,string|number>>} ctrl
|
||||
*
|
||||
* @property {number} origin_uid
|
||||
* @property {string} origin_uname
|
||||
* @property {string} origin_rid_str
|
||||
* @property {string} origin_dynamic_id
|
||||
* @property {number} orig_type
|
||||
* @property {string} origin_description
|
||||
* @property {boolean} origin_hasOfficialLottery
|
||||
*
|
||||
* @param {object} dynamic_detail_card
|
||||
* @return {UsefulDynamicInfo}
|
||||
*/
|
||||
function parseDynamicCard(dynamic_detail_card) {
|
||||
const { strToJson } = Util;
|
||||
/**临时储存单个动态中的信息 */
|
||||
let obj = {};
|
||||
const { desc, card, extension, extend_json } = dynamic_detail_card
|
||||
, { info } = desc.user_profile
|
||||
, cardToJson = strToJson(card)
|
||||
, { item } = cardToJson;
|
||||
/* 转发者的UID */
|
||||
obj.uid = info.uid;
|
||||
/* 转发者的name */
|
||||
obj.uname = info.uname;
|
||||
/* 动态的ts10 */
|
||||
obj.createtime = desc.timestamp
|
||||
/* 动态类型 */
|
||||
obj.type = desc.type
|
||||
/* 用于发送评论 */
|
||||
obj.rid_str = desc.rid_str.length > 12 ? desc.dynamic_id_str : desc.rid_str;
|
||||
/* 源动态类型 */
|
||||
obj.orig_type = desc.orig_type
|
||||
/* 转发者的动态ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */
|
||||
obj.dynamic_id = desc.dynamic_id_str;
|
||||
/* 定位@信息 */
|
||||
obj.ctrl = (extend_json && strToJson(extend_json).ctrl) || [];
|
||||
/* 是否有官方抽奖 */
|
||||
obj.hasOfficialLottery = extension && extension.lott && true;
|
||||
/* 转发者的描述 后两个分别是视频动态的描述和视频本身的描述*/
|
||||
obj.description = (item && (item.content || item.description || cardToJson.dynamic || cardToJson.desc)) || '';
|
||||
if (obj.type === 1) {
|
||||
const { origin_extension, origin } = cardToJson
|
||||
, originToJson = strToJson(origin)
|
||||
, { user, item } = originToJson;
|
||||
/* 被转发者的UID */
|
||||
obj.origin_uid = desc.origin.uid;
|
||||
/* 被转发者的rid(用于发评论) */
|
||||
obj.origin_rid_str = desc.origin.rid_str.length > 12 ? desc.origin.dynamic_id_str : desc.origin.rid_str;
|
||||
/* 被转发者的动态的ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */
|
||||
obj.origin_dynamic_id = desc.orig_dy_id_str;
|
||||
/* 是否有官方抽奖 */
|
||||
obj.origin_hasOfficialLottery = origin_extension && origin_extension.lott;
|
||||
/* 被转发者的name */
|
||||
obj.origin_uname = (user && (user.name || user.uname)) || '';
|
||||
/* 被转发者的描述 */
|
||||
obj.origin_description = (item && (item.content || item.description || originToJson.dynamic || originToJson.desc)) || '';
|
||||
}
|
||||
|
||||
return obj
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理来自个人动态或话题页面的一组动态数据
|
||||
* @param {String} res
|
||||
* @returns {{modifyDynamicResArray: UsefulDynamicInfo[], nextinfo: {has_more: number, next_offset: string}} | UsefulDynamicInfo |null}
|
||||
*/
|
||||
function modifyDynamicRes(res) {
|
||||
const
|
||||
{ data = {}, code } = Util.strToJson(res),
|
||||
{ cards = [], has_more, offset } = data;
|
||||
|
||||
if (code !== 0) {
|
||||
log.error('处理动态数据', '获取动态数据出错,可能是访问太频繁 \n' + res);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!cards.length) {
|
||||
log.warn('处理动态数据', '未找到任何动态信息')
|
||||
}
|
||||
|
||||
const
|
||||
/**
|
||||
* 字符串offset防止损失精度
|
||||
*/
|
||||
next = {
|
||||
has_more,
|
||||
next_offset: typeof offset === 'string'
|
||||
? offset
|
||||
: /(?<=next_offset":)[0-9]+/.exec(res)[0]
|
||||
},
|
||||
/**
|
||||
* 储存获取到的一组动态中的信息
|
||||
*/
|
||||
array = next.has_more === 0
|
||||
? []
|
||||
: cards.map(parseDynamicCard)
|
||||
|
||||
log.info('处理动态数据', `动态数据读取完毕(${cards.length})(${next.has_more})`);
|
||||
|
||||
return {
|
||||
modifyDynamicResArray: array,
|
||||
nextinfo: next
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 基础功能
|
||||
*/
|
||||
class Public {
|
||||
constructor() { }
|
||||
/**
|
||||
* 提取出的有用动态信息
|
||||
* @typedef {object} UsefulDynamicInfo
|
||||
* @property {number} uid
|
||||
* @property {string} uname
|
||||
* @property {number} createtime 10
|
||||
* @property {string} rid_str
|
||||
* @property {string} dynamic_id
|
||||
* @property {number} type
|
||||
* @property {string} description
|
||||
* @property {boolean} hasOfficialLottery
|
||||
* @property {Array<Object.<string,string|number>>} ctrl
|
||||
*
|
||||
* @property {number} origin_uid
|
||||
* @property {string} origin_uname
|
||||
* @property {string} origin_rid_str
|
||||
* @property {string} origin_dynamic_id
|
||||
* @property {number} orig_type
|
||||
* @property {string} origin_description
|
||||
* @property {boolean} origin_hasOfficialLottery
|
||||
*/
|
||||
/**
|
||||
* 检查所有的动态信息
|
||||
* @param {string} UID 指定的用户UID
|
||||
* @param {number} pages 读取页数
|
||||
* @param {number} time 时延
|
||||
* @param {string} [_offset] 默认'0'
|
||||
* @returns {Promise<{allModifyDynamicResArray: UsefulDynamicInfo[];offset: string}>} 获取前 `pages*12` 个动态信息
|
||||
*/
|
||||
async checkAllDynamic(hostuid, pages, time = 0, _offset = '0') {
|
||||
log.info('检查所有动态', `准备读取${pages}页动态`);
|
||||
const mDR = this.modifyDynamicRes,
|
||||
getOneDynamicInfoByUID = BiliAPI.getOneDynamicInfoByUID,
|
||||
curriedGetOneDynamicInfoByUID = Util.curryify(getOneDynamicInfoByUID); /* 柯里化的请求函数 */
|
||||
/**
|
||||
* 储存了特定UID的请求函数
|
||||
*/
|
||||
let hadUidGetOneDynamicInfoByUID = curriedGetOneDynamicInfoByUID(hostuid);
|
||||
/**
|
||||
* 储存所有经过整理后信息
|
||||
* [{}{}...{}]
|
||||
*/
|
||||
let allModifyDynamicResArray = [];
|
||||
let offset = _offset;
|
||||
for (let i = 0; i < pages; i++) {
|
||||
log.info('检查所有动态', `正在读取其中第${i + 1}页动态`);
|
||||
let OneDynamicInfo = await hadUidGetOneDynamicInfoByUID(offset);
|
||||
const mDRdata = mDR(OneDynamicInfo);
|
||||
if (mDRdata === null) {
|
||||
break;
|
||||
}
|
||||
/**
|
||||
* 储存一片动态信息
|
||||
* [{}{}...{}]
|
||||
*/
|
||||
const mDRArry = mDRdata.modifyDynamicResArray,
|
||||
nextinfo = mDRdata.nextinfo;
|
||||
if (nextinfo.has_more === 0) {
|
||||
offset = nextinfo.next_offset;
|
||||
log.info('检查所有动态', `成功读取${i + 1}页信息(已经是最后一页了故无法读取更多)`);
|
||||
break;
|
||||
} else {
|
||||
allModifyDynamicResArray.push.apply(allModifyDynamicResArray, mDRArry);
|
||||
i + 1 < pages
|
||||
? log.info('检查所有动态', `开始读取第${i + 2}页动态信息`)
|
||||
: log.info('检查所有动态', `第${pages}页信息读取完成`);
|
||||
offset = nextinfo.next_offset;
|
||||
}
|
||||
await Util.delay(time);
|
||||
}
|
||||
return ({ allModifyDynamicResArray, offset });
|
||||
}
|
||||
/**
|
||||
* 互动抽奖
|
||||
* 处理来自动态页面的数据
|
||||
* @param {String} res
|
||||
* @returns {{modifyDynamicResArray: UsefulDynamicInfo[];nextinfo: {has_more: number;next_offset: string;};} | null}
|
||||
*/
|
||||
modifyDynamicRes(res) {
|
||||
const strToJson = Util.strToJson,
|
||||
{ data, code } = strToJson(res);
|
||||
if (code !== 0) {
|
||||
log.error('处理动态数据', '获取动态数据出错,可能是访问太频繁 \n' + res);
|
||||
return null;
|
||||
}
|
||||
/* 字符串offset防止损失精度 */
|
||||
const offset = typeof data.offset === 'string' ? data.offset : /(?<=next_offset":)[0-9]*/.exec(res)[0]
|
||||
, next = {
|
||||
has_more: data.has_more,
|
||||
next_offset: offset
|
||||
};
|
||||
/**
|
||||
* 储存获取到的一组动态中的信息
|
||||
*/
|
||||
let array = [];
|
||||
if (next.has_more === 0) {
|
||||
log.info('处理动态数据', '动态数据读取完毕');
|
||||
} else {
|
||||
/**
|
||||
* 空动态无cards
|
||||
*/
|
||||
const Cards = data.cards || [];
|
||||
Cards.forEach(onecard => {
|
||||
/**临时储存单个动态中的信息 */
|
||||
let obj = {};
|
||||
const { desc, card } = onecard
|
||||
, { info } = desc.user_profile
|
||||
, cardToJson = strToJson(card);
|
||||
/* 转发者的UID */
|
||||
obj.uid = info.uid;
|
||||
/* 转发者的name */
|
||||
obj.uname = info.uname;
|
||||
/* 动态的ts10 */
|
||||
obj.createtime = desc.timestamp
|
||||
/* 动态类型 */
|
||||
obj.type = desc.type
|
||||
/* 用于发送评论 */
|
||||
obj.rid_str = desc.rid_str.length > 12 ? desc.dynamic_id_str : desc.rid_str;
|
||||
/* 源动态类型 */
|
||||
obj.orig_type = desc.orig_type
|
||||
/* 转发者的动态ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */
|
||||
obj.dynamic_id = desc.dynamic_id_str;
|
||||
const { extension, extend_json } = onecard;
|
||||
/* 定位@信息 */
|
||||
obj.ctrl = (typeof extend_json === 'undefined') ? [] : strToJson(extend_json).ctrl || [];
|
||||
/* 是否有官方抽奖 */
|
||||
obj.hasOfficialLottery = (typeof extension === 'undefined') ? false : typeof extension.lott === 'undefined' ? false : true;
|
||||
const { item = {} } = cardToJson;
|
||||
/* 转发者的描述 后两个分别是视频动态的描述和视频本身的描述*/
|
||||
obj.description = item.content || item.description || cardToJson.dynamic || cardToJson.desc || '';
|
||||
if (obj.type === 1) {
|
||||
/* 被转发者的UID */
|
||||
obj.origin_uid = desc.origin.uid;
|
||||
/* 被转发者的rid(用于发评论) */
|
||||
obj.origin_rid_str = desc.origin.rid_str.length > 12 ? desc.origin.dynamic_id_str : desc.origin.rid_str;
|
||||
/* 被转发者的动态的ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */
|
||||
obj.origin_dynamic_id = desc.orig_dy_id_str;
|
||||
const { origin_extension } = cardToJson;
|
||||
/* 是否有官方抽奖 */
|
||||
obj.origin_hasOfficialLottery = typeof origin_extension === 'undefined' ?
|
||||
false : typeof origin_extension.lott === 'undefined' ?
|
||||
false : true;
|
||||
const origin = cardToJson.origin || '{}';
|
||||
const originToJson = strToJson(origin);
|
||||
const { user, item } = originToJson;
|
||||
/* 被转发者的name */
|
||||
obj.origin_uname = typeof user === 'undefined'
|
||||
? '' : user.name || user.uname || '';
|
||||
/* 被转发者的描述 */
|
||||
obj.origin_description = typeof item === 'undefined'
|
||||
? '' : item.content || item.description || originToJson.dynamic || originToJson.desc || '';
|
||||
}
|
||||
array.push(obj);
|
||||
});
|
||||
}
|
||||
return {
|
||||
modifyDynamicResArray: array,
|
||||
nextinfo: next
|
||||
};
|
||||
}
|
||||
/**
|
||||
* 整理后的抽奖信息
|
||||
* @typedef {object} LotteryInfo
|
||||
* @property {string} lottery_info_type
|
||||
* @property {number[]} uids `[uid,ouid]`
|
||||
@@ -179,6 +141,97 @@ class Public {
|
||||
* @property {number} type
|
||||
* @property {boolean} hasOfficialLottery 是否官方
|
||||
*/
|
||||
/**
|
||||
* 检查指定用户的所有的动态信息
|
||||
* @param {number} hostuid 指定的用户UID
|
||||
* @param {number} pages 读取页数
|
||||
* @param {number} time 时延
|
||||
* @param {string} [offset] 默认'0'
|
||||
* @returns {Promise<{allModifyDynamicResArray: UsefulDynamicInfo[], offset: string}>} 获取前 `pages*12` 个动态信息
|
||||
*/
|
||||
async checkAllDynamic(hostuid, pages, time = 0, offset = '0') {
|
||||
log.info('检查所有动态', `准备读取${pages}页动态`);
|
||||
|
||||
const { getOneDynamicInfoByUID } = BiliAPI,
|
||||
/**
|
||||
* 柯里化请求函数
|
||||
*/
|
||||
curriedGetOneDynamicInfoByUID = Util.curryify(getOneDynamicInfoByUID),
|
||||
/**
|
||||
* 储存了特定UID的请求函数
|
||||
*/
|
||||
hadUidGetOneDynamicInfoByUID = curriedGetOneDynamicInfoByUID(hostuid);
|
||||
|
||||
/**
|
||||
* 储存所有经过整理后信息
|
||||
* @type { UsefulDynamicInfo[] }
|
||||
*/
|
||||
let allModifyDynamicResArray = [];
|
||||
|
||||
for (let i = 0; i < pages; i++) {
|
||||
log.info('检查所有动态', `正在读取其中第${i + 1}页动态`);
|
||||
|
||||
const
|
||||
OneDynamicInfo = await hadUidGetOneDynamicInfoByUID(offset),
|
||||
mDRdata = modifyDynamicRes(OneDynamicInfo);
|
||||
|
||||
if (mDRdata === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
const
|
||||
/**
|
||||
* 一片动态
|
||||
*/
|
||||
mDRArry = mDRdata.modifyDynamicResArray,
|
||||
nextinfo = mDRdata.nextinfo;
|
||||
|
||||
if (nextinfo.has_more === 0) {
|
||||
offset = nextinfo.next_offset;
|
||||
log.info('检查所有动态', `已经是最后一页了故无法读取更多`);
|
||||
break;
|
||||
} else {
|
||||
/**合并 */
|
||||
allModifyDynamicResArray.push.apply(allModifyDynamicResArray, mDRArry);
|
||||
offset = nextinfo.next_offset;
|
||||
}
|
||||
|
||||
await Util.delay(time);
|
||||
}
|
||||
|
||||
log.info('检查所有动态', `${pages}页信息读取完成`)
|
||||
|
||||
return ({ allModifyDynamicResArray, offset });
|
||||
}
|
||||
/**
|
||||
* 获取最新动态信息(转发子动态)
|
||||
* 并初步整理
|
||||
* @param {string} UID
|
||||
* @returns {Promise<LotteryInfo[] | null>}
|
||||
*/
|
||||
async getLotteryInfoByUID(UID) {
|
||||
log.info('获取动态', `开始获取用户${UID}的动态信息`);
|
||||
const { allModifyDynamicResArray } = await this.checkAllDynamic(UID, config.uid_scan_page, config.search_wait);
|
||||
|
||||
if (!allModifyDynamicResArray.length) return null;
|
||||
|
||||
const fomatdata = allModifyDynamicResArray.map(o => {
|
||||
return {
|
||||
lottery_info_type: 'uid',
|
||||
uids: [o.uid, o.origin_uid],
|
||||
uname: o.origin_uname,
|
||||
ctrl: [],
|
||||
dyid: o.origin_dynamic_id,
|
||||
rid: o.origin_rid_str,
|
||||
des: o.origin_description,
|
||||
type: o.orig_type,
|
||||
hasOfficialLottery: o.origin_hasOfficialLottery
|
||||
}
|
||||
}).filter(a => a.type != 0)
|
||||
log.info('获取动态', `成功获取用户${UID}的动态信息`);
|
||||
|
||||
return fomatdata;
|
||||
}
|
||||
/**
|
||||
* 获取tag下的抽奖信息(转发母动态)
|
||||
* 并初步整理
|
||||
@@ -186,22 +239,33 @@ class Public {
|
||||
* @returns {Promise<LotteryInfo[] | null>}
|
||||
*/
|
||||
async getLotteryInfoByTag(tag_name) {
|
||||
const self = this,
|
||||
const
|
||||
tag_id = await BiliAPI.getTagIDByTagName(tag_name),
|
||||
hotdy = await BiliAPI.getHotDynamicInfoByTagID(tag_id),
|
||||
modDR = self.modifyDynamicRes(hotdy);
|
||||
modDR = modifyDynamicRes(hotdy);
|
||||
|
||||
if (modDR === null) return null;
|
||||
|
||||
log.info('获取动态', `开始获取带话题#${tag_name}#的动态信息`);
|
||||
log.info('获取动态', '成功获取热门动态');
|
||||
let mDRdata = modDR.modifyDynamicResArray; /* 热门动态 */
|
||||
|
||||
/**
|
||||
* 热门动态
|
||||
*/
|
||||
let mDRdata = modDR.modifyDynamicResArray;
|
||||
let next_offset = modDR.nextinfo.next_offset;
|
||||
for (let index = 0; index < config.scan_page_num; index++) {
|
||||
log.info('获取动态', `成功读取${index + 1}页动态`);
|
||||
const newdy = await BiliAPI.getOneDynamicInfoByTag(tag_name, next_offset);
|
||||
const _modify = self.modifyDynamicRes(newdy);
|
||||
|
||||
for (let index = 0; index < config.tag_scan_page; index++) {
|
||||
log.info('获取动态', `读取第${index + 1}页动态`);
|
||||
const
|
||||
newdy = await BiliAPI.getOneDynamicInfoByTag(tag_name, next_offset),
|
||||
_modify = modifyDynamicRes(newdy);
|
||||
|
||||
if (_modify === null) return null;
|
||||
|
||||
mDRdata.push.apply(mDRdata, _modify.modifyDynamicResArray);
|
||||
next_offset = _modify.nextinfo.next_offset;
|
||||
|
||||
await Util.delay(config.search_wait);
|
||||
}
|
||||
const fomatdata = mDRdata.map(o => {
|
||||
@@ -218,33 +282,81 @@ class Public {
|
||||
};
|
||||
})
|
||||
log.info('获取动态', `成功获取带话题#${tag_name}#的动态信息`);
|
||||
|
||||
return fomatdata
|
||||
}
|
||||
/**
|
||||
* 获取最新动态信息(转发子动态)
|
||||
* 并初步整理
|
||||
* @param {string} UID
|
||||
* 从专栏中获取抽奖信息
|
||||
* @param {string} key_words
|
||||
* @returns {Promise<LotteryInfo[] | null>}
|
||||
*/
|
||||
async getLotteryInfoByUID(UID) {
|
||||
log.info('获取动态', `开始获取用户${UID}的动态信息`);
|
||||
const { allModifyDynamicResArray: aMDRA } = await this.checkAllDynamic(UID, config.scan_page_num, config.search_wait);
|
||||
if (!aMDRA.length) return null;
|
||||
const fomatdata = aMDRA.map(o => {
|
||||
return {
|
||||
lottery_info_type: 'uid',
|
||||
uids: [o.uid, o.origin_uid],
|
||||
uname: o.origin_uname,
|
||||
ctrl: [],
|
||||
dyid: o.origin_dynamic_id,
|
||||
rid: o.origin_rid_str,
|
||||
des: o.origin_description,
|
||||
type: o.orig_type,
|
||||
hasOfficialLottery: o.origin_hasOfficialLottery
|
||||
async getLotteryInfoByArticle(key_words) {
|
||||
log.info('获取动态', `开始获取含关键词${key_words}的专栏信息`);
|
||||
const cvs = (await BiliAPI.searchArticlesByKeyword(key_words)).slice(0, config.article_scan_page);
|
||||
|
||||
let dyinfos = [];
|
||||
for (const cv of cvs) {
|
||||
const
|
||||
content = await BiliAPI.getOneArticleByCv(cv),
|
||||
dyids = content.match(/(?<=t.bilibili.com\/)[0-9]+/g) || [],
|
||||
dyids_set = [...new Set(dyids)],
|
||||
/**判断此专栏是否查看过的权重 */
|
||||
weight = dyids_set.length / 2;
|
||||
|
||||
let { length } = dyids_set,
|
||||
_weight = 0;
|
||||
log.info('获取动态', `提取专栏(${cv})中提及的dyid(${length})`)
|
||||
for (const dyid of dyids_set) {
|
||||
const isRelayed = await MyStorage.searchDyid(dyid);
|
||||
if (isRelayed) {
|
||||
_weight += 1;
|
||||
}
|
||||
if (_weight >= weight) {
|
||||
log.warn('获取动态', `1/2动态曾经转过,该专栏或已查看,故中止`)
|
||||
dyinfos = []
|
||||
break
|
||||
}
|
||||
if (dyid.length === Util.dyid_length) {
|
||||
if (!isRelayed) {
|
||||
log.info('获取动态', `查看动态(${dyid})的细节 (${length--})`)
|
||||
const res = await BiliAPI.getOneDynamicByDyid(dyid)
|
||||
, { code, data = {} } = Util.strToJson(res)
|
||||
, { card } = data;
|
||||
|
||||
if (code !== 0) {
|
||||
log.error('获取动态', '获取动态数据出错,可能是访问太频繁 \n' + res)
|
||||
break
|
||||
}
|
||||
|
||||
await Util.delay(2000)
|
||||
|
||||
if (card) {
|
||||
dyinfos.push(parseDynamicCard(card));
|
||||
}
|
||||
} else {
|
||||
log.info('获取动态', `动态(${dyid})已转发过 (${length--})`)
|
||||
}
|
||||
} else {
|
||||
log.warn('获取动态', `动态(${dyid})无效 (${length--})`)
|
||||
}
|
||||
}
|
||||
}).filter(a => a.type === 0 ? false : true)
|
||||
log.info('获取动态', `成功获取用户${UID}的动态信息`);
|
||||
return fomatdata;
|
||||
}
|
||||
const fomatdata = dyinfos.map(o => {
|
||||
return {
|
||||
lottery_info_type: 'article',
|
||||
uids: [o.uid, o.origin_uid],
|
||||
uname: o.uname,
|
||||
ctrl: o.ctrl,
|
||||
dyid: o.dynamic_id,
|
||||
rid: o.rid_str,
|
||||
des: o.description,
|
||||
type: o.type,
|
||||
hasOfficialLottery: o.hasOfficialLottery
|
||||
};
|
||||
})
|
||||
log.info('获取动态', `成功获取含关键词${key_words}的专栏信息`);
|
||||
|
||||
return fomatdata
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+37
-5
@@ -18,7 +18,7 @@ const Util = {
|
||||
* 超出精度的数转为字符串
|
||||
* @param {string} params
|
||||
* @return {object}
|
||||
* 返回对象
|
||||
* 返回对象 解析失败返回 `{}`
|
||||
*/
|
||||
strToJson(params) {
|
||||
const isJSON = (str => {
|
||||
@@ -47,9 +47,10 @@ const Util = {
|
||||
},
|
||||
/**
|
||||
* 函数柯里化
|
||||
* @param {function} func
|
||||
* @template T
|
||||
* @param {(arg, arg) => T} func
|
||||
* 要被柯里化的函数
|
||||
* @returns {function}
|
||||
* @returns {(arg) => (arg) => T)}
|
||||
* 一次接受一个参数并返回一个接受余下参数的函数
|
||||
*/
|
||||
curryify(func) {
|
||||
@@ -68,7 +69,7 @@ const Util = {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
delay(time) {
|
||||
Util.log.info('时延', `${time}ms`);
|
||||
Util.log.info('时延', `${~~time}ms`);
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
@@ -92,6 +93,15 @@ const Util = {
|
||||
}
|
||||
return c
|
||||
},
|
||||
/**
|
||||
* 无限序列
|
||||
* `[0..]`
|
||||
*/
|
||||
*infiniteNumber() {
|
||||
for (let index = 0; ; index++) {
|
||||
yield index
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 随机获取数组中的一个元素
|
||||
* @template T
|
||||
@@ -105,6 +115,24 @@ const Util = {
|
||||
}
|
||||
return RandomOne
|
||||
},
|
||||
/**
|
||||
* Fisher–Yates shuffle洗牌
|
||||
* @template T
|
||||
* @param {Array<T>} array
|
||||
* @return {Array<T>}
|
||||
*/
|
||||
shuffle(array) {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
}
|
||||
return array;
|
||||
},
|
||||
/**
|
||||
* 是否有指定环境变量
|
||||
* @param {string} env_name
|
||||
* @returns
|
||||
*/
|
||||
hasEnv(env_name) {
|
||||
return process.env[env_name] ? true : false;
|
||||
},
|
||||
@@ -228,6 +256,10 @@ const Util = {
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* dyid长度
|
||||
*/
|
||||
dyid_length: 18,
|
||||
/**
|
||||
* 读取dyid文件
|
||||
* @param {number} num
|
||||
@@ -235,7 +267,7 @@ const Util = {
|
||||
*/
|
||||
readDyidFile(num) {
|
||||
const fpath = num < 2 ? path.join(this.dyids_dir, 'dyid.txt') : path.join(this.dyids_dir, `dyid${num}.txt`);
|
||||
return fs.createReadStream(fpath, { encoding: 'utf8', highWaterMark: 19 * 1000 })
|
||||
return fs.createReadStream(fpath, { encoding: 'utf8', highWaterMark: (this.dyid_length + 1) * 1000 })
|
||||
},
|
||||
/**
|
||||
* 追加dyid
|
||||
|
||||
+41
-25
@@ -1,12 +1,9 @@
|
||||
const { log, delay } = require("./Util");
|
||||
const { log, delay, infiniteNumber } = require("./Util");
|
||||
const BiliAPI = require("./BiliAPI");
|
||||
const Public = require("./Public");
|
||||
const GlobalVar = require('./GlobalVar');
|
||||
const config = require("./config");
|
||||
|
||||
/**动态偏移量 */
|
||||
let offset = '0';
|
||||
|
||||
/**
|
||||
* 获取关注分区里的uid
|
||||
* @returns { Promise<number[]> }
|
||||
@@ -36,31 +33,47 @@ async function clear() {
|
||||
const { clear_white_list, clear_max_day, clear_remove_dynamic, clear_remove_attention, clear_remove_delay, clear_dynamic_type } = config;
|
||||
let success = true;
|
||||
const uid_list = await getFollowList();
|
||||
if (!uid_list.length) {
|
||||
log.info('清理关注', `关注为空`)
|
||||
} else {
|
||||
log.info('清理关注', `共有${uid_list.length}个关注`)
|
||||
}
|
||||
if (!clear_remove_dynamic && clear_remove_attention) {
|
||||
log.info('清理关注', '进入只清理关注模式')
|
||||
/* 专清关注 */
|
||||
for (let index = 0; index < uid_list.length; index++) {
|
||||
const uid = uid_list[index];
|
||||
for (const [index, uid] of uid_list.entries()) {
|
||||
log.info('清理关注', `(${index}) (${uid})`)
|
||||
/* 取消关注 */
|
||||
success = await BiliAPI.cancelAttention(uid);
|
||||
if (await BiliAPI.cancelAttention(uid)) {
|
||||
log.info('清理关注', '成功')
|
||||
} else {
|
||||
log.error('清理关注', '失败')
|
||||
break
|
||||
}
|
||||
/* 延时 */
|
||||
await delay(clear_remove_delay);
|
||||
|
||||
if (!success) break;
|
||||
}
|
||||
} else {
|
||||
const now = Date.now() / 1000;
|
||||
let before_separate = [];
|
||||
const MY_UID = Number(GlobalVar.get('myUID'));
|
||||
for (let index = 0; ; index++) {
|
||||
log.info('清理动态', `开始读取第${index + 1}页(12条)`);
|
||||
const { allModifyDynamicResArray, offset: _offset } = await Public.prototype.checkAllDynamic(GlobalVar.get("myUID"), 1, 5 * 1000, offset);
|
||||
offset = _offset;
|
||||
for (let index = 0; index < allModifyDynamicResArray.length; index++) {
|
||||
const res = allModifyDynamicResArray[index];
|
||||
const { type, dynamic_id, createtime } = res;
|
||||
const
|
||||
Now = Date.now() / 1000,
|
||||
MY_UID = Number(GlobalVar.get('myUID'));
|
||||
|
||||
let next_offset = '0',
|
||||
before_separate = [];
|
||||
|
||||
for (const page of infiniteNumber()) {
|
||||
log.info('清理动态', `开始读取第${page + 1}页`);
|
||||
const { allModifyDynamicResArray, offset } = await Public.prototype.checkAllDynamic(MY_UID, 1, 5 * 1000, next_offset);
|
||||
next_offset = offset;
|
||||
for (const [index, dyinfo] of allModifyDynamicResArray.entries()) {
|
||||
log.info('清理动态', `第${page + 1}页中的第${index + 1}个动态`)
|
||||
const { type, dynamic_id, createtime } = dyinfo || {};
|
||||
if (type === clear_dynamic_type) {
|
||||
const { origin_uid } = res;
|
||||
if ((now - createtime) > 86400 * clear_max_day) {
|
||||
const
|
||||
{ origin_uid } = dyinfo,
|
||||
days_ago = (Now - createtime) / 86400;
|
||||
|
||||
if (days_ago > clear_max_day) {
|
||||
/* 移除动态 */
|
||||
if (dynamic_id
|
||||
&& clear_remove_dynamic
|
||||
@@ -77,17 +90,20 @@ async function clear() {
|
||||
success = await BiliAPI.cancelAttention(origin_uid);
|
||||
}
|
||||
|
||||
if (!success) break;
|
||||
/* 延时 */
|
||||
await delay(clear_remove_delay);
|
||||
|
||||
if (!success) break;
|
||||
} else {
|
||||
log.info('清理动态', `已设置跳过${clear_max_day}天 当前动态发布时间: ${~~days_ago}天前`)
|
||||
log.info('清理动态', `储存用户(${origin_uid})防止误删`)
|
||||
before_separate.push(origin_uid)
|
||||
}
|
||||
} else {
|
||||
log.info('清理动态', `此动态类型为${type} != 要清理的动态类型${clear_dynamic_type}`)
|
||||
}
|
||||
}
|
||||
log.info('清理动态', `第${index + 1}页中的转发动态与关注全部处理成功`)
|
||||
if (offset === '0' || !success) break;
|
||||
log.info('清理动态', `第${page + 1}页(${allModifyDynamicResArray.length})中的转发动态与关注全部处理成功`)
|
||||
if (next_offset === '0' || !success) break;
|
||||
}
|
||||
}
|
||||
return
|
||||
|
||||
+12
-10
@@ -47,8 +47,8 @@ function start() {
|
||||
return;
|
||||
}
|
||||
const lottery = lotterys[times.next()];
|
||||
const nlottery = Number(lottery);
|
||||
await (new Monitor(isNaN(nlottery) ? lottery : nlottery)).init();
|
||||
|
||||
await (new Monitor(lottery)).init();
|
||||
});
|
||||
eventBus.on('Turn_off_the_Monitor', async (msg) => {
|
||||
await createRandomDynamic(config.create_dy_num);
|
||||
@@ -85,9 +85,8 @@ async function isMe() {
|
||||
if (follow_unread + unfollow_unread > 0) {
|
||||
const check = async (type) => {
|
||||
let session_t = '';
|
||||
let max = 0;
|
||||
let MySession = await BiliAPI.getSessionInfo(type)
|
||||
do {
|
||||
for (const index of Util.infiniteNumber()) {
|
||||
for (const Session of MySession.data) {
|
||||
const { content, sender_uid, session_ts, timestamp, talker_id } = Session;
|
||||
session_t = session_ts;
|
||||
@@ -103,12 +102,13 @@ async function isMe() {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (MySession.has_more) {
|
||||
if (MySession.has_more && index < 16) {
|
||||
await Util.delay(3e3);
|
||||
MySession = await BiliAPI.getSessionInfo(type, session_t)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
max++
|
||||
} while (MySession.has_more && max < 10);
|
||||
}
|
||||
}
|
||||
if (follow_unread) {
|
||||
log.info('中奖检测', '<-- 正在检查已关注者的私信')
|
||||
@@ -121,6 +121,7 @@ async function isMe() {
|
||||
log.info('中奖检测', '--> OK');
|
||||
}
|
||||
if (desp) {
|
||||
desp += '中奖了别忘给脚本(https://github.com/shanmiteko/LotteryAutoScript)点一个Star哦, 赞助一两块也不是不可以_(:з」∠)_\n\n'
|
||||
log.info(desp);
|
||||
await sendNotify('可能中奖了', desp);
|
||||
} else {
|
||||
@@ -134,12 +135,13 @@ async function isMe() {
|
||||
* @param {string} num
|
||||
*/
|
||||
async function checkCookie(num) {
|
||||
const My_UID = GlobalVar.get("myUID");
|
||||
if (await BiliAPI.getMyinfo()) {
|
||||
log.info('Cookie有效性检测', '成功登录');
|
||||
log.info('Cookie有效性检测', `成功登录 UID:${My_UID}`);
|
||||
return true;
|
||||
} else {
|
||||
log.error('Cookie有效性检测', `登录失败 COOKIE${num} 已失效 UID:${GlobalVar.get("myUID")}`);
|
||||
await sendNotify('动态抽奖出错-登录失败', `COOKIE${num} 已失效 UID:${GlobalVar.get("myUID")}`)
|
||||
log.error('Cookie有效性检测', `登录失败 COOKIE${num} 已失效 UID:${My_UID}`);
|
||||
await sendNotify('动态抽奖出错-登录失败', `COOKIE${num} 已失效 UID:${My_UID}`)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -15,12 +15,20 @@ async function setVariable(cookie, n) {
|
||||
config.updata(process.env.NUMBER);
|
||||
|
||||
GlobalVar.set('cookie', cookie);
|
||||
|
||||
cookie.split(/\s*;\s*/).forEach(item => {
|
||||
const _item = item.split('=');
|
||||
if (key_map.has(_item[0]))
|
||||
GlobalVar.set(key_map.get(_item[0]), _item[1]);
|
||||
});
|
||||
GlobalVar.set('Lottery', [...config.UIDs, ...config.TAGs]);
|
||||
|
||||
const { UIDs = [], TAGs = [], Articles = [] } = config;
|
||||
GlobalVar.set('Lottery', [
|
||||
...UIDs.map(it => ['UIDs', it]),
|
||||
...TAGs.map(it => ['TAGs', it]),
|
||||
...Articles.map(it => ['Articles', it])
|
||||
]);
|
||||
|
||||
GlobalVar.set('remoteconfig', await Util.getRemoteConfig());
|
||||
}
|
||||
await Util.createDir('dyids');
|
||||
|
||||
@@ -10,7 +10,7 @@ const metainfo = [
|
||||
` __/ | | | `,
|
||||
` |___/ |_| `,
|
||||
` `,
|
||||
` v1.9.0 by shanmite`,
|
||||
` v2.0.0 by shanmite`,
|
||||
]
|
||||
/**多账号存储 */
|
||||
let multiple_account = [];
|
||||
@@ -33,8 +33,12 @@ async function main() {
|
||||
process.env.COOKIE = acco.COOKIE;
|
||||
process.env.NUMBER = acco.NUMBER;
|
||||
process.env.CLEAR = acco.CLEAR;
|
||||
await main();
|
||||
await delay(acco.WAIT);
|
||||
const err_msg = await main();
|
||||
if (err_msg) {
|
||||
return err_msg
|
||||
} else {
|
||||
await delay(acco.WAIT);
|
||||
}
|
||||
}
|
||||
|
||||
/**多账号状态还原 */
|
||||
|
||||
+20
-3
@@ -12,6 +12,13 @@ module.exports = {
|
||||
241675899
|
||||
],
|
||||
|
||||
/**
|
||||
* 监视的专栏关键词
|
||||
*/
|
||||
Articles: [
|
||||
'抽奖合集'
|
||||
],
|
||||
|
||||
/**
|
||||
* 监视的tag
|
||||
*/
|
||||
@@ -53,9 +60,19 @@ module.exports = {
|
||||
is_imitator: false,
|
||||
|
||||
/**
|
||||
* - 在uid或tag里检索的页数
|
||||
* - 在uid里检索的页数
|
||||
*/
|
||||
scan_page_num: 3,
|
||||
uid_scan_page: 3,
|
||||
|
||||
/**
|
||||
* - 在tag里检索的页数
|
||||
*/
|
||||
tag_scan_page: 3,
|
||||
|
||||
/**
|
||||
* - 获取专栏数量
|
||||
*/
|
||||
article_scan_page: 3,
|
||||
|
||||
/**
|
||||
* - 开奖时间距离现在的最大天数
|
||||
@@ -67,7 +84,7 @@ module.exports = {
|
||||
* - 循环等待时间(指所有操作完毕后的休眠时间)
|
||||
* - 单位毫秒
|
||||
*/
|
||||
lottery_loop_wait: 60 * 60 * 1000,
|
||||
lottery_loop_wait: 0,
|
||||
check_loop_wait: 0,
|
||||
clear_loop_wait: 0,
|
||||
|
||||
|
||||
+4
-5
@@ -23,7 +23,7 @@
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/shanmite/AutoScript.git"
|
||||
"url": "https://github.com/shanmiteko/AutoScript.git"
|
||||
},
|
||||
"keywords": [
|
||||
"auto",
|
||||
@@ -32,16 +32,15 @@
|
||||
"author": "shanmite",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"bugs": {
|
||||
"url": "https://github.com/shanmite/AutoScript/issues"
|
||||
"url": "https://github.com/shanmiteko/AutoScript/issues"
|
||||
},
|
||||
"homepage": "https://github.com/shanmite/AutoScript#readme",
|
||||
"homepage": "https://github.com/shanmiteko/AutoScript#readme",
|
||||
"devDependencies": {
|
||||
"eslint": "^7.17.0",
|
||||
"pkg": "^5.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "^4.1.1",
|
||||
"nodemailer": "^6.5.0",
|
||||
"unzipper": "^0.10.11"
|
||||
"nodemailer": "^6.5.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# 脚本根目录
|
||||
SCRIPT_FOLDER=lottery
|
||||
@@ -61,7 +62,7 @@ docker run \
|
||||
$DOCKER_REPO \
|
||||
start" \
|
||||
> start.sh
|
||||
chmod 777 start.sh
|
||||
chmod +x start.sh
|
||||
|
||||
echo "create check.sh"
|
||||
echo -e "#!/bin/bash\n\
|
||||
@@ -72,7 +73,7 @@ docker run \
|
||||
$DOCKER_REPO \
|
||||
check" \
|
||||
> check.sh
|
||||
chmod 777 check.sh
|
||||
chmod +x check.sh
|
||||
|
||||
echo "create clear.sh"
|
||||
echo -e "#!/bin/bash\n\
|
||||
@@ -83,4 +84,4 @@ docker run \
|
||||
$DOCKER_REPO \
|
||||
clear" \
|
||||
> clear.sh
|
||||
chmod 777 clear.sh
|
||||
chmod +x clear.sh
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
cd ..
|
||||
cd ..
|
||||
npm i
|
||||
npm run check
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
cd ..
|
||||
cd ..
|
||||
npm i
|
||||
npm run clear
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
cd ..
|
||||
cd ..
|
||||
npm i
|
||||
npm run start
|
||||
+11
-2
@@ -1,3 +1,4 @@
|
||||
$README = "README.md"
|
||||
$TEMPLATE_CONFIG_FILE = "my_config.example.js"
|
||||
$TEMPLATE_ENV_FILE = "env.example.js"
|
||||
|
||||
@@ -14,10 +15,10 @@ $TRIARR = @(
|
||||
|
||||
Copy-Item -Path $TEMPLATE_ENV_FILE -Destination $TARGET_DIR -Force
|
||||
Copy-Item -Path $TEMPLATE_CONFIG_FILE -Destination $TARGET_DIR -Force
|
||||
Copy-Item -Path $README -Destination $TARGET_DIR -Force
|
||||
|
||||
Set-Location -Path $TARGET_DIR
|
||||
|
||||
# 重命名文件
|
||||
Move-Item -Path $TEMPLATE_ENV_FILE -Destination $ENV_FILE -Force
|
||||
Move-Item -Path $TEMPLATE_CONFIG_FILE -Destination $CONFIG_FILE -Force
|
||||
|
||||
@@ -31,9 +32,17 @@ foreach ($TRI in $TRIARR) {
|
||||
Move-Item -Path $BIN -Destination $DIR -Force
|
||||
Copy-Item -Path $ENV_FILE -Destination $DIR -Force
|
||||
Copy-Item -Path $CONFIG_FILE -Destination $DIR -Force
|
||||
Copy-Item -Path $README -Destination $DIR -Force
|
||||
|
||||
if ($DIR -eq "nlts-win-x64") {
|
||||
New-Item -Path $DIR -Name "start.bat" -ItemType File -Value "@echo off && lottery start && pause" -Force
|
||||
New-Item -Path $DIR -Name "check.bat" -ItemType File -Value "@echo off && lottery check && pause" -Force
|
||||
New-Item -Path $DIR -Name "clear.bat" -ItemType File -Value "@echo off && lottery clear && pause" -Force
|
||||
}
|
||||
|
||||
Compress-Archive -Path $DIR -DestinationPath "$($DIR)-$(Get-Date -Format "yyyyMMd")" -Force
|
||||
}
|
||||
|
||||
Remove-Item -Path $ENV_FILE
|
||||
Remove-Item -Path $CONFIG_FILE
|
||||
Remove-Item -Path $CONFIG_FILE
|
||||
Remove-Item -Path $README
|
||||
@@ -1,9 +0,0 @@
|
||||
chcp 65001
|
||||
|
||||
cd ..
|
||||
cd ..
|
||||
npm i
|
||||
npm run check
|
||||
|
||||
# 暂停
|
||||
pause
|
||||
@@ -1,9 +0,0 @@
|
||||
chcp 65001
|
||||
|
||||
cd ..
|
||||
cd ..
|
||||
npm i
|
||||
npm run clear
|
||||
|
||||
# 暂停
|
||||
pause
|
||||
@@ -1,9 +0,0 @@
|
||||
chcp 65001
|
||||
|
||||
cd ..
|
||||
cd ..
|
||||
npm i
|
||||
npm run start
|
||||
|
||||
# 暂停
|
||||
pause
|
||||
Reference in New Issue
Block a user