koishi-plugin-bilibili-notify 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/biliAPI.d.ts +29 -0
- package/lib/biliAPI.js +196 -0
- package/lib/comRegister.d.ts +17 -0
- package/lib/comRegister.js +402 -0
- package/lib/database.d.ts +23 -0
- package/lib/database.js +23 -0
- package/lib/generateImg.d.ts +25 -0
- package/lib/generateImg.js +698 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +80 -0
- package/lib/wbi.d.ts +22 -0
- package/lib/wbi.js +77 -0
- package/package.json +50 -0
- package/readme.md +5 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Context, Schema } from 'koishi';
|
|
2
|
+
export declare const name = "bilibili-notify";
|
|
3
|
+
export interface Config {
|
|
4
|
+
pushTime: number;
|
|
5
|
+
pushCardColorStart: string;
|
|
6
|
+
pushCardColorEnd: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const Config: Schema<Config>;
|
|
9
|
+
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.apply = exports.Config = exports.name = void 0;
|
|
30
|
+
const koishi_1 = require("koishi");
|
|
31
|
+
// import crypto
|
|
32
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
33
|
+
// import plugins
|
|
34
|
+
const comRegister_1 = __importDefault(require("./comRegister"));
|
|
35
|
+
const Database = __importStar(require("./database"));
|
|
36
|
+
// import Service
|
|
37
|
+
const wbi_1 = __importDefault(require("./wbi"));
|
|
38
|
+
const generateImg_1 = __importDefault(require("./generateImg"));
|
|
39
|
+
const biliAPI_1 = __importDefault(require("./biliAPI"));
|
|
40
|
+
exports.name = 'bilibili-notify';
|
|
41
|
+
exports.Config = koishi_1.Schema.object({
|
|
42
|
+
pushTime: koishi_1.Schema.number()
|
|
43
|
+
.min(0)
|
|
44
|
+
.max(24)
|
|
45
|
+
.step(1)
|
|
46
|
+
.role('slider')
|
|
47
|
+
.default(1)
|
|
48
|
+
.description('设定隔多长时间推送一次直播状态,单位为半小时'),
|
|
49
|
+
pushCardColorStart: koishi_1.Schema.string()
|
|
50
|
+
.pattern(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)
|
|
51
|
+
.default('#F38AB5')
|
|
52
|
+
.description('推送卡片的开始渐变背景色,请填入16进制颜色代码,参考网站:https://webkul.github.io/coolhue/'),
|
|
53
|
+
pushCardColorEnd: koishi_1.Schema.string()
|
|
54
|
+
.pattern(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)
|
|
55
|
+
.default('#F9CCDF')
|
|
56
|
+
.description('推送卡片的结束渐变背景色,请填入16进制颜色代码,参考网站:https://colorate.azurewebsites.net/')
|
|
57
|
+
});
|
|
58
|
+
function apply(ctx, config) {
|
|
59
|
+
// load database
|
|
60
|
+
ctx.plugin(Database);
|
|
61
|
+
// Regist server
|
|
62
|
+
ctx.plugin(wbi_1.default);
|
|
63
|
+
ctx.plugin(generateImg_1.default, { pushCardColorStart: config.pushCardColorStart, pushCardColorEnd: config.pushCardColorEnd });
|
|
64
|
+
ctx.plugin(biliAPI_1.default);
|
|
65
|
+
// load plugin
|
|
66
|
+
ctx.plugin(comRegister_1.default, { pushTime: config.pushTime });
|
|
67
|
+
// 当用户输入“恶魔兔,启动!”时,执行 help 指令
|
|
68
|
+
ctx.middleware((session, next) => {
|
|
69
|
+
if (session.content === '恶魔兔,启动!') {
|
|
70
|
+
return session.execute('help', next);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return next();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
exports.apply = apply;
|
|
78
|
+
function generateKey() {
|
|
79
|
+
return crypto_1.default.randomBytes(32).toString('hex');
|
|
80
|
+
}
|
package/lib/wbi.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Context, Service } from "koishi";
|
|
2
|
+
declare module 'koishi' {
|
|
3
|
+
interface Context {
|
|
4
|
+
wbi: Wbi;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
declare class Wbi extends Service {
|
|
8
|
+
key: string;
|
|
9
|
+
mixinKeyEncTab: number[];
|
|
10
|
+
constructor(ctx: Context);
|
|
11
|
+
protected start(): void | Promise<void>;
|
|
12
|
+
getMixinKey: (orig: any) => string;
|
|
13
|
+
encWbi(params: any, img_key: any, sub_key: any): string;
|
|
14
|
+
getWbiKeys(): Promise<{
|
|
15
|
+
img_key: any;
|
|
16
|
+
sub_key: any;
|
|
17
|
+
}>;
|
|
18
|
+
getWbi(params: any): Promise<string>;
|
|
19
|
+
encrypt(text: string, secretKey?: string): string;
|
|
20
|
+
decrypt(text: string, secretKey?: string): string;
|
|
21
|
+
}
|
|
22
|
+
export default Wbi;
|
package/lib/wbi.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const koishi_1 = require("koishi");
|
|
7
|
+
const md5_1 = __importDefault(require("md5"));
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
class Wbi extends koishi_1.Service {
|
|
10
|
+
key = '36e9cdb0934c27949003b3644b593e42';
|
|
11
|
+
mixinKeyEncTab = [
|
|
12
|
+
46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49,
|
|
13
|
+
33, 9, 42, 19, 29, 28, 14, 39, 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40,
|
|
14
|
+
61, 26, 17, 0, 1, 60, 51, 30, 4, 22, 25, 54, 21, 56, 59, 6, 63, 57, 62, 11,
|
|
15
|
+
36, 20, 34, 44, 52
|
|
16
|
+
];
|
|
17
|
+
constructor(ctx) {
|
|
18
|
+
super(ctx, 'wbi');
|
|
19
|
+
}
|
|
20
|
+
start() {
|
|
21
|
+
this.logger.info('wbi已被注册到Context中');
|
|
22
|
+
}
|
|
23
|
+
// 对 imgKey 和 subKey 进行字符顺序打乱编码
|
|
24
|
+
getMixinKey = (orig) => this.mixinKeyEncTab.map(n => orig[n]).join('').slice(0, 32);
|
|
25
|
+
// 为请求参数进行 wbi 签名
|
|
26
|
+
encWbi(params, img_key, sub_key) {
|
|
27
|
+
const mixin_key = this.getMixinKey(img_key + sub_key), curr_time = Math.round(Date.now() / 1000), chr_filter = /[!'()*]/g;
|
|
28
|
+
Object.assign(params, { wts: curr_time }); // 添加 wts 字段
|
|
29
|
+
// 按照 key 重排参数
|
|
30
|
+
const query = Object
|
|
31
|
+
.keys(params)
|
|
32
|
+
.sort()
|
|
33
|
+
.map(key => {
|
|
34
|
+
// 过滤 value 中的 "!'()*" 字符
|
|
35
|
+
const value = params[key].toString().replace(chr_filter, '');
|
|
36
|
+
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
37
|
+
})
|
|
38
|
+
.join('&');
|
|
39
|
+
const wbi_sign = (0, md5_1.default)(query + mixin_key); // 计算 w_rid
|
|
40
|
+
return query + '&w_rid=' + wbi_sign;
|
|
41
|
+
}
|
|
42
|
+
// 获取最新的 img_key 和 sub_key
|
|
43
|
+
async getWbiKeys() {
|
|
44
|
+
const res = await fetch('https://api.bilibili.com/x/web-interface/nav', {
|
|
45
|
+
headers: {
|
|
46
|
+
// SESSDATA 字段
|
|
47
|
+
Cookie: "SESSDATA=xxxxxx"
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
const { data: { wbi_img: { img_url, sub_url } } } = await res.json();
|
|
51
|
+
return {
|
|
52
|
+
img_key: img_url.slice(img_url.lastIndexOf('/') + 1, img_url.lastIndexOf('.')),
|
|
53
|
+
sub_key: sub_url.slice(sub_url.lastIndexOf('/') + 1, sub_url.lastIndexOf('.'))
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async getWbi(params) {
|
|
57
|
+
const web_keys = await this.getWbiKeys();
|
|
58
|
+
const img_key = web_keys.img_key, sub_key = web_keys.sub_key;
|
|
59
|
+
const query = this.encWbi(params, img_key, sub_key);
|
|
60
|
+
return query;
|
|
61
|
+
}
|
|
62
|
+
encrypt(text, secretKey) {
|
|
63
|
+
const iv = crypto_1.default.randomBytes(16);
|
|
64
|
+
const cipher = crypto_1.default.createCipheriv('aes-256-cbc', Buffer.from(this.key), iv);
|
|
65
|
+
const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
|
|
66
|
+
return iv.toString('hex') + ':' + encrypted.toString('hex');
|
|
67
|
+
}
|
|
68
|
+
decrypt(text, secretKey) {
|
|
69
|
+
let textParts = text.split(':');
|
|
70
|
+
let iv = Buffer.from(textParts.shift(), 'hex');
|
|
71
|
+
let encryptedText = Buffer.from(textParts.join(':'), 'hex');
|
|
72
|
+
let decipher = crypto_1.default.createDecipheriv('aes-256-cbc', Buffer.from(this.key), iv);
|
|
73
|
+
let decrypted = Buffer.concat([decipher.update(encryptedText), decipher.final()]);
|
|
74
|
+
return decrypted.toString();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.default = Wbi;
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-bilibili-notify",
|
|
3
|
+
"description": "Koishi bilibili notify plugin",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"contributors": [
|
|
6
|
+
"Akokko <admin@akokko.com>"
|
|
7
|
+
],
|
|
8
|
+
"main": "lib/index.js",
|
|
9
|
+
"typings": "lib/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"lib",
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"scripts": {},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"chatbot",
|
|
18
|
+
"koishi",
|
|
19
|
+
"plugin",
|
|
20
|
+
"bilibili"
|
|
21
|
+
],
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"koishi": "^4.16.4"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"axios-cookiejar-support": "^4.0.7",
|
|
27
|
+
"jsdom": "^23.2.0",
|
|
28
|
+
"md5": "^2.3.0",
|
|
29
|
+
"qrcode": "^1.5.3",
|
|
30
|
+
"tough-cookie": "^4.1.3"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"koishi-plugin-puppeteer": "^3.7.3"
|
|
34
|
+
},
|
|
35
|
+
"service": {
|
|
36
|
+
"required": [
|
|
37
|
+
"puppeteer",
|
|
38
|
+
"database"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
"koishi": {
|
|
42
|
+
"preview": true,
|
|
43
|
+
"description": {
|
|
44
|
+
"zh": "开发中的Bilibili直播通知,动态推送插件。目前还只是个雏形,不建议使用,发布做测试用"
|
|
45
|
+
},
|
|
46
|
+
"locales": [
|
|
47
|
+
"zh"
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
}
|