mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-06-04 21:01:17 +08:00
fix: 私信检测(#9)
This commit is contained in:
parent
a1b055b9de
commit
26ae391eee
@ -94,28 +94,25 @@ const BiliAPI = {
|
||||
* @property {string} session_ts
|
||||
* @property {string} content
|
||||
* @property {number} timestamp
|
||||
* @property {number} unread_count
|
||||
* @property {number} sender_uid
|
||||
* @property {number} talker_id
|
||||
* @property {number} msg_seqno
|
||||
*
|
||||
* @typedef SessionInfo
|
||||
* @property {number} has_more
|
||||
* @property {SessionData[]} data
|
||||
*
|
||||
* @param {number} session_type 1 已关注 2 未关注
|
||||
* @param {number} session_type 1 已关注 2 未关注 3 应援团
|
||||
* @param {string} [ts_16]
|
||||
* @returns {Promise<SessionInfo>}
|
||||
*/
|
||||
async getSessionInfo(session_type, ts_16 = '') {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.post({
|
||||
Ajax.get({
|
||||
url: 'https://api.vc.bilibili.com/session_svr/v1/session_svr/get_sessions',
|
||||
data: {
|
||||
queryStringsObj: {
|
||||
session_type,
|
||||
group_fold: 1,
|
||||
unfollow_fold: 1,
|
||||
sort_rule: 2,
|
||||
build: 0,
|
||||
mobi_app: 'web',
|
||||
end_ts: ts_16,
|
||||
},
|
||||
success: responseText => {
|
||||
@ -127,10 +124,13 @@ const BiliAPI = {
|
||||
const has_more = res.data.has_more;
|
||||
const data = sessions.map(session => {
|
||||
const { session_ts, last_msg = {}, unread_count, talker_id } = session;
|
||||
const { content = '', timestamp = 0, sender_uid = 0 } = last_msg;
|
||||
return { session_ts, content, timestamp, sender_uid, talker_id: unread_count ? talker_id : undefined }
|
||||
const { content = '', timestamp = 0, sender_uid = 0, msg_seqno } = last_msg;
|
||||
return { session_ts, content, timestamp, sender_uid, unread_count, talker_id, msg_seqno }
|
||||
})
|
||||
resolve({ has_more, data })
|
||||
} else if (res.code === 2) {
|
||||
log.error('获取私信', `API抽风...请再次尝试`);
|
||||
resolve({ has_more: 0, data: [] });
|
||||
} else {
|
||||
log.error('获取私信', `失败\n${responseText}`);
|
||||
resolve({ has_more: 0, data: [] });
|
||||
@ -164,17 +164,19 @@ const BiliAPI = {
|
||||
/**
|
||||
* 私信已读
|
||||
* @param {number} talker_id
|
||||
* @param {number} session_type
|
||||
* @param {number} msg_seqno
|
||||
*/
|
||||
updateSessionStatus(talker_id) {
|
||||
updateSessionStatus(talker_id, session_type, msg_seqno) {
|
||||
Ajax.post({
|
||||
url: 'https://api.vc.bilibili.com/session_svr/v1/session_svr/update_ack',
|
||||
retry: false,
|
||||
data: {
|
||||
talker_id,
|
||||
session_type: 1,
|
||||
ack_seqno: 1,
|
||||
mobi_app: "web",
|
||||
csrf_token: GlobalVar.get("csrf")
|
||||
session_type,
|
||||
ack_seqno: msg_seqno,
|
||||
csrf_token: GlobalVar.get("csrf"),
|
||||
csrf: GlobalVar.get("csrf")
|
||||
},
|
||||
success: responseText => {
|
||||
let res = strToJson(responseText);
|
||||
|
||||
@ -88,10 +88,10 @@ async function isMe() {
|
||||
let MySession = await BiliAPI.getSessionInfo(type)
|
||||
for (const index of Util.infiniteNumber()) {
|
||||
for (const Session of MySession.data) {
|
||||
const { content, sender_uid, session_ts, timestamp, talker_id } = Session;
|
||||
const { content, sender_uid, session_ts, timestamp, unread_count, talker_id, msg_seqno } = Session;
|
||||
session_t = session_ts;
|
||||
if (talker_id) {
|
||||
BiliAPI.updateSessionStatus(talker_id);
|
||||
if (unread_count) {
|
||||
BiliAPI.updateSessionStatus(talker_id, type, msg_seqno);
|
||||
await Util.delay(1000);
|
||||
if (config.notice_key_words.some(it => new RegExp(it).test(content))) {
|
||||
desp += `发生时间: ${new Date(timestamp * 1000).toLocaleString()} \n\n`
|
||||
@ -122,7 +122,7 @@ async function isMe() {
|
||||
}
|
||||
if (desp) {
|
||||
desp += '中奖了别忘给脚本(https://github.com/shanmiteko/LotteryAutoScript)点一个Star哦, 赞助一两块也不是不可以_(:з」∠)_\n\n'
|
||||
log.info(desp);
|
||||
log.info('可能中奖了', desp);
|
||||
await sendNotify('可能中奖了', desp);
|
||||
} else {
|
||||
log.info('中奖检测', "未中奖");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user