Compare commits

...
5 Commits
13 changed files with 173 additions and 207 deletions
-2
View File
@@ -1,7 +1,5 @@
node_modules/
dyids/
dist/
lib/dyid*.txt
dyid.zip
env.js
my_config.js
+15 -14
View File
@@ -5,7 +5,7 @@
- [获取COOKIE](#获取cookie)
- [本地运行](#本地运行)
- [可执行文件](#可执行文件)
- [搭建运行环境](#搭建运行环境)
- [以源码方式运行](#以源码方式运行)
- [Windows](#windows)
- [Linux](#linux)
- [Docker](#docker)
@@ -38,7 +38,7 @@ Chrome浏览器:
2. 进入Application找到Cookies栏中的SESSDATA将HttpOnly选项**取消**勾选
(此步骤是为了方便后续采用JS获取Cookies)
(此步骤是为了方便后续采用JS获取Cookies,获取完毕后应再次勾选)
![取消httponly](doc/pic/getCookies.png)
@@ -66,20 +66,19 @@ Chrome浏览器:
↓↓
### 本地运行
设置环境变量中的cookie和推送相关参数
具体操作详见[env.example.js](env.example.js)文件内注释
#### 可执行文件
在当前目录下[打开终端](https://cn.bing.com/search?q=%E5%A6%82%E4%BD%95%E5%9C%A8%E5%BD%93%E5%89%8D%E7%9B%AE%E5%BD%95%E6%89%93%E5%BC%80%E7%BB%88%E7%AB%AF)运行内部的可执行文件即可
1. [[下载](https://github.com/shanmiteko/LotteryAutoScript/releases)|[cnpmjs镜像下载](https://github.com.cnpmjs.org/shanmiteko/LotteryAutoScript/releases)|[Fastgit镜像下载](https://hub.fastgit.org/shanmiteko/LotteryAutoScript/releases)]压缩包并解压
```
env.js
lottery.exe
my_config.js
```
2. `env.js`中填入`COOKIE`和推送参数
3. `my_config.js`中自定义设置
4. 在当前目录下打开终端运行可执行文件`lottery`
[下载](https://github.com/shanmiteko/LotteryAutoScript/releases)
[cnpmjs镜像下载](https://github.com.cnpmjs.org/shanmiteko/LotteryAutoScript/releases)
[Fastgit镜像下载](https://hub.fastgit.org/shanmiteko/LotteryAutoScript/releases)
#### 搭建运行环境
#### 以源码方式运行
<details>
@@ -179,7 +178,7 @@ cd lottery
进入lottery上一级目录
```bash
docker image rm shanmite/lottery_auto_docker
docker image rm -f shanmite/lottery_auto_docker
rm -rf lottery/
```
@@ -234,4 +233,6 @@ rm -rf lottery/
----------------------------------------
## 设置说明
详见[env.example.js](./env.example.js)文件内部注释
详见[my_config.example.js](./my_config.example.js)文件内部注释
+5 -5
View File
@@ -8,7 +8,9 @@
* ## 账号相关参数
* - `COOKIE` 是必填项
* - `NUMBER` 表示是第几个账号
* - `PAT` 与 `GITHUB_REPOSITORY` 如果之前在Github Action上运行过脚本, 可填写已下载转发过的动态dyid, 之后可移除
* - `CLEAR` 是否启用清理功能
* - `ENABLE_MULTIPLE_ACCOUNT` 是否启用多账号
* - `MULTIPLE_ACCOUNT_PARM` 多账号参数(JSON格式)
*
* ## 多账号
* 1. 将 ENABLE_MULTIPLE_ACCOUNT 的值改为true
@@ -21,10 +23,8 @@ const account_parm = {
COOKIE: "",
NUMBER: 1,
CLEAR: true,
LOCALLAUNCH: true,
PAT: "",
GITHUB_REPOSITORY: "用户名/仓库名",
ENABLE_MULTIPLE_ACCOUNT: false
ENABLE_MULTIPLE_ACCOUNT: false,
MULTIPLE_ACCOUNT_PARM: ""
}
/**
+3 -2
View File
@@ -149,6 +149,7 @@ class Monitor extends Public {
if (lottery_info_type === 'uid' && is_imitator) {
isLottery = true;
isSendChat = chatmodel[1] === '1' || chatmodel[1] === '1';
} else if (hasOfficialLottery && model[0] === '1') {
({ ts } = await BiliAPI.getLotteryNotice(dyid));
if (ts < 0) { alllotteryinfo = null; break }
@@ -172,7 +173,7 @@ class Monitor extends Public {
const isFollowed = (new RegExp(uid)).test(self.attentionList);
if (only_followed && !isFollowed) continue;
/* 判断是否转发过 */
const isRelay = await MyStorage.searchDyid(dyid);
const isRelayed = await MyStorage.searchDyid(dyid);
/* 获取黑名单并去重合并 */
const { blacklist: remote_blacklist } = GlobalVar.get("remoteconfig");
const new_blacklist = remote_blacklist ?
@@ -181,7 +182,7 @@ class Monitor extends Public {
if ((new RegExp(dyid + '|' + uid)).test(new_blacklist)) continue;
onelotteryinfo.uid = [] /**初始化待关注列表 */
if (!isFollowed) onelotteryinfo.uid.push(uid);
if (!isRelay) {
if (!isRelayed) {
onelotteryinfo.dyid = dyid;
let RandomStr = Base.getRandomOne(config.relay);
let new_ctrl = [];
-25
View File
@@ -1,31 +1,6 @@
const Base = require("./Base");
const GihubAPI = require("./GithubAPI");
const MyStorage = {
/**
* 初始化dyid.txt
*/
init: () => {
return new Promise((resolve) => {
GihubAPI.listArtifacts().then(async artifact => {
const { id, size_in_bytes } = artifact;
if (size_in_bytes) {
GihubAPI.downloadArtifacts(id).then(async status => {
if (status) {
Base.tooltip.log('存储初始化成功');
} else {
Base.tooltip.log('存储初始化失败');
await Base.createFile('dyid.txt', '', 'a')
}
resolve()
})
} else {
await Base.createFile('dyid.txt', '', 'a')
resolve()
}
})
});
},
/**
* 搜索dyid
* @param {string} dyid
+49 -28
View File
@@ -86,13 +86,12 @@ class Public {
*/
modifyDynamicRes(res) {
const strToJson = Base.strToJson,
jsonRes = strToJson(res),
{ data } = jsonRes;
if (jsonRes.code !== 0) {
Base.tooltip.warn('获取动态数据出错,可能是访问太频繁');
{ data, code } = strToJson(res);
if (code !== 0) {
Base.tooltip.warn('获取动态数据出错,可能是访问太频繁 \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,
@@ -108,7 +107,7 @@ class Public {
/**
* 空动态无cards
*/
const Cards = data.cards;
const Cards = data.cards || [];
Cards.forEach(onecard => {
/**临时储存单个动态中的信息 */
let obj = {};
@@ -116,38 +115,59 @@ class Public {
, { info, card: user_profile_card } = desc.user_profile
, { official_verify } = user_profile_card
, cardToJson = strToJson(card);
obj.uid = info.uid; /* 转发者的UID */
obj.uname = info.uname;/* 转发者的name */
obj.official_verify = official_verify.type > -1 ? true : false; /* 是否官方号 */
obj.createtime = desc.timestamp /* 动态的ts10 */
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 /* 动态类型 */
obj.dynamic_id = desc.dynamic_id_str; /* 转发者的动态ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */
/* 转发者的UID */
obj.uid = info.uid;
/* 转发者的name */
obj.uname = info.uname;
/* 是否官方号 */
obj.official_verify = official_verify.type > -1 ? true : false;
/* 动态的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.item || {};
obj.description = item.content || item.description || ''; /* 转发者的描述 */
/* 定位@信息 */
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) {
obj.origin_uid = desc.origin.uid; /* 被转发者的UID */
obj.origin_rid_str = desc.origin.rid_str.length > 12 ? desc.origin.dynamic_id_str : desc.origin.rid_str; /* 被转发者的rid(用于发评论) */
obj.origin_dynamic_id = desc.orig_dy_id_str; /* 被转发者的动态的ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */
/* 被转发者的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, origin_user } = cardToJson;
try {
/* 是否官方号 */
obj.origin_official_verify = typeof origin_user === 'undefined' ?
false : origin_user.card.official_verify.type < 0 ?
false : true; /* 是否官方号 */
} catch (error) {
false : true;
} catch (_) {
obj.origin_official_verify = false;
}
/* 是否有官方抽奖 */
obj.origin_hasOfficialLottery = typeof origin_extension === 'undefined' ?
false : typeof origin_extension.lott === 'undefined' ?
false : true; /* 是否有官方抽奖 */
false : true;
const origin = cardToJson.origin || '{}';
const { user, item } = strToJson(origin);
obj.origin_uname = typeof user === 'undefined' ? '' : user.name || user.uname || ''; /* 被转发者的name */
obj.origin_description = typeof item === 'undefined' ? '' : item.content || item.description || ''; /* 被转发者的描述 */
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);
});
@@ -245,4 +265,5 @@ class Public {
}
}
module.exports = Public;
module.exports = Public;
-12
View File
@@ -1,13 +1,10 @@
const Base = require("./Base");
const BiliAPI = require("./BiliAPI");
const { trigger } = require("./GithubAPI");
const Public = require("./Public");
const GlobalVar = require('./GlobalVar');
const { followWhiteList } = require("./config");
const config = require("./config");
/** Github运行限制时间*/
const MAX_TIME = 6 * 60 * 60 * 1000 - 6 * 60 * 1000;
/**动态偏移量 */
let offset = '0';
@@ -35,15 +32,6 @@ async function getFollowList() {
*/
async function clear() {
const { clear_max_day, clear_remove_dynamic, clear_remove_attention, clear_remove_delay, clear_dynamic_type } = config;
if (!process.env.LOCALLAUNCH) {
setTimeout(() => {
Base.tooltip.log('运行时间超过Actions上限 - 6小时');
Base.tooltip.log('尝试再次触发clear 并中止此任务')
trigger('clear.yml').then(() => {
process.exit(0);
})
}, MAX_TIME);
}
let success = true;
const uid_list = await getFollowList();
if (!clear_remove_dynamic && clear_remove_attention) {
+2 -11
View File
@@ -1,14 +1,5 @@
const { config_file, tooltip } = require('./Base');
const my_config = (() => {
let _my_config = {}
try {
_my_config = require(config_file)
} catch (e) {
tooltip.log("[config]自定义设置异常 原因如下:\n" + e);
}
return _my_config;
})();
const { config_file } = require('./Base');
const my_config = require(config_file);
const config = {
...my_config["default_config"],
+3 -21
View File
@@ -1,6 +1,5 @@
const Base = require('./Base');
const BiliAPI = require('./BiliAPI');
const GihubAPI = require("./GithubAPI");
const eventBus = require('./eventBus');
const GlobalVar = require('./GlobalVar');
const Public = require('./Public');
@@ -8,12 +7,9 @@ const Monitor = require('./Monitor');
const { sendNotify } = require('./sendNotify');
const config = require('./config');
/** Github运行限制时间*/
const MAX_TIME = 6 * 60 * 60 * 1000 - 6 * 60 * 1000;
async function createRandomDynamic(num) {
Base.tooltip.log(`准备创建${num}条随机动态`);
if (config.create_dy) {
Base.tooltip.log(`准备创建${num}条随机动态`);
const Dynamic = await Public.prototype.checkAllDynamic(GlobalVar.get("myUID"), 1);
if ((Dynamic.allModifyDynamicResArray[0] || { type: 0 }).type === 1) {
for (let index = 0; index < num; index++) {
@@ -27,7 +23,7 @@ async function createRandomDynamic(num) {
}
/**
* 主函数
* 抽奖主函数
* @param {string} cookie
* @returns {Promise<void>}
*/
@@ -59,21 +55,7 @@ function start() {
eventBus.flush();
resolve();
})
if (process.env.LOCALLAUNCH) {
eventBus.emit('Turn_on_the_Monitor');
} else {
setTimeout(() => {
eventBus.emit('Turn_off_the_Monitor', '运行时间超过Actions上限 - 6小时')
}, MAX_TIME);
GihubAPI.hasLotteryRun().then(s => {
if (s) {
Base.tooltip.log("有冲突的工作流故终止此任务");
resolve()
} else {
eventBus.emit('Turn_on_the_Monitor');
}
})
}
eventBus.emit('Turn_on_the_Monitor');
});
}
+1 -9
View File
@@ -1,6 +1,5 @@
const Base = require("./Base");
const GlobalVar = require("./GlobalVar");
const MyStorage = require("./MyStorage");
const config = require("./config");
const key_map = new Map([['DedeUserID', 'myUID'], ['bili_jct', 'csrf']]);
@@ -24,14 +23,7 @@ async function setVariable(cookie, n) {
GlobalVar.set('remoteconfig', await Base.getRemoteConfig());
}
await Base.createDir('dyids');
if (process.env.PAT) {
if (process.env.CI) {
process.env.NUMBER = 1;
}
await MyStorage.init()
} else {
await Base.createFile(n < 2 ? 'dyid.txt' : `dyid${n}.txt`, '', 'a')
}
await Base.createFile(n < 2 ? 'dyid.txt' : `dyid${n}.txt`, '', 'a')
return
}
+64 -53
View File
@@ -1,5 +1,7 @@
const { env_file, tooltip, delay } = require("./lib/Base");
const { loop_wait } = require("./lib/config");
/**多账号存储 */
let multiple_account = [];
if (!process.env.CI) {
@@ -10,62 +12,64 @@ if (!process.env.CI) {
initEnv()
}
/**
* @returns {Promise<string>} 错误信息
*/
async function main() {
const { COOKIE, NUMBER, CLEAR, PAT, LOCALLAUNCH, ENABLE_MULTIPLE_ACCOUNT, MULTIPLE_ACCOUNT } = process.env;
if (LOCALLAUNCH || PAT) {
if (ENABLE_MULTIPLE_ACCOUNT) {
let muti_acco = multiple_account.length
? multiple_account
: JSON.parse(MULTIPLE_ACCOUNT);
const { COOKIE, NUMBER, CLEAR, ENABLE_MULTIPLE_ACCOUNT, MULTIPLE_ACCOUNT_PARM } = process.env;
if (ENABLE_MULTIPLE_ACCOUNT) {
let muti_acco = multiple_account.length
? multiple_account
: JSON.parse(MULTIPLE_ACCOUNT_PARM);
process.env.ENABLE_MULTIPLE_ACCOUNT = '';
process.env.ENABLE_MULTIPLE_ACCOUNT = '';
for (const acco of muti_acco) {
process.env.COOKIE = acco.COOKIE;
process.env.NUMBER = acco.NUMBER;
process.env.CLEAR = acco.CLEAR;
await main();
await delay(acco.WAIT);
}
} else {
if (COOKIE) {
const { setVariable } = require("./lib/setVariable");
await setVariable(COOKIE, Number(NUMBER));
const { start, isMe, checkCookie } = require("./lib/lottery-in-nodejs");
const { clear } = require("./lib/clear");
tooltip.log('[LotteryAutoScript] 账号' + NUMBER);
if (await checkCookie(NUMBER)) {
const mode = process.env.lottery_mode;
switch (mode) {
case 'start':
tooltip.log('开始参与抽奖');
await start();
break;
case 'check':
tooltip.log('检查是否中奖');
await isMe();
break;
case 'clear':
if (CLEAR) {
tooltip.log('开始清理动态');
await clear();
tooltip.log('清理动态完毕');
}
break;
default:
console.log(`Usage: lottery-in-bili [OPTIONS]`)
console.log(`错误OPTIONS: ${mode} 正确OPTIONS: start,check,clear`);
}
}
} else {
tooltip.log('请查看README文件, 在env.js指定位置填入cookie')
}
for (const acco of muti_acco) {
process.env.COOKIE = acco.COOKIE;
process.env.NUMBER = acco.NUMBER;
process.env.CLEAR = acco.CLEAR;
await main();
await delay(acco.WAIT);
}
} else {
tooltip.log('请查看README文件, 填入相应的PAT, 若是本地运行则设LOCALLAUNCH为true');
if (!COOKIE) {
return '请查看README文件, 在env.js指定位置填入cookie'
}
const { setVariable } = require("./lib/setVariable");
await setVariable(COOKIE, Number(NUMBER));
const { start, isMe, checkCookie } = require("./lib/lottery-in-nodejs");
const { clear } = require("./lib/clear");
tooltip.log('[LotteryAutoScript] 账号' + NUMBER);
if (await checkCookie(NUMBER)) {
const mode = process.env.lottery_mode;
const help_msg = "用法: lottery [OPTIONS]\n\nOPTIONS:\n\tstart 启动抽奖\n\tcheck 中奖检查\n\tclear 清理动态和关注\n\thelp 帮助信息\n";
switch (mode) {
case 'start':
tooltip.log('开始参与抽奖');
await start();
break;
case 'check':
tooltip.log('检查是否中奖');
await isMe();
break;
case 'clear':
if (CLEAR) {
tooltip.log('开始清理动态');
await clear();
tooltip.log('清理动态完毕');
}
break;
case 'help':
return help_msg
case undefined:
return "错误: 未提供以下参数\n\t[OPTIONS]\n\n" + help_msg
default:
return `错误: 提供了错误的[OPTIONS] -> ${mode}\n\n` + help_msg
}
}
}
}
@@ -84,7 +88,14 @@ async function main() {
console.log(metainfo);
/**OPTIONS */
process.env.lottery_mode = process.argv[2]
await main();
const err_msg = await main();
if (err_msg) {
console.log(err_msg);
} else {
tooltip.log(`休眠${loop_wait / 1000}秒后再次启动`)
await delay(loop_wait);
}
tooltip.log('5秒后自动退出');
await delay(5 * 1000);
process.exit(0)
process.exit(0);
})()
+13 -7
View File
@@ -8,7 +8,6 @@ module.exports = {
*/
UIDs: [
31252386,
35719643,
689277291
],
@@ -63,12 +62,18 @@ module.exports = {
*/
maxday: Infinity,
/**
* - 整体循环等待时间(指所有转发完毕后的休眠时间)
* - 单位毫秒
*/
loop_wait: 60 * 60 * 1000,
/**
* - 转发间隔时间
* - 单位毫秒
* - 上下浮动50%
*/
wait: 100000,
wait: 100 * 1000,
/**
* - 检索动态间隔
@@ -127,7 +132,7 @@ module.exports = {
/**
* 屏蔽词
*/
blockword: ["脚本抽奖", "恭喜", "结果", "抽奖号"],
blockword: ["脚本抽奖", "恭喜", "结果", "抽奖号", "钓鱼"],
/**
* 取关白名单
@@ -151,7 +156,8 @@ module.exports = {
],
/**
* 抽奖UP用户分组id(网页端点击分区后地址栏中的tagid)
* - 抽奖UP用户分组id(网页端点击分区后地址栏中的tagid)
* - 自动获取
*/
partition_id: 0,
@@ -161,7 +167,8 @@ module.exports = {
is_exception: false,
/**
* 取关分区
* - 取关分区
* - 默认为: 此处存放因抽奖临时关注的up
*/
clear_partition: '',
@@ -207,5 +214,4 @@ module.exports = {
config_1: {},
config_2: {},
config_3: {}
}
}
+18 -18
View File
@@ -6,33 +6,33 @@ $ENV_FILE = "env.js"
$TARGET_DIR = ".\dist"
$WIN_BIN = "lottery-in-bili-win.exe"
$LINUX_BIN = "lottery-in-bili-linux"
$MACOS_BIN = "lottery-in-bili-macos"
$WIN_X64 = "nlts-win-x64"
$LINUX_X64 = "nlts-linux-x64"
$MACOS_X64 = "nlts-macos-x64"
$MAP = @{ $WIN_X64 = $WIN_BIN; $LINUX_X64 = $LINUX_BIN; $MACOS_X64 = $MACOS_BIN}
$TRIARR = @(
@("lottery-in-bili-win.exe", "lottery.exe", "nlts-win-x64"),
@("lottery-in-bili-linux", "lottery", "nlts-linux-x64"),
@("lottery-in-bili-macos", "lottery", "nlts-macos-x64")
)
Copy-Item -Path $TEMPLATE_ENV_FILE -Destination $TARGET_DIR -Force
Copy-Item -Path $TEMPLATE_CONFIG_FILE -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
foreach($X64 in $MAP.Keys) {
$BIN = $MAP[$X64]
if (!(Test-Path $X64 -PathType Container)) {
New-Item -ItemType Directory -Force -Path $X64
}
Move-Item -Path $BIN -Destination $X64 -Force
Copy-Item -Path $ENV_FILE -Destination $X64 -Force
Copy-Item -Path $CONFIG_FILE -Destination $X64 -Force
Compress-Archive -Path $X64 -DestinationPath $X64 -Force
foreach ($TRI in $TRIARR) {
$PROTO_BIN,$BIN,$DIR = $TRI
New-Item -ItemType Directory -Force -Path $DIR
Move-Item -Path $PROTO_BIN -Destination $BIN -Force
Move-Item -Path $BIN -Destination $DIR -Force
Copy-Item -Path $ENV_FILE -Destination $DIR -Force
Copy-Item -Path $CONFIG_FILE -Destination $DIR -Force
Compress-Archive -Path $DIR -DestinationPath "$($DIR)-$(Get-Date -Format "yyyyMMd")" -Force
}
Remove-Item -Path $ENV_FILE