This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathB站监听番剧.js
78 lines (69 loc) · 2.61 KB
/
B站监听番剧.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// ==UserScript==
// @name B站番剧监听
// @author 简律纯
// @version 1.0.0
// @description bangumi
// 2023-03-27
// @license by-nc-sa 4.0
// @homepageURL https://github.com/HsiangNianian/sealdice
// ==/UserScript==
let ext = seal.ext.find('bangumi');
if (!ext) {
ext = seal.ext.new('bangumi', '简律纯', '1.0.0');
seal.ext.register(ext);
}
const bangumi = seal.ext.newCmdItemInfo();
bangumi.solve = (ctx, msg, cmdArgs) => {
const http = require('http');
const async = require('async');
var bangumiIDs = [44860, 5678, 9012]; // 要监听的番剧ID列表
function checkBangumiUpdate(bangumiID, callback) {
var options = {
hostname: 'api.bilibili.com',
path: '/pgc/web/season/stat?season_id=' + bangumiID,
method: 'GET'
};
var req = http.request(options, function (res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
var response = JSON.parse(chunk);
if (response.result.episode_status == 13) {
// 番剧有更新,回调通知
callback(null, bangumiID);
} else {
callback(null);
}
});
});
req.on('error', function (e) {
callback(e);
});
req.end();
}
// 异步并发监听番剧更新
async.whilst(
function () { return true; }, // 持续监听
function (callback) {
async.map(bangumiIDs, checkBangumiUpdate, function (err, results) {
if (err) {
console.error("监听出错:" + err);
seal.replyToSender(ctx, msg, `"监听出错:" + ${err}`);
return seal.ext.newCmdExecuteResult(true);
} else if (results.length > 0) {
console.log("番剧更新了:" + results.join(', '));
seal.replyToSender(ctx, msg, `"番剧更新了:" + ${results.join(', ')}`);
return seal.ext.newCmdExecuteResult(true);
} else {
console.log("监听ing...")
}
setTimeout(callback, 1000); // 每60秒检查一次是否有更新
});
},
function (err) {
console.error("监听出错:" + err);
seal.replyToSender(ctx, msg, `"监听出错:" + ${err}`);
return seal.ext.newCmdExecuteResult(true);
}
);
}
ext.cmdMap['bangumi'] = bangumi;