feat: 自动参与预约抽奖(#155)

fixed #155
This commit is contained in:
shanmite 2022-06-24 10:27:11 +08:00
parent 3bc7dafe3e
commit 329c5e506f
6 changed files with 77 additions and 27 deletions

View File

@ -28,6 +28,7 @@
- 监控话题页面
- 监控专栏合集
- 自动点赞、评论、乱序转发、@好友、带话题、可选随机动态
- 直播预约抽奖
- 检测是否中奖
- 已读@
- 已读私信
@ -266,31 +267,31 @@ $ tree
以下是支持的推送方式
| Name | 归属 | 说明 |
| :---------------: | :--------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SCKEY` | 微信server酱推送(于2021/4月下线) | server酱的微信通知[官方文档](http://sc.ftqq.com/3.version) |
| `SENDKEY` | 微信server酱(Turbo版)推送 | [获取SENDKEY](https://sct.ftqq.com/sendkey) [选择消息通道](https://sct.ftqq.com/forward) |
| Name | 归属 | 说明 |
| :---------------: | :--------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SCKEY` | 微信server酱推送(于2021/4月下线) | server酱的微信通知[官方文档](http://sc.ftqq.com/3.version) |
| `SENDKEY` | 微信server酱(Turbo版)推送 | [获取SENDKEY](https://sct.ftqq.com/sendkey) [选择消息通道](https://sct.ftqq.com/forward) |
| `BARK_PUSH` | [BARK推送](https://apps.apple.com/us/app/bark-customed-notifications/id1403753865) | IOS用户下载BARK这个APP,填写内容是app提供的`设备码`,例如:<https://api.day.app/123> ,那么此处的设备码就是`123`,再不懂看 [这个图](https://gitlab.com/shanmiteko/LotteryAutoScript/-/raw/main/doc/pic/bark.jpg)(注:支持自建填完整链接即可) |
| `BARK_SOUND` | [BARK推送](https://apps.apple.com/us/app/bark-customed-notifications/id1403753865) | bark推送声音设置例如`choo`,具体值请在`bark`-`推送铃声`-`查看所有铃声` |
| `TG_BOT_TOKEN` | telegram推送 | tg推送(需设备可连接外网),`TG_BOT_TOKEN`和`TG_USER_ID`两者必需,填写自己申请[@BotFather](https://t.me/BotFather)的Token,如`10xxx4:AAFcqxxxxgER5uw` , [具体教程](doc/TG_PUSH.md) |
| `TG_USER_ID` | telegram推送 | tg推送(需设备可连接外网),`TG_BOT_TOKEN`和`TG_USER_ID`两者必需,填写[@getuseridbot](https://t.me/getuseridbot)中获取到的纯数字ID, [具体教程](doc/TG_PUSH.md) |
| `TG_PROXY_HOST` | Telegram 代理的 IP | 代理类型为 http。例子http代理 <http://127.0.0.1:1080> 则填写 127.0.0.1 |
| `TG_PROXY_PORT` | Telegram 代理的端口 | 例子http代理 <http://127.0.0.1:1080> 则填写 1080 |
| `DD_BOT_TOKEN` | 钉钉推送 | 钉钉推送(`DD_BOT_TOKEN`和`DD_BOT_SECRET`两者必需)[官方文档](https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq) ,只需`https://oapi.dingtalk.com/robot/send?access_token=XXX` 等于`=`符号后面的XXX即可 |
| `BARK_SOUND` | [BARK推送](https://apps.apple.com/us/app/bark-customed-notifications/id1403753865) | bark推送声音设置例如`choo`,具体值请在`bark`-`推送铃声`-`查看所有铃声` |
| `TG_BOT_TOKEN` | telegram推送 | tg推送(需设备可连接外网),`TG_BOT_TOKEN`和`TG_USER_ID`两者必需,填写自己申请[@BotFather](https://t.me/BotFather)的Token,如`10xxx4:AAFcqxxxxgER5uw` , [具体教程](doc/TG_PUSH.md) |
| `TG_USER_ID` | telegram推送 | tg推送(需设备可连接外网),`TG_BOT_TOKEN`和`TG_USER_ID`两者必需,填写[@getuseridbot](https://t.me/getuseridbot)中获取到的纯数字ID, [具体教程](doc/TG_PUSH.md) |
| `TG_PROXY_HOST` | Telegram 代理的 IP | 代理类型为 http。例子http代理 <http://127.0.0.1:1080> 则填写 127.0.0.1 |
| `TG_PROXY_PORT` | Telegram 代理的端口 | 例子http代理 <http://127.0.0.1:1080> 则填写 1080 |
| `DD_BOT_TOKEN` | 钉钉推送 | 钉钉推送(`DD_BOT_TOKEN`和`DD_BOT_SECRET`两者必需)[官方文档](https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq) ,只需`https://oapi.dingtalk.com/robot/send?access_token=XXX` 等于`=`符号后面的XXX即可 |
| `DD_BOT_SECRET` | 钉钉推送 | (`DD_BOT_TOKEN`和`DD_BOT_SECRET`两者必需) ,密钥机器人安全设置页面加签一栏下面显示的SEC开头的`SECXXXXXXXXXX`等字符 , 注:钉钉机器人安全设置只需勾选`加签`即可,其他选项不要勾选,再不懂看 [这个图](https://gitlab.com/shanmiteko/LotteryAutoScript/-/raw/main/doc/pic/DD_bot.png) |
| `IGOT_PUSH_KEY` | iGot推送 | iGot聚合推送支持多方式推送确保消息可达。 [参考文档](https://wahao.github.io/Bark-MP-helper ) |
| `QQ_SKEY` | 酷推(Cool Push)推送 | 推送所需的Skey,登录后获取Skey [参考文档](https://cp.xuthus.cc/) |
| `QQ_MODE` | 酷推(Cool Push)推送 | 推送方式(send或group或者wx默认send) [参考文档](https://cp.xuthus.cc/) |
| `QYWX_KEY` | 企业微信推送 | 密钥,企业微信推送 webhook 后面的 key [详见官方说明文档](https://work.weixin.qq.com/api/doc/90000/90136/91770) |
| `PUSH_PLUS_TOKEN` | pushplus推送 | 微信扫码登录后一对一推送或一对多推送下面的token(您的Token) [官方网站](http://pushplus.hxtrip.com/) |
| `PUSH_PLUS_USER` | pushplus推送 | 一对多推送的“群组编码”(一对多推送下面->您的群组(如无则新建)->群组编码)注:(1、需订阅者扫描二维码 2、如果您是创建群组所属人也需点击“查看二维码”扫描绑定否则不能接受群组消息推送),只填`PUSH_PLUS_TOKEN`默认为一对一推送 |
| `QMSG_KEY` | [Qmsg酱](https://qmsg.zendee.cn)私聊推送 | [Qmsg注册](https://qmsg.zendee.cn/login.html) |
| `QMSG_QQ` | 私聊消息推送接口指定需要接收消息的QQ | 指定的QQ号必须在你的[管理台](https://qmsg.zendee.cn/me.html)已添加 |
| `SMTP_HOST` | 电子邮件 | smtp服务器的主机名 如: `smtp.qq.com` |
| `SMTP_PORT` | 电子邮件 | smtp服务器的端口 如: `465` |
| `SMTP_USER` | 电子邮件 | 发送方的电子邮件 如: `xxxxxxxxx@qq.com` |
| `SMTP_PASS` | 电子邮件 | smtp服务对应的授权码 |
| `SMTP_TO_USER` | 电子邮件 | 接收方电子邮件 |
| `IGOT_PUSH_KEY` | iGot推送 | iGot聚合推送支持多方式推送确保消息可达。 [参考文档](https://wahao.github.io/Bark-MP-helper ) |
| `QQ_SKEY` | 酷推(Cool Push)推送 | 推送所需的Skey,登录后获取Skey [参考文档](https://cp.xuthus.cc/) |
| `QQ_MODE` | 酷推(Cool Push)推送 | 推送方式(send或group或者wx默认send) [参考文档](https://cp.xuthus.cc/) |
| `QYWX_KEY` | 企业微信推送 | 密钥,企业微信推送 webhook 后面的 key [详见官方说明文档](https://work.weixin.qq.com/api/doc/90000/90136/91770) |
| `PUSH_PLUS_TOKEN` | pushplus推送 | 微信扫码登录后一对一推送或一对多推送下面的token(您的Token) [官方网站](http://pushplus.hxtrip.com/) |
| `PUSH_PLUS_USER` | pushplus推送 | 一对多推送的“群组编码”(一对多推送下面->您的群组(如无则新建)->群组编码)注:(1、需订阅者扫描二维码 2、如果您是创建群组所属人也需点击“查看二维码”扫描绑定否则不能接受群组消息推送),只填`PUSH_PLUS_TOKEN`默认为一对一推送 |
| `QMSG_KEY` | [Qmsg酱](https://qmsg.zendee.cn)私聊推送 | [Qmsg注册](https://qmsg.zendee.cn/login.html) |
| `QMSG_QQ` | 私聊消息推送接口指定需要接收消息的QQ | 指定的QQ号必须在你的[管理台](https://qmsg.zendee.cn/me.html)已添加 |
| `SMTP_HOST` | 电子邮件 | smtp服务器的主机名 如: `smtp.qq.com` |
| `SMTP_PORT` | 电子邮件 | smtp服务器的端口 如: `465` |
| `SMTP_USER` | 电子邮件 | 发送方的电子邮件 如: `xxxxxxxxx@qq.com` |
| `SMTP_PASS` | 电子邮件 | smtp服务对应的授权码 |
| `SMTP_TO_USER` | 电子邮件 | 接收方电子邮件 |
----------------------------------------

View File

@ -303,7 +303,7 @@ class Monitor extends Searcher {
await try_for_each(protoLotteryInfo, async function (lottery_info) {
const {
lottery_info_type, is_liked,
uids, uname, dyid, create_time,
uids, uname, dyid, reserve_id, create_time,
ctrl, rid, des, type,
hasOfficialLottery
} = lottery_info;
@ -405,6 +405,10 @@ class Monitor extends Searcher {
return false
}
if (reserve_id) {
await bili.reserve_lottery(reserve_id)
}
if (isLottery) {
const { uname_map = {} } = global_var.get("remoteconfig")
let onelotteryinfo = {};

View File

@ -18,6 +18,7 @@ const { log } = utils
* @property {string} dynamic_id
* @property {number} type
* @property {string} description
* @property {number} reserve_id
* @property {boolean} hasOfficialLottery
* @property {Array<Object.<string,string|number>>} ctrl
* @property {number} origin_create_time 10
@ -27,6 +28,7 @@ const { log } = utils
* @property {string} origin_dynamic_id
* @property {number} orig_type
* @property {string} origin_description
* @property {number} origin_reserve_id
* @property {boolean} origin_hasOfficialLottery
*
* 整理后的抽奖信息
@ -38,6 +40,7 @@ const { log } = utils
* @property {string} uname
* @property {Array<{}>} ctrl
* @property {string} dyid
* @property {number} reserve_id
* @property {string} rid
* @property {string} des
* @property {number} type
@ -53,6 +56,7 @@ function parseDynamicCard(dynamic_detail_card) {
const { desc, card, extension, extend_json } = dynamic_detail_card
, { is_liked = 1, user_profile = {} } = desc
, { info = {} } = user_profile
, extendjsonToJson = strToJson(extend_json)
, cardToJson = strToJson(card)
, { item } = cardToJson;
/* 转发者的UID */
@ -72,7 +76,12 @@ function parseDynamicCard(dynamic_detail_card) {
/* 转发者的动态ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */
obj.dynamic_id = desc.dynamic_id_str;
/* 定位@信息 */
obj.ctrl = (extend_json && strToJson(extend_json).ctrl) || [];
obj.ctrl = (extendjsonToJson.ctrl) || [];
/* 预约抽奖信息 */
if (extendjsonToJson.reserve) {
let { reserve_id, reserve_lottery } = extendjsonToJson.reserve;
obj.reserve_id = reserve_lottery === 1 ? reserve_id : 0;
}
/* 是否有官方抽奖 */
obj.hasOfficialLottery = extension && extension.lott && true;
/* 转发者的描述 纯文字内容 图片动态描述 后两个分别是视频动态的描述和视频本身的描述*/
@ -81,8 +90,9 @@ function parseDynamicCard(dynamic_detail_card) {
|| (cardToJson.dynamic || '' + cardToJson.desc || '')
|| '';
if (obj.type === 1) {
const { origin_extension, origin } = cardToJson
const { origin_extension, origin, origin_extend_json } = cardToJson
, originToJson = strToJson(origin)
, originextendjsonToJson = strToJson(origin_extend_json)
, { user, item } = originToJson;
/* 源动态的ts10 */
obj.origin_create_time = desc.origin.timestamp;
@ -92,6 +102,11 @@ function parseDynamicCard(dynamic_detail_card) {
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;
/* 预约抽奖信息 */
if (originextendjsonToJson.reserve) {
let { reserve_id, reserve_lottery } = originextendjsonToJson.reserve;
obj.origin_reserve_id = reserve_lottery === 1 ? reserve_id : 0;
}
/* 是否有官方抽奖 */
obj.origin_hasOfficialLottery = origin_extension && origin_extension.lott;
/* 被转发者的name */
@ -263,6 +278,7 @@ class Searcher {
uname: cur.origin_uname,
ctrl: [],
dyid: cur.origin_dynamic_id,
reserve_id: cur.origin_reserve_id,
rid: cur.origin_rid_str,
des: cur.origin_description,
type: cur.orig_type,
@ -321,6 +337,7 @@ class Searcher {
uname: o.uname,
ctrl: o.ctrl,
dyid: o.dynamic_id,
reserve_id: o.reserve_id,
rid: o.rid_str,
des: o.description,
type: o.type,
@ -409,6 +426,7 @@ class Searcher {
uname: o.uname,
ctrl: o.ctrl,
dyid: o.dynamic_id,
reserve_id: o.reserve_id,
rid: o.rid_str,
des: o.description,
type: o.type,

View File

@ -1,5 +1,6 @@
module.exports = Object.freeze({
DYNAMIC_LIKE_THUMB: 'https://api.vc.bilibili.com/dynamic_like/v1/dynamic_like/thumb',
DYNAMIC_MIX_RESERVE_ATTACH_CARD_BUTTON: 'https://api.vc.bilibili.com/dynamic_mix/v1/dynamic_mix/reserve_attach_card_button',
DYNAMIC_REPOST_REPOST: 'https://api.vc.bilibili.com/dynamic_repost/v1/dynamic_repost/repost',
DYNAMIC_REPOST_SHARE: 'https://api.vc.bilibili.com/dynamic_repost/v1/dynamic_repost/share',
DYNAMIC_SVR_CREATE_DRAW: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/create_draw',
@ -7,9 +8,9 @@ module.exports = Object.freeze({
DYNAMIC_SVR_GET_DYNAMIC_DETAIL: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/get_dynamic_detail',
DYNAMIC_SVR_RM_DYNAMIC: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/rm_dynamic',
DYNAMIC_SVR_SPACE_HISTORY: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history',
FETCH_SESSION_MSGS: 'https://api.vc.bilibili.com/svr_sync/v1/svr_sync/fetch_session_msgs',
FEED_GET_ATTENTION_LIST: 'https://api.vc.bilibili.com/feed/v1/feed/get_attention_list',
FEED_SETUSERFOLLOW: 'https://api.vc.bilibili.com/feed/v1/feed/SetUserFollow',
FETCH_SESSION_MSGS: 'https://api.vc.bilibili.com/svr_sync/v1/svr_sync/fetch_session_msgs',
LOTTERY_SVR_LOTTERY_NOTICE: 'https://api.vc.bilibili.com/lottery_svr/v1/lottery_svr/lottery_notice',
MSGFEED_AT: 'https://api.bilibili.com/x/msgfeed/at',
MSGFEED_REPLAY: 'https://api.bilibili.com/x/msgfeed/reply',

View File

@ -817,6 +817,31 @@ const bili_client = {
return 1;
}
},
/**
* 预约抽奖
* @param {number} reserve_id
* @returns
*/
async reserve_lottery(reserve_id) {
const
responseText = await post({
url: API.DYNAMIC_MIX_RESERVE_ATTACH_CARD_BUTTON,
contents: {
cur_btn_status: "1",
reserve_id,
csrf: GlobalVar.get("csrf")
}
}),
res = strToJson(responseText);
switch (res.code) {
case 0:
log.info('预约抽奖', '预约成功');
return 0;
default:
log.error('预约抽奖', `未知错误\n${responseText}`);
return 1;
}
},
/**
* @typedef Picture
* @property {string} img_src

View File

@ -38,6 +38,7 @@ module.exports = Object.freeze({
* @property {string} uname
* @property {Array<{}>} ctrl
* @property {string} dyid
* @property {number} reserve_id
* @property {string} rid
* @property {string} des
* @property {number} type